From 8c4a76529b3a438e406351a083d74935a818e3e9 Mon Sep 17 00:00:00 2001 From: Jugwan Eom Date: Wed, 16 Mar 2022 07:04:18 +0000 Subject: [PATCH 1/2] add admin-tools wftpl for keycloak --- .../install-admin-tools-wftpl.yaml | 130 ++++++++++++++++++ .../remove-admin-tools-wftpl.yaml | 18 +++ 2 files changed, 148 insertions(+) create mode 100644 templates/decapod-apps/install-admin-tools-wftpl.yaml create mode 100644 templates/decapod-apps/remove-admin-tools-wftpl.yaml diff --git a/templates/decapod-apps/install-admin-tools-wftpl.yaml b/templates/decapod-apps/install-admin-tools-wftpl.yaml new file mode 100644 index 0000000..28f507a --- /dev/null +++ b/templates/decapod-apps/install-admin-tools-wftpl.yaml @@ -0,0 +1,130 @@ +apiVersion: argoproj.io/v1alpha1 +kind: WorkflowTemplate +metadata: + name: install-admin-tools + namespace: argo +spec: + entrypoint: deploy + arguments: + parameters: + - name: site_name + value: hanu-reference + - name: manifest_repo_url + value: 'https://github.com/openinfradev/decapod-manifests' + - name: revision + value: main + - name: app_prefix + value: "" + - name: keycloak_namespace + value: keycloak + - name: keycloak_db_user_password + value: keycloak + templates: + - name: deploy + dag: + tasks: + - name: create-namespace-for-keycloak + template: create-namespace + arguments: + parameters: + - name: target_namespace + value: "{{workflow.parameters.keycloak_namespace}}" + + - name: keycloak-db-init + template: keycloak-db-init + dependencies: + - create-namespace-for-keycloak + + - name: keycloak-operator + templateRef: + name: create-application + template: installApps + arguments: + parameters: + - name: list + value: | + [ + { "app_group": "admin-tools", "path": "keycloak-operator", "namespace": "{{workflow.parameters.keycloak_namespace}}", "target_cluster": "" } + ] + dependencies: + - create-namespace-for-keycloak + + - name: keycloak + templateRef: + name: create-application + template: installApps + arguments: + parameters: + - name: list + value: | + [ + { "app_group": "admin-tools", "path": "keycloak-resources", "namespace": "{{workflow.parameters.keycloak_namespace}}", "target_cluster": "" } + ] + dependencies: + - keycloak-operator + + - name: create-namespace + arguments: {} + inputs: + parameters: + - name: target_namespace + outputs: {} + metadata: {} + container: + name: create-namespace + image: 'k8s.gcr.io/hyperkube:v1.18.6' + command: + - /bin/bash + - '-c' + - | + function log() { + level=$1 + msg=$2 + date=$(date '+%F %H:%M:%S') + echo "[$date] $level $msg" + } + + kubectl get ns ${TARGET_NAMESPACE} + if [[ $? =~ 1 ]]; then + kubectl create ns ${TARGET_NAMESPACE} + kubectl label ns ${TARGET_NAMESPACE} name=${TARGET_NAMESPACE} + log "INFO" "${TARGET_NAMESPACE} successfully created." + fi + env: + - name: TARGET_NAMESPACE + value: '{{inputs.parameters.target_namespace}}' + resources: {} + activeDeadlineSeconds: 900 + retryStrategy: + limit: 2 + + - name: keycloak-db-init + arguments: {} + inputs: {} + outputs: {} + metadata: {} + container: + name: db-init + image: 'docker.io/bitnami/postgresql:11.12.0-debian-10-r44' + command: + - /bin/bash + - '-cx' + - | + function log() { + level=$1 + msg=$2 + date=$(date '+%F %H:%M:%S') + echo "[$date] $level $msg" + } + + export PGPASSWORD=tacopassword + + /opt/bitnami/postgresql/bin/psql -h postgresql.decapod-db.svc -U postgres -c "CREATE DATABASE keycloak;" + /opt/bitnami/postgresql/bin/psql -h postgresql.decapod-db.svc -U postgres -c "CREATE USER keycloak WITH ENCRYPTED PASSWORD '{{workflow.parameters.keycloak_db_user_password}}';" + /opt/bitnami/postgresql/bin/psql -h postgresql.decapod-db.svc -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE keycloak TO keycloak;" + + log "INFO" "database and user for keycloak are successfully created." + resources: {} + activeDeadlineSeconds: 900 + retryStrategy: + limit: 2 diff --git a/templates/decapod-apps/remove-admin-tools-wftpl.yaml b/templates/decapod-apps/remove-admin-tools-wftpl.yaml new file mode 100644 index 0000000..e830dd6 --- /dev/null +++ b/templates/decapod-apps/remove-admin-tools-wftpl.yaml @@ -0,0 +1,18 @@ +apiVersion: argoproj.io/v1alpha1 +kind: WorkflowTemplate +metadata: + name: remove-admin-tools + namespace: argo +spec: + entrypoint: process + arguments: + parameters: + - name: filter + value: "app=admin-tools" + templates: + - name: process + steps: + - - name: remove_admin-tools + templateRef: + name: delete-apps + template: DeleteAppsByLabel From 0ef4410c95cce02c84064c79551360523f4f55d6 Mon Sep 17 00:00:00 2001 From: Jugwan Eom Date: Thu, 17 Mar 2022 04:54:24 +0000 Subject: [PATCH 2/2] add admin-tools project --- templates/argo-cd/prepare-argocd-wftpl.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/templates/argo-cd/prepare-argocd-wftpl.yaml b/templates/argo-cd/prepare-argocd-wftpl.yaml index 0c08a7b..d185818 100644 --- a/templates/argo-cd/prepare-argocd-wftpl.yaml +++ b/templates/argo-cd/prepare-argocd-wftpl.yaml @@ -81,6 +81,11 @@ spec: if [[ $? != 0 ]]; then ./argocd proj create tks-cluster-aws --dest "*,*" --src "*" --allow-cluster-resource "*/*" fi + + ./argocd proj get admin-tools + if [[ $? != 0 ]]; then + ./argocd proj create admin-tools --dest "*,*" --src "*" --allow-cluster-resource "*/*" + fi env: - name: ARGO_SERVER value: '{{workflow.parameters.argo_server}}'