From d6a7888c3241b91c6eb5f4866e70b3fe1b1c51b8 Mon Sep 17 00:00:00 2001 From: Martin Jackson Date: Tue, 21 Sep 2021 13:33:22 -0500 Subject: [PATCH 1/6] Add argocd secret handling --- Makefile | 6 ++++++ util/argo-secret.sh | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 util/argo-secret.sh diff --git a/Makefile b/Makefile index 36df5e9a..f51ca688 100644 --- a/Makefile +++ b/Makefile @@ -12,9 +12,15 @@ init: deploy: helm install $(NAME) install/ -f $(SECRETS) --set main.git.repoURL="$(TARGET_REPO)" --set main.git.revision=$(TARGET_BRANCH) --set main.options.bootstrap=$(BOOTSTRAP) +ifeq ($(BOOTSTRAP),1) + bash util/argocd-secret.sh +endif upgrade: helm upgrade $(NAME) install/ -f $(SECRETS) --set main.git.repoURL="$(TARGET_REPO)" --set main.git.revision=$(TARGET_BRANCH) --set main.options.bootstrap=$(BOOTSTRAP) +ifeq ($(BOOTSTRAP),1) + bash util/argocd-secret.sh +endif uninstall: helm uninstall $(NAME) diff --git a/util/argo-secret.sh b/util/argo-secret.sh new file mode 100755 index 00000000..f98ed6ac --- /dev/null +++ b/util/argo-secret.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +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 manuela-ci >/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) + +cat < Date: Tue, 21 Sep 2021 15:32:14 -0500 Subject: [PATCH 2/6] Add argosecret target --- Makefile | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Makefile b/Makefile index f51ca688..053ecd62 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,43 @@ 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- + 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) From be4ecad99c244cf2491b43d5f11c6526ccba83dc Mon Sep 17 00:00:00 2001 From: Martin Jackson Date: Tue, 21 Sep 2021 15:44:33 -0500 Subject: [PATCH 3/6] Remove unneeded util dir --- util/argo-secret.sh | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100755 util/argo-secret.sh diff --git a/util/argo-secret.sh b/util/argo-secret.sh deleted file mode 100755 index f98ed6ac..00000000 --- a/util/argo-secret.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -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 manuela-ci >/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) - -cat < Date: Tue, 21 Sep 2021 15:46:58 -0500 Subject: [PATCH 4/6] Explain how to use common makefile --- Makefile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 053ecd62..207d0d69 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,8 @@ argosecret: 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) @@ -49,15 +51,9 @@ init: deploy: helm install $(NAME) install/ -f $(SECRETS) --set main.git.repoURL="$(TARGET_REPO)" --set main.git.revision=$(TARGET_BRANCH) --set main.options.bootstrap=$(BOOTSTRAP) -ifeq ($(BOOTSTRAP),1) - bash util/argocd-secret.sh -endif upgrade: helm upgrade $(NAME) install/ -f $(SECRETS) --set main.git.repoURL="$(TARGET_REPO)" --set main.git.revision=$(TARGET_BRANCH) --set main.options.bootstrap=$(BOOTSTRAP) -ifeq ($(BOOTSTRAP),1) - bash util/argocd-secret.sh -endif uninstall: helm uninstall $(NAME) From eda487e16ba13a5c5eeed4d51947c413276831bb Mon Sep 17 00:00:00 2001 From: Andrew Beekhof Date: Tue, 21 Sep 2021 14:11:42 +1000 Subject: [PATCH 5/6] Allow namespaces without operatorgroups for charts that already include them --- site/templates/operatorgroup.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 From 2635a7db35b1ab02d4c51b7d0ffcf8e34d3e5d34 Mon Sep 17 00:00:00 2001 From: Martin Jackson Date: Tue, 21 Sep 2021 18:13:27 -0500 Subject: [PATCH 6/6] Add template toplevel makefile --- Makefile.toplevel | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Makefile.toplevel 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