Skip to content

Commit

Permalink
Install kustomize if not present
Browse files Browse the repository at this point in the history
  • Loading branch information
toonsevrin committed Mar 12, 2020
1 parent c749b4c commit 54ac4ba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
3 changes: 3 additions & 0 deletions pkg/scaffold/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const (
ControllerRuntimeVersion = "v0.5.0"
// ControllerToolsVersion is the kubernetes-sigs/controller-tools version to be used in the project
ControllerToolsVersion = "v0.2.5"
// KustomizeVersion is the kubernetes-sigs/kustomize version to be used in the project
KustomizeVersion = "v3.5.4"

imageName = "controller:latest"
)
Expand Down Expand Up @@ -160,6 +162,7 @@ func (s *initScaffolder) scaffoldV2() error {
Image: imageName,
BoilerplatePath: s.boilerplatePath,
ControllerToolsVersion: ControllerToolsVersion,
KustomizeVersion: KustomizeVersion,
},
&templatesv2.Dockerfile{},
&templatesv2.Kustomize{},
Expand Down
29 changes: 23 additions & 6 deletions pkg/scaffold/internal/templates/v2/makefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type Makefile struct {
BoilerplatePath string
// Controller tools version to use in the project
ControllerToolsVersion string
//Kustomize version to use in the project
KustomizeVersion string
}

// SetTemplateDefaults implements input.Template
Expand Down Expand Up @@ -80,17 +82,17 @@ run: generate fmt vet manifests
go run ./main.go
# Install CRDs into a cluster
install: manifests
kustomize build config/crd | kubectl apply -f -
install: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl apply -f -
# Uninstall CRDs from a cluster
uninstall: manifests
kustomize build config/crd | kubectl delete -f -
uninstall: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl delete -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests
deploy: manifests kustomize
cd config/manager && kustomize edit set image controller=${IMG}
kustomize build config/default | kubectl apply -f -
$(KUSTOMIZE) build config/default | kubectl apply -f -
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
Expand Down Expand Up @@ -132,4 +134,19 @@ CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
kustomize:
ifeq (, $(shell which kustomize))
@{ \
set -e ;\
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/kustomize/kustomize/v3@{{ .KustomizeVersion }} ;\
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
}
KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell which kustomize)
endif
`

0 comments on commit 54ac4ba

Please sign in to comment.