From fb383798ee6438b688a2168c967bcea304885643 Mon Sep 17 00:00:00 2001 From: "J. Harte" <13206585+boonware@users.noreply.github.com> Date: Thu, 13 Feb 2025 14:57:20 +0000 Subject: [PATCH 1/4] migrate to jinjanate --- image/cli/mascli/functions/gitops_bootstrap | 6 ++--- .../mascli/functions/gitops_cis_compliance | 2 +- image/cli/mascli/functions/gitops_cluster | 26 +++++++++---------- image/cli/mascli/functions/gitops_cp4d | 2 +- .../cli/mascli/functions/gitops_cp4d_service | 4 +-- image/cli/mascli/functions/gitops_db2u | 2 +- .../cli/mascli/functions/gitops_db2u_database | 4 +-- image/cli/mascli/functions/gitops_dro | 2 +- image/cli/mascli/functions/gitops_mas_config | 4 +-- image/cli/mascli/functions/gitops_nvidia_gpu | 2 +- image/cli/mascli/functions/gitops_suite | 6 ++--- .../mascli/functions/gitops_suite_app_config | 6 ++--- .../mascli/functions/gitops_suite_app_install | 4 +-- .../mascli/functions/gitops_suite_workspace | 4 +-- image/cli/mascli/functions/internal/utils | 13 ++++++++++ image/cli/mascli/templates/filters/yaml.py | 6 +++++ 16 files changed, 56 insertions(+), 37 deletions(-) create mode 100644 image/cli/mascli/templates/filters/yaml.py diff --git a/image/cli/mascli/functions/gitops_bootstrap b/image/cli/mascli/functions/gitops_bootstrap index 8080dce3a4..53727b54d7 100644 --- a/image/cli/mascli/functions/gitops_bootstrap +++ b/image/cli/mascli/functions/gitops_bootstrap @@ -179,7 +179,7 @@ function gitops_bootstrap() { # 2. Create Secret Manager secret echo 'Create Secret Manager Backend Secret' - jinja -X .+ ${CLI_DIR}/templates/gitops/bootstrap/secret-${AVP_TYPE}.yaml.j2 | oc apply -f - + jinja ${CLI_DIR}/templates/gitops/bootstrap/secret-${AVP_TYPE}.yaml.j2 | oc apply -f - # 3. Create repo server SA echo 'Create ArgoCD repo server service account' @@ -204,11 +204,11 @@ function gitops_bootstrap() { oc wait --for=jsonpath='{.status.applicationController}'=Running argocd/openshift-gitops -n openshift-gitops --timeout=30m # 6. Add the GitHub PAT secret (used to authenticate to your environment repository, which is assumed to be private) - jinja -X .+ ${CLI_DIR}/templates/gitops/bootstrap/secret-github.yaml.j2 | oc apply -f - + jinja ${CLI_DIR}/templates/gitops/bootstrap/secret-github.yaml.j2 | oc apply -f - # 7. Add the root project and application oc apply -f ${CLI_DIR}/templates/gitops/bootstrap/mas-appproject.yaml - jinja -X .+ ${CLI_DIR}/templates/gitops/bootstrap/root-application.yaml.j2 | oc apply -f - + jinja ${CLI_DIR}/templates/gitops/bootstrap/root-application.yaml.j2 | oc apply -f - # 8. Patch openshift-marketplace and kube-system to allow GitOps to manage resources in the namespace echo 'Patch standard namespaces to enable GitOps management' diff --git a/image/cli/mascli/functions/gitops_cis_compliance b/image/cli/mascli/functions/gitops_cis_compliance index 4a6ad59a7a..361bab49b8 100644 --- a/image/cli/mascli/functions/gitops_cis_compliance +++ b/image/cli/mascli/functions/gitops_cis_compliance @@ -202,7 +202,7 @@ function gitops_cis_compliance() { echo echo_h2 "Generating Argo Applications" echo "- IBM Cis Compliance" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/cis-compliance.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/cis-compliance.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/cis-compliance.yaml.j2 ${GITOPS_CLUSTER_DIR}/cis-compliance.yaml # Commit and push to github target repo # --------------------------------------------------------------------------- diff --git a/image/cli/mascli/functions/gitops_cluster b/image/cli/mascli/functions/gitops_cluster index 0e8e3151d2..79bf62b6b7 100644 --- a/image/cli/mascli/functions/gitops_cluster +++ b/image/cli/mascli/functions/gitops_cluster @@ -587,7 +587,7 @@ function gitops_cluster() { export ICR_AUTH_TOKEN=$(echo -n $ICR_USERNAME:$ICR_PASSWORD | base64 -w 0) echo "- Generate image pull secret" - jinja -X .+ $CLI_DIR/templates/gitops/ibm-entitlement-with-artifactory.json.j2 -o ${GITOPS_CLUSTER_DIR}/ibm-entitlement-with-artifactory.json + jinja $CLI_DIR/templates/gitops/ibm-entitlement-with-artifactory.json.j2 ${GITOPS_CLUSTER_DIR}/ibm-entitlement-with-artifactory.json IBM_ENTITLEMENT_WITH_ARTIFACTORY=${GITOPS_CLUSTER_DIR}/ibm-entitlement-with-artifactory.json IBM_ENTITLEMENT_WITH_ARTIFACTORY=$(cat $IBM_ENTITLEMENT_WITH_ARTIFACTORY) @@ -620,63 +620,63 @@ function gitops_cluster() { echo_h2 "Generating Argo Applications" echo "- Base Config" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/ibm-mas-cluster-base.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/ibm-mas-cluster-base.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/ibm-mas-cluster-base.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-mas-cluster-base.yaml echo "- IBM Operator Catalog" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/ibm-operator-catalog.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/ibm-operator-catalog.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/ibm-operator-catalog.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-operator-catalog.yaml echo "- Redhat Cert Manager" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/redhat-cert-manager.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/redhat-cert-manager.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/redhat-cert-manager.yaml.j2 ${GITOPS_CLUSTER_DIR}/redhat-cert-manager.yaml if [[ "$INSTALL_SELENIUM_GRID" == "true" ]]; then echo "- Selenium Grid" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/selenium-grid.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/selenium-grid.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/selenium-grid.yaml.j2 ${GITOPS_CLUSTER_DIR}/selenium-grid.yaml fi if [[ "$CLUSTER_PROMOTION" == "true" ]]; then ESCAPED_CLUSTER_VALUES=${CLUSTER_PROMOTION_CLUSTER_VALUES//\"/\\\"} export ESCAPED_CLUSTER_VALUES=${ESCAPED_CLUSTER_VALUES//$'\n'/\\n} echo "- Cluster Promotion" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/cluster-promotion.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/cluster-promotion.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/cluster-promotion.yaml.j2 ${GITOPS_CLUSTER_DIR}/cluster-promotion.yaml fi if [[ -n "$CUSTOM_SA_NAMESPACE" ]]; then echo "- Custom Cluster Service Accounts" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/custom-sa.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/custom-sa.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/custom-sa.yaml.j2 ${GITOPS_CLUSTER_DIR}/custom-sa.yaml fi if [[ -n "$DNS_PROVIDER" ]]; then echo "- IBM CIS Cert Manager" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/ibm-cis-cert-manager.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/ibm-cis-cert-manager.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/ibm-cis-cert-manager.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-cis-cert-manager.yaml fi if [[ "$INSTALL_GROUP_SYNC_OPERATOR" == "true" ]]; then echo "- Group Sync Operator" sm_verify_secret_exists $SECRET_NAME_ISV_CLIENT "client_secret,client_id" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/group-sync-operator.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/group-sync-operator.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/group-sync-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/group-sync-operator.yaml fi if [[ "$INSTALL_IBM_RBAC" == "true" ]]; then echo "- IBM RBAC" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/ibm-rbac.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/ibm-rbac.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/ibm-rbac.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-rbac.yaml fi if [[ "$INSTALL_FALCON_OPERATOR" == "true" ]]; then echo "- CrowdStrike Falcon Operator" sm_verify_secret_exists $SECRET_NAME_FALCON_CLIENT "client_secret,client_id" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/falcon-operator.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/falcon-operator.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/falcon-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/falcon-operator.yaml fi if [[ -n "$CLUSTER_LOGGING_OPERATOR_INSTALL" ]]; then echo "- Cluster Logging Operator" sm_verify_secret_exists $SECRET_NAME_CLOUDWATCH "aws_access_key_id,aws_secret_access_key" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/cluster-logging-operator.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/cluster-logging-operator.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/cluster-logging-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/cluster-logging-operator.yaml fi if [[ -n "$INSTANA_AGENT_OPERATOR_INSTALL" ]]; then echo "- Instana Agent Operator" sm_verify_secret_exists $SECRET_NAME_INSTANA "key" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/instana-agent-operator.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/instana-agent-operator.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instana-agent-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/instana-agent-operator.yaml fi # Commit and push to github target repo diff --git a/image/cli/mascli/functions/gitops_cp4d b/image/cli/mascli/functions/gitops_cp4d index f4f2ce9969..5510362369 100644 --- a/image/cli/mascli/functions/gitops_cp4d +++ b/image/cli/mascli/functions/gitops_cp4d @@ -312,7 +312,7 @@ function gitops_cp4d() { echo "- CP4D operator" echo "Generating IBM CP4D file ${GITOPS_INSTANCE_DIR}/ibm-cp4d.yaml" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-cp4d.yaml.j2 -o ${GITOPS_INSTANCE_DIR}/ibm-cp4d.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-cp4d.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-cp4d.yaml # Commit and push to github target repo diff --git a/image/cli/mascli/functions/gitops_cp4d_service b/image/cli/mascli/functions/gitops_cp4d_service index 71c1fae445..27ad5dcf5f 100644 --- a/image/cli/mascli/functions/gitops_cp4d_service +++ b/image/cli/mascli/functions/gitops_cp4d_service @@ -378,14 +378,14 @@ function gitops_cp4d_service() { if [[ "$CPD_SERVICE_NAME" == "wsl" || "$CPD_SERVICE_NAME" == "wml" || "$CPD_SERVICE_NAME" == "spss" ]]; then echo "Generating IBM CPD Service file ${GITOPS_INSTANCE_DIR}/ibm-cp4d-services-base.yaml" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-cp4d-services-base.yaml.j2 -o ${GITOPS_INSTANCE_DIR}/ibm-cp4d-services-base.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-cp4d-services-base.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-cp4d-services-base.yaml fi echo echo "- ${CPD_SERVICE_NAME} operator" echo "Generating IBM CPD Service file ${GITOPS_INSTANCE_DIR}/ibm-${CPD_SERVICE_NAME}.yaml" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-${CPD_SERVICE_NAME}.yaml.j2 -o ${GITOPS_INSTANCE_DIR}/ibm-${CPD_SERVICE_NAME}.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-${CPD_SERVICE_NAME}.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-${CPD_SERVICE_NAME}.yaml # Commit and push to github target repo # --------------------------------------------------------------------------- diff --git a/image/cli/mascli/functions/gitops_db2u b/image/cli/mascli/functions/gitops_db2u index 3823f82573..7fdae30d6b 100644 --- a/image/cli/mascli/functions/gitops_db2u +++ b/image/cli/mascli/functions/gitops_db2u @@ -262,7 +262,7 @@ function gitops_db2u() { export IBM_ENTITLEMENT_KEY=$SECRET_KEY_IBM_ENTITLEMENT echo "Generating DB2U file ${GITOPS_INSTANCE_DIR}/ibm-db2u.yaml" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-db2u.yaml.j2 -o ${GITOPS_INSTANCE_DIR}/ibm-db2u.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-db2u.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-db2u.yaml # Commit and push to github target repo # --------------------------------------------------------------------------- diff --git a/image/cli/mascli/functions/gitops_db2u_database b/image/cli/mascli/functions/gitops_db2u_database index 94820b736c..29908a10d7 100644 --- a/image/cli/mascli/functions/gitops_db2u_database +++ b/image/cli/mascli/functions/gitops_db2u_database @@ -730,7 +730,7 @@ DB2_WORKLOAD: '${DB2_WORKLOAD}'" # If the file doesn't exist, create a blank one if ! [ -f ${CONFIGS_FILE} ]; then - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/instance/db2-databases/ibm-db2u-database-common.yaml.j2 > $CONFIGS_FILE + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/db2-databases/ibm-db2u-database-common.yaml.j2 $CONFIGS_FILE fi # Remove any existing config with this name @@ -740,7 +740,7 @@ DB2_WORKLOAD: '${DB2_WORKLOAD}'" echo -n "" > ${TEMP_DIR}/newconfig.yaml # Render the appropriate template for the config into a new file. For standby database, it will be generated only if it is a replica task and replica is enabled. if [[ (${IS_REPLICA_TASK} == 'false') || (${IS_REPLICA_TASK} == 'true' && ${REPLICA_DB} == 'true') ]]; then - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/instance/db2-databases/ibm-db2u-database.yaml.j2 | yq '{"ibm_db2u_databases": [] + .}' > ${TEMP_DIR}/newconfig.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/db2-databases/ibm-db2u-database.yaml.j2 | yq '{"ibm_db2u_databases": [] + .}' > ${TEMP_DIR}/newconfig.yaml fi # Merge the two files diff --git a/image/cli/mascli/functions/gitops_dro b/image/cli/mascli/functions/gitops_dro index d0a6e3d497..ff1a34f9e9 100644 --- a/image/cli/mascli/functions/gitops_dro +++ b/image/cli/mascli/functions/gitops_dro @@ -292,7 +292,7 @@ function gitops_dro() { export IBM_ENTITLEMENT_KEY=$SECRET_KEY_IBM_ENTITLEMENT echo "Generating dro file ${GITOPS_CLUSTER_DIR}/ibm-dro.yaml" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/ibm-dro.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/ibm-dro.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/ibm-dro.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-dro.yaml # Commit and push to github target repo # --------------------------------------------------------------------------- diff --git a/image/cli/mascli/functions/gitops_mas_config b/image/cli/mascli/functions/gitops_mas_config index 0bda9a950e..de50dbc748 100644 --- a/image/cli/mascli/functions/gitops_mas_config +++ b/image/cli/mascli/functions/gitops_mas_config @@ -839,14 +839,14 @@ function gitops_mas_config() { # If the file doesn't exist, create a blank one if ! [ -f ${CONFIGS_FILE} ]; then - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/instance/configs/ibm-mas-config-common.yaml.j2 > $CONFIGS_FILE + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/configs/ibm-mas-config-common.yaml.j2 $CONFIGS_FILE fi # Remove any existing config with this name yq 'del(.ibm_mas_suite_configs[] | select(.mas_config_name == "'${MAS_CONFIG_NAME}'"))' $CONFIGS_FILE > $TEMP_DIR/configs.yaml # Render the appropriate template for the config into a new file - jinja -X .+ -d $ADDITIONAL_JINJA_PARAMS_FILE $CLI_DIR/templates/gitops/appset-configs/cluster/instance/configs/ibm-mas-${MAS_CONFIG_TYPE}-config.yaml.j2 | yq '{"ibm_mas_suite_configs": [] + .}' > ${TEMP_DIR}/newconfig.yaml + jinjanate --quiet --undefined $CLI_DIR/templates/gitops/appset-configs/cluster/instance/configs/ibm-mas-${MAS_CONFIG_TYPE}-config.yaml.j2 $ADDITIONAL_JINJA_PARAMS_FILE | yq '{"ibm_mas_suite_configs": [] + .}' > ${TEMP_DIR}/newconfig.yaml # Merge the two files yq eval-all '. as $item ireduce ({}; . *+ $item)' $TEMP_DIR/configs.yaml ${TEMP_DIR}/newconfig.yaml > $CONFIGS_FILE diff --git a/image/cli/mascli/functions/gitops_nvidia_gpu b/image/cli/mascli/functions/gitops_nvidia_gpu index 98e99e100b..73d9f34301 100644 --- a/image/cli/mascli/functions/gitops_nvidia_gpu +++ b/image/cli/mascli/functions/gitops_nvidia_gpu @@ -285,7 +285,7 @@ function gitops_nvidia_gpu() { echo "- Nvidia GPU Operator" echo "Generating Nvidia GPU operator file ${GITOPS_CLUSTER_DIR}/nvidia-gpu-operator.yaml" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/nvidia-gpu-operator.yaml.j2 -o ${GITOPS_CLUSTER_DIR}/nvidia-gpu-operator.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/nvidia-gpu-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/nvidia-gpu-operator.yaml # Commit and push to github target repo # --------------------------------------------------------------------------- diff --git a/image/cli/mascli/functions/gitops_suite b/image/cli/mascli/functions/gitops_suite index 2f13c14bf2..1a7c89c569 100644 --- a/image/cli/mascli/functions/gitops_suite +++ b/image/cli/mascli/functions/gitops_suite @@ -692,13 +692,13 @@ function gitops_suite() { echo_h2 "Generating Argo Project and Applications" echo "- Base Config" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-instance-base.yaml.j2 -o ${GITOPS_INSTANCE_DIR}/ibm-mas-instance-base.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-instance-base.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-mas-instance-base.yaml echo "- IBM Suite License Service" - jinja -X .+ -d $MONGO_CONFIG_FILE $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-sls.yaml.j2 -o ${GITOPS_INSTANCE_DIR}/ibm-sls.yaml + jinjanate --quiet --undefined $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-sls.yaml.j2 $MONGO_CONFIG_FILE -o ${GITOPS_INSTANCE_DIR}/ibm-sls.yaml echo "- IBM Maximo Application Suite Core Platform" - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-suite.yaml.j2 -o ${GITOPS_INSTANCE_DIR}/ibm-mas-suite.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-suite.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-mas-suite.yaml # Commit and push to github target repo diff --git a/image/cli/mascli/functions/gitops_suite_app_config b/image/cli/mascli/functions/gitops_suite_app_config index 2523257a70..465da1dd2e 100644 --- a/image/cli/mascli/functions/gitops_suite_app_config +++ b/image/cli/mascli/functions/gitops_suite_app_config @@ -512,7 +512,7 @@ function gitops_suite_app_config() { else echo echo_h2 "Using default application spec for $MAS_APP_ID" - jinja -X .+ $CLI_DIR/templates/gitops/app-ws-spec-defaults/${MAS_APP_ID}.yaml.j2 -o ${TEMP_DIR}/${MAS_APP_ID}-appws-spec.yaml + jinja $CLI_DIR/templates/gitops/app-ws-spec-defaults/${MAS_APP_ID}.yaml.j2 ${TEMP_DIR}/${MAS_APP_ID}-appws-spec.yaml export MAS_APPWS_SPEC=$(cat ${TEMP_DIR}/${MAS_APP_ID}-appws-spec.yaml | yq '.' --output-format yaml) fi echo @@ -562,7 +562,7 @@ function gitops_suite_app_config() { # If the file doesn't exist, create a blank one if ! [ -f ${CONFIGS_FILE} ]; then - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/instance/masapp/ibm-mas-masapp-config-common.yaml.j2 > $CONFIGS_FILE + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/masapp/ibm-mas-masapp-config-common.yaml.j2 $CONFIGS_FILE fi @@ -570,7 +570,7 @@ function gitops_suite_app_config() { yq 'del(.ibm_mas_masapp_configs[] | select(.mas_app_id == "'${MAS_APP_ID}'" and .mas_workspace_id == "'${MAS_WORKSPACE_ID}'"))' $CONFIGS_FILE > $TEMP_DIR/configs.yaml # Render the appropriate template for the config into a new file - jinja -X .+ -d $ADDITIONAL_JINJA_PARAMS_FILE $CLI_DIR/templates/gitops/appset-configs/cluster/instance/masapp/ibm-mas-masapp-config.yaml.j2 | yq '{"ibm_mas_masapp_configs": [] + .}' > ${TEMP_DIR}/newconfig.yaml + jinjanate --quiet --undefined $CLI_DIR/templates/gitops/appset-configs/cluster/instance/masapp/ibm-mas-masapp-config.yaml.j2 $ADDITIONAL_JINJA_PARAMS_FILE | yq '{"ibm_mas_masapp_configs": [] + .}' > ${TEMP_DIR}/newconfig.yaml # Merge the two files yq eval-all '. as $item ireduce ({}; . *+ $item)' $TEMP_DIR/configs.yaml ${TEMP_DIR}/newconfig.yaml > $CONFIGS_FILE diff --git a/image/cli/mascli/functions/gitops_suite_app_install b/image/cli/mascli/functions/gitops_suite_app_install index 1d9011d253..23a271dc75 100644 --- a/image/cli/mascli/functions/gitops_suite_app_install +++ b/image/cli/mascli/functions/gitops_suite_app_install @@ -363,7 +363,7 @@ function gitops_suite_app_install() { else echo echo_h2 "Using default application spec for $MAS_APP_ID" - jinja -X .+ $CLI_DIR/templates/gitops/app-spec-defaults/${MAS_APP_ID}.yaml.j2 -o ${TEMP_DIR}/${MAS_APP_ID}-app-spec.yaml + jinja $CLI_DIR/templates/gitops/app-spec-defaults/${MAS_APP_ID}.yaml.j2 ${TEMP_DIR}/${MAS_APP_ID}-app-spec.yaml export MAS_APP_SPEC=$(cat ${TEMP_DIR}/${MAS_APP_ID}-app-spec.yaml | yq '.' --output-format yaml) fi echo_reset_dim "MAS_APP_SPEC ............................ ${COLOR_MAGENTA}${MAS_APP_SPEC}" @@ -428,7 +428,7 @@ function gitops_suite_app_install() { echo "- IBM MAS Application Install" CONFIG_FILE=${GITOPS_INSTANCE_DIR}/ibm-mas-masapp-${MAS_APP_ID}-install.yaml - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/instance/masapp/ibm-mas-masapp-install.yaml.j2 -o ${CONFIG_FILE} + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/masapp/ibm-mas-masapp-install.yaml.j2 ${CONFIG_FILE} echo_h2 "Generated configuration file (${CONFIG_FILE})" diff --git a/image/cli/mascli/functions/gitops_suite_workspace b/image/cli/mascli/functions/gitops_suite_workspace index a5cb1a542e..da66dba9c4 100644 --- a/image/cli/mascli/functions/gitops_suite_workspace +++ b/image/cli/mascli/functions/gitops_suite_workspace @@ -236,14 +236,14 @@ function gitops_suite_workspace() { # If the file doesn't exist, create a blank one if ! [ -f ${CONFIGS_FILE} ]; then - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-workspaces-common.yaml.j2 > $CONFIGS_FILE + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-workspaces-common.yaml.j2 $CONFIGS_FILE fi # Remove any existing config with this name yq 'del(.ibm_mas_workspaces[] | select(.mas_workspace_id == "'${MAS_WORKSPACE_ID}'"))' $CONFIGS_FILE > $TEMP_DIR/configs.yaml # Render the appropriate template for the config into a new file - jinja -X .+ $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-workspace.yaml.j2 | yq '{"ibm_mas_workspaces": [] + .}' > ${TEMP_DIR}/newconfig.yaml + jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-workspace.yaml.j2 | yq '{"ibm_mas_workspaces": [] + .}' > ${TEMP_DIR}/newconfig.yaml # Merge the two files yq eval-all '. as $item ireduce ({}; . *+ $item)' $TEMP_DIR/configs.yaml ${TEMP_DIR}/newconfig.yaml > $CONFIGS_FILE diff --git a/image/cli/mascli/functions/internal/utils b/image/cli/mascli/functions/internal/utils index aeb4a5533f..706c0b2c1c 100644 --- a/image/cli/mascli/functions/internal/utils +++ b/image/cli/mascli/functions/internal/utils @@ -347,3 +347,16 @@ function ocp_version_check() { exit 1 fi } + +function jinja() { + local template_path=$1 + local output_path=$2 + local filter_files=$(ls $CLI_DIR/templates/filters/*.py) + for file in $filter_files; do + local filter_params="${filter_params} --filters ${file}" + done + if [ -n "$output_path" ]; then + local output_opts="-o ${output_path}" + fi + jinjanate --quiet --undefined $filter_params $template_path $output_opts +} diff --git a/image/cli/mascli/templates/filters/yaml.py b/image/cli/mascli/templates/filters/yaml.py new file mode 100644 index 0000000000..2aa564cbbe --- /dev/null +++ b/image/cli/mascli/templates/filters/yaml.py @@ -0,0 +1,6 @@ +import yaml + + +# Convert a string representation of YAML to actual YAML +def toYaml(value: str) -> dict: + return yaml.safe_load(value) From 66616b395223ec625bea65d9dfbd206f41e980da Mon Sep 17 00:00:00 2001 From: "J. Harte" <13206585+boonware@users.noreply.github.com> Date: Tue, 18 Feb 2025 09:33:39 +0000 Subject: [PATCH 2/4] import env --- image/cli/mascli/functions/gitops_mas_config | 2 +- image/cli/mascli/functions/gitops_suite | 2 +- image/cli/mascli/functions/gitops_suite_app_config | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/image/cli/mascli/functions/gitops_mas_config b/image/cli/mascli/functions/gitops_mas_config index de50dbc748..371398a869 100644 --- a/image/cli/mascli/functions/gitops_mas_config +++ b/image/cli/mascli/functions/gitops_mas_config @@ -846,7 +846,7 @@ function gitops_mas_config() { yq 'del(.ibm_mas_suite_configs[] | select(.mas_config_name == "'${MAS_CONFIG_NAME}'"))' $CONFIGS_FILE > $TEMP_DIR/configs.yaml # Render the appropriate template for the config into a new file - jinjanate --quiet --undefined $CLI_DIR/templates/gitops/appset-configs/cluster/instance/configs/ibm-mas-${MAS_CONFIG_TYPE}-config.yaml.j2 $ADDITIONAL_JINJA_PARAMS_FILE | yq '{"ibm_mas_suite_configs": [] + .}' > ${TEMP_DIR}/newconfig.yaml + jinjanate --quiet --undefined --import-env='' $CLI_DIR/templates/gitops/appset-configs/cluster/instance/configs/ibm-mas-${MAS_CONFIG_TYPE}-config.yaml.j2 $ADDITIONAL_JINJA_PARAMS_FILE | yq '{"ibm_mas_suite_configs": [] + .}' > ${TEMP_DIR}/newconfig.yaml # Merge the two files yq eval-all '. as $item ireduce ({}; . *+ $item)' $TEMP_DIR/configs.yaml ${TEMP_DIR}/newconfig.yaml > $CONFIGS_FILE diff --git a/image/cli/mascli/functions/gitops_suite b/image/cli/mascli/functions/gitops_suite index 1a7c89c569..3d11120e99 100644 --- a/image/cli/mascli/functions/gitops_suite +++ b/image/cli/mascli/functions/gitops_suite @@ -695,7 +695,7 @@ function gitops_suite() { jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-instance-base.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-mas-instance-base.yaml echo "- IBM Suite License Service" - jinjanate --quiet --undefined $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-sls.yaml.j2 $MONGO_CONFIG_FILE -o ${GITOPS_INSTANCE_DIR}/ibm-sls.yaml + jinjanate --quiet --undefined --import-env='' $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-sls.yaml.j2 $MONGO_CONFIG_FILE -o ${GITOPS_INSTANCE_DIR}/ibm-sls.yaml echo "- IBM Maximo Application Suite Core Platform" jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-suite.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-mas-suite.yaml diff --git a/image/cli/mascli/functions/gitops_suite_app_config b/image/cli/mascli/functions/gitops_suite_app_config index 465da1dd2e..c46816dd12 100644 --- a/image/cli/mascli/functions/gitops_suite_app_config +++ b/image/cli/mascli/functions/gitops_suite_app_config @@ -570,7 +570,7 @@ function gitops_suite_app_config() { yq 'del(.ibm_mas_masapp_configs[] | select(.mas_app_id == "'${MAS_APP_ID}'" and .mas_workspace_id == "'${MAS_WORKSPACE_ID}'"))' $CONFIGS_FILE > $TEMP_DIR/configs.yaml # Render the appropriate template for the config into a new file - jinjanate --quiet --undefined $CLI_DIR/templates/gitops/appset-configs/cluster/instance/masapp/ibm-mas-masapp-config.yaml.j2 $ADDITIONAL_JINJA_PARAMS_FILE | yq '{"ibm_mas_masapp_configs": [] + .}' > ${TEMP_DIR}/newconfig.yaml + jinjanate --quiet --undefined --import-env='' $CLI_DIR/templates/gitops/appset-configs/cluster/instance/masapp/ibm-mas-masapp-config.yaml.j2 $ADDITIONAL_JINJA_PARAMS_FILE | yq '{"ibm_mas_masapp_configs": [] + .}' > ${TEMP_DIR}/newconfig.yaml # Merge the two files yq eval-all '. as $item ireduce ({}; . *+ $item)' $TEMP_DIR/configs.yaml ${TEMP_DIR}/newconfig.yaml > $CONFIGS_FILE From 5be17e90efc493d89caa58a8504523ad247e776a Mon Sep 17 00:00:00 2001 From: "J. Harte" <13206585+boonware@users.noreply.github.com> Date: Wed, 19 Feb 2025 10:22:18 +0000 Subject: [PATCH 3/4] refactor Jinja templates --- .secrets.baseline | 4 ++-- .../cluster/group-sync-operator.yaml.j2 | 18 +----------------- .../appset-configs/cluster/ibm-rbac.yaml.j2 | 11 +---------- 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index eb81451757..739c4c9df9 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "^.secrets.baseline$", "lines": null }, - "generated_at": "2025-02-12T12:31:53Z", + "generated_at": "2025-02-19T10:22:06Z", "plugins_used": [ { "name": "AWSKeyDetector" @@ -424,7 +424,7 @@ "hashed_secret": "fee2d55ad9a49a95fc89abe8f414dad66704ebfd", "is_secret": false, "is_verified": false, - "line_number": 22, + "line_number": 7, "type": "Secret Keyword", "verified_result": null } diff --git a/image/cli/mascli/templates/gitops/appset-configs/cluster/group-sync-operator.yaml.j2 b/image/cli/mascli/templates/gitops/appset-configs/cluster/group-sync-operator.yaml.j2 index e28d599c2d..8975cb134a 100644 --- a/image/cli/mascli/templates/gitops/appset-configs/cluster/group-sync-operator.yaml.j2 +++ b/image/cli/mascli/templates/gitops/appset-configs/cluster/group-sync-operator.yaml.j2 @@ -1,24 +1,8 @@ merge-key: "{{ ACCOUNT_ID }}/{{ CLUSTER_ID }}" -{#- Parses the ISV groups from a string representation of a list of maps #} -{#- Example: "- name: 'admin'\n id: 645001Z1WP\n- name: 'developer'\n id: 645001Z1WR\n" #} -{%- set group_namespace = namespace(isv_groups = []) %} -{%- set group_strs = GROUP_SYNC_OPERATOR_ISV_GROUPS.split('-') %} -{%- set _ = group_strs.remove('') %} -{%- for group_str in group_strs %} - {%- set group_loop = loop %} - {%- set _ = group_namespace.isv_groups.append(dict()) %} - {%- set pairs = group_str.strip('\n').split('\n') %} - {%- for pair in pairs %} - {%- set items = pair.split(':') %} - {%- set _ = group_namespace.isv_groups[group_loop.index - 1].__setitem__(items[0].strip().strip("'"), items[1].strip().strip("'")) %} - {%- endfor %} -{%- endfor %} - group_sync_operator: cron_schedule: "{{ GROUP_SYNC_OPERATOR_CRON_SCHEDULE }}" isv_tenant_url: "{{ GROUP_SYNC_OPERATOR_ISV_TENANT_URL }}" isv_client_id: "" isv_client_secret: "" - isv_groups: - {{ group_namespace.isv_groups }} + isv_groups: {{ GROUP_SYNC_OPERATOR_ISV_GROUPS | toYaml }} diff --git a/image/cli/mascli/templates/gitops/appset-configs/cluster/ibm-rbac.yaml.j2 b/image/cli/mascli/templates/gitops/appset-configs/cluster/ibm-rbac.yaml.j2 index 22b861f0d3..f69256e562 100644 --- a/image/cli/mascli/templates/gitops/appset-configs/cluster/ibm-rbac.yaml.j2 +++ b/image/cli/mascli/templates/gitops/appset-configs/cluster/ibm-rbac.yaml.j2 @@ -1,13 +1,4 @@ merge-key: "{{ ACCOUNT_ID }}/{{ CLUSTER_ID }}" -{#- Parses the IBM RBAC binding-to-group mapping from a string representation to a map #} -{#- Example: "a: b\nc: d\n" #} -{%- set rbac_namespace = namespace(binding_mappings = dict()) %} -{%- set item_strs = IBM_RBAC_BINDING_TO_GROUP.split('\n') %} -{%- for item_str in item_strs %} - {%- set pair = item_str.strip('\n').split(':') %} - {%- set _ = rbac_namespace.binding_mappings.__setitem__(pair[0].strip().strip("'"), pair[1].strip().strip("'")) %} -{%- endfor %} - ibm_rbac: - binding_to_group: {{ rbac_namespace.binding_mappings }} + binding_to_group: {{ IBM_RBAC_BINDING_TO_GROUP | toYaml }} From 4cba9468e720edbc9f76dae77b6599c82214b3b5 Mon Sep 17 00:00:00 2001 From: "J. Harte" <13206585+boonware@users.noreply.github.com> Date: Fri, 21 Feb 2025 11:20:02 +0000 Subject: [PATCH 4/4] rename function --- docs/examples/minimal-rbac.md | 4 ++- image/cli/mascli/functions/gitops_bootstrap | 6 ++--- .../mascli/functions/gitops_cis_compliance | 2 +- image/cli/mascli/functions/gitops_cluster | 26 +++++++++---------- image/cli/mascli/functions/gitops_cp4d | 2 +- .../cli/mascli/functions/gitops_cp4d_service | 4 +-- image/cli/mascli/functions/gitops_db2u | 2 +- .../cli/mascli/functions/gitops_db2u_database | 4 +-- image/cli/mascli/functions/gitops_dro | 2 +- image/cli/mascli/functions/gitops_mas_config | 2 +- image/cli/mascli/functions/gitops_nvidia_gpu | 2 +- image/cli/mascli/functions/gitops_suite | 4 +-- .../mascli/functions/gitops_suite_app_config | 4 +-- .../mascli/functions/gitops_suite_app_install | 4 +-- .../mascli/functions/gitops_suite_workspace | 4 +-- image/cli/mascli/functions/internal/utils | 3 ++- 16 files changed, 39 insertions(+), 36 deletions(-) diff --git a/docs/examples/minimal-rbac.md b/docs/examples/minimal-rbac.md index 66075dffec..d5c50278e4 100644 --- a/docs/examples/minimal-rbac.md +++ b/docs/examples/minimal-rbac.md @@ -40,7 +40,9 @@ MAS_INSTANCE_ID=dev1 export SERVER=https://myocp.net # Install the minimal RBAC for the MAS install (as OpenShift administrator) oc login --token xxx --server=$SERVER -kustomize build rbac/install | jinja -D mas_instance_id $MAS_INSTANCE_ID | oc apply -f - +export mas_instance_id=$MAS_INSTANCE_ID +kustomize build rbac/install > rbac-install.yaml +jinjanate rbac-install.yaml | oc apply -f - # Get the access token for the user export INSTALL_TOKEN=$(oc -n mas-${MAS_INSTANCE_ID}-pipelines get secret mas-${MAS_INSTANCE_ID}-install-token -o jsonpath="{.data.token}" | base64 -d) diff --git a/image/cli/mascli/functions/gitops_bootstrap b/image/cli/mascli/functions/gitops_bootstrap index 53727b54d7..4bb61b4ded 100644 --- a/image/cli/mascli/functions/gitops_bootstrap +++ b/image/cli/mascli/functions/gitops_bootstrap @@ -179,7 +179,7 @@ function gitops_bootstrap() { # 2. Create Secret Manager secret echo 'Create Secret Manager Backend Secret' - jinja ${CLI_DIR}/templates/gitops/bootstrap/secret-${AVP_TYPE}.yaml.j2 | oc apply -f - + jinjanate_commmon ${CLI_DIR}/templates/gitops/bootstrap/secret-${AVP_TYPE}.yaml.j2 | oc apply -f - # 3. Create repo server SA echo 'Create ArgoCD repo server service account' @@ -204,11 +204,11 @@ function gitops_bootstrap() { oc wait --for=jsonpath='{.status.applicationController}'=Running argocd/openshift-gitops -n openshift-gitops --timeout=30m # 6. Add the GitHub PAT secret (used to authenticate to your environment repository, which is assumed to be private) - jinja ${CLI_DIR}/templates/gitops/bootstrap/secret-github.yaml.j2 | oc apply -f - + jinjanate_commmon ${CLI_DIR}/templates/gitops/bootstrap/secret-github.yaml.j2 | oc apply -f - # 7. Add the root project and application oc apply -f ${CLI_DIR}/templates/gitops/bootstrap/mas-appproject.yaml - jinja ${CLI_DIR}/templates/gitops/bootstrap/root-application.yaml.j2 | oc apply -f - + jinjanate_commmon ${CLI_DIR}/templates/gitops/bootstrap/root-application.yaml.j2 | oc apply -f - # 8. Patch openshift-marketplace and kube-system to allow GitOps to manage resources in the namespace echo 'Patch standard namespaces to enable GitOps management' diff --git a/image/cli/mascli/functions/gitops_cis_compliance b/image/cli/mascli/functions/gitops_cis_compliance index 361bab49b8..66835bc990 100644 --- a/image/cli/mascli/functions/gitops_cis_compliance +++ b/image/cli/mascli/functions/gitops_cis_compliance @@ -202,7 +202,7 @@ function gitops_cis_compliance() { echo echo_h2 "Generating Argo Applications" echo "- IBM Cis Compliance" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/cis-compliance.yaml.j2 ${GITOPS_CLUSTER_DIR}/cis-compliance.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/cis-compliance.yaml.j2 ${GITOPS_CLUSTER_DIR}/cis-compliance.yaml # Commit and push to github target repo # --------------------------------------------------------------------------- diff --git a/image/cli/mascli/functions/gitops_cluster b/image/cli/mascli/functions/gitops_cluster index 79bf62b6b7..ce9dedea2f 100644 --- a/image/cli/mascli/functions/gitops_cluster +++ b/image/cli/mascli/functions/gitops_cluster @@ -587,7 +587,7 @@ function gitops_cluster() { export ICR_AUTH_TOKEN=$(echo -n $ICR_USERNAME:$ICR_PASSWORD | base64 -w 0) echo "- Generate image pull secret" - jinja $CLI_DIR/templates/gitops/ibm-entitlement-with-artifactory.json.j2 ${GITOPS_CLUSTER_DIR}/ibm-entitlement-with-artifactory.json + jinjanate_commmon $CLI_DIR/templates/gitops/ibm-entitlement-with-artifactory.json.j2 ${GITOPS_CLUSTER_DIR}/ibm-entitlement-with-artifactory.json IBM_ENTITLEMENT_WITH_ARTIFACTORY=${GITOPS_CLUSTER_DIR}/ibm-entitlement-with-artifactory.json IBM_ENTITLEMENT_WITH_ARTIFACTORY=$(cat $IBM_ENTITLEMENT_WITH_ARTIFACTORY) @@ -620,63 +620,63 @@ function gitops_cluster() { echo_h2 "Generating Argo Applications" echo "- Base Config" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/ibm-mas-cluster-base.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-mas-cluster-base.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/ibm-mas-cluster-base.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-mas-cluster-base.yaml echo "- IBM Operator Catalog" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/ibm-operator-catalog.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-operator-catalog.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/ibm-operator-catalog.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-operator-catalog.yaml echo "- Redhat Cert Manager" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/redhat-cert-manager.yaml.j2 ${GITOPS_CLUSTER_DIR}/redhat-cert-manager.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/redhat-cert-manager.yaml.j2 ${GITOPS_CLUSTER_DIR}/redhat-cert-manager.yaml if [[ "$INSTALL_SELENIUM_GRID" == "true" ]]; then echo "- Selenium Grid" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/selenium-grid.yaml.j2 ${GITOPS_CLUSTER_DIR}/selenium-grid.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/selenium-grid.yaml.j2 ${GITOPS_CLUSTER_DIR}/selenium-grid.yaml fi if [[ "$CLUSTER_PROMOTION" == "true" ]]; then ESCAPED_CLUSTER_VALUES=${CLUSTER_PROMOTION_CLUSTER_VALUES//\"/\\\"} export ESCAPED_CLUSTER_VALUES=${ESCAPED_CLUSTER_VALUES//$'\n'/\\n} echo "- Cluster Promotion" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/cluster-promotion.yaml.j2 ${GITOPS_CLUSTER_DIR}/cluster-promotion.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/cluster-promotion.yaml.j2 ${GITOPS_CLUSTER_DIR}/cluster-promotion.yaml fi if [[ -n "$CUSTOM_SA_NAMESPACE" ]]; then echo "- Custom Cluster Service Accounts" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/custom-sa.yaml.j2 ${GITOPS_CLUSTER_DIR}/custom-sa.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/custom-sa.yaml.j2 ${GITOPS_CLUSTER_DIR}/custom-sa.yaml fi if [[ -n "$DNS_PROVIDER" ]]; then echo "- IBM CIS Cert Manager" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/ibm-cis-cert-manager.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-cis-cert-manager.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/phase1/ibm-cis-cert-manager.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-cis-cert-manager.yaml fi if [[ "$INSTALL_GROUP_SYNC_OPERATOR" == "true" ]]; then echo "- Group Sync Operator" sm_verify_secret_exists $SECRET_NAME_ISV_CLIENT "client_secret,client_id" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/group-sync-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/group-sync-operator.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/group-sync-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/group-sync-operator.yaml fi if [[ "$INSTALL_IBM_RBAC" == "true" ]]; then echo "- IBM RBAC" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/ibm-rbac.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-rbac.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/ibm-rbac.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-rbac.yaml fi if [[ "$INSTALL_FALCON_OPERATOR" == "true" ]]; then echo "- CrowdStrike Falcon Operator" sm_verify_secret_exists $SECRET_NAME_FALCON_CLIENT "client_secret,client_id" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/falcon-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/falcon-operator.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/falcon-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/falcon-operator.yaml fi if [[ -n "$CLUSTER_LOGGING_OPERATOR_INSTALL" ]]; then echo "- Cluster Logging Operator" sm_verify_secret_exists $SECRET_NAME_CLOUDWATCH "aws_access_key_id,aws_secret_access_key" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/cluster-logging-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/cluster-logging-operator.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/cluster-logging-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/cluster-logging-operator.yaml fi if [[ -n "$INSTANA_AGENT_OPERATOR_INSTALL" ]]; then echo "- Instana Agent Operator" sm_verify_secret_exists $SECRET_NAME_INSTANA "key" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instana-agent-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/instana-agent-operator.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/instana-agent-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/instana-agent-operator.yaml fi # Commit and push to github target repo diff --git a/image/cli/mascli/functions/gitops_cp4d b/image/cli/mascli/functions/gitops_cp4d index 5510362369..c0160a0b48 100644 --- a/image/cli/mascli/functions/gitops_cp4d +++ b/image/cli/mascli/functions/gitops_cp4d @@ -312,7 +312,7 @@ function gitops_cp4d() { echo "- CP4D operator" echo "Generating IBM CP4D file ${GITOPS_INSTANCE_DIR}/ibm-cp4d.yaml" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-cp4d.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-cp4d.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-cp4d.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-cp4d.yaml # Commit and push to github target repo diff --git a/image/cli/mascli/functions/gitops_cp4d_service b/image/cli/mascli/functions/gitops_cp4d_service index 27ad5dcf5f..6ad12dcdc9 100644 --- a/image/cli/mascli/functions/gitops_cp4d_service +++ b/image/cli/mascli/functions/gitops_cp4d_service @@ -378,14 +378,14 @@ function gitops_cp4d_service() { if [[ "$CPD_SERVICE_NAME" == "wsl" || "$CPD_SERVICE_NAME" == "wml" || "$CPD_SERVICE_NAME" == "spss" ]]; then echo "Generating IBM CPD Service file ${GITOPS_INSTANCE_DIR}/ibm-cp4d-services-base.yaml" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-cp4d-services-base.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-cp4d-services-base.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-cp4d-services-base.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-cp4d-services-base.yaml fi echo echo "- ${CPD_SERVICE_NAME} operator" echo "Generating IBM CPD Service file ${GITOPS_INSTANCE_DIR}/ibm-${CPD_SERVICE_NAME}.yaml" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-${CPD_SERVICE_NAME}.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-${CPD_SERVICE_NAME}.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-${CPD_SERVICE_NAME}.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-${CPD_SERVICE_NAME}.yaml # Commit and push to github target repo # --------------------------------------------------------------------------- diff --git a/image/cli/mascli/functions/gitops_db2u b/image/cli/mascli/functions/gitops_db2u index 7fdae30d6b..b52775d278 100644 --- a/image/cli/mascli/functions/gitops_db2u +++ b/image/cli/mascli/functions/gitops_db2u @@ -262,7 +262,7 @@ function gitops_db2u() { export IBM_ENTITLEMENT_KEY=$SECRET_KEY_IBM_ENTITLEMENT echo "Generating DB2U file ${GITOPS_INSTANCE_DIR}/ibm-db2u.yaml" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-db2u.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-db2u.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-db2u.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-db2u.yaml # Commit and push to github target repo # --------------------------------------------------------------------------- diff --git a/image/cli/mascli/functions/gitops_db2u_database b/image/cli/mascli/functions/gitops_db2u_database index 29908a10d7..1d0c7bfd2d 100644 --- a/image/cli/mascli/functions/gitops_db2u_database +++ b/image/cli/mascli/functions/gitops_db2u_database @@ -730,7 +730,7 @@ DB2_WORKLOAD: '${DB2_WORKLOAD}'" # If the file doesn't exist, create a blank one if ! [ -f ${CONFIGS_FILE} ]; then - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/db2-databases/ibm-db2u-database-common.yaml.j2 $CONFIGS_FILE + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/instance/db2-databases/ibm-db2u-database-common.yaml.j2 $CONFIGS_FILE fi # Remove any existing config with this name @@ -740,7 +740,7 @@ DB2_WORKLOAD: '${DB2_WORKLOAD}'" echo -n "" > ${TEMP_DIR}/newconfig.yaml # Render the appropriate template for the config into a new file. For standby database, it will be generated only if it is a replica task and replica is enabled. if [[ (${IS_REPLICA_TASK} == 'false') || (${IS_REPLICA_TASK} == 'true' && ${REPLICA_DB} == 'true') ]]; then - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/db2-databases/ibm-db2u-database.yaml.j2 | yq '{"ibm_db2u_databases": [] + .}' > ${TEMP_DIR}/newconfig.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/instance/db2-databases/ibm-db2u-database.yaml.j2 | yq '{"ibm_db2u_databases": [] + .}' > ${TEMP_DIR}/newconfig.yaml fi # Merge the two files diff --git a/image/cli/mascli/functions/gitops_dro b/image/cli/mascli/functions/gitops_dro index ff1a34f9e9..5c36ab667a 100644 --- a/image/cli/mascli/functions/gitops_dro +++ b/image/cli/mascli/functions/gitops_dro @@ -292,7 +292,7 @@ function gitops_dro() { export IBM_ENTITLEMENT_KEY=$SECRET_KEY_IBM_ENTITLEMENT echo "Generating dro file ${GITOPS_CLUSTER_DIR}/ibm-dro.yaml" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/ibm-dro.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-dro.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/ibm-dro.yaml.j2 ${GITOPS_CLUSTER_DIR}/ibm-dro.yaml # Commit and push to github target repo # --------------------------------------------------------------------------- diff --git a/image/cli/mascli/functions/gitops_mas_config b/image/cli/mascli/functions/gitops_mas_config index 371398a869..01cb58e6e9 100644 --- a/image/cli/mascli/functions/gitops_mas_config +++ b/image/cli/mascli/functions/gitops_mas_config @@ -839,7 +839,7 @@ function gitops_mas_config() { # If the file doesn't exist, create a blank one if ! [ -f ${CONFIGS_FILE} ]; then - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/configs/ibm-mas-config-common.yaml.j2 $CONFIGS_FILE + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/instance/configs/ibm-mas-config-common.yaml.j2 $CONFIGS_FILE fi # Remove any existing config with this name diff --git a/image/cli/mascli/functions/gitops_nvidia_gpu b/image/cli/mascli/functions/gitops_nvidia_gpu index 73d9f34301..7d9c2b1fa9 100644 --- a/image/cli/mascli/functions/gitops_nvidia_gpu +++ b/image/cli/mascli/functions/gitops_nvidia_gpu @@ -285,7 +285,7 @@ function gitops_nvidia_gpu() { echo "- Nvidia GPU Operator" echo "Generating Nvidia GPU operator file ${GITOPS_CLUSTER_DIR}/nvidia-gpu-operator.yaml" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/nvidia-gpu-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/nvidia-gpu-operator.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/nvidia-gpu-operator.yaml.j2 ${GITOPS_CLUSTER_DIR}/nvidia-gpu-operator.yaml # Commit and push to github target repo # --------------------------------------------------------------------------- diff --git a/image/cli/mascli/functions/gitops_suite b/image/cli/mascli/functions/gitops_suite index 3d11120e99..1f8bb3d229 100644 --- a/image/cli/mascli/functions/gitops_suite +++ b/image/cli/mascli/functions/gitops_suite @@ -692,13 +692,13 @@ function gitops_suite() { echo_h2 "Generating Argo Project and Applications" echo "- Base Config" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-instance-base.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-mas-instance-base.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-instance-base.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-mas-instance-base.yaml echo "- IBM Suite License Service" jinjanate --quiet --undefined --import-env='' $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-sls.yaml.j2 $MONGO_CONFIG_FILE -o ${GITOPS_INSTANCE_DIR}/ibm-sls.yaml echo "- IBM Maximo Application Suite Core Platform" - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-suite.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-mas-suite.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-suite.yaml.j2 ${GITOPS_INSTANCE_DIR}/ibm-mas-suite.yaml # Commit and push to github target repo diff --git a/image/cli/mascli/functions/gitops_suite_app_config b/image/cli/mascli/functions/gitops_suite_app_config index c46816dd12..add5dd5943 100644 --- a/image/cli/mascli/functions/gitops_suite_app_config +++ b/image/cli/mascli/functions/gitops_suite_app_config @@ -512,7 +512,7 @@ function gitops_suite_app_config() { else echo echo_h2 "Using default application spec for $MAS_APP_ID" - jinja $CLI_DIR/templates/gitops/app-ws-spec-defaults/${MAS_APP_ID}.yaml.j2 ${TEMP_DIR}/${MAS_APP_ID}-appws-spec.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/app-ws-spec-defaults/${MAS_APP_ID}.yaml.j2 ${TEMP_DIR}/${MAS_APP_ID}-appws-spec.yaml export MAS_APPWS_SPEC=$(cat ${TEMP_DIR}/${MAS_APP_ID}-appws-spec.yaml | yq '.' --output-format yaml) fi echo @@ -562,7 +562,7 @@ function gitops_suite_app_config() { # If the file doesn't exist, create a blank one if ! [ -f ${CONFIGS_FILE} ]; then - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/masapp/ibm-mas-masapp-config-common.yaml.j2 $CONFIGS_FILE + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/instance/masapp/ibm-mas-masapp-config-common.yaml.j2 $CONFIGS_FILE fi diff --git a/image/cli/mascli/functions/gitops_suite_app_install b/image/cli/mascli/functions/gitops_suite_app_install index 23a271dc75..adb0f1d002 100644 --- a/image/cli/mascli/functions/gitops_suite_app_install +++ b/image/cli/mascli/functions/gitops_suite_app_install @@ -363,7 +363,7 @@ function gitops_suite_app_install() { else echo echo_h2 "Using default application spec for $MAS_APP_ID" - jinja $CLI_DIR/templates/gitops/app-spec-defaults/${MAS_APP_ID}.yaml.j2 ${TEMP_DIR}/${MAS_APP_ID}-app-spec.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/app-spec-defaults/${MAS_APP_ID}.yaml.j2 ${TEMP_DIR}/${MAS_APP_ID}-app-spec.yaml export MAS_APP_SPEC=$(cat ${TEMP_DIR}/${MAS_APP_ID}-app-spec.yaml | yq '.' --output-format yaml) fi echo_reset_dim "MAS_APP_SPEC ............................ ${COLOR_MAGENTA}${MAS_APP_SPEC}" @@ -428,7 +428,7 @@ function gitops_suite_app_install() { echo "- IBM MAS Application Install" CONFIG_FILE=${GITOPS_INSTANCE_DIR}/ibm-mas-masapp-${MAS_APP_ID}-install.yaml - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/masapp/ibm-mas-masapp-install.yaml.j2 ${CONFIG_FILE} + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/instance/masapp/ibm-mas-masapp-install.yaml.j2 ${CONFIG_FILE} echo_h2 "Generated configuration file (${CONFIG_FILE})" diff --git a/image/cli/mascli/functions/gitops_suite_workspace b/image/cli/mascli/functions/gitops_suite_workspace index da66dba9c4..c908d5bd15 100644 --- a/image/cli/mascli/functions/gitops_suite_workspace +++ b/image/cli/mascli/functions/gitops_suite_workspace @@ -236,14 +236,14 @@ function gitops_suite_workspace() { # If the file doesn't exist, create a blank one if ! [ -f ${CONFIGS_FILE} ]; then - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-workspaces-common.yaml.j2 $CONFIGS_FILE + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-workspaces-common.yaml.j2 $CONFIGS_FILE fi # Remove any existing config with this name yq 'del(.ibm_mas_workspaces[] | select(.mas_workspace_id == "'${MAS_WORKSPACE_ID}'"))' $CONFIGS_FILE > $TEMP_DIR/configs.yaml # Render the appropriate template for the config into a new file - jinja $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-workspace.yaml.j2 | yq '{"ibm_mas_workspaces": [] + .}' > ${TEMP_DIR}/newconfig.yaml + jinjanate_commmon $CLI_DIR/templates/gitops/appset-configs/cluster/instance/ibm-mas-workspace.yaml.j2 | yq '{"ibm_mas_workspaces": [] + .}' > ${TEMP_DIR}/newconfig.yaml # Merge the two files yq eval-all '. as $item ireduce ({}; . *+ $item)' $TEMP_DIR/configs.yaml ${TEMP_DIR}/newconfig.yaml > $CONFIGS_FILE diff --git a/image/cli/mascli/functions/internal/utils b/image/cli/mascli/functions/internal/utils index 706c0b2c1c..b01a2536de 100644 --- a/image/cli/mascli/functions/internal/utils +++ b/image/cli/mascli/functions/internal/utils @@ -348,7 +348,8 @@ function ocp_version_check() { fi } -function jinja() { +# Calls jinjanate with common arguments. Call jinjanate directly if this does not suit your use case. +function jinjanate_commmon() { local template_path=$1 local output_path=$2 local filter_files=$(ls $CLI_DIR/templates/filters/*.py)