Skip to content

Commit e1b13f9

Browse files
authored
Merge pull request #3 from rustrial/feature/next-release
Upgrade dependencies and kubebuilder tooling
2 parents 57da4ed + 7821d62 commit e1b13f9

File tree

61 files changed

+784
-599
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+784
-599
lines changed

.github/workflows/build.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@ jobs:
2424
- name: Setup Go
2525
uses: actions/setup-go@v3
2626
with:
27-
go-version: 1.19.x
27+
go-version: 1.20.x
2828
- name: Setup Kubernetes
2929
uses: helm/[email protected]
3030
with:
31-
version: v0.17.0 # https://github.com/kubernetes-sigs/kind/releases
32-
node_image: "kindest/node:v1.25.3@sha256:f52781bc0d7a19fb6c405c2af83abfeb311f130707a0e219175677e366cc45d1"
31+
version: "v0.20.0" # https://github.com/kubernetes-sigs/kind/releases
32+
node_image: "kindest/node:v1.26.6"
3333
cluster_name: kind
3434
- name: Setup Helm
3535
uses: fluxcd/pkg/actions/helm@main
3636
with:
37-
version: "3.10.0"
37+
version: "3.12.1"
3838
- name: Setup Kustomize
3939
uses: fluxcd/pkg/actions/kustomize@main
4040
with:
41-
version: "4.5.7"
41+
version: "5.1.0"
4242
- name: Setup Kubebuilder
4343
uses: RyanSiu1995/[email protected]
4444
with:
45-
version: "3.9.0"
45+
version: "3.11.0"
4646
- name: Setup Kubectl
4747
uses: fluxcd/pkg/actions/kubectl@main
4848
with:
49-
version: "1.26.0"
49+
version: "1.26.6"
5050
- name: Run tests
5151
run: make test
5252
env:

.github/workflows/publish.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ jobs:
5252
strategy:
5353
matrix:
5454
k8s: # Must be available from https://github.com/kubernetes-sigs/kind/releases
55-
- v1.22.15
56-
- v1.23.13
57-
- v1.24.7
58-
- v1.25.3
55+
- v1.23.17
56+
- v1.24.15
57+
- v1.25.11
58+
- v1.26.6
59+
- v1.27.3
5960
steps:
6061
- name: Checkout
6162
uses: actions/checkout@v3
@@ -64,13 +65,13 @@ jobs:
6465
- name: Set up Helm
6566
uses: azure/setup-helm@v1
6667
with:
67-
version: v3.10.0
68+
version: "v3.12.1"
6869
- name: Run chart-testing (lint)
6970
run: (cd charts/k8s-gitops-secrets-controller && helm lint .)
7071
- name: Create kind ${{ matrix.k8s }} cluster
7172
uses: helm/[email protected]
7273
with:
73-
version: v0.17.0 # https://github.com/kubernetes-sigs/kind/releases
74+
version: "v0.20.0" # https://github.com/kubernetes-sigs/kind/releases
7475
node_image: kindest/node:${{ matrix.k8s }}
7576
- name: Install chart
7677
run: (cd charts/k8s-gitops-secrets-controller && helm install k8s-gitops-secrets-controller . -n k8s-gitops-secrets-system --create-namespace --wait --set fullnameOverride=k8s-gitops-secrets-controller-manager --set-string image.tag=${{env.VERSION}})
@@ -105,7 +106,7 @@ jobs:
105106
- name: Setup Go
106107
uses: actions/setup-go@v3
107108
with:
108-
go-version: 1.19.x
109+
go-version: 1.20.x
109110
- name: Build seals CLI
110111
run: make cli
111112
- name: Extract TAG_NAME from GITHUB_REF
@@ -194,7 +195,7 @@ jobs:
194195
- name: Install Helm
195196
uses: azure/setup-helm@v1
196197
with:
197-
version: v3.10.0
198+
version: v3.12.1
198199
- name: Install CR
199200
run: .github/install-cr.sh
200201
- name: Update Helm Chart versions

Dockerfile

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
# Build the manager binary
2-
FROM golang:1.19 as builder
3-
4-
ARG TARGETARCH
5-
2+
FROM golang:1.20 as builder
63
ARG TARGETOS
7-
8-
ENV GOARCH=${TARGETARCH}
9-
10-
ENV GOOS=${TARGETOS}
4+
ARG TARGETARCH
115

126
WORKDIR /workspace
137
# Copy the Go Modules manifests
@@ -18,13 +12,16 @@ COPY go.sum go.sum
1812
RUN go mod download
1913

