Skip to content

Commit

Permalink
Deploy nginx-ingress operator with scripts (#516)
Browse files Browse the repository at this point in the history
* Add nginx operator for testing

* Scripts to add operator deployment
  • Loading branch information
bnshr authored Nov 29, 2024
1 parent 6800d3a commit b2320f9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ install:
./scripts/delete-standard-storageclass.sh
./scripts/deploy-cr-scale-operator.sh
./scripts/deploy-custom-catalogsource.sh
./scripts/deploy-operator.sh

# Creates an install path specifically for the Kind QE clusters to use
install-for-qe:
Expand Down Expand Up @@ -152,4 +153,4 @@ deploy-cr-scale-operator:
./scripts/deploy-cr-scale-operator.sh

lint:
shellcheck scripts/*.sh
shellcheck --nocomments scripts/*.sh
7 changes: 6 additions & 1 deletion scripts/delete-operator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ SCRIPT_DIR=$(dirname "$0")
# shellcheck disable=SC1091 # Not following.
source "$SCRIPT_DIR"/init-env.sh

# shellcheck disable=SC2016
: '
# Cleanup previous deployment if present
operator-sdk cleanup nginx-operator -n "$CERTSUITE_EXAMPLE_NAMESPACE"
#Wait until pod is deleted
until [[ -z "$(oc get pod "$OPERATOR_REGISTRY_POD_NAME" -n "$CERTSUITE_EXAMPLE_NAMESPACE" 2>/dev/null)" ]]; do sleep 5; done
'

# Delete nginx-operator in ninginx-ops namespace
echo "Deleting nginx-ingress-operator .."

NGINX_OPERATOR_NS="nginx-ops"
NGINX_APPS_NS="nginx-apps"

CSV=$(oc get subscription nginx-ingress-operator -n "$NGINX_OPERATOR_NS" -o json | jq -r '.status.installedCSV')
CSV=$(oc get subscription nginx-ingress-operator -n "$NGINX_OPERATOR_NS" -o json | jq -r ".status.installedCSV")
oc delete subscription nginx-ingress-operator -n "$NGINX_OPERATOR_NS"
oc delete csv "$CSV" -n "$NGINX_OPERATOR_NS"
oc delete csv "$CSV" -n "$NGINX_APPS_NS"
Expand Down
44 changes: 25 additions & 19 deletions scripts/deploy-operator.sh
Original file line number Diff line number Diff line change
@@ -1,46 +1,52 @@
#!/usr/bin/env bash
# shellcheck disable=SC2016,SC2086,SC1083

# Initialization
SCRIPT_DIR=$(dirname "$0")

# shellcheck disable=SC1091 # Not following.
source "$SCRIPT_DIR"/init-env.sh

: '
#check if operator-sdk is installed and install it if needed
if [[ -z "$(which operator-sdk 2>/dev/null)" ]]; then
echo "operator-sdk executable cannot be found in the path. Will try to install it."
"$SCRIPT_DIR"/install-operator-sdk.sh
else
echo "operator-sdk was found in the path, no need to install it"
fi
'

# Installing OLM
"$SCRIPT_DIR"/install-olm.sh
"$SCRIPT_DIR"/delete-operator.sh

# Creates a secret if a pem file exists
"$SCRIPT_DIR"/create-secret.sh
: '
# Creates a secret if a pem file exists
"$SCRIPT_DIR"/create-secret.sh
ADD_SECRET=""
ADD_SECRET=""
# shellcheck disable=SC2143 # Use grep -q.
if [[ -n "$(oc get secret -n "$CERTSUITE_EXAMPLE_NAMESPACE" | awk '{print $1}' | grep "$SECRET_NAME")" ]]; then
ADD_SECRET="--ca-secret-name $SECRET_NAME"
fi
# shellcheck disable=SC2143 # Use grep -q.
if [[ -n "$(oc get secret -n "$CERTSUITE_EXAMPLE_NAMESPACE" | awk '{print $1}' | grep "$SECRET_NAME")" ]]; then
ADD_SECRET="--ca-secret-name $SECRET_NAME"
fi
# Deploy the operator bundle
operator-sdk run bundle "$OPERATOR_BUNDLE_IMAGE_FULL_NAME" -n "$CERTSUITE_EXAMPLE_NAMESPACE" "$ADD_SECRET"
# Deploy the operator bundle
operator-sdk run bundle "$OPERATOR_BUNDLE_IMAGE_FULL_NAME" -n "$CERTSUITE_EXAMPLE_NAMESPACE" "$ADD_SECRET"
# Important: this line (output of command is now captured) is required to enable csv short names with non-ocp cluster
# If short name "csv" is used, the call will fail the first time
# With long name the first time it will work and subsequent time it will work with long or short names
CSV_MATCH=$(oc get clusterserviceversions.operators.coreos.com -n "$CERTSUITE_EXAMPLE_NAMESPACE" -ogo-template='{{ range .items}}{{.metadata.name}}{{end}}' 2>/dev/null | grep "nginx-operator.v0.0.1")
if [ "$CSV_MATCH" = "nginx-operator.v0.0.1" ]; then
echo "CSV successfully deployed"
else
echo "ERROR: CSV not deployed. Operator deployment failed -- interrupting tests"
exit 1
fi
# Important: this line (output of command is now captured) is required to enable csv short names with non-ocp cluster
# If short name "csv" is used, the call will fail the first time
# With long name the first time it will work and subsequent time it will work with long or short names
CSV_MATCH=$(oc get clusterserviceversions.operators.coreos.com -n "$CERTSUITE_EXAMPLE_NAMESPACE" -ogo-template='{{ range .items}}{{.metadata.name}}{{end}}' 2>/dev/null | grep "nginx-operator.v0.0.1")
if [ "$CSV_MATCH" = "nginx-operator.v0.0.1" ]; then
echo "CSV successfully deployed"
else
echo "ERROR: CSV not deployed. Operator deployment failed -- interrupting tests"
exit 1
fi
'

# deploy single namespace operator nginx in namespace nginx-ops
oc apply --filename ./test-target/operator-single-install-mode.yaml
2 changes: 0 additions & 2 deletions test-target/operator-single-install-mode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ kind: Subscription
metadata:
name: nginx-ingress-operator
namespace: nginx-ops
labels:
nginx-ingress-operator.v2.4.2
spec:
channel: alpha
installPlanApproval: Automatic
Expand Down

0 comments on commit b2320f9

Please sign in to comment.