From 30bfec6cf3888896872aa5aa4dcacabed53bd9f5 Mon Sep 17 00:00:00 2001 From: Omar Al Jaljuli Date: Wed, 11 Dec 2024 12:35:17 -0500 Subject: [PATCH] tidy up code --- .ibm/pipelines/cluster/aks/deployment.sh | 8 +++- .ibm/pipelines/cluster/gke/deployment.sh | 8 +++- .ibm/pipelines/jobs/aks.sh | 4 +- .ibm/pipelines/jobs/gke.sh | 4 +- .ibm/pipelines/jobs/main.sh | 2 +- .ibm/pipelines/jobs/operator.sh | 46 +++++++++++++++++- .ibm/pipelines/jobs/periodic.sh | 4 +- .ibm/pipelines/utils.sh | 59 +++--------------------- 8 files changed, 71 insertions(+), 64 deletions(-) diff --git a/.ibm/pipelines/cluster/aks/deployment.sh b/.ibm/pipelines/cluster/aks/deployment.sh index a359edc786..20c88a5e9c 100644 --- a/.ibm/pipelines/cluster/aks/deployment.sh +++ b/.ibm/pipelines/cluster/aks/deployment.sh @@ -1,4 +1,6 @@ initiate_aks_deployment() { + local url=$1 + add_helm_repos delete_namespace "${NAME_SPACE_RBAC_K8S}" configure_namespace "${NAME_SPACE_K8S}" @@ -6,7 +8,7 @@ initiate_aks_deployment() { # install_tekton_pipelines uninstall_helmchart "${NAME_SPACE_K8S}" "${RELEASE_NAME}" cd "${DIR}" - apply_yaml_files "${DIR}" "${NAME_SPACE_K8S}" "${RELEASE_NAME}" + apply_yaml_files "${DIR}" "${NAME_SPACE_K8S}" "${url}" yq_merge_value_files "${DIR}/value_files/${HELM_CHART_VALUE_FILE_NAME}" "${DIR}/value_files/${HELM_CHART_AKS_DIFF_VALUE_FILE_NAME}" "/tmp/${HELM_CHART_K8S_MERGED_VALUE_FILE_NAME}" mkdir -p "${ARTIFACT_DIR}/${NAME_SPACE_K8S}" cp -a "/tmp/${HELM_CHART_K8S_MERGED_VALUE_FILE_NAME}" "${ARTIFACT_DIR}/${NAME_SPACE_K8S}/" # Save the final value-file into the artifacts directory. @@ -19,6 +21,8 @@ initiate_aks_deployment() { } initiate_rbac_aks_deployment() { + local url=$1 + add_helm_repos delete_namespace "${NAME_SPACE_K8S}" configure_namespace "${NAME_SPACE_RBAC_K8S}" @@ -26,7 +30,7 @@ initiate_rbac_aks_deployment() { # install_tekton_pipelines uninstall_helmchart "${NAME_SPACE_RBAC_K8S}" "${RELEASE_NAME_RBAC}" cd "${DIR}" - apply_yaml_files "${DIR}" "${NAME_SPACE_RBAC_K8S}" "${RELEASE_NAME_RBAC}" + apply_yaml_files "${DIR}" "${NAME_SPACE_RBAC_K8S}" "${url}" yq_merge_value_files "${DIR}/value_files/${HELM_CHART_RBAC_VALUE_FILE_NAME}" "${DIR}/value_files/${HELM_CHART_RBAC_AKS_DIFF_VALUE_FILE_NAME}" "/tmp/${HELM_CHART_RBAC_K8S_MERGED_VALUE_FILE_NAME}" mkdir -p "${ARTIFACT_DIR}/${NAME_SPACE_RBAC_K8S}" cp -a "/tmp/${HELM_CHART_RBAC_K8S_MERGED_VALUE_FILE_NAME}" "${ARTIFACT_DIR}/${NAME_SPACE_RBAC_K8S}/" # Save the final value-file into the artifacts directory. diff --git a/.ibm/pipelines/cluster/gke/deployment.sh b/.ibm/pipelines/cluster/gke/deployment.sh index ff24ada7a9..dcd15184e8 100644 --- a/.ibm/pipelines/cluster/gke/deployment.sh +++ b/.ibm/pipelines/cluster/gke/deployment.sh @@ -1,4 +1,6 @@ initiate_gke_deployment() { + local url=$1 + gcloud_ssl_cert_create $GKE_CERT_NAME $GKE_INSTANCE_DOMAIN_NAME $GOOGLE_CLOUD_PROJECT add_helm_repos delete_namespace "${NAME_SPACE_RBAC_K8S}" @@ -7,7 +9,7 @@ initiate_gke_deployment() { # install_tekton_pipelines uninstall_helmchart "${NAME_SPACE_K8S}" "${RELEASE_NAME}" cd "${DIR}" - apply_yaml_files "${DIR}" "${NAME_SPACE_K8S}" "${RELEASE_NAME}" + apply_yaml_files "${DIR}" "${NAME_SPACE_K8S}" "${url}" oc apply -f "${DIR}/cluster/gke/frontend-config.yaml" --namespace="${project}" yq_merge_value_files "${DIR}/value_files/${HELM_CHART_VALUE_FILE_NAME}" "${DIR}/value_files/${HELM_CHART_GKE_DIFF_VALUE_FILE_NAME}" "/tmp/${HELM_CHART_K8S_MERGED_VALUE_FILE_NAME}" mkdir -p "${ARTIFACT_DIR}/${NAME_SPACE_K8S}" @@ -22,6 +24,8 @@ initiate_gke_deployment() { } initiate_rbac_gke_deployment() { + local url=$1 + gcloud_ssl_cert_create $GKE_CERT_NAME $GKE_INSTANCE_DOMAIN_NAME $GOOGLE_CLOUD_PROJECT add_helm_repos delete_namespace "${NAME_SPACE_K8S}" @@ -30,7 +34,7 @@ initiate_rbac_gke_deployment() { # install_tekton_pipelines uninstall_helmchart "${NAME_SPACE_RBAC_K8S}" "${RELEASE_NAME_RBAC}" cd "${DIR}" - apply_yaml_files "${DIR}" "${NAME_SPACE_RBAC_K8S}" "${RELEASE_NAME_RBAC}" + apply_yaml_files "${DIR}" "${NAME_SPACE_RBAC_K8S}" "${url}" yq_merge_value_files "${DIR}/value_files/${HELM_CHART_RBAC_VALUE_FILE_NAME}" "${DIR}/value_files/${HELM_CHART_RBAC_GKE_DIFF_VALUE_FILE_NAME}" "/tmp/${HELM_CHART_RBAC_K8S_MERGED_VALUE_FILE_NAME}" mkdir -p "${ARTIFACT_DIR}/${NAME_SPACE_RBAC_K8S}" cp -a "/tmp/${HELM_CHART_RBAC_K8S_MERGED_VALUE_FILE_NAME}" "${ARTIFACT_DIR}/${NAME_SPACE_RBAC_K8S}/" # Save the final value-file into the artifacts directory. diff --git a/.ibm/pipelines/jobs/aks.sh b/.ibm/pipelines/jobs/aks.sh index ddf4d33c56..e0bb92d19e 100644 --- a/.ibm/pipelines/jobs/aks.sh +++ b/.ibm/pipelines/jobs/aks.sh @@ -19,10 +19,10 @@ handle_aks() { set_github_app_3_credentials - initiate_aks_deployment + initiate_aks_deployment "${url}" check_and_test "${RELEASE_NAME}" "${NAME_SPACE_K8S}" "${url}" delete_namespace "${NAME_SPACE_K8S}" - initiate_rbac_aks_deployment + initiate_rbac_aks_deployment "${url}" check_and_test "${RELEASE_NAME_RBAC}" "${NAME_SPACE_RBAC_K8S}" delete_namespace "${NAME_SPACE_RBAC_K8S}" } diff --git a/.ibm/pipelines/jobs/gke.sh b/.ibm/pipelines/jobs/gke.sh index 71e8de697c..cb02970589 100644 --- a/.ibm/pipelines/jobs/gke.sh +++ b/.ibm/pipelines/jobs/gke.sh @@ -14,10 +14,10 @@ handle_gke() { set_github_app_3_credentials - initiate_gke_deployment + initiate_gke_deployment "${url}" check_and_test "${RELEASE_NAME}" "${NAME_SPACE_K8S}" "${url}" delete_namespace "${NAME_SPACE_K8S}" - initiate_rbac_gke_deployment + initiate_rbac_gke_deployment "${url}" check_and_test "${RELEASE_NAME_RBAC}" "${NAME_SPACE_RBAC_K8S}" delete_namespace "${NAME_SPACE_RBAC_K8S}" diff --git a/.ibm/pipelines/jobs/main.sh b/.ibm/pipelines/jobs/main.sh index 9d4db8133e..a94caf634e 100644 --- a/.ibm/pipelines/jobs/main.sh +++ b/.ibm/pipelines/jobs/main.sh @@ -8,7 +8,7 @@ handle_main() { export K8S_CLUSTER_ROUTER_BASE=$(oc get route console -n openshift-console -o=jsonpath='{.spec.host}' | sed 's/^[^.]*\.//') local url="https://${RELEASE_NAME}-backstage-${NAME_SPACE}.${K8S_CLUSTER_ROUTER_BASE}" cluster_setup - initiate_deployments + initiate_deployments "${url}" deploy_test_backstage_provider "${NAME_SPACE}" check_and_test "${RELEASE_NAME}" "${NAME_SPACE}" "${url}" check_and_test "${RELEASE_NAME_RBAC}" "${NAME_SPACE_RBAC}" "${url}" diff --git a/.ibm/pipelines/jobs/operator.sh b/.ibm/pipelines/jobs/operator.sh index 6f3169f0c8..0157a6a45a 100644 --- a/.ibm/pipelines/jobs/operator.sh +++ b/.ibm/pipelines/jobs/operator.sh @@ -1,5 +1,49 @@ #!/bin/sh +install_rhdh_operator() { + local dir=$1 + local namespace=$2 + + configure_namespace $namespace + + # Make sure script is up to date + rm -f /tmp/install-rhdh-catalog-source.sh + curl -L https://raw.githubusercontent.com/redhat-developer/rhdh-operator/refs/heads/main/.rhdh/scripts/install-rhdh-catalog-source.sh > /tmp/install-rhdh-catalog-source.sh + chmod +x /tmp/install-rhdh-catalog-source.sh + bash -x /tmp/install-rhdh-catalog-source.sh --next --install-operator rhdh +} + +deploy_rhdh_operator() { + local dir=$1 + local namespace=$2 + + if [[ "${namespace}" == "showcase-op-rbac-nightly" ]]; then + oc apply -f "${dir}/resources/rhdh-operator/rhdh-start-rbac.yaml" -n "${namespace}" + else + oc apply -f "${dir}/resources/rhdh-operator/rhdh-start.yaml" -n "${namespace}" + fi +} + +initiate_operator_deployments() { + local url=$1 + + configure_namespace "${OPERATOR_MANAGER}" + install_rhdh_operator "${DIR}" "${OPERATOR_MANAGER}" + + configure_namespace "${NAME_SPACE}" + apply_yaml_files "${DIR}" "${NAME_SPACE}" "${url}" + create_dynamic_plugins_config "${DIR}/value_files/${HELM_CHART_VALUE_FILE_NAME}" "/tmp/configmap-dynamic-plugins.yaml" + oc apply -f /tmp/configmap-dynamic-plugins.yaml -n "${NAME_SPACE}" + oc apply -f "$DIR/resources/redis-cache/redis-deployment.yaml" --namespace="${NAME_SPACE}" + deploy_rhdh_operator "${DIR}" "${NAME_SPACE}" + + configure_namespace "${NAME_SPACE_RBAC}" + apply_yaml_files "${DIR}" "${NAME_SPACE_RBAC}" "${url}" + create_dynamic_plugins_config "${DIR}/value_files/${HELM_CHART_RBAC_VALUE_FILE_NAME}" "/tmp/configmap-dynamic-plugins-rbac.yaml" + oc apply -f /tmp/configmap-dynamic-plugins-rbac.yaml -n "${NAME_SPACE_RBAC}" + deploy_rhdh_operator "${DIR}" "${NAME_SPACE_RBAC}" +} + handle_operator() { set_github_app_3_credentials oc_login @@ -10,7 +54,7 @@ handle_operator() { export K8S_CLUSTER_ROUTER_BASE=$(oc get route console -n openshift-console -o=jsonpath='{.spec.host}' | sed 's/^[^.]*\.//') local url="https://backstage-${release_name}-${project}.${K8S_CLUSTER_ROUTER_BASE}" - initiate_operator_deployments + initiate_operator_deployments "${url}" deploy_test_backstage_provider "${NAME_SPACE}" check_and_test "${RELEASE_NAME}" "${NAME_SPACE}" "${url}" check_and_test "${RELEASE_NAME_RBAC}" "${NAME_SPACE_RBAC}" "${url}" diff --git a/.ibm/pipelines/jobs/periodic.sh b/.ibm/pipelines/jobs/periodic.sh index 30ddc9dcfc..3efdd6f7d7 100644 --- a/.ibm/pipelines/jobs/periodic.sh +++ b/.ibm/pipelines/jobs/periodic.sh @@ -15,7 +15,7 @@ handle_nightly() { deploy_test_backstage_provider "${NAME_SPACE}" local url="https://${RELEASE_NAME}-backstage-${NAME_SPACE}.${K8S_CLUSTER_ROUTER_BASE}" cluster_setup - initiate_deployments + initiate_deployments "${url}" check_and_test "${RELEASE_NAME}" "${NAME_SPACE}" "${url}" check_and_test "${RELEASE_NAME_RBAC}" "${NAME_SPACE_RBAC}" "${url}" @@ -27,7 +27,7 @@ handle_nightly() { configure_namespace "${NAME_SPACE_RUNTIME}" uninstall_helmchart "${NAME_SPACE_RUNTIME}" "${RELEASE_NAME}" oc apply -f "$DIR/resources/redis-cache/redis-deployment.yaml" --namespace="${NAME_SPACE_RUNTIME}" - apply_yaml_files "${DIR}" "${NAME_SPACE_RUNTIME}" "${RELEASE_NAME}" + apply_yaml_files "${DIR}" "${NAME_SPACE_RUNTIME}" "${url}" helm upgrade -i "${RELEASE_NAME}" -n "${NAME_SPACE_RUNTIME}" "${HELM_REPO_NAME}/${HELM_IMAGE_NAME}" --version "${CHART_VERSION}" -f "${DIR}/value_files/${HELM_CHART_VALUE_FILE_NAME}" --set global.clusterRouterBase="${K8S_CLUSTER_ROUTER_BASE}" --set upstream.backstage.image.repository="${QUAY_REPO}" --set upstream.backstage.image.tag="${TAG_NAME}" check_and_test "${RELEASE_NAME}" "${NAME_SPACE_RUNTIME}" "${url}" } diff --git a/.ibm/pipelines/utils.sh b/.ibm/pipelines/utils.sh index 27132095b6..49f82da229 100755 --- a/.ibm/pipelines/utils.sh +++ b/.ibm/pipelines/utils.sh @@ -400,7 +400,7 @@ set_github_app_3_credentials() { apply_yaml_files() { local dir=$1 local project=$2 - local release_name=$3 + local url=$3 echo "Applying YAML files to namespace ${project}" oc config set-context --current --namespace="${project}" @@ -418,12 +418,8 @@ apply_yaml_files() { done DH_TARGET_URL=$(echo -n "test-backstage-customization-provider-${project}.${K8S_CLUSTER_ROUTER_BASE}" | base64 -w 0) - local RHDH_BASE_URL=$(echo -n "https://${release_name}-backstage-${project}.${K8S_CLUSTER_ROUTER_BASE}" | base64 | tr -d '\n') - if [[ "$JOB_NAME" == *aks* || "$JOB_NAME" == *gke* ]]; then - RHDH_BASE_URL=$(echo -n "https://${K8S_CLUSTER_ROUTER_BASE}" | base64 | tr -d '\n') - elif [[ "$JOB_NAME" == *operator* ]]; then - RHDH_BASE_URL=$(echo -n "https://backstage-${release_name}-${project}.${K8S_CLUSTER_ROUTER_BASE}" | base64 | tr -d '\n') - fi + local RHDH_BASE_URL=$(echo -n "${url}" | base64 | tr -d '\n') + for key in GITHUB_APP_APP_ID GITHUB_APP_CLIENT_ID GITHUB_APP_PRIVATE_KEY GITHUB_APP_CLIENT_SECRET GITHUB_APP_JANUS_TEST_APP_ID GITHUB_APP_JANUS_TEST_CLIENT_ID GITHUB_APP_JANUS_TEST_CLIENT_SECRET GITHUB_APP_JANUS_TEST_PRIVATE_KEY GITHUB_APP_WEBHOOK_URL GITHUB_APP_WEBHOOK_SECRET KEYCLOAK_CLIENT_SECRET ACR_SECRET GOOGLE_CLIENT_ID GOOGLE_CLIENT_SECRET K8S_CLUSTER_TOKEN_ENCODED OCM_CLUSTER_URL GITLAB_TOKEN KEYCLOAK_AUTH_BASE_URL KEYCLOAK_AUTH_CLIENTID KEYCLOAK_AUTH_CLIENT_SECRET KEYCLOAK_AUTH_LOGIN_REALM KEYCLOAK_AUTH_REALM RHDH_BASE_URL; do sed -i "s|${key}:.*|${key}: ${!key}|g" "$dir/auth/secrets-rhdh-secrets.yaml" done @@ -664,13 +660,15 @@ cluster_setup() { } initiate_deployments() { + local url=$1 + configure_namespace ${NAME_SPACE} # Deploy redis cache db. oc apply -f "$DIR/resources/redis-cache/redis-deployment.yaml" --namespace="${NAME_SPACE}" cd "${DIR}" - apply_yaml_files "${DIR}" "${NAME_SPACE}" "${RELEASE_NAME}" + apply_yaml_files "${DIR}" "${NAME_SPACE}" "${url}" echo "Deploying image from repository: ${QUAY_REPO}, TAG_NAME: ${TAG_NAME}, in NAME_SPACE: ${NAME_SPACE}" helm upgrade -i "${RELEASE_NAME}" -n "${NAME_SPACE}" "${HELM_REPO_NAME}/${HELM_IMAGE_NAME}" --version "${CHART_VERSION}" -f "${DIR}/value_files/${HELM_CHART_VALUE_FILE_NAME}" --set global.clusterRouterBase="${K8S_CLUSTER_ROUTER_BASE}" --set upstream.backstage.image.repository="${QUAY_REPO}" --set upstream.backstage.image.tag="${TAG_NAME}" @@ -679,7 +677,7 @@ initiate_deployments() { configure_external_postgres_db "${NAME_SPACE_RBAC}" # Initiate rbac instace deployment. - apply_yaml_files "${DIR}" "${NAME_SPACE_RBAC}" "${RELEASE_NAME_RBAC}" + apply_yaml_files "${DIR}" "${NAME_SPACE_RBAC}" "${url}" echo "Deploying image from repository: ${QUAY_REPO}, TAG_NAME: ${TAG_NAME}, in NAME_SPACE: ${RELEASE_NAME_RBAC}" helm upgrade -i "${RELEASE_NAME_RBAC}" -n "${NAME_SPACE_RBAC}" "${HELM_REPO_NAME}/${HELM_IMAGE_NAME}" --version "${CHART_VERSION}" -f "${DIR}/value_files/${HELM_CHART_RBAC_VALUE_FILE_NAME}" --set global.clusterRouterBase="${K8S_CLUSTER_ROUTER_BASE}" --set upstream.backstage.image.repository="${QUAY_REPO}" --set upstream.backstage.image.tag="${TAG_NAME}" } @@ -745,46 +743,3 @@ oc_login() { echo "OCP version: $(oc version)" export K8S_CLUSTER_ROUTER_BASE=$(oc get route console -n openshift-console -o=jsonpath='{.spec.host}' | sed 's/^[^.]*\.//') } - -# Functions needed to deploy operator instances -install_rhdh_operator() { - local dir=$1 - local namespace=$2 - - configure_namespace $namespace - - # Make sure script is up to date - rm -f /tmp/install-rhdh-catalog-source.sh - curl -L https://raw.githubusercontent.com/redhat-developer/rhdh-operator/refs/heads/main/.rhdh/scripts/install-rhdh-catalog-source.sh > /tmp/install-rhdh-catalog-source.sh - chmod +x /tmp/install-rhdh-catalog-source.sh - bash -x /tmp/install-rhdh-catalog-source.sh --next --install-operator rhdh -} - -deploy_rhdh_operator() { - local dir=$1 - local namespace=$2 - - if [[ "${namespace}" == "showcase-op-rbac-nightly" ]]; then - oc apply -f "${dir}/resources/rhdh-operator/rhdh-start-rbac.yaml" -n "${namespace}" - else - oc apply -f "${dir}/resources/rhdh-operator/rhdh-start.yaml" -n "${namespace}" - fi -} - -initiate_operator_deployments() { - configure_namespace "${OPERATOR_MANAGER}" - install_rhdh_operator "${DIR}" "${OPERATOR_MANAGER}" - - configure_namespace "${NAME_SPACE}" - apply_yaml_files "${DIR}" "${NAME_SPACE}" "${RELEASE_NAME}" - create_dynamic_plugins_config "${DIR}/value_files/${HELM_CHART_VALUE_FILE_NAME}" "/tmp/configmap-dynamic-plugins.yaml" - oc apply -f /tmp/configmap-dynamic-plugins.yaml -n "${NAME_SPACE}" - oc apply -f "$DIR/resources/redis-cache/redis-deployment.yaml" --namespace="${NAME_SPACE}" - deploy_rhdh_operator "${DIR}" "${NAME_SPACE}" - - configure_namespace "${NAME_SPACE_RBAC}" - apply_yaml_files "${DIR}" "${NAME_SPACE_RBAC}" "${RELEASE_NAME_RBAC}" - create_dynamic_plugins_config "${DIR}/value_files/${HELM_CHART_RBAC_VALUE_FILE_NAME}" "/tmp/configmap-dynamic-plugins-rbac.yaml" - oc apply -f /tmp/configmap-dynamic-plugins-rbac.yaml -n "${NAME_SPACE_RBAC}" - deploy_rhdh_operator "${DIR}" "${NAME_SPACE_RBAC}" -}