diff --git a/Makefile b/Makefile index 36df5e9a..207d0d69 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,45 @@ NAME=$(shell basename `pwd`) TARGET_REPO=$(shell git remote show origin | grep Push | sed -e 's/.*URL://' -e 's%:%/%' -e 's%git@%https://%') TARGET_BRANCH=$(shell git branch --show-current) +# This is to eliminate the need to install and worry about a separate shell script somewhere in the directory structure +# There's a lot of GNU Make magic happening here: +# .ONESHELL passes the whole task into a single shell instance +# $$ is a Makefile idiom to preserve the single $ otherwise make consumes them +# tabs are necessary +# The patch to oc apply uses JSON because it's not as sensitive to indentation and doesn't need heredoc +.ONESHELL: +SHELL = bash +argosecret: + target_ns=$(TARGET_NAMESPACE) + ns=0 + gitops=0 + + # Check for Namespaces and Secrets to be ready (it takes the cluster a while to deploy them) + while [ 1 ]; do + if [ oc get namespace $$target_ns >/dev/null 2>/dev/null ]; then + ns=0 + else + ns=1 + fi + + if [ oc -n openshift-gitops extract secrets/openshift-gitops-cluster --to=- 1>/dev/null 2>/dev/null ]; then + gitops=0 + else + gitops=1 + fi + + if [ "$$gitops" == 1 -a "$$ns" == 1 ]; then + break + fi + done + + user=$$(echo admin | base64) + password=$$(oc -n openshift-gitops extract secrets/openshift-gitops-cluster --to=- 2>/dev/null | base64) + + echo "{ \"apiVersion\": \"v1\", \"kind\": \"Secret\", \"metadata\": { \"name\": \"argocd-env\", \"namespace\": \"$$target_ns\" }, \"data\": { \"ARGOCD_PASSWORD\": \"$$password\", \"ARGOCD_USERNAME\": \"$$user\" }, \"type\": \"Opaque\" }" | oc apply -f- + +# Makefiles in the individual patterns should call these targets explicitly +# e.g. from manufacturing-ai-ml-edge: make -f common/Makefile show show: helm template install/ --name-template $(NAME) -f $(SECRETS) --set main.git.repoURL="$(TARGET_REPO)" --set main.git.revision=$(TARGET_BRANCH) --set main.options.bootstrap=$(BOOTSTRAP) diff --git a/Makefile.toplevel b/Makefile.toplevel new file mode 100644 index 00000000..b82b5d77 --- /dev/null +++ b/Makefile.toplevel @@ -0,0 +1,26 @@ +# This is an example top-level makefile for a new pattern. It delegates the tasks to the common makefile. +BOOTSTRAP=1 +ARGO_TARGET_NAMESPACE=replaceme + +show: + make -f common/Makefile show + +init: + make -f common/Makefile init + +deploy: + make -f common/Makefile deploy +ifeq ($(BOOTSTRAP),1) + make -f common/Makefile TARGET_NAMESPACE=$(ARGO_TARGET_NAMESPACE) argosecret +endif + +upgrade: + make -f common/Makefile upgrade +ifeq ($(BOOTSTRAP),1) + make -f common/Makefile TARGET_NAMESPACE=$(ARGO_TARGET_NAMESPACE) argosecret +endif + +uninstall: + make -f common/Makefile uninstall + +.phony: install diff --git a/site/templates/operatorgroup.yaml b/site/templates/operatorgroup.yaml index 52b873c3..d22b6299 100644 --- a/site/templates/operatorgroup.yaml +++ b/site/templates/operatorgroup.yaml @@ -1,4 +1,6 @@ {{- range .Values.site.namespaces }} + +{{- if empty $.Values.site.operatorgroupExcludes }} apiVersion: operators.coreos.com/v1 kind: OperatorGroup metadata: @@ -8,4 +10,16 @@ spec: targetNamespaces: - {{ . }} --- +{{- else if not (has . $.Values.site.operatorgroupExcludes) }} +apiVersion: operators.coreos.com/v1 +kind: OperatorGroup +metadata: + name: {{ . }}-operator-group + namespace: {{ . }} +spec: + targetNamespaces: + - {{ . }} +--- +{{- end }} + {{- end }} \ No newline at end of file