-
Notifications
You must be signed in to change notification settings - Fork 113
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 make target for generating crds through controller-gen #629
Conversation
Skipping CI for Draft Pull Request. |
I am able to use controller-gen tool to generate CRDs successfully, the name of generated manifests is different with existing ones, the generated name has
So the 1st question is whether we need to use these generated names or rename to existing ones? Also there lead to another question about the location/directory where to save these crd files. The operator-sdk 1.x migration doc recommends to follow kubebuilder's convention to save these crds under I also compared the content of generated manifests with existing ones. There is not much different, there added a new annotation for
|
Thanks Matt!
Can controller-gen tool generate CRD name as our original name by leverage its command parameter directly? If no, I suggest to switch to the new name directly. The second folder problem is similar. I prefer to use a native/default way of the tool (no patch). BTW, can we add our |
hack/install-controller-gen.sh
Outdated
if [ ! -f "${GOPATH}/bin/controller-gen" ] ; then | ||
echo "# Installing controller-gen..." | ||
go get sigs.k8s.io/controller-tools/cmd/controller-gen@"${CONTROLLER_GEN_VERSION}" | ||
fi |
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.
Until we can use the Go 1.16 improved go get/install that does not fiddle with the current Go modules file, I would suggest to do the installation part in a temporary directory.
if [ ! -f "${GOPATH}/bin/controller-gen" ] ; then | |
echo "# Installing controller-gen..." | |
go get sigs.k8s.io/controller-tools/cmd/controller-gen@"${CONTROLLER_GEN_VERSION}" | |
fi | |
if [ ! -f "${GOPATH}/bin/controller-gen" ] ; then | |
echo "# Installing controller-gen..." | |
pushd "$(mktemp -d)" >/dev/null 2>&1 | |
go get sigs.k8s.io/controller-tools/cmd/controller-gen@"${CONTROLLER_GEN_VERSION}" | |
popd >/dev/null 2>&1 | |
fi |
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, Matthias. I updated the code according to your suggestion, BTW, do you think if it's needed to clean up this temporary dir after installation? Thanks.
04d7466
to
beada30
Compare
Yes, I added a simple instruction in this doc. |
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.
Quick question, I tried it locally and with the proposed GO111MODULE fix it was able to create the custom resource definition files. However, the file paths were different to the ones we currently have:
# New files
deploy/crds/shipwright.io_buildruns.yaml
deploy/crds/shipwright.io_builds.yaml
deploy/crds/shipwright.io_buildstrategies.yaml
deploy/crds/shipwright.io_clusterbuildstrategies.yaml
# Current files
ls -1 deploy/crds/
build.yaml
buildrun.yaml
buildstrategy.yaml
clusterbuildstrategy.yaml
hack/install-controller-gen.sh
Outdated
if [ ! -f "${GOPATH}/bin/controller-gen" ] ; then | ||
echo "# Installing controller-gen..." | ||
pushd "$(mktemp -d)" >/dev/null 2>&1 | ||
go get sigs.k8s.io/controller-tools/cmd/controller-gen@"${CONTROLLER_GEN_VERSION}" |
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.
Just found out that in this particular case we have to make sure that it uses Go Modules otherwise you cannot specify a specific version. Tested it in an empty Docker container and with the environment variable it works for me.
go get sigs.k8s.io/controller-tools/cmd/controller-gen@"${CONTROLLER_GEN_VERSION}" | |
GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/controller-gen@"${CONTROLLER_GEN_VERSION}" |
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.
+1, just hit the same issue
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, @HeavyWombat , I added.
@mattcui @HeavyWombat the names where changed in here . I think also the operator-sdk (when doing an @mattcui one more thing, so I compared the files and I see this will introduce new fields in the CRD definition, as follows: $ dyff between build.yaml shipwright.io_builds.yaml
_ __ __
_| |_ _ / _|/ _| between github.com/shipwright-io/build/deploy/crds/build.yaml
/ _' | | | | |_| |_ and github.com/shipwright-io/build/deploy/crds/shipwright.io_builds.yaml
| (_| | |_| | _| _|
\__,_|\__, |_| |_| returned two differences
|___/
(root level)
+ one map entry added:
status:
│ acceptedNames:
│ │ kind:
│ │ plural:
│ conditions: []
│ storedVersions: []
metadata
+ two map entries added:
annotations:
│ controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null $ dyff between buildrun.yaml shipwright.io_buildruns.yaml
_ __ __
_| |_ _ / _|/ _| between github.com/shipwright-io/build/deploy/crds/buildrun.yaml
/ _' | | | | |_| |_ and github.com/shipwright-io/build/deploy/crds/shipwright.io_buildruns.yaml
| (_| | |_| | _| _|
\__,_|\__, |_| |_| returned two differences
|___/
(root level)
+ one map entry added:
status:
│ acceptedNames:
│ │ kind:
│ │ plural:
│ conditions: []
│ storedVersions: []
metadata
+ two map entries added:
annotations:
│ controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
$ dyff between buildstrategy.yaml shipwright.io_buildstrategies.yaml
_ __ __
_| |_ _ / _|/ _| between github.com/shipwright-io/build/deploy/crds/buildstrategy.yaml
/ _' | | | | |_| |_ and github.com/shipwright-io/build/deploy/crds/shipwright.io_buildstrategies.yaml
| (_| | |_| | _| _|
\__,_|\__, |_| |_| returned two differences
|___/
(root level)
+ one map entry added:
status:
│ acceptedNames:
│ │ kind:
│ │ plural:
│ conditions: []
│ storedVersions: []
metadata
+ two map entries added:
annotations:
│ controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null $ dyff between clusterbuildstrategy.yaml shipwright.io_clusterbuildstrategies.yaml
_ __ __
_| |_ _ / _|/ _| between github.com/shipwright-io/build/deploy/crds/clusterbuildstrategy.yaml
/ _' | | | | |_| |_ and github.com/shipwright-io/build/deploy/crds/shipwright.io_clusterbuildstrategies.yaml
| (_| | |_| | _| _|
\__,_|\__, |_| |_| returned two differences
|___/
(root level)
+ one map entry added:
status:
│ acceptedNames:
│ │ kind:
│ │ plural:
│ conditions: []
│ storedVersions: []
metadata
+ two map entries added:
annotations:
│ controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null any ideas on why this is happening? |
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.
Asking some questions on the current setup, overall this looks good!
I also posted the diff in my comment , the 1st difference, I think, it's controller-gen that adds itself |
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
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: qu1queee 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
This PR is for changing to use controller-gen tool from kubebuilder to generate CRDs
Fixes #579
-->
Submitter Checklist
See the contributor guide
for details on coding conventions, github and prow interactions, and the code review process.
Release Notes
Added a script and make target to install controller-gen tool and generate CRDs with this tool