Skip to content

Commit e225162

Browse files
committed
Rework cluster local deployment for multitenancy
- Upgrade calico version (not needed but local version and version used in Github actions are same) - Adapt Api Helm Chart to manage multitenancy - Adapt deploy_via_helm-dev.sh script to use multitenancy by default
1 parent 682d7fc commit e225162

File tree

3 files changed

+79
-41
lines changed

3 files changed

+79
-41
lines changed

api/kubernetes/deploy_via_helm-dev.sh

Lines changed: 74 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ help() {
1515
echo "- NAMESPACE | string | name of the targeted namespace. Generated when not set"
1616
echo "- ARGO_MINIO_ACCESS_KEY | string | AccessKey for MinIO. Generated when not set"
1717
echo "- ARGO_MINIO_SECRET_KEY | string | SecretKey for MinIO. Generated when not set"
18+
echo "- ARGO_VERSION | string | Version for Argo. default 3.4.9"
19+
echo "- ARGO_CHART_VERSION | string | Version for Argo chart used for Argo. default 0.32.2"
20+
echo "- ARGO_MINIO_VERSION | string | Version for MinIO in Argo. default 12.1.3"
21+
echo "- ARGO_POSTGRESQL_VERSION | string | Version for PostgreSQL in Argo. default 12.1.3"
1822
echo "- ARGO_REQUEUE_TIME | string | Workflow requeue time, 1s by default"
1923
echo "- ARGO_MINIO_REQUESTS_MEMORY | units of bytes (default is 4Gi) | Memory requests for the Argo MinIO server"
2024
echo "- LOKI_PERSISTENCE_MEMORY | units of bytes (default is 4Gi) | Memory for persistence of Loki system"
@@ -29,7 +33,6 @@ help() {
2933
echo "- KEYCLOAK_ADMIN_PASSWORD | admin password for keycloak (generated if not specified)"
3034
echo "- KEYCLOAK_DB_PASSWORD | admin password for keycloak db (generated if not specified)"
3135
echo "- KEYCLOAK_DB_USER_PASSWORD | admin password for keycloak db user (generated if not specified)"
32-
echo "- MULTI_TENANT | boolean | enable multi-tenant mode (default is false)"
3336
echo
3437
echo "Usage: ./$(basename "$0") API_IMAGE_TAG NAMESPACE ARGO_POSTGRESQL_PASSWORD API_VERSION [any additional options to pass as is to the cosmotech-api Helm Chart]"
3538
}
@@ -54,13 +57,13 @@ export ARGO_POSTGRESQL_PASSWORD="$3"
5457
export API_VERSION="$4"
5558
export REQUEUE_TIME="${ARGO_REQUEUE_TIME:-1s}"
5659

57-
export ARGO_RELEASE_NAME=argocsmv2
58-
export MINIO_RELEASE_NAME=miniocsmv2
59-
export POSTGRES_RELEASE_NAME=postgrescsmv2
60-
export ARGO_VERSION="3.4.9"
61-
export ARGO_CHART_VERSION="0.32.2"
62-
export MINIO_VERSION="12.1.3"
63-
export POSTGRESQL_VERSION="11.6.12"
60+
export ARGO_RELEASE_NAME=argo-${NAMESPACE}
61+
export MINIO_RELEASE_NAME=argo-minio-${NAMESPACE}
62+
export POSTGRES_RELEASE_NAME=argo-postgres-${NAMESPACE}
63+
export ARGO_VERSION_ENV=${ARGO_VERSION:-"3.4.9"}
64+
export ARGO_CHART_VERSION_ENV=${ARGO_CHART_VERSION:-"0.32.2"}
65+
export MINIO_VERSION_ENV=${ARGO_MINIO_VERSION:-"12.1.3"}
66+
export POSTGRESQL_VERSION_ENV=${ARGO_POSTGRESQL_VERSION:-"11.6.12"}
6467
export VERSION_REDIS="17.3.14"
6568
export VERSION_REDIS_COSMOTECH="1.0.7"
6669
export VERSION_REDIS_INSIGHT="0.1.0"
@@ -71,7 +74,7 @@ export KEYCLOAK_VERSION="13.4.1"
7174
export ARGO_DATABASE=argo_workflows
7275
export ARGO_POSTGRESQL_USER=argo
7376
export ARGO_BUCKET_NAME=argo-workflows
74-
export ARGO_SERVICE_ACCOUNT=workflowcsmv2
77+
export ARGO_SERVICE_ACCOUNT=argo-${NAMESPACE}-service-account
7578

7679
export NAMESPACE_NGINX="ingress-nginx"
7780
export MONITORING_NAMESPACE="cosmotech-monitoring"
@@ -81,20 +84,21 @@ HELM_CHARTS_BASE_PATH=$(realpath "$(dirname "$0")")
8184
WORKING_DIR=$(mktemp -d -t cosmotech-api-helm-XXXXXXXXXX)
8285
echo "[info] Working directory: ${WORKING_DIR}"
8386
pushd "${WORKING_DIR}"
84-
export KEYCLOAK_NAMESPACE="keycloak"
87+
#export KEYCLOAK_NAMESPACE="cosmotech-iam"
88+
export KEYCLOAK_NAMESPACE="${NAMESPACE}"
8589

8690
# Create namespace if it does not exist
8791
kubectl create namespace "${NAMESPACE}" --dry-run=client -o yaml | kubectl apply -f -
8892

8993
# common exports
90-
export COSMOTECH_API_RELEASE_NAME="cosmotech-api-${API_VERSION}"
94+
export COSMOTECH_API_RELEASE_NAME="cosmotech-api-${NAMESPACE}-${API_VERSION}"
9195
export REDIS_PORT=6379
9296
REDIS_PASSWORD=${REDIS_ADMIN_PASSWORD:-$(kubectl get secret --namespace ${NAMESPACE} cosmotechredis -o jsonpath="{.data.redis-password}" | base64 -d || "")}
9397
if [[ -z "${REDIS_PASSWORD}" ]] ; then
9498
REDIS_PASSWORD=$(date +%s | sha256sum | base64 | head -c 32)
9599
fi
96100

97-
PROM_PASSWORD=${PROM_ADMIN_PASSWORD:-$(kubectl get secret --namespace ${NAMESPACE}-monitoring prometheus-operator-grafana -o jsonpath="{.data.admin-password}" | base64 -d || "")}
101+
PROM_PASSWORD=${PROM_ADMIN_PASSWORD:-$(kubectl get secret --namespace ${MONITORING_NAMESPACE} prometheus-operator-grafana -o jsonpath="{.data.admin-password}" | base64 -d || "")}
98102
if [[ -z "${PROM_PASSWORD}" ]] ; then
99103
PROM_PASSWORD=$(date +%s | sha256sum | base64 | head -c 32)
100104
fi
@@ -106,7 +110,7 @@ kubectl create namespace "${MONITORING_NAMESPACE}" --dry-run=client -o yaml | ku
106110
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
107111
helm repo update
108112

109-
curl -sSL "https://raw.githubusercontent.com/Cosmo-Tech/azure-platform-deployment-tools/main/deployment_scripts/v3.0/kube-prometheus-stack-template.yaml" \
113+
curl -sSL "https://raw.githubusercontent.com/Cosmo-Tech/azure-platform-deployment-tools/JREY/keycloak/deployment_scripts/v3.0/kube-prometheus-stack-template.yaml" \
110114
-o "${WORKING_DIR}"/kube-prometheus-stack-template.yaml
111115

112116
MONITORING_NAMESPACE_VAR=${MONITORING_NAMESPACE} \
@@ -130,17 +134,17 @@ helm upgrade --install prometheus-operator prometheus-community/kube-prometheus-
130134
# Create namespace keycloak if it does not exist
131135
kubectl create namespace ${KEYCLOAK_NAMESPACE} --dry-run=client -o yaml | kubectl apply -f -
132136

133-
KEYCLOAK_ADM_PASSWORD=${KEYCLOAK_ADMIN_PASSWORD:-$(kubectl get secret --namespace ${KEYCLOAK_NAMESPACE} csm-keycloak -o jsonpath="{.data.admin-password}" | base64 -d || "")}
137+
KEYCLOAK_ADM_PASSWORD=${KEYCLOAK_ADMIN_PASSWORD:-$(kubectl get secret --namespace ${KEYCLOAK_NAMESPACE} ${NAMESPACE}-keycloak -o jsonpath="{.data.admin-password}" | base64 -d || "")}
134138
if [[ -z "${KEYCLOAK_ADM_PASSWORD}" ]] ; then
135139
KEYCLOAK_ADM_PASSWORD=$(date +%s | sha256sum | base64 | head -c 32)
136140
fi
137141

138-
KEYCLOAK_DB_PASS=${KEYCLOAK_DB_PASSWORD:-$(kubectl get secret --namespace ${KEYCLOAK_NAMESPACE} csm-keycloak-postgresql -o jsonpath="{.data.postgres-password}" | base64 -d || "")}
142+
KEYCLOAK_DB_PASS=${KEYCLOAK_DB_PASSWORD:-$(kubectl get secret --namespace ${KEYCLOAK_NAMESPACE} ${NAMESPACE}-keycloak-postgresql -o jsonpath="{.data.postgres-password}" | base64 -d || "")}
139143
if [[ -z "${KEYCLOAK_DB_PASS}" ]] ; then
140144
KEYCLOAK_DB_PASS=$(date +%s | sha256sum | base64 | head -c 32)
141145
fi
142146

143-
KEYCLOAK_DB_USER_PASS=${KEYCLOAK_DB_USER_PASSWORD:-$(kubectl get secret --namespace ${KEYCLOAK_NAMESPACE} csm-keycloak-postgresql -o jsonpath="{.data.password}" | base64 -d || "")}
147+
KEYCLOAK_DB_USER_PASS=${KEYCLOAK_DB_USER_PASSWORD:-$(kubectl get secret --namespace ${KEYCLOAK_NAMESPACE} ${NAMESPACE}-keycloak-postgresql -o jsonpath="{.data.password}" | base64 -d || "")}
144148
if [[ -z "${KEYCLOAK_DB_USER_PASS}" ]] ; then
145149
KEYCLOAK_DB_USER_PASS=$(date +%s | sha256sum | base64 | head -c 32)
146150
fi
@@ -152,17 +156,18 @@ curl -sSL "https://raw.githubusercontent.com/Cosmo-Tech/azure-platform-deploymen
152156
-o "${WORKING_DIR}"/csm-keycloak-config-map.yaml
153157

154158
# Create config map for Keycloak base configuration
155-
kubectl create configmap csm-keycloak-map -n ${KEYCLOAK_NAMESPACE} --from-file=csm-keycloak-config-map.yaml -o yaml --dry-run=client | kubectl -n ${KEYCLOAK_NAMESPACE} apply -f -
159+
kubectl create configmap ${NAMESPACE}-keycloak-map -n ${KEYCLOAK_NAMESPACE} --from-file=csm-keycloak-config-map.yaml -o yaml --dry-run=client | kubectl -n ${KEYCLOAK_NAMESPACE} apply -f -
156160

157161
KEYCLOAK_ADM_PASSWORD_VAR=${KEYCLOAK_ADM_PASSWORD} \
158162
KEYCLOAK_DB_PASS_VAR=${KEYCLOAK_DB_PASS} \
159163
KEYCLOAK_DB_USER_PASS_VAR=${KEYCLOAK_DB_USER_PASS} \
164+
NAMESPACE_VAR=${NAMESPACE} \
160165
envsubst < "${WORKING_DIR}"/values-keycloak-config-map-template.yaml > "${WORKING_DIR}"/values-keycloak-config-map.yaml
161166

162167
helm repo add bitnami https://charts.bitnami.com/bitnami
163168
helm repo update
164169

165-
helm upgrade --install csm-keycloak bitnami/keycloak -n ${KEYCLOAK_NAMESPACE} --version ${KEYCLOAK_VERSION} \
170+
helm upgrade --install ${NAMESPACE}-keycloak bitnami/keycloak -n ${KEYCLOAK_NAMESPACE} --version ${KEYCLOAK_VERSION} \
166171
--values values-keycloak-config-map.yaml \
167172
--wait \
168173
--timeout 10m0s
@@ -245,8 +250,8 @@ helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx \
245250

246251
# Redis Cluster
247252

248-
export REDIS_PV_NAME="redis-persistence-volume"
249-
export REDIS_PVC_NAME="redis-persistence-volume-claim"
253+
export REDIS_PV_NAME="${NAMESPACE}-redis-persistence-volume"
254+
export REDIS_PVC_NAME="${NAMESPACE}-redis-persistence-volume-claim"
250255

251256
cat <<EOF > redis-pv.yaml
252257
apiVersion: v1
@@ -373,7 +378,7 @@ metrics:
373378
scrapeTimeout: 10s
374379
EOF
375380

376-
helm upgrade --install ${MINIO_RELEASE_NAME} bitnami/minio --namespace ${NAMESPACE} --version ${MINIO_VERSION} --values values-minio.yaml
381+
helm upgrade --install ${MINIO_RELEASE_NAME} bitnami/minio --namespace ${NAMESPACE} --version ${MINIO_VERSION_ENV} --values values-minio.yaml
377382

378383
# Postgres
379384
cat <<EOF > values-postgresql.yaml
@@ -415,7 +420,7 @@ metrics:
415420
scrapeTimeout: 10s
416421
EOF
417422

418-
helm upgrade --install -n ${NAMESPACE} ${POSTGRES_RELEASE_NAME} bitnami/postgresql --version ${POSTGRESQL_VERSION} --values values-postgresql.yaml
423+
helm upgrade --install -n ${NAMESPACE} ${POSTGRES_RELEASE_NAME} bitnami/postgresql --version ${POSTGRESQL_VERSION_ENV} --values values-postgresql.yaml
419424

420425
export ARGO_POSTGRESQL_SECRET_NAME=argo-postgres-config
421426
cat <<EOF > postgres-secret.yaml
@@ -435,15 +440,22 @@ kubectl apply -n ${NAMESPACE} -f postgres-secret.yaml
435440

436441
# Argo
437442
## CRDs
438-
echo "Installing Argo CRDs"
439-
kubectl apply -n ${NAMESPACE} -f https://raw.githubusercontent.com/argoproj/argo-workflows/v${ARGO_VERSION}/manifests/base/crds/minimal/argoproj.io_clusterworkflowtemplates.yaml
440-
kubectl apply -n ${NAMESPACE} -f https://raw.githubusercontent.com/argoproj/argo-workflows/v${ARGO_VERSION}/manifests/base/crds/minimal/argoproj.io_cronworkflows.yaml
441-
kubectl apply -n ${NAMESPACE} -f https://raw.githubusercontent.com/argoproj/argo-workflows/v${ARGO_VERSION}/manifests/base/crds/minimal/argoproj.io_workflowartifactgctasks.yaml
442-
kubectl apply -n ${NAMESPACE} -f https://raw.githubusercontent.com/argoproj/argo-workflows/v${ARGO_VERSION}/manifests/base/crds/minimal/argoproj.io_workfloweventbindings.yaml
443-
kubectl apply -n ${NAMESPACE} -f https://raw.githubusercontent.com/argoproj/argo-workflows/v${ARGO_VERSION}/manifests/base/crds/minimal/argoproj.io_workflows.yaml
444-
kubectl apply -n ${NAMESPACE} -f https://raw.githubusercontent.com/argoproj/argo-workflows/v${ARGO_VERSION}/manifests/base/crds/minimal/argoproj.io_workflowtaskresults.yaml
445-
kubectl apply -n ${NAMESPACE} -f https://raw.githubusercontent.com/argoproj/argo-workflows/v${ARGO_VERSION}/manifests/base/crds/minimal/argoproj.io_workflowtasksets.yaml
446-
kubectl apply -n ${NAMESPACE} -f https://raw.githubusercontent.com/argoproj/argo-workflows/v${ARGO_VERSION}/manifests/base/crds/minimal/argoproj.io_workflowtemplates.yaml
443+
444+
CRD=('argoproj.io_clusterworkflowtemplates.yaml' 'argoproj.io_cronworkflows.yaml' \
445+
'argoproj.io_workflowartifactgctasks.yaml' 'argoproj.io_workfloweventbindings.yaml' \
446+
'argoproj.io_workflows.yaml' 'argoproj.io_workflowtaskresults.yaml' 'argoproj.io_workflowtasksets.yaml' \
447+
'argoproj.io_workflowtemplates.yaml')
448+
449+
for crd in "${CRD[@]}"
450+
do
451+
echo "Downloading Argo CRDs: https://raw.githubusercontent.com/argoproj/argo-workflows/v${ARGO_VERSION_ENV}/manifests/base/crds/minimal/$crd"
452+
curl -sSL --fail "https://raw.githubusercontent.com/argoproj/argo-workflows/v${ARGO_VERSION_ENV}/manifests/base/crds/minimal/$crd" -o $crd || true
453+
if [[ -e "$crd" ]] ; then
454+
echo "Installing Argo CRDs: $crd"
455+
kubectl apply -n ${NAMESPACE} -f "$crd"
456+
fi
457+
done
458+
447459

448460
## Chart
449461
cat <<EOF > values-argo.yaml
@@ -569,7 +581,7 @@ mainContainer:
569581
EOF
570582

571583
helm repo add argo https://argoproj.github.io/argo-helm
572-
helm upgrade --install -n ${NAMESPACE} ${ARGO_RELEASE_NAME} argo/argo-workflows --version ${ARGO_CHART_VERSION} --values values-argo.yaml
584+
helm upgrade --install -n ${NAMESPACE} ${ARGO_RELEASE_NAME} argo/argo-workflows --version ${ARGO_CHART_VERSION_ENV} --values values-argo.yaml
573585

574586
LOKI_RELEASE_NAME="loki"
575587
helm repo add grafana https://grafana.github.io/helm-charts
@@ -641,15 +653,44 @@ cat <<EOF > values-cosmotech-api-deploy.yaml
641653
replicaCount: 2
642654
api:
643655
version: "$API_VERSION"
644-
multiTenant: ${MULTI_TENANT:-false}
656+
multiTenant: ${MULTI_TENANT:-true}
657+
645658
646659
image:
647660
repository: ghcr.io/cosmo-tech/cosmotech-api
648661
tag: "$API_IMAGE_TAG"
649662
650663
config:
664+
spring:
665+
security:
666+
oauth2:
667+
resource-server:
668+
jwt:
669+
issuer-uri: "https://localhost/${NAMESPACE}/auth/realms/cosmotech"
670+
jwk-set-uri: "http://${NAMESPACE}-keycloak.${NAMESPACE}.svc.cluster.local/auth/realms/cosmotech/protocol/openid-connect/certs"
671+
audiences:
672+
- "account"
651673
csm:
652674
platform:
675+
authorization:
676+
allowed-tenants:
677+
- "${NAMESPACE}"
678+
- "cosmotech"
679+
identityProvider:
680+
code: keycloak
681+
# Use to overwrite openAPI configuration
682+
authorizationUrl: "https://localhost/${NAMESPACE}/auth/realms/cosmotech/protocol/openid-connect/auth"
683+
tokenUrl: "https://localhost/${NAMESPACE}/auth/realms/cosmotech/protocol/openid-connect/token"
684+
defaultScopes:
685+
openid: "OpenId Scope"
686+
email: "Email Scope"
687+
#containerScopes:
688+
# csm.scenario.read: "Read access to scenarios"
689+
# Here you can set custom user and admin groups
690+
# - adminGroup will have same rights that Organization.Admin
691+
# - userGroup will have same rights that Organization.User
692+
# - viewerGroup will have same rights that Organization.Viewer
693+
# Use to define Okta Configuration
653694
argo:
654695
base-uri: "http://${ARGO_RELEASE_NAME}-argo-workflows-server.${NAMESPACE}.svc.cluster.local:2746"
655696
workflows:

api/kubernetes/helm-chart/templates/_helpers.tpl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,17 @@ Create Docker secrets so Argo Workflows can pull images from a private container
8080
Default Ingress path
8181
*/}}
8282
{{- define "cosmotech-api.ingressTenantPath" -}}
83-
{{- if .Values.api.multiTenant }}
84-
{{- printf "%s/%s/" (printf "%s" .Values.api.servletContextPath | trimSuffix "/" ) .Release.Namespace }}
85-
{{- else }}
86-
{{- printf "%s/" (printf "%s" .Values.api.servletContextPath | trimSuffix "/" ) }}
87-
{{- end }}
83+
{{- printf "%s" (printf "%s" .Values.api.servletContextPath | trimSuffix "/" ) }}
8884
{{- end }}
8985

