Skip to content

Commit

Permalink
build: BPFMAN_IMG & BPFMAN_AGENT_IMG to overwrite image
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Billy99 committed Jun 3, 2024
1 parent f8d1443 commit 5ab8047
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ go.work

# make generate folder
/github.com

# Temproary Kustomize file
config/bpfman-deployment/kustomization.yaml
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 0 additions & 11 deletions config/bpfman-deployment/kustomization.yaml

This file was deleted.

14 changes: 14 additions & 0 deletions config/bpfman-deployment/kustomization.yaml.env
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5ab8047

Please sign in to comment.