2014
# Copy the go source
21-
COPY main.go main.go
22-
COPY apis/ apis/
23-
COPY controllers/ controllers/
15+
COPY cmd/ cmd/
16+
COPY api/ api/
2417
COPY internal/ internal/
2518

2619
# Build
27-
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -o manager main.go
20+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
21+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
22+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
23+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
2825

2926
# Use distroless as minimal base image to package the manager binary
3027
# Refer to https://github.com/GoogleContainerTools/distroless for more details

Makefile

Lines changed: 147 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
# Image URL to use all building/pushing image targets
33
IMG ?= controller:latest
4-
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
5-
CRD_OPTIONS ?= "crd"
4+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5+
ENVTEST_K8S_VERSION = 1.27.1
66

77
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
88
ifeq (,$(shell go env GOBIN))
@@ -11,20 +11,64 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

14-
all: manager api-docs seals charts
14+
# CONTAINER_TOOL defines the container tool to be used for building images.
15+
# Be aware that the target commands are only tested with Docker which is
16+
# scaffolded by default. However, you might want to replace it to use other
17+
# tools. (i.e. podman)
18+
CONTAINER_TOOL ?= docker
19+
20+
# Setting SHELL to bash allows bash commands to be executed by recipes.
21+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
22+
SHELL = /usr/bin/env bash -o pipefail
23+
.SHELLFLAGS = -ec
24+
25+
.PHONY: all
26+
all: build api-docs charts
27+
28+
##@ General
29+
30+
# The help target prints out all targets with their descriptions organized
31+
# beneath their categories. The categories are represented by '##@' and the
32+
# target descriptions by '##'. The awk commands is responsible for reading the
33+
# entire set of makefiles included in this invocation, looking for lines of the
34+
# file as xyz: ## something, and then pretty-format the target and help. Then,
35+
# if there's a line with ##@ something, that gets pretty-printed as a category.
36+
# More info on the usage of ANSI control characters for terminal formatting:
37+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
38+
# More info on the awk command:
39+
# http://linuxcommand.org/lc3_adv_awk.php
40+
41+
.PHONY: help
42+
help: ## Display this help.
43+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
44+
45+
##@ Development
46+
47+
.PHONY: manifests
48+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
49+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
50+
51+
.PHONY: generate
52+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
53+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
54+
55+
.PHONY: fmt
56+
fmt: ## Run go fmt against code.
57+
go fmt ./...
58+
59+
.PHONY: vet
60+
vet: ## Run go vet against code.
61+
go vet ./...
1562

16-
# Run tests
17-
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
18-
test: generate fmt vet manifests
19-
mkdir -p ${ENVTEST_ASSETS_DIR}
20-
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.14.1/hack/setup-envtest.sh
21-
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
63+
.PHONY: test
64+
test: manifests generate fmt vet envtest ## Run tests.
65+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
2266

23-
# Build manager binary
24-
manager: generate fmt vet
25-
go build -o bin/manager main.go
67+
##@ Build
2668

27-
seals:
69+
.PHONY: build
70+
build: manifests generate fmt vet ## Build manager binary.
71+
go build -o bin/manager cmd/main.go
2872
go build -o bin/seals cmd/seals/main.go
2973

3074
cli:
@@ -39,95 +83,105 @@ cli:
3983
GOOS=linux GOARCH=arm64 go build -o build/linux/arm64/seals cmd/seals/main.go
4084
cat build/linux/arm64/seals | gzip > build/linux/arm64/seals.gz
4185