9086
{{/*
9187
API Base path with servlet context, namespace, version
9288
*/}}
9389
{{- define "cosmotech-api.apiBasePath" -}}
9490
{{- if eq .Values.api.version "latest" }}
95-
{{- printf "%s/" (include "cosmotech-api.ingressTenantPath" . | trimSuffix "/" ) }}
91+
{{- printf "%s" (include "cosmotech-api.ingressTenantPath" . | trimSuffix "/" ) }}
9692
{{- else }}
97-
{{- printf "%s/%s/" (include "cosmotech-api.ingressTenantPath" . | trimSuffix "/" ) (printf "%s" .Values.api.version | trimSuffix "/" ) }}
93+
{{- printf "%s/%s" (include "cosmotech-api.ingressTenantPath" . | trimSuffix "/" ) (printf "%s" .Values.api.version | trimSuffix "/" ) }}
9894
{{- end }}
9995
{{- end }}
10096

@@ -108,6 +104,7 @@ spring:
108104

109105
api:
110106
version: "{{ .Values.api.version }}"
107+
servletContextPath: {{ include "cosmotech-api.apiBasePath" . }}
111108

112109
server:
113110
servlet:

scripts/kubernetes/create-local-k8s-cluster.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,4 @@ helm repo add projectcalico https://docs.tigera.io/calico/charts
165165
helm --kube-context="${kubectl_ctx}" \
166166
install calico \
167167
projectcalico/tigera-operator \
168-
--version v3.21.2
168+
--version v3.24.3

0 commit comments

Comments
 (0)