From 6a0d6f867a2eb4f0e569bcf097603dd1dbdf452d Mon Sep 17 00:00:00 2001 From: Billy McFall <22157057+Billy99@users.noreply.github.com> Date: Mon, 3 Jun 2024 16:10:56 -0400 Subject: [PATCH] build: BPFMAN_IMG & BPFMAN_AGENT_IMG to overwrite image The bpfman-operator is setup to allow BPFMAN_IMG to overwrite the default bpfman image, and BPFMAN_AGENT_IMG to overwrite the bpfman-agent image. However, the Makefile is leveraging kustomize. kustomize can replace an image string in a yaml when it knows the k8s object layout, but these images are passed via a ConfigMap, which is opaque data. So the current implementation doesn't work. kustomize does have a ConfigMapGenrator, which can replace the contents of a ConfigMap. The change is to: * Change the kustomization.yaml to use a `configMapGenerator`. * Use `sed` to replace the default images with those passed in (or just the default image if none were passed in). The `kustomize edit set image` command doesn't work. The `sed` command is changing the file content, so rename kustomization.yaml to kustomization.yaml.env and piped the changes to kustomization.yaml. * Add kustomization.yaml to .gitignore so changes aren't tracked by git. Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com> --- .gitignore | 3 +++ Makefile | 18 ++++++++++++------ config/bpfman-deployment/kustomization.yaml | 11 ----------- .../bpfman-deployment/kustomization.yaml.env | 14 ++++++++++++++ 4 files changed, 29 insertions(+), 17 deletions(-) delete mode 100644 config/bpfman-deployment/kustomization.yaml create mode 100644 config/bpfman-deployment/kustomization.yaml.env diff --git a/.gitignore b/.gitignore index b4beb720c..ad1c9235b 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ go.work # make generate folder /github.com + +# Temporary Kustomize file +config/bpfman-deployment/kustomization.yaml diff --git a/Makefile b/Makefile index 4ee221cf8..f6d9d4955 100644 --- a/Makefile +++ b/Makefile @@ -300,8 +300,10 @@ test-integration: ## Run Integration tests. .PHONY: bundle bundle: operator-sdk generate kustomize manifests ## Generate bundle manifests and metadata, then validate generated files. cd config/bpfman-operator-deployment && $(KUSTOMIZE) edit set image quay.io/bpfman/bpfman-operator=${BPFMAN_OPERATOR_IMG} - cd config/bpfman-deployment && $(KUSTOMIZE) edit set image quay.io/bpfman/bpfman=${BPFMAN_IMG} &&\ - $(KUSTOMIZE) edit set image quay.io/bpfman/bpfman-agent=${BPFMAN_AGENT_IMG} + cd config/bpfman-deployment && \ + sed -e 's@bpfman\.image=.*@bpfman.image=$(BPFMAN_IMG)@' \ + -e 's@bpfman\.agent\.image=.*@bpfman.agent.image=$(BPFMAN_AGENT_IMG)@' \ + kustomization.yaml.env > kustomization.yaml $(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS) cp config/manifests/dependencies.yaml bundle/metadata/ $(OPERATOR_SDK) bundle validate ./bundle @@ -456,8 +458,10 @@ destroy-kind: ## Destroy Kind cluster .PHONY: deploy deploy: manifests kustomize ## Deploy bpfman-operator to the K8s cluster specified in ~/.kube/config with the csi driver initialized. cd config/bpfman-operator-deployment && $(KUSTOMIZE) edit set image quay.io/bpfman/bpfman-operator=${BPFMAN_OPERATOR_IMG} - cd config/bpfman-deployment && $(KUSTOMIZE) edit set image quay.io/bpfman/bpfman=${BPFMAN_IMG} && \ - $(KUSTOMIZE) edit set image quay.io/bpfman/bpfman-agent=${BPFMAN_AGENT_IMG} + cd config/bpfman-deployment && \ + sed -e 's@bpfman\.image=.*@bpfman.image=$(BPFMAN_IMG)@' \ + -e 's@bpfman\.agent\.image=.*@bpfman.agent.image=$(BPFMAN_AGENT_IMG)@' \ + kustomization.yaml.env > kustomization.yaml $(KUSTOMIZE) build config/default | kubectl apply -f - .PHONY: undeploy @@ -479,8 +483,10 @@ run-on-kind: kustomize setup-kind build-images load-images-kind deploy ## Kind D .PHONY: deploy-openshift deploy-openshift: manifests kustomize ## Deploy bpfman-operator to the Openshift cluster specified in ~/.kube/config. cd config/bpfman-operator-deployment && $(KUSTOMIZE) edit set image quay.io/bpfman/bpfman-operator=${BPFMAN_OPERATOR_IMG} - cd config/bpfman-deployment && $(KUSTOMIZE) edit set image quay.io/bpfman/bpfman=${BPFMAN_IMG} \ - && $(KUSTOMIZE) edit set image quay.io/bpfman/bpfman-agent=${BPFMAN_AGENT_IMG} + cd config/bpfman-deployment && \ + sed -e 's@bpfman\.image=.*@bpfman.image=$(BPFMAN_IMG)@' \ + -e 's@bpfman\.agent\.image=.*@bpfman.agent.image=$(BPFMAN_AGENT_IMG)@' \ + kustomization.yaml.env > kustomization.yaml $(KUSTOMIZE) build config/openshift | kubectl apply -f - .PHONY: undeploy-openshift diff --git a/config/bpfman-deployment/kustomization.yaml b/config/bpfman-deployment/kustomization.yaml deleted file mode 100644 index 588074f99..000000000 --- a/config/bpfman-deployment/kustomization.yaml +++ /dev/null @@ -1,11 +0,0 @@ -resources: -- config.yaml -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -images: -- name: quay.io/bpfman/bpfman - newName: quay.io/bpfman/bpfman - newTag: latest -- name: quay.io/bpfman/bpfman-agent - newName: quay.io/bpfman/bpfman-agent - newTag: latest diff --git a/config/bpfman-deployment/kustomization.yaml.env b/config/bpfman-deployment/kustomization.yaml.env new file mode 100644 index 000000000..675494aea --- /dev/null +++ b/config/bpfman-deployment/kustomization.yaml.env @@ -0,0 +1,14 @@ +resources: +- config.yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +# Patch the config.yaml to change bpfman and bpfman-agent image and tag. +# Because it is of "kind: ConfigMap", the data is opaque and kustomize can't +# update image magically. +configMapGenerator: +- behavior: merge + literals: + - bpfman.image=quay.io/bpfman/bpfman:latest + - bpfman.agent.image=quay.io/bpfman/bpfman-agent:latest + name: config + namespace: kube-system