-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add support for creating core type controllers #132
Conversation
b6db00e
to
17a7a2a
Compare
23c8f1d
to
2b25ee4
Compare
Add parseDomain from file directly and remove a lot of |
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.
Took a quick look, have couple of comments.
glog.Fatal(err) | ||
} | ||
|
||
comments := Comments(lines) |
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.
May be, we can move this logic in the scanner
loop itself itself. Ignore the line if its not a comment, else invoke Comments(line) and check for domain ?
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.
I updated this function to ignore the lines not a comment.
Comments(line)
is left after all comments are get since Comments
is the same type of []string
.
@@ -42,11 +42,17 @@ import ( | |||
"github.com/kubernetes-sigs/kubebuilder/pkg/controller" | |||
"github.com/kubernetes-sigs/kubebuilder/pkg/controller/types" | |||
"k8s.io/client-go/tools/record" | |||
|
|||
{{if .CoreType}} |
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.
What does CoreType means here ?
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.
Should be ControllerOnly
, will fix it.
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.
Done
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.
I changed it back to CoreType
in create controller
command. It makes sense now compared with ControllerOnly
.
|
||
func AddInit(cmd *cobra.Command) { | ||
cmd.AddCommand(repoCmd) | ||
repoCmd.Flags().StringVar(&domain, "domain", "", "domain for the API groups") | ||
repoCmd.Flags().StringVar(©right, "copyright", filepath.Join("hack", "boilerplate.go.txt"), "Location of copyright boilerplate file.") | ||
repoCmd.Flags().BoolVar(&bazel, "bazel", false, "if true, setup Bazel workspace artifacts") | ||
repoCmd.Flags().BoolVar(&controllerOnly, "controller-only", false, "if true, setup controller only") |
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 I add API resource to a project which has been initialized as "controller-only" ?
If yes, then does this flag makes sense ?
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.
It won't work since the pkg/inject
won't build
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.
Hmm.... it will be great if we can remove this restriction.
Ideal workflow is - to be able to not to take this flag as input for init
command and then be able to add resources for non-core type and controllers for core-types.
Lets discuss today to explore if we can make this happen.
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.
I agree with you, it's nice to remove the restriction.
The divergence comes from the different dependencies for core type controller and CRD behaviors. Having a flag in init
command, we can easily distinguish the different dependencies.
Let's discuss to see if there's better solution.
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.
As discussed offline, we keep this flag for now. Later when the dynamic client is added in the kube builder library, we will try to remove this flag.
@@ -61,6 +62,7 @@ func AddCreateResource(cmd *cobra.Command) { | |||
createResourceCmd.Flags().BoolVar(&nonNamespacedKind, "non-namespaced", false, "if set, the API kind will be non namespaced") | |||
createResourceCmd.Flags().BoolVar(&controller, "controller", true, "if true, generate the controller code for the resource") | |||
createResourceCmd.Flags().BoolVar(&generate, "generate", true, "generate source code") | |||
createResourceCmd.Flags().BoolVar(&controllerOnly, "controller-only", false, "skip resources, generate controller only") |
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.
hmm.... add a resource with --controller-only looks a bit confusing. "Add controller" should address this use case right ?
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.
I didn't realize that it might cause confusion. Do you suggest to add a new command like add controller
or create controller
? This new command will have almost the same flags and need to call the same functions as current create resource
. I'm not sure if it worth to do it.
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.
yeah I think create controller
makes sense. We don't actually want to create a resource in this case.
b295792
to
ed6ab6b
Compare
Add a subcommand |
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.
Looks good to me. Was wondering if we can improve the test coverage ?
@Liujingfang1 travis tests are failing on this one. |
I updated the test script in travis-ci. Seems it's not properly added. I'll fix it. |
Change the command in test.sh as
|
13a802b
to
57bd34d
Compare
Add two different workflows in test.sh
Note that for the type |
190b139
to
23a42ba
Compare
@droot @pwittrock All tests passed, PTAL |
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.
Thanks for working on the tests for this one.
Have some more comments.
"k8s.io/client-go/kubernetes/scheme", | ||
"rscheme " + "\"" + repo + "/pkg/client/clientset/versioned/scheme\""}... | ||
) | ||
} |
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.
Keeping track of these imports feels like a lot of hand-written magic :)
Another possible approach could be ...we add all the imports and then run goimports
to remove extra imports.
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.
As discussed offline, Let goimports
add imports could be risky. We may only allow goimports
to remove extra imports. It can be done in a different PR.
{{if .CoreType}} | ||
"{{ .Repo }}/pkg/inject" | ||
"{{ .Repo }}/pkg/inject/args" | ||
{{else}} | ||
"{{ .Repo }}/pkg/client/clientset/versioned" |
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.
may be just have the clienset/versioned guarded ?
var nonNamespacedKind bool | ||
var generate bool | ||
var CoreType bool | ||
|
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 move away from this pattern of defining pkg level globals for command options. Currently all commands are implemented like this but its an anti-pattern where push down cobra.command and these globals too deep in to the business logic.
Idea is to define a separate struct for command args:
type controllerArgs struct { namespaced bool coreType bool generate bool }
Bind above struct field to the command-args. So filling of struct is delegated to cobra with some basic validation.
Then have validate() method on controllerArgs
And then execution should NOT take cobra.cmd or args as input like we do today.
Not a deal breaker, but wanted to bring it out (can be handled in separate PR but will be good if we can do it in current PR because then we can point people to the pattern here to refactor commands):
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.
I can do it in this PR.
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.
Done
|
||
func AddInit(cmd *cobra.Command) { | ||
cmd.AddCommand(repoCmd) | ||
repoCmd.Flags().StringVar(&domain, "domain", "", "domain for the API groups") | ||
repoCmd.Flags().StringVar(©right, "copyright", filepath.Join("hack", "boilerplate.go.txt"), "Location of copyright boilerplate file.") | ||
repoCmd.Flags().BoolVar(&bazel, "bazel", false, "if true, setup Bazel workspace artifacts") | ||
repoCmd.Flags().BoolVar(&controllerOnly, "controller-only", false, "if true, setup controller only") |
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.
Hmm.... it will be great if we can remove this restriction.
Ideal workflow is - to be able to not to take this flag as input for init
command and then be able to add resources for non-core type and controllers for core-types.
Lets discuss today to explore if we can make this happen.
test.sh
Outdated
export PATH=/tmp/kubebuilder/bin/:$PATH | ||
export TEST_ASSET_KUBECTL=/tmp/kubebuilder/bin/kubectl | ||
export TEST_ASSET_KUBE_APISERVER=/tmp/kubebuilder/bin/kube-apiserver | ||
export TEST_ASSET_ETCD=/tmp/kubebuilder/bin/etcd |
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 can set these env once ?
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.
Done
} | ||
|
||
function update_controller_test { | ||
# Update import |
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.
Its not very clear what are we doing here ?
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.
Explained offline. Also added a comment for explanation.
52c95aa
to
e61782f
Compare
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.
LGTM.
Lets check with @pwittrock if he has any ideas to workaround the restriction of "not being able to add API resource to a project created using --controller-only flag during init"
…rence-markers-rbac zh-translation:/reference/markers/rbac.md
controller-only
to initcreate controller
with flag--core-type
create controller --core-type
in test.shThis is to fix (L) Support for creating controllers for core types #41