-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat(build): introduces controller-gen scaffolding #121
feat(build): introduces controller-gen scaffolding #121
Conversation
Skipping CI for Draft Pull Request. |
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.
How did you create MeshFederation
resource? I was trying to add a resource with the following command:
kubebuilder create api --group federation --version v1alpha1 --kind ImportedService
but I got this error:
FATA failed to create API: unable to run pre-scaffold tasks of "base.go.kubebuilder.io/v4": cmd/main.go file should present in the root directory
Are you going to change cmd
package in this PR?
I scaffolded a new project and API using kubebuilder, then copied the files in
I wasn't intending to. I think enabling us to use |
Ok, that works for me. |
44bd8a2
to
bc1d832
Compare
f353806
to
24ec1d5
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.
I think we can simplify the entire generation to one command. You can bundle my suggestions to a single commit.
@@ -36,7 +47,7 @@ deps: ## Downloads required dependencies | |||
|
|||
EXTRA_BUILD_ARGS?= | |||
.PHONY: build | |||
build: deps $(PROTOBUF_GEN) ## Builds the project | |||
build: deps $(PROTOBUF_GEN) $(DEEP_COPY_GEN) $(CRD_GEN) ## Builds the project |
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.
build: deps $(PROTOBUF_GEN) $(DEEP_COPY_GEN) $(CRD_GEN) ## Builds the project | |
build: deps $(PROTOBUF_GEN) $(CRD_GEN) ## Builds the project |
Makefile
Outdated
DEEP_COPY_DIR := $(PROJECT_DIR)/api/v1alpha1 | ||
DEEP_COPY_SRC := $(shell find $(DEEP_COPY_DIR) -type f -not -name "*deepcopy.go") | ||
DEEP_COPY_GEN := $(DEEP_COPY_DIR)/zz_generated.deepcopy.go | ||
|
||
CRD_SRC_DIR := $(PROJECT_DIR)/api/v1alpha1 | ||
CRD_SRC := $(shell find $(CRD_SRC_DIR) -type f -name "*.go") | ||
CRD_GEN_DIR := $(PROJECT_DIR)/chart/crds | ||
CRD_GEN := $(shell find $(CRD_GEN_DIR) -type f -name "*.yaml") |
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.
DEEP_COPY_DIR := $(PROJECT_DIR)/api/v1alpha1 | |
DEEP_COPY_SRC := $(shell find $(DEEP_COPY_DIR) -type f -not -name "*deepcopy.go") | |
DEEP_COPY_GEN := $(DEEP_COPY_DIR)/zz_generated.deepcopy.go | |
CRD_SRC_DIR := $(PROJECT_DIR)/api/v1alpha1 | |
CRD_SRC := $(shell find $(CRD_SRC_DIR) -type f -name "*.go") | |
CRD_GEN_DIR := $(PROJECT_DIR)/chart/crds | |
CRD_GEN := $(shell find $(CRD_GEN_DIR) -type f -name "*.yaml") | |
CRD_SRC_DIR := $(PROJECT_DIR)/api/v1alpha1 | |
CRD_SRC := $(shell find $(CRD_SRC_DIR) -type f -name "*.go") | |
CRD_GEN_DIR := $(PROJECT_DIR)/chart/crds | |
CRD_GEN := $(shell find $(CRD_GEN_DIR) -type f -name "*.yaml") |
Makefile
Outdated
$(DEEP_COPY_GEN): $(DEEP_COPY_SRC) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. | ||
$(CONTROLLER_GEN) object:headerFile=$(LICENSE_FILE) paths="./..." | ||
|
||
$(CRD_GEN): $(CRD_SRC) ## Generate CustomResourceDefinition objects. | ||
$(CONTROLLER_GEN) crd paths="./..." output:crd:artifacts:config=chart/crds | ||
|
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.
Moving forward we will also add webhooks, so having the entire generation as one command will be more efficient.
What we missed here is dependency to the controller-gen
itself - if it's not present in the path it will now be automatically fetched.
$(DEEP_COPY_GEN): $(DEEP_COPY_SRC) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. | |
$(CONTROLLER_GEN) object:headerFile=$(LICENSE_FILE) paths="./..." | |
$(CRD_GEN): $(CRD_SRC) ## Generate CustomResourceDefinition objects. | |
$(CONTROLLER_GEN) crd paths="./..." output:crd:artifacts:config=chart/crds | |
$(CRD_GEN): $(CRD_SRC) $(CONTROLLER_GEN) ## Generates CRDs and other controller-runtime scaffolding. | |
$(CONTROLLER_GEN) paths="$(CRD_SRC_DIR)/..." \ | |
crd output:crd:artifacts:config="$(CRD_GEN_DIR)" \ | |
object:headerFile="$(LICENSE_FILE)" |
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.
There's more to that btw (RBAC generation, kube-builder directives in controllers etc), but we can fine-tune it as we 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.
One other thing from the top of my head - if someone opens PR with code changes but forgets to regenerate CRDs and other stuff we will end up with misaligned artifacts, i.e. YAMLs will be behind. I will capture it as an 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.
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.
/retest |
b0ea4ff
into
openshift-service-mesh:master
Part of #148 |
These changes introduce the
controller-gen
tool and a make target to generate CRDs and DeepCopy methods. This target is added as a dependency of thebuild
target, and runs only when changes are made to source files of the generated CRDs and methods.Placeholder types for the
MeshFederation
kind have been added to verify generation.