42-
# Run against the configured Kubernetes cluster in ~/.kube/config
43-
run: generate fmt vet manifests
44-
go run ./main.go
45-
46-
# Install CRDs into a cluster
47-
install: manifests kustomize
48-
$(KUSTOMIZE) build config/crd | kubectl apply -f -
49-
50-
# Uninstall CRDs from a cluster
51-
uninstall: manifests kustomize
52-
$(KUSTOMIZE) build config/crd | kubectl delete -f -
53-
54-
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
55-
deploy: manifests kustomize
56-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
57-
$(KUSTOMIZE) build config/default | kubectl apply -f -
58-
59-
# UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config
60-
undeploy:
61-
$(KUSTOMIZE) build config/default | kubectl delete -f -
62-
63-
# Generate manifests e.g. CRD, RBAC etc.
64-
manifests: controller-gen
65-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
66-
67-
# Generate API reference documentation
68-
api-docs: gen-crd-api-reference-docs
69-
$(API_REF_GEN) -api-dir=./apis/secrets/v1beta1 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/api/SealedSecret.md
70-
71-
# Run go fmt against code
72-
fmt:
73-
go fmt ./...
74-
75-
# Run go vet against code
76-
vet:
77-
go vet ./...
78-
79-
# Generate code
80-
generate: controller-gen
81-
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
82-
83-
# Build the docker image
84-
docker-build: test
85-
docker build -t ${IMG} .
86-
87-
# Push the docker image
88-
docker-push:
89-
docker push ${IMG}
90-
91-
# Download controller-gen locally if necessary
92-
controller-gen:
93-
ifeq (, $(shell which controller-gen))
94-
@{ \
95-
set -e ;\
96-
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
97-
cd $$CONTROLLER_GEN_TMP_DIR ;\
98-
go mod init tmp ;\
99-
go install sigs.k8s.io/controller-tools/cmd/[email protected] ;\
100-
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
101-
}
102-
CONTROLLER_GEN=$(GOBIN)/controller-gen
103-
else
104-
CONTROLLER_GEN=$(shell which controller-gen)
86+
.PHONY: run
87+
run: manifests generate fmt vet ## Run a controller from your host.
88+
go run ./cmd/main.go
89+
90+
# If you wish built the manager image targeting other platforms you can use the --platform flag.
91+
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
92+
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
93+
.PHONY: docker-build
94+
docker-build: test ## Build docker image with the manager.
95+
$(CONTAINER_TOOL) build -t ${IMG} .
96+
97+
.PHONY: docker-push
98+
docker-push: ## Push docker image with the manager.
99+
$(CONTAINER_TOOL) push ${IMG}
100+
101+
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
102+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
103+
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
104+
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
105+
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
106+
# To properly provided solutions that supports more than one platform you should use this option.
107+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
108+
.PHONY: docker-buildx
109+
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
110+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
111+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
112+
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
113+
$(CONTAINER_TOOL) buildx use project-v3-builder
114+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
115+
- $(CONTAINER_TOOL) buildx rm project-v3-builder
116+
rm Dockerfile.cross
117+
118+
##@ Deployment
119+
120+
ifndef ignore-not-found
121+
ignore-not-found = false
105122
endif
106123

124+
.PHONY: install
125+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
126+
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
107127

128+
.PHONY: uninstall
129+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
130+
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
108131

132+
.PHONY: deploy
133+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
134+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
135+
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
136+
137+
.PHONY: undeploy
138+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
139+
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
140+
141+
##@ Build Dependencies
142+
143+
## Location to install dependencies to
144+
LOCALBIN ?= $(shell pwd)/bin
145+
$(LOCALBIN):
146+
mkdir -p $(LOCALBIN)
147+
148+
## Tool Binaries
149+
KUBECTL ?= kubectl
150+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
151+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
152+
ENVTEST ?= $(LOCALBIN)/setup-envtest
153+
154+
## Tool Versions
155+
KUSTOMIZE_VERSION ?= v5.0.1
156+
CONTROLLER_TOOLS_VERSION ?= v0.12.0
157+
158+
.PHONY: kustomize
159+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
160+
$(KUSTOMIZE): $(LOCALBIN)
161+
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
162+
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
163+
rm -rf $(LOCALBIN)/kustomize; \
164+
fi
165+
test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)
166+
167+
.PHONY: controller-gen
168+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
169+
$(CONTROLLER_GEN): $(LOCALBIN)
170+
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
171+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
172+
173+
.PHONY: envtest
174+
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
175+
$(ENVTEST): $(LOCALBIN)
176+
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
109177

110-
# Download kustomize locally if necessary
111-
KUSTOMIZE = $(shell pwd)/bin/kustomize
112-
kustomize:
113-
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
114178

115179
charts: manifests
116180
cp config/crd/bases/* charts/k8s-gitops-secrets-controller/crds
117181

118-
# go-get-tool will 'go get' any package $2 and install it to $1.
119-
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
120-
define go-get-tool
121-
@[ -f $(1) ] || { \
122-
set -e ;\
123-
TMP_DIR=$$(mktemp -d) ;\
124-
cd $$TMP_DIR ;\
125-
go mod init tmp ;\
126-
echo "Downloading $(2)" ;\
127-
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
128-
rm -rf $$TMP_DIR ;\
129-
}
130-
endef
182+
# Generate API reference documentation
183+
api-docs: gen-crd-api-reference-docs
184+
$(API_REF_GEN) -api-dir=./api/secrets/v1beta1 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/api/SealedSecret.md
131185

132186
# Find or download gen-crd-api-reference-docs
133187
gen-crd-api-reference-docs:

0 commit comments

Comments
 (0)