Skip to content

Commit

Permalink
Generate manifests via make generate, remove make manifests (#919)
Browse files Browse the repository at this point in the history
We currently see issues with Go >1.21 and our current controller-gen
version, so a reasonable workaround is to always run with Go 1.21
instead of using whatever the system happens to have installed.

Easiest way to do that is by doing the manifest generation inside a
container, and `make generate` already serves that purpose, so this
commit changes the generation script to *also* generate the manifests.

This commit also removes all prior occurrences of `make manifests`.

Fixes #885.
  • Loading branch information
sharnoff authored Apr 29, 2024
1 parent 4d83eb6 commit 774a6d5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 35 deletions.
25 changes: 2 additions & 23 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,8 @@ jobs:
exit 1
fi
manifests:
name: check generated manifests
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: make manifests
run: |
make manifests
- name: check diff
run: |
if ! test -z "$(git ls-files --exclude-standard --others .)$(git diff .)"; then
git ls-files --exclude-standard --others .
git diff .
echo "ERROR: 'make manifests' modified the source tree."
exit 1
fi
generated-go:
name: check generated go files
generated:
name: check generated files
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
Expand Down
13 changes: 3 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ generate: ## Generate boilerplate DeepCopy methods, manifests, and Go client
rm -rf $$iidfile
go fmt ./...

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./neonvm/..." \
output:crd:artifacts:config=neonvm/config/crd/bases \
output:rbac:artifacts:config=neonvm/config/rbac \
output:webhook:artifacts:config=neonvm/config/webhook

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
Expand Down Expand Up @@ -240,11 +233,11 @@ check-local-context: ## Asserts that the current kubectl context is pointing at
@if [ "$$($(KUBECTL) config current-context)" != 'k3d-$(CLUSTER_NAME)' ] && [ "$$($(KUBECTL) config current-context)" != 'kind-$(CLUSTER_NAME)' ]; then echo "kubectl context is not pointing to local k3d or kind cluster (must be k3d-$(CLUSTER_NAME) or kind-$(CLUSTER_NAME))"; exit 1; fi

.PHONY: install
install: check-local-context manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
install: check-local-context kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build neonvm/config/crd | kubectl apply -f -

.PHONY: uninstall
uninstall: check-local-context manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
uninstall: check-local-context kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build neonvm/config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

BUILDTS := $(shell date +%s)
Expand Down Expand Up @@ -297,7 +290,7 @@ render-release: $(RENDERED) kustomize
cd deploy/agent && $(KUSTOMIZE) edit set image autoscaler-agent=autoscaler-agent:dev

.PHONY: deploy
deploy: check-local-context docker-build load-images manifests render-manifests kubectl ## Deploy controller to the K8s cluster specified in ~/.kube/config.
deploy: check-local-context docker-build load-images render-manifests kubectl ## Deploy controller to the K8s cluster specified in ~/.kube/config.
$(KUBECTL) apply -f $(RENDERED)/multus.yaml
$(KUBECTL) -n kube-system rollout status daemonset kube-multus-ds
$(KUBECTL) apply -f $(RENDERED)/whereabouts.yaml
Expand Down
2 changes: 1 addition & 1 deletion neonvm/controllers/virtualmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type VirtualMachineReconciler struct {
}

// The following markers are used to generate the rules permissions (RBAC) on config/rbac using controller-gen
// when the command <make manifests> is executed.
// when controller-gen (used by 'make generate') is executed.
// To know more about markers see: https://book.kubebuilder.io/reference/markers.html

//+kubebuilder:rbac:groups=vm.neon.tech,resources=virtualmachines,verbs=get;list;watch;create;update;patch;delete
Expand Down
2 changes: 1 addition & 1 deletion neonvm/controllers/virtualmachinemigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type VirtualMachineMigrationReconciler struct {
}

// The following markers are used to generate the rules permissions (RBAC) on config/rbac using controller-gen
// when the command <make manifests> is executed.
// when controller-gen (used by 'make generate') is executed.
// To know more about markers see: https://book.kubebuilder.io/reference/markers.html

//+kubebuilder:rbac:groups=vm.neon.tech,resources=virtualmachinemigrations,verbs=get;list;watch;create;update;patch;delete
Expand Down
5 changes: 5 additions & 0 deletions neonvm/hack/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ bash $GOPATH/src/k8s.io/code-generator/generate-groups.sh "deepcopy,client,infor
--go-header-file neonvm/hack/boilerplate.go.txt

controller-gen object:headerFile="neonvm/hack/boilerplate.go.txt" paths="./neonvm/apis/..."

controller-gen rbac:roleName=manager-role crd webhook paths="./neonvm/..." \
output:crd:artifacts:config=neonvm/config/crd/bases \
output:rbac:artifacts:config=neonvm/config/rbac \
output:webhook:artifacts:config=neonvm/config/webhook

0 comments on commit 774a6d5

Please sign in to comment.