Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NO-JIRA: fix(build): use yq to modify kustomization.yaml during deploy targets #828

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ OS_ARCH=$(shell go env GOOS)/$(shell go env GOARCH)
IMAGE_TAG ?= $(RELEASE)_$(DATE)
KUBECTL_BIN ?= bin/kubectl
KUBECTL_VERSION ?= v1.23.11
YQ_BIN ?= bin/yq
YQ_VERSION ?= v4.44.6
NOTEBOOK_REPO_BRANCH_BASE ?= https://raw.githubusercontent.com/opendatahub-io/notebooks/main
REQUIRED_RUNTIME_IMAGE_COMMANDS="curl python3"
REQUIRED_CODE_SERVER_IMAGE_COMMANDS="curl python oc code-server"
Expand Down Expand Up @@ -285,17 +287,28 @@ ifeq (,$(wildcard $(KUBECTL_BIN)))
@chmod +x $(KUBECTL_BIN)
endif

# Download yq binary
.PHONY: bin/yq
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One point of interest here (as this merely follows the pattern established from bin/kubectl) ...

I wonder if we should actually NOT declare a .PHONY target here? as the bin/yq (and likewise bin/kubectl) are actual files on the filesystem... such that we could simply allow make to do what it does ?

pros:

  • wouldn't run and download "stuff" on every invocation

cons:

  • users would ned to manually intervene if we needed to upgrade the version of the binary we pull down

bin/yq:
$(eval YQ_RELEASE_FILE := yq_$(subst /,_,$(OS_ARCH)))
ifeq (,$(wildcard $(YQ_BIN)))
@mkdir -p bin
@curl -sSL https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/${YQ_RELEASE_FILE} > \
$(YQ_BIN)
@chmod +x $(YQ_BIN)
endif

.PHONY: deploy9
deploy9-%: bin/kubectl
deploy9-%: bin/kubectl bin/yq
$(eval TARGET := $(shell echo $* | sed 's/-ubi9-python.*//'))
$(eval PYTHON_VERSION := $(shell echo $* | sed 's/.*-python-//'))
$(eval NOTEBOOK_DIR := $(subst -,/,$(subst cuda-,,$(TARGET)))/ubi9-python-$(PYTHON_VERSION)/kustomize/base)
ifndef NOTEBOOK_TAG
$(eval NOTEBOOK_TAG := $*-$(IMAGE_TAG))
endif
$(info # Deploying notebook from $(NOTEBOOK_DIR) directory...)
@sed -i 's,newName: .*,newName: $(IMAGE_REGISTRY),g' $(NOTEBOOK_DIR)/kustomization.yaml
@sed -i 's,newTag: .*,newTag: $(NOTEBOOK_TAG),g' $(NOTEBOOK_DIR)/kustomization.yaml
@arg=$(IMAGE_REGISTRY) $(YQ_BIN) e -i '.images[].newName = strenv(arg)' $(NOTEBOOK_DIR)/kustomization.yaml
@arg=$(NOTEBOOK_TAG) $(YQ_BIN) e -i '.images[].newTag = strenv(arg)' $(NOTEBOOK_DIR)/kustomization.yaml
$(KUBECTL_BIN) apply -k $(NOTEBOOK_DIR)

.PHONY: undeploy9
Expand All @@ -307,16 +320,16 @@ undeploy9-%: bin/kubectl
$(KUBECTL_BIN) delete -k $(NOTEBOOK_DIR)

.PHONY: deploy-c9s
deploy-c9s-%: bin/kubectl
deploy-c9s-%: bin/kubectl bin/yq
$(eval TARGET := $(shell echo $* | sed 's/-c9s-python.*//'))
$(eval PYTHON_VERSION := $(shell echo $* | sed 's/.*-python-//'))
$(eval NOTEBOOK_DIR := $(subst -,/,$(subst cuda-,,$(TARGET)))/c9s-python-$(PYTHON_VERSION)/kustomize/base)
ifndef NOTEBOOK_TAG
$(eval NOTEBOOK_TAG := $*-$(IMAGE_TAG))
endif
$(info # Deploying notebook from $(NOTEBOOK_DIR) directory...)
@sed -i 's,newName: .*,newName: $(IMAGE_REGISTRY),g' $(NOTEBOOK_DIR)/kustomization.yaml
@sed -i 's,newTag: .*,newTag: $(NOTEBOOK_TAG),g' $(NOTEBOOK_DIR)/kustomization.yaml
@arg=$(IMAGE_REGISTRY) $(YQ_BIN) e -i '.images[].newName = strenv(arg)' $(NOTEBOOK_DIR)/kustomization.yaml
@arg=$(NOTEBOOK_TAG) $(YQ_BIN) e -i '.images[].newTag = strenv(arg)' $(NOTEBOOK_DIR)/kustomization.yaml
$(KUBECTL_BIN) apply -k $(NOTEBOOK_DIR)

.PHONY: undeploy-c9s
Expand Down
Loading