Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/verify client generator in scripts #19139

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/libs/go2idl/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ import (
// Default returns a defaulted GeneratorArgs. You may change the defaults
// before calling AddFlags.
func Default() *GeneratorArgs {
return &GeneratorArgs{
generatorArgs := &GeneratorArgs{
OutputBase: DefaultSourceTree(),
GoHeaderFilePath: filepath.Join(DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt"),
}
generatorArgs.AddFlags(pflag.CommandLine)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if a user doesn't use the Default() to generate args? So IMO calling the AddFlags in Execute is better. [edit] Is there any compelling reason to move AddFlags to here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, I think the argument can go either way. Users are supposed to call Default() to generate the args, and if they don't, probably they don't want to parse the flags either. So LGTM :)

return generatorArgs
}

// GeneratorArgs has arguments common to most generators.
Expand Down Expand Up @@ -105,7 +107,6 @@ func DefaultSourceTree() string {
// If you don't need any non-default behavior, use as:
// args.Default().Execute(...)
func (g *GeneratorArgs) Execute(nameSystems namer.NameSystems, defaultSystem string, pkgs func(*generator.Context, *GeneratorArgs) generator.Packages) error {
g.AddFlags(pflag.CommandLine)
pflag.Parse()

b, err := g.NewBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,11 @@ func (c *testTypes) Delete(name string, options *api.DeleteOptions) error {

// DeleteCollection deletes a collection of objects.
func (c *testTypes) DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error {
if options == nil {
return c.client.Delete().
NamespaceIfScoped(c.ns, len(c.ns) > 0).
Resource("testTypes").
VersionedParams(&listOptions, api.Scheme).
Do().
Error()
}
body, err := api.Scheme.EncodeToVersion(options, c.client.APIVersion().String())
if err != nil {
return err
}
return c.client.Delete().
NamespaceIfScoped(c.ns, len(c.ns) > 0).
Resource("testTypes").
VersionedParams(&listOptions, api.Scheme).
Body(body).
Body(options).
Do().
Error()
}
Expand Down
5 changes: 4 additions & 1 deletion hack/after-build/run-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
kube::golang::setup_env

setgen=$(kube::util::find-binary "set-gen")
clientgen=$(kube::util::find-binary "client-gen")

# Please do not add any logic to this shell script. Add logic to the go code
# that generates the set-gen program.
#
# This can be called with one flag, --verify-only, so it works for both the
# update- and verify- scripts.
${clientgen} "$@"
${clientgen} -t "$@"
${setgen} "$@"

# You may add additional calls of code generators like set-gen below.
# You may add additional calls of code generators like set-gen above.
1 change: 1 addition & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ source "${KUBE_ROOT}/hack/lib/init.sh"

kube::golang::setup_env

"${KUBE_ROOT}/hack/build-go.sh" cmd/libs/go2idl/client-gen
"${KUBE_ROOT}/hack/build-go.sh" cmd/libs/go2idl/set-gen

"${KUBE_ROOT}/hack/after-build/run-codegen.sh" "$@"
1 change: 1 addition & 0 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ source "${KUBE_ROOT}/hack/lib/init.sh"

kube::golang::setup_env

"${KUBE_ROOT}/hack/build-go.sh" cmd/libs/go2idl/client-gen
"${KUBE_ROOT}/hack/build-go.sh" cmd/libs/go2idl/set-gen

"${KUBE_ROOT}/hack/after-build/run-codegen.sh" --verify-only