Developing and debugging kpt functions

119 views
Skip to first unread message

Jeremy Lewi

unread,
Jun 2, 2020, 12:27:25 PM6/2/20
to kpt-users
Hi

I'm trying to develop a kpt function to transform images. I'd like to identify all images with a given prefix and change that prefix to a new prefix.

I initially created a function based off the kustomize fn examples. This worked but it uses annotations on every object to specify the new refix and old prefix.

I'm now trying to change it to match the kpt fn examples because I'd like to configure it declaratively using a clientside custom resource to configure the function.

My new code is here

I tried creating a config and then running my function

I ran kpt fn run ./ and it ran with no errors but had no effect. So now I need to debug and figure out what's going wrong.

Is there a way I can invoke main.go directly so I can invoke it in my debugger?

It looks like the main is just reading from stdin and writing to stdout so I tried just using cat to stream the input

cat ./kubeflow-apps/apps_v1_deployment_jupyter-web-app-deployment.yaml image-prefix-function.yaml | ~/git_kubeflow-kfctl/kustomize-fns/kustomize-fns 

Is that the right approach? 

Thanks
J

Jeremy Lewi

unread,
Jun 2, 2020, 3:42:31 PM6/2/20
to kpt-users
I think I figured this out.

It looks like the main function for the kpt functions expects a ResourceLists file that lists the resources and the function to apply. I was able to
produce this using kpt

kpt fn source ${DIR} --function-config=${FN_CFG}


I was then able to pipe that directly to my binary to invoke it. I also added a debug subcommand to my main.go because that plays better with Goland IDE.

J

Frank Farzan

unread,
Jun 5, 2020, 7:11:39 PM6/5/20
to kpt-users
Jeremy, seems like to you figured this out. Let me know if we can improve the docs here.

Prachi Pendse

unread,
Jun 5, 2020, 7:22:13 PM6/5/20
to Frank Farzan, kpt-users
I followed up with Jeremy offline, my takeaways:

- kpt guides should be accessible from command reference docs, e.g. have a "What's next?" section at the bottom of each page linking to appropriate docs
- we need to streamline kpt function docs to work with existing kustomize function docs

Jeremy, please add anything I may have missed.

Thanks,
Prachi


--
You received this message because you are subscribed to the Google Groups "kpt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kpt-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kpt-users/e48e014c-0bea-460f-81dd-73546c31eb58o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages