kubernetes-client / gen

Common generator scripts for all client libraries
Apache License 2.0
150 stars 147 forks source link

Fixed error when PACKAGE_NAME is not 'client'. #242

Closed tyama711 closed 1 year ago

tyama711 commented 1 year ago

When executing python-crd-cmd.sh with the -n option specifying the package name, an error occurs as shown below:

$ ./python-crd-cmd.sh -o <output_dir> -n <api_group> -p <package_name>
...
--- Patching generated code...
find: ‘<output_dir>/client/’: No such file or directory

This is because the client directory is not created when the -n option is explicitly specified (client is the default value of the -n option). I fixed the error by checking package name before the find command.

linux-foundation-easycla[bot] commented 1 year ago

CLA Signed

The committers listed above are authorized under a signed CLA.

k8s-ci-robot commented 1 year ago

Welcome @tyama711!

It looks like this is your first PR to kubernetes-client/gen 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/gen has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. :smiley:

brendandburns commented 1 year ago

Thanks for the PR.

Don't we want to run this same sed command on the custom directory also?

tyama711 commented 1 year ago

@brendandburns Thank you for your comment.

I thought that the sed command was only necessary when python.sh is used for generating source code in the kubernetes-client/python repository, and that it would not be necessary for users who generate code independent of the kubernetes-client/python repository, such as when python.sh is executed from python-crd-cmd.sh. Therefore, I modified the script to only run sed when PACKAGE_NAME is "client".

Should the sed command always be executed? If so, I will make the necessary changes.

brendandburns commented 1 year ago

I was thinking that this was rewriting imports for things like the V1Metadata which is in the Kubernetes client package, but perhaps I was wrong?

Does the generated client work for you without the sed ... commands?

brendandburns commented 1 year ago

cc @roycaihw to see what he thinks since he is more of a Python client expert than I am.

tyama711 commented 1 year ago

This sed command is executed to replace, for example,

from client.configuration import Configuration

with

from kubernetes.client.configuration import Configuration

as seen in https://github.com/kubernetes-client/python/blob/master/kubernetes/client/api_client.py#L27.

In my use case where I want to generate client code for my own CRD, this process is not necessary and the script works fine without it.

brendandburns commented 1 year ago

/lgtm /approve

k8s-ci-robot commented 1 year ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, tyama711

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/kubernetes-client/gen/blob/master/OWNERS)~~ [brendandburns] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
brendandburns commented 1 year ago

Good enough for me :)