Skip to content

Commit 2d52540

Browse files
makefile: Update Makefile (#1571)
Update Makefile based on new project generated via: ```shell operator-sdk init --plugins go/v4 --domain example.org --repo github.com/marcofranssen/test ``` Signed-off-by: Marco Franssen <[email protected]>
1 parent 1e740c0 commit 2d52540

File tree

4 files changed

+184
-90
lines changed

4 files changed

+184
-90
lines changed

.github/workflows/main.yaml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ on:
3939
- "Makefile"
4040
- "go.mod"
4141
- "go.sum"
42+
43+
env:
44+
KUBECTL_VERSION: v1.25.1
45+
HELM_VERSION: v3.17.2
46+
4247
jobs:
4348
basic_tests:
4449
runs-on: ubuntu-22.04
@@ -95,11 +100,13 @@ jobs:
95100
go-version-file: go.mod
96101
cache-dependency-path: go.sum
97102

103+
- name: Setup kubectl
104+
uses: marcofranssen/setup-kubectl@d81bf181729cee2bc813ac2ea2f74dec90f01f99 # v1.3.0
105+
with:
106+
kubectlVersion: ${{ env.KUBECTL_VERSION }}
107+
98108
- name: Install dependences
99-
run: |
100-
command -v ginkgo || go install github.com/onsi/ginkgo/v2/ginkgo@latest
101-
go install sigs.k8s.io/[email protected]
102-
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.25.1/bin/linux/amd64/kubectl && sudo install kubectl /usr/local/bin/kubectl
109+
run: make ginkgo kind
103110

104111
- name: Run e2e tests
105112
run: make e2e
@@ -122,16 +129,18 @@ jobs:
122129
go-version-file: go.mod
123130
cache-dependency-path: go.sum
124131

125-
- name: Install dependences
126-
run: |
127-
command -v ginkgo || go install github.com/onsi/ginkgo/v2/ginkgo@latest
128-
go install sigs.k8s.io/[email protected]
129-
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.25.1/bin/linux/amd64/kubectl && sudo install kubectl /usr/local/bin/kubectl
132+
- name: Setup kubectl
133+
uses: marcofranssen/setup-kubectl@d81bf181729cee2bc813ac2ea2f74dec90f01f99 # v1.3.0
134+
with:
135+
kubectlVersion: ${{ env.KUBECTL_VERSION }}
130136

131137
- name: Install Helm
132138
uses: azure/setup-helm@b9e51907a09c216f16ebe8536097933489208112 # v4.3.0
133139
with:
134-
version: v3.17.2
140+
version: ${{ env.HELM_VERSION }}
141+
142+
- name: Install dependences
143+
run: make ginkgo kind
135144

136145
- name: Run helm e2e tests
137146
run: make helm-e2e

Makefile

Lines changed: 165 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ else
2727
GOBIN = $(shell go env GOBIN)
2828
endif
2929

30+
.PHONY: all
3031
all: build
3132

3233
##@ General
@@ -50,6 +51,7 @@ help: ## Display this help.
5051
shellcheck:
5152
@find . -type f -name *.sh -exec docker run --rm -v $(shell pwd):/mnt koalaman/shellcheck:stable {} +
5253

54+
.PHONY: manifests
5355
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
5456
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./apis/fluentbit/..." output:crd:artifacts:config=config/crd/bases
5557
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./apis/fluentd/..." output:crd:artifacts:config=config/crd/bases
@@ -58,13 +60,15 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
5860
kubectl kustomize config/crd/bases/ | sed -e '/creationTimestamp/d' > manifests/setup/fluent-operator-crd.yaml
5961
kubectl kustomize manifests/setup/ | sed -e '/creationTimestamp/d' > manifests/setup/setup.yaml
6062

63+
.PHONY: generate
6164
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
6265
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
63-
./hack/update-codegen.sh
6466

67+
PHONY: fmt
6568
fmt: ## Run go fmt against code.
6669
go fmt ./...
6770

71+
PHONY: vet
6872
vet: ## Run go vet against code.
6973
go vet ./...
7074

@@ -81,6 +85,19 @@ setup-envtest: install-setup-envtest ## Download and set up the envtest binary
8185
test: manifests generate fmt vet setup-envtest ## Run tests.
8286
go test ./apis/... -coverprofile cover.out
8387

88+
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
89+
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
90+
test-e2e:
91+
go test ./test/e2e/ -v -ginkgo.v
92+
93+
.PHONY: lint
94+
lint: golangci-lint ## Run golangci-lint linter
95+
$(GOLANGCI_LINT) run
96+
97+
.PHONY: lint-fix
98+
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
99+
$(GOLANGCI_LINT) run --fix
100+
84101
##@ Build
85102

86103
binary:
@@ -159,39 +176,156 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
159176
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
160177
kubectl delete -f manifests/setup/setup.yaml
161178

162-
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
163-
controller-gen: go-deps ## Download controller-gen locally if necessary.
164-
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
165-
166-
GINKGO = $(shell pwd)/bin/ginkgo
167-
ginkgo: go-deps ## Download controller-gen locally if necessary.
168-
$(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/v2/[email protected])
169-
170-
171-
KUSTOMIZE = $(shell pwd)/bin/kustomize
172-
kustomize: go-deps ## Download kustomize locally if necessary.
173-
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
174-
175-
CODE_GENERATOR = $(shell go env GOPATH)/pkg/mod/k8s.io/[email protected]
176-
code-generator: go-deps ## Download code-generator locally if necessary
177-
$(call go-get-tool,$(CODE_GENERATOR),k8s.io/[email protected])
178-
179-
# go-get-tool will 'go get' any package $2 and install it to $1.
180-
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
181-
define go-get-tool
182-
@[ -f $(1) ] || { \
183-
set -e ;\
184-
TMP_DIR=$$(mktemp -d) ;\
185-
cd $$TMP_DIR ;\
186-
go mod init tmp ;\
187-
echo "Downloading $(2)" ;\
188-
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
189-
rm -rf $$TMP_DIR ;\
190-
}
179+
##@ Dependencies
180+
181+
## Location to install dependencies to
182+
LOCALBIN ?= $(shell pwd)/bin
183+
$(LOCALBIN):
184+
mkdir -p $(LOCALBIN)
185+
186+
## Tool Binaries
187+
KUBECTL ?= kubectl
188+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
189+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
190+
ENVTEST ?= $(LOCALBIN)/setup-envtest
191+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
192+
GINKGO = $(LOCALBIN)/ginkgo
193+
CODE_GENERATOR = $(LOCALBIN)/code-generator
194+
KIND = $(LOCALBIN)/kind
195+
196+
## Tool Versions
197+
KUSTOMIZE_VERSION ?= v5.6.0
198+
CONTROLLER_TOOLS_VERSION ?= v0.15.0
199+
ENVTEST_VERSION ?= release-0.19
200+
GOLANGCI_LINT_VERSION ?= v1.59.1
201+
GINKGO_VERSION ?= v2.23.4
202+
CODE_GENERATOR_VERSION ?= v0.32.3
203+
KIND_VERSION ?= v0.17.0
204+
205+
.PHONY: kustomize
206+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
207+
$(KUSTOMIZE): $(LOCALBIN)
208+
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
209+
210+
.PHONY: controller-gen
211+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
212+
$(CONTROLLER_GEN): $(LOCALBIN)
213+
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
214+
215+
.PHONY: envtest
216+
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
217+
$(ENVTEST): $(LOCALBIN)
218+
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
219+
220+
.PHONY: golangci-lint
221+
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
222+
$(GOLANGCI_LINT): $(LOCALBIN)
223+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
224+
225+
.PHONY: ginkgo
226+
ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
227+
$(GINKGO): $(LOCALBIN)
228+
$(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo,$(GINKGO_VERSION))
229+
230+
.PHONY: code-generator
231+
code-generator: $(CODE_GENERATOR) ## Download code-generator locally if necessary.
232+
$(CODE_GENERATOR): $(LOCALBIN)
233+
$(call go-install-tool,$(CODE_GENERATOR),k8s.io/code-generator,$(CODE_GENERATOR_VERSION))
234+
235+
.PHONY: kind
236+
kind: $(KIND) ## Download code-generator locally if necessary.
237+
$(KIND): $(LOCALBIN)
238+
$(call go-install-tool,$(KIND),sigs.k8s.io/kind,$(KIND_VERSION))
239+
240+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
241+
# $1 - target path with name of binary
242+
# $2 - package url which can be installed
243+
# $3 - specific version of package
244+
define go-install-tool
245+
@[ -f "$(1)-$(3)" ] || { \
246+
set -e; \
247+
package=$(2)@$(3) ;\
248+
echo "Downloading $${package}" ;\
249+
rm -f $(1) || true ;\
250+
GOBIN=$(LOCALBIN) go install $${package} ;\
251+
mv $(1) $(1)-$(3) ;\
252+
} ;\
253+
ln -sf $(1)-$(3) $(1)
191254
endef
192255

256+
.PHONY: operator-sdk
257+
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
258+
operator-sdk: ## Download operator-sdk locally if necessary.
259+
ifeq (,$(wildcard $(OPERATOR_SDK)))
260+
ifeq (, $(shell which operator-sdk 2>/dev/null))
261+
@{ \
262+
set -e ;\
263+
mkdir -p $(dir $(OPERATOR_SDK)) ;\
264+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
265+
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
266+
chmod +x $(OPERATOR_SDK) ;\
267+
}
268+
else
269+
OPERATOR_SDK = $(shell which operator-sdk)
270+
endif
271+
endif
272+
.PHONY: bundle
273+
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
274+
$(OPERATOR_SDK) generate kustomize manifests -q
275+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
276+
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
277+
$(OPERATOR_SDK) bundle validate ./bundle
278+
279+
.PHONY: bundle-build
280+
bundle-build: ## Build the bundle image.
281+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
282+
283+
.PHONY: bundle-push
284+
bundle-push: ## Push the bundle image.
285+
$(MAKE) docker-push IMG=$(BUNDLE_IMG)
286+
287+
.PHONY: opm
288+
OPM = $(LOCALBIN)/opm
289+
opm: ## Download opm locally if necessary.
290+
ifeq (,$(wildcard $(OPM)))
291+
ifeq (,$(shell which opm 2>/dev/null))
292+
@{ \
293+
set -e ;\
294+
mkdir -p $(dir $(OPM)) ;\
295+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
296+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
297+
chmod +x $(OPM) ;\
298+
}
299+
else
300+
OPM = $(shell which opm)
301+
endif
302+
endif
303+
304+
# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
305+
# These images MUST exist in a registry and be pull-able.
306+
BUNDLE_IMGS ?= $(BUNDLE_IMG)
307+
308+
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
309+
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
310+
311+
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
312+
ifneq ($(origin CATALOG_BASE_IMG), undefined)
313+
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
314+
endif
315+
316+
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
317+
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
318+
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
319+
.PHONY: catalog-build
320+
catalog-build: opm ## Build a catalog image.
321+
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
322+
323+
# Push the catalog image.
324+
.PHONY: catalog-push
325+
catalog-push: ## Push a catalog image.
326+
$(MAKE) docker-push IMG=$(CATALOG_IMG)
327+
193328
go-deps: # download go dependencies
194-
go get k8s.io/[email protected]
195329
go mod download
196330

197331
docs-update: # update api docs

hack/update-codegen.sh

Lines changed: 0 additions & 48 deletions
This file was deleted.

hack/verify-codegen.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ cleanup
2424
mkdir -p "${TMP_DIFFROOT}"
2525
cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}"
2626

27-
"${SCRIPT_ROOT}/hack/update-codegen.sh"
2827
echo "diffing ${DIFFROOT} against freshly generated clientset"
2928
ret=0
3029
diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$?

0 commit comments

Comments
 (0)