Skip to content

Commit

Permalink
Merge pull request #44 from juanluisvaladas/improve-makefile
Browse files Browse the repository at this point in the history
Make controller-gen targets non .PHONY
  • Loading branch information
juanluisvaladas authored May 3, 2023
2 parents a3a0e62 + 1ab15d8 commit 7c25acd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 36 deletions.
63 changes: 33 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
include Makefile.variables
include inttest/Makefile.variables

.DELETE_ON_ERROR:

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

# Image URL to use all building/pushing image targets
IMG ?= quay.io/k0sproject/k0smotron:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
Expand Down Expand Up @@ -41,14 +55,20 @@ help: ## Display this help.

##@ Development

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

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
manifests: $(manifests_targets) ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.

### generate
generate_targets += api/v1beta1/zz_generated.deepcopy.go
api/v1beta1/zz_generated.deepcopy.go: $(CONTROLLER_GEN)
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

generate: $(generate_targets) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
Expand Down Expand Up @@ -132,34 +152,12 @@ release: manifests kustomize ## Deploy controller to the K8s cluster specified i
git checkout config/manager/kustomization.yaml
##@ Build Dependencies

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v4.5.7
CONTROLLER_TOOLS_VERSION ?= v0.11.1

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
$(KUSTOMIZE): $(LOCALBIN)
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
rm -rf $(LOCALBIN)/kustomize; \
fi
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }

.PHONY: controller-gen
$(KUSTOMIZE): Makefile.variables | $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)

controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
$(CONTROLLER_GEN): Makefile.variables | $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: envtest
Expand Down Expand Up @@ -191,6 +189,11 @@ smoketests: $(smoketests)
clean:
-$(MAKE) -C inttest clean
rm -f hack/lint/.golangci-lint.stamp
rm -rf \
$(generate_targets) \
$(manifests_targets) \
k0smotron-image-bundle.tar \
$(LOCALBIN)

hack/lint/.golangci-lint.stamp: hack/lint/Dockerfile
docker build \
Expand Down
2 changes: 2 additions & 0 deletions Makefile.variables
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
KUSTOMIZE_VERSION ?= v5.0.1
CONTROLLER_TOOLS_VERSION ?= v0.11.4
3 changes: 1 addition & 2 deletions config/crd/bases/k0smotron.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.11.4
name: clusters.k0smotron.io
spec:
group: k0smotron.io
Expand Down
1 change: 0 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
Expand Down
4 changes: 1 addition & 3 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.11.4
name: clusters.k0smotron.io
spec:
group: k0smotron.io
Expand Down Expand Up @@ -517,7 +516,6 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: k0smotron-manager-role
rules:
- apiGroups:
Expand Down

0 comments on commit 7c25acd

Please sign in to comment.