From f4957db45431a092205b5ff48428c9db54e25a2c Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 2 Nov 2021 14:51:52 +0100 Subject: [PATCH 1/3] Update to Go 1.17, speed up local image build --- Dockerfile | 18 +++++++++++++++++- Makefile | 22 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 28a1a77f..0bf243e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,26 @@ +ARG baseImage="golang:1.17" # Build the manager binary -FROM golang:1.16 as builder +FROM ${baseImage} as builder WORKDIR /workspace + +# Download dependencies in it's own step to optimize caching during docker build +COPY go.mod . +COPY go.sum . +RUN go mod download all + +# Download and cache controller-gen +COPY Makefile . +RUN make controller-gen + COPY . . RUN make +# Start obj-cache +# https://medium.com/windmill-engineering/tips-tricks-for-making-your-golang-container-builds-10x-faster-4cc618a43827 +FROM golang:1.17 as obj-cache +COPY --from=builder /root/.cache /root/.cache + # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details FROM gcr.io/distroless/static:nonroot diff --git a/Makefile b/Makefile index 3af51ae8..62ade1cc 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,10 @@ POSTGRES_OPERATOR_VERSION ?= v1.6.0 POSTGRES_OPERATOR_URL ?= https://raw.githubusercontent.com/zalando/postgres-operator/$(POSTGRES_OPERATOR_VERSION)/manifests POSTGRES_CRD_URL ?= https://raw.githubusercontent.com/zalando/postgres-operator/$(POSTGRES_OPERATOR_VERSION)/charts/postgres-operator/crds/postgresqls.yaml +# Object cache variables +CACHEOBJ_IMG ?= local/postgreslet-builder-cacheobjs +CACHEOBJ_VERSION ?= previous + all: manager # Run tests @@ -90,11 +94,23 @@ generate: controller-gen docker-build: docker build . -t ${IMG}:${VERSION} + +cacheobjs-daily-base: + if [ "$(shell docker images ${CACHEOBJ_IMG}:${CACHEOBJ_VERSION} -q)" = "" ]; then \ + docker build -t ${CACHEOBJ_IMG}:${CACHEOBJ_VERSION} -f Dockerfile --target=obj-cache .; \ + fi; + +cacheobjs: cacheobjs-daily-base + $(call inject-nonce) + docker build --build-arg baseImage=${CACHEOBJ_IMG}:${CACHEOBJ_VERSION} \ + -t ${IMG}:${VERSION} \ + -f Dockerfile . + # Push the docker image docker-push: docker push ${IMG}:${VERSION} -kind-load-image: docker-build +kind-load-image: cacheobjs kind load docker-image ${IMG}:${VERSION} -v 1 # find or download controller-gen @@ -220,5 +236,9 @@ two-kind-clusters: make install-crd-servicemonitor helm upgrade --install postgreslet postgreslet-0.1.0.tgz --namespace postgreslet-system --set-file controlplaneKubeconfig=kubeconfig --set image.tag=latest +destroy-two-kind-clusters: + kind delete cluster --name ctrl + kind delete cluster --name kind + install-crd-servicemonitor: kubectl apply -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.45.0/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml From 0f773742419096ba893d122764e7c74e480af9da Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 2 Nov 2021 16:58:53 +0100 Subject: [PATCH 2/3] update local setup with two clusters --- Makefile | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 62ade1cc..18689f5c 100644 --- a/Makefile +++ b/Makefile @@ -218,15 +218,17 @@ kubebuilder-version-ci: @echo ${KUBEBUILDER_VERSION} two-kind-clusters: - # control-plane-cluster + # + ## control-plane-cluster + ######################## kind create cluster --name ctrl --kubeconfig ./kubeconfig container_ip=$$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 'ctrl-control-plane') ;\ kubectl --kubeconfig=kubeconfig config set-cluster 'kind-ctrl' --server="https://$${container_ip}:6443" make install make create-postgres - # service-clsuter - make helm-clean - make helm + # + ## service-cluster + ######################## kind create cluster sed 's/z.Spec.Volume.StorageClass/\/\/z.Spec.Volume.StorageClass/' -i api/v1/postgres_types.go make kind-load-image @@ -234,7 +236,10 @@ two-kind-clusters: kubectl create ns postgreslet-system --dry-run=client --save-config -o yaml | kubectl apply -f - make install-crd-cwnp make install-crd-servicemonitor - helm upgrade --install postgreslet postgreslet-0.1.0.tgz --namespace postgreslet-system --set-file controlplaneKubeconfig=kubeconfig --set image.tag=latest + # helm repo add metal-stack https://helm.metal-stack.io # stable repo + # helm upgrade --install postgreslet metal-stack/postgreslet --namespace postgreslet-system --values svc-cluster-values.yaml --set-file controlplaneKubeconfig=kubeconfig + helm repo add metal-stack-30 https://helm.metal-stack.io/pull_requests/custom-operator-image # PR repo + helm upgrade --install postgreslet metal-stack-30/postgreslet --namespace postgreslet-system --values svc-cluster-values.yaml --set-file controlplaneKubeconfig=kubeconfig destroy-two-kind-clusters: kind delete cluster --name ctrl @@ -242,3 +247,9 @@ destroy-two-kind-clusters: install-crd-servicemonitor: kubectl apply -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.45.0/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml + +reinstall-postgreslet: kind-load-image + # helm repo add metal-stack https://helm.metal-stack.io # stable repo + # helm upgrade --install postgreslet metal-stack/postgreslet --namespace postgreslet-system --values svc-cluster-values.yaml --set-file controlplaneKubeconfig=kubeconfig + helm repo add metal-stack-30 https://helm.metal-stack.io/pull_requests/custom-operator-image # PR repo + helm upgrade --install postgreslet metal-stack-30/postgreslet --namespace postgreslet-system --values svc-cluster-values.yaml --set-file controlplaneKubeconfig=kubeconfig \ No newline at end of file From 30d52bef9bc266d883ad82181725a62ce2a94414 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 5 Nov 2021 09:30:49 +0100 Subject: [PATCH 3/3] Add linter to Makefile --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 18689f5c..42c97923 100644 --- a/Makefile +++ b/Makefile @@ -252,4 +252,7 @@ reinstall-postgreslet: kind-load-image # helm repo add metal-stack https://helm.metal-stack.io # stable repo # helm upgrade --install postgreslet metal-stack/postgreslet --namespace postgreslet-system --values svc-cluster-values.yaml --set-file controlplaneKubeconfig=kubeconfig helm repo add metal-stack-30 https://helm.metal-stack.io/pull_requests/custom-operator-image # PR repo - helm upgrade --install postgreslet metal-stack-30/postgreslet --namespace postgreslet-system --values svc-cluster-values.yaml --set-file controlplaneKubeconfig=kubeconfig \ No newline at end of file + helm upgrade --install postgreslet metal-stack-30/postgreslet --namespace postgreslet-system --values svc-cluster-values.yaml --set-file controlplaneKubeconfig=kubeconfig + +lint: + golangci-lint run -p bugs -p unused --timeout=5m \ No newline at end of file