-
Notifications
You must be signed in to change notification settings - Fork 332
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
Optionally generate an init func for an informer #2989
Optionally generate an init func for an informer #2989
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2989 +/- ##
=======================================
Coverage 78.68% 78.68%
=======================================
Files 188 188
Lines 11051 11051
=======================================
Hits 8695 8695
Misses 2092 2092
Partials 264 264 ☔ View full report in Codecov by Sentry. |
codegen/cmd/injection-gen/main.go
Outdated
@@ -36,13 +37,17 @@ func main() { | |||
genericArgs.AddFlags(pflag.CommandLine) | |||
customArgs.AddFlags(pflag.CommandLine) | |||
flag.Set("logtostderr", "true") | |||
skipInitFuncForInformer := flag.Bool("skipInitFuncForInformer", false, "Skip the init function for informer") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Args can be added here: https://github.com/knative/pkg/blob/main/codegen/cmd/injection-gen/args/args.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I was not sure if I should touch those.
codegen/cmd/injection-gen/main.go
Outdated
if *skipInitFuncForInformer { | ||
os.Setenv(generators.SkipInitFuncForInformerEnv, "true") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed if we setup args properly
if os.Getenv(SkipInitFuncForInformerEnv) == "true" { | ||
sw.Do(strings.ReplaceAll(injectionInformer, "withInformer", "WithInformer"), m) | ||
} else { | ||
sw.Do(initFunc+injectionInformer, m) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we pass the flag value to the context map m
and just do the if
logic in the template?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I didn't see it was using go templates behind the scenes, now it makes sense.
@dprotaso gentle ping |
@@ -49,6 +49,8 @@ func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) { | |||
|
|||
fs.BoolVar(&ca.ListerHasPointerElem, "lister-has-pointer-elem", false, "") | |||
fs.MarkDeprecated("lister-has-pointer-elem", "this flag has no effect") | |||
|
|||
fs.Bool("skipInitFuncForInformer", false, "Skip the init function for informer") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should wire this to the CustomArgs
structs like we do for the other flags
Also can we follow the flag naming convention we are using which is snake-case
I'd probably call this disable-informer-init
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dprotaso ok done
@dprotaso pls take another look, thanks for the review! |
@@ -78,6 +80,8 @@ func (g *injectionGenerator) GenerateType(c *generator.Context, t *types.Type, w | |||
|
|||
klog.V(5).Info("processing type ", t) | |||
|
|||
disableInformerInit, _ := pflag.CommandLine.GetBool("disable-informer-init") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should be pulling this from the custom args struct and the funneling it into this generator
customArgs, ok := arguments.CustomArgs.(*informergenargs.CustomArgs) |
packageList = append(packageList, versionInformerPackages(versionPackagePath, groupPackageName, gv, groupGoNames[groupPackageName], boilerplate, typesWithInformers, customArgs)...) |
otherwise it's like we're reaching for globals.
The logic in packages is a bit verbose :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dprotaso done.
@dprotaso ready, could you stamp it? |
/lgtm thanks @skonto |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dprotaso, skonto 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:
Approvers can indicate their approval by writing |
Changes
and then on demand register the right informer:
types eg.
+skipInitInformer
and thus pass this directly to the InformerGenerator./assign @dprotaso
/kind enhancement
Release Note
Docs