-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add medik8s-operator-subscribe Prow step for OLM operator installation #79547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ugreener
wants to merge
1
commit into
openshift:main
Choose a base branch
from
ugreener:rhwa-operator-subscribe
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
ci-operator/step-registry/medik8s/operator-subscribe/OWNERS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| approvers: | ||
| - beekhof | ||
| - clobrano | ||
| - maximunited | ||
| - mshitrit | ||
| - razo7 | ||
| - slintes | ||
| - ugreener | ||
| reviewers: | ||
| - beekhof | ||
| - clobrano | ||
| - maximunited | ||
| - mshitrit | ||
| - razo7 | ||
| - slintes | ||
| - ugreener |
190 changes: 190 additions & 0 deletions
190
ci-operator/step-registry/medik8s/operator-subscribe/medik8s-operator-subscribe-commands.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| #!/bin/bash | ||
| set -eu -o pipefail | ||
|
|
||
| declare CATALOG_SOURCE_NAME="${CATALOG_SOURCE_NAME:-medik8s-catalog}" | ||
| declare OO_CHANNEL="${OO_CHANNEL:-candidate}" | ||
| declare INSTALL_NAMESPACE="${INSTALL_NAMESPACE:-openshift-workload-availability}" | ||
| declare OPERATORS="${OPERATORS:-}" | ||
|
|
||
| set_proxy() { | ||
| [[ -f "${SHARED_DIR}/proxy-conf.sh" ]] && { | ||
| echo "setting proxy" | ||
| source "${SHARED_DIR}/proxy-conf.sh" | ||
| } | ||
| return 0 | ||
| } | ||
|
|
||
| ensure_namespace() { | ||
| echo "Ensuring namespace ${INSTALL_NAMESPACE}..." | ||
| cat <<EOF | oc apply -f - | ||
| apiVersion: v1 | ||
| kind: Namespace | ||
| metadata: | ||
| labels: | ||
| security.openshift.io/scc.podSecurityLabelSync: "false" | ||
| pod-security.kubernetes.io/enforce: privileged | ||
| pod-security.kubernetes.io/audit: privileged | ||
| pod-security.kubernetes.io/warn: privileged | ||
| name: ${INSTALL_NAMESPACE} | ||
| EOF | ||
| } | ||
|
|
||
| ensure_operatorgroup() { | ||
| local existing | ||
| existing=$(oc -n "$INSTALL_NAMESPACE" get operatorgroup -o jsonpath="{.items[*].metadata.name}" 2>/dev/null || true) | ||
| if [[ -n "$existing" ]]; then | ||
| local count | ||
| count=$(echo "$existing" | wc -w) | ||
| if [[ $count -gt 1 ]]; then | ||
| echo "ERROR: Multiple OperatorGroups in namespace ${INSTALL_NAMESPACE}: $existing" | ||
| oc -n "$INSTALL_NAMESPACE" get operatorgroup -o yaml || true | ||
| return 1 | ||
| fi | ||
| echo "OperatorGroup already exists: $existing" | ||
| return 0 | ||
| fi | ||
|
|
||
| echo "Creating OperatorGroup in ${INSTALL_NAMESPACE}..." | ||
| cat <<EOF | oc apply -f - | ||
| apiVersion: operators.coreos.com/v1 | ||
| kind: OperatorGroup | ||
| metadata: | ||
| name: medik8s-og | ||
| namespace: ${INSTALL_NAMESPACE} | ||
| spec: | ||
| targetNamespaces: | ||
| - ${INSTALL_NAMESPACE} | ||
| EOF | ||
| } | ||
|
|
||
| wait_for_package_manifest() { | ||
| local pkg="$1" | ||
| echo "Waiting for PackageManifest ${pkg} in CatalogSource ${CATALOG_SOURCE_NAME}..." | ||
| local -i deadline=$(( SECONDS + 120 )) | ||
| while (( SECONDS < deadline )); do | ||
| if oc get packagemanifest -n openshift-marketplace \ | ||
| -l "catalog=${CATALOG_SOURCE_NAME}" \ | ||
| --field-selector "metadata.name=${pkg}" -o name 2>/dev/null | grep -q .; then | ||
| echo "PackageManifest ${pkg} found" | ||
| return 0 | ||
| fi | ||
| echo " ${SECONDS}s — not found yet, waiting 5s..." | ||
| sleep 5 | ||
| done | ||
| echo "ERROR: PackageManifest ${pkg} not found after 120s" | ||
| oc get packagemanifest -n openshift-marketplace -l "catalog=${CATALOG_SOURCE_NAME}" || true | ||
| return 1 | ||
| } | ||
|
|
||
| create_subscription() { | ||
| local pkg="$1" | ||
| echo "Creating Subscription for ${pkg} (channel: ${OO_CHANNEL}, source: ${CATALOG_SOURCE_NAME})..." | ||
| cat <<EOF | oc apply -f - | ||
| apiVersion: operators.coreos.com/v1alpha1 | ||
| kind: Subscription | ||
| metadata: | ||
| name: ${pkg} | ||
| namespace: ${INSTALL_NAMESPACE} | ||
| spec: | ||
| channel: ${OO_CHANNEL} | ||
| name: ${pkg} | ||
| source: ${CATALOG_SOURCE_NAME} | ||
| sourceNamespace: openshift-marketplace | ||
| installPlanApproval: Automatic | ||
| EOF | ||
| } | ||
|
|
||
| wait_for_csv() { | ||
| local pkg="$1" | ||
| echo "Waiting for CSV from subscription ${pkg}..." | ||
|
|
||
| local csv="" | ||
| local -i deadline=$(( SECONDS + 600 )) | ||
| while (( SECONDS < deadline )); do | ||
| csv=$(oc get subscription "$pkg" -n "$INSTALL_NAMESPACE" \ | ||
| -o jsonpath='{.status.installedCSV}' 2>/dev/null || true) | ||
| if [[ -n "$csv" ]]; then | ||
| echo "Found CSV: $csv" | ||
| break | ||
| fi | ||
| echo " ${SECONDS}s — CSV not ready yet, waiting 10s..." | ||
| sleep 10 | ||
| done | ||
|
|
||
| if [[ -z "$csv" ]]; then | ||
| echo "ERROR: No CSV installed for subscription ${pkg} after 10m" | ||
| echo "--- Debug info ---" | ||
| oc get subscription "$pkg" -n "$INSTALL_NAMESPACE" -o yaml || true | ||
| oc get installplan -n "$INSTALL_NAMESPACE" || true | ||
| oc get events -n "$INSTALL_NAMESPACE" --sort-by='.lastTimestamp' 2>/dev/null | tail -20 || true | ||
| return 1 | ||
| fi | ||
|
|
||
| echo "Waiting for CSV ${csv} to reach Succeeded phase..." | ||
| if oc wait --for=jsonpath='{.status.phase}'=Succeeded "csv/${csv}" \ | ||
| -n "$INSTALL_NAMESPACE" --timeout=5m; then | ||
| echo "CSV ${csv} is Succeeded" | ||
| return 0 | ||
| fi | ||
|
|
||
| echo "ERROR: CSV ${csv} did not reach Succeeded within 5m" | ||
| oc get csv "$csv" -n "$INSTALL_NAMESPACE" -o yaml || true | ||
| return 1 | ||
| } | ||
|
|
||
| main() { | ||
| echo "=== medik8s Operator Subscribe ===" | ||
| set_proxy | ||
|
|
||
| if [[ -z "${OPERATORS//[[:space:],]/}" ]]; then | ||
| echo "ERROR: OPERATORS env var is required (comma-separated OLM package names)" | ||
| echo "Example: OPERATORS=fence-agents-remediation,storage-based-remediation" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ -f "${SHARED_DIR}/catsrc_name" ]]; then | ||
| CATALOG_SOURCE_NAME=$(cat "${SHARED_DIR}/catsrc_name") | ||
| echo "Using CatalogSource name from SHARED_DIR: ${CATALOG_SOURCE_NAME}" | ||
| fi | ||
|
|
||
| echo "CatalogSource: ${CATALOG_SOURCE_NAME}" | ||
| echo "Channel: ${OO_CHANNEL}" | ||
| echo "Namespace: ${INSTALL_NAMESPACE}" | ||
| echo "Operators: ${OPERATORS}" | ||
|
|
||
| ensure_namespace | ||
| ensure_operatorgroup | ||
|
|
||
| IFS=',' read -ra OPERATOR_LIST <<< "$OPERATORS" | ||
|
|
||
| for pkg in "${OPERATOR_LIST[@]}"; do | ||
| pkg="${pkg//[[:space:]]/}" | ||
| [[ -z "$pkg" ]] && continue | ||
| echo "" | ||
| echo "--- Installing operator: ${pkg} ---" | ||
| wait_for_package_manifest "$pkg" || exit 1 | ||
| create_subscription "$pkg" | ||
| done | ||
|
|
||
| sleep 10 | ||
|
|
||
| local failed=0 | ||
| for pkg in "${OPERATOR_LIST[@]}"; do | ||
| pkg="${pkg//[[:space:]]/}" | ||
| [[ -z "$pkg" ]] && continue | ||
| if ! wait_for_csv "$pkg"; then | ||
| failed=1 | ||
| fi | ||
| done | ||
|
|
||
| if [[ $failed -eq 1 ]]; then | ||
| echo "ERROR: One or more operators failed to install" | ||
| oc get csv -n "$INSTALL_NAMESPACE" || true | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "" | ||
| echo "=== All operators installed successfully ===" | ||
| oc get csv -n "$INSTALL_NAMESPACE" | ||
| } | ||
| main | ||
23 changes: 23 additions & 0 deletions
23
...tor/step-registry/medik8s/operator-subscribe/medik8s-operator-subscribe-ref.metadata.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "path": "medik8s/operator-subscribe/medik8s-operator-subscribe-ref.yaml", | ||
| "owners": { | ||
| "approvers": [ | ||
| "beekhof", | ||
| "clobrano", | ||
| "maximunited", | ||
| "mshitrit", | ||
| "razo7", | ||
| "slintes", | ||
| "ugreener" | ||
| ], | ||
| "reviewers": [ | ||
| "beekhof", | ||
| "clobrano", | ||
| "maximunited", | ||
| "mshitrit", | ||
| "razo7", | ||
| "slintes", | ||
| "ugreener" | ||
| ] | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
ci-operator/step-registry/medik8s/operator-subscribe/medik8s-operator-subscribe-ref.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| ref: | ||
| as: medik8s-operator-subscribe | ||
| from: upi-installer | ||
| cli: latest | ||
| grace_period: 10m | ||
| commands: medik8s-operator-subscribe-commands.sh | ||
| resources: | ||
| requests: | ||
| cpu: 100m | ||
| memory: 100Mi | ||
| env: | ||
| - name: OPERATORS | ||
| documentation: |- | ||
| Comma-separated list of OLM package names to install. | ||
| Example: "fence-agents-remediation,storage-based-remediation" | ||
| default: "" | ||
| - name: CATALOG_SOURCE_NAME | ||
| documentation: |- | ||
| Name of the CatalogSource to subscribe from. Must already exist in openshift-marketplace. | ||
| Typically created by the medik8s-catalogsource step. | ||
| default: "medik8s-catalog" | ||
| - name: OO_CHANNEL | ||
| documentation: OLM subscription channel for operator installation. | ||
| default: "candidate" | ||
| - name: INSTALL_NAMESPACE | ||
| documentation: Namespace where operators will be installed. | ||
| default: "openshift-workload-availability" | ||
| documentation: |- | ||
| Installs medik8s/RHWA operators via OLM Subscription from an existing CatalogSource. | ||
| Creates the namespace, OperatorGroup, and Subscriptions, then waits for CSVs to reach Succeeded. | ||
| Designed to run after the medik8s-catalogsource step. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.