Skip to content

Commit

Permalink
tidy up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar-AlJaljuli committed Dec 11, 2024
1 parent d48d430 commit 30bfec6
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 64 deletions.
8 changes: 6 additions & 2 deletions .ibm/pipelines/cluster/aks/deployment.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
initiate_aks_deployment() {
local url=$1

add_helm_repos
delete_namespace "${NAME_SPACE_RBAC_K8S}"
configure_namespace "${NAME_SPACE_K8S}"
# Renable when namespace termination issue is solved
# 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.
Expand All @@ -19,14 +21,16 @@ initiate_aks_deployment() {
}

initiate_rbac_aks_deployment() {
local url=$1

add_helm_repos
delete_namespace "${NAME_SPACE_K8S}"
configure_namespace "${NAME_SPACE_RBAC_K8S}"
# Renable when namespace termination issue is solved
# 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.
Expand Down
8 changes: 6 additions & 2 deletions .ibm/pipelines/cluster/gke/deployment.sh
Original file line number Diff line number Diff line change
@@ -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}"
Expand All @@ -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}"
Expand All @@ -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}"
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions .ibm/pipelines/jobs/aks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
Expand Down
4 changes: 2 additions & 2 deletions .ibm/pipelines/jobs/gke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down
2 changes: 1 addition & 1 deletion .ibm/pipelines/jobs/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
46 changes: 45 additions & 1 deletion .ibm/pipelines/jobs/operator.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}"
Expand Down
4 changes: 2 additions & 2 deletions .ibm/pipelines/jobs/periodic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand All @@ -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}"
}
59 changes: 7 additions & 52 deletions .ibm/pipelines/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
Expand Down Expand Up @@ -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}"

Expand All @@ -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}"
}
Expand Down Expand Up @@ -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}"
}

0 comments on commit 30bfec6

Please sign in to comment.