Skip to content

Commit

Permalink
validate OCP marketplace
Browse files Browse the repository at this point in the history
  • Loading branch information
stuggi committed Apr 24, 2024
1 parent e0252b6 commit 02f0bc3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,8 @@ endif

##@ OPENSTACK

OPENSTACK_PREP_DEPS := $(if $(findstring true,$(INSTALL_CERT_MANAGER)), certmanager)
OPENSTACK_PREP_DEPS := validate_marketplace
OPENSTACK_PREP_DEPS += $(if $(findstring true,$(INSTALL_CERT_MANAGER)), certmanager)
OPENSTACK_PREP_DEPS += $(if $(findstring true,$(NETWORK_ISOLATION)), nmstate nncp netattach metallb metallb_config)
OPENSTACK_PREP_DEPS += $(if $(findstring true,$(NETWORK_BGP)), nmstate nncp netattach metallb metallb_config)
OPENSTACK_PREP_DEPS += $(if $(findstring true,$(BMO_SETUP)), crc_bmo_setup)
Expand Down Expand Up @@ -2548,3 +2549,8 @@ certmanager_cleanup:
oc delete -n ${OPERATOR_NAMESPACE} csv --all --ignore-not-found=true
oc delete -n ${NAMESPACE} installplan --all --ignore-not-found=true
oc delete -n cert-manager deployment --all

.PHONY: validate_marketplace
validate_marketplace: ## validates that the openshift marketplace is healthy and has the packagemanifests for the required operators
$(eval $(call vars,$@,openshift-marketplace))
bash scripts/validate-marketplace.sh
49 changes: 49 additions & 0 deletions scripts/validate-marketplace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
#
# Copyright 2024 Red Hat Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
set -x

if [ -z "${TIMEOUT}" ]; then
echo "Please set TIMEOUT"; exit 1
fi

OPERATOR_NAMESPACE=openshift-marketplace

oc get pods -n ${OPERATOR_NAMESPACE} | grep "CrashLoopBackOff"
if [ $? -eq 0 ]; then
oc patch OperatorHub cluster --type json -p '[{"op": "add", "path": "/spec/disableAllDefaultSources", "value": true}]'
oc wait pod --for=delete -n ${OPERATOR_NAMESPACE} -l olm.managed --timeout=${TIMEOUT}
oc patch OperatorHub cluster --type json -p '[{"op": "add", "path": "/spec/disableAllDefaultSources", "value": false}]'
oc wait pod -n ${OPERATOR_NAMESPACE} -l olm.managed --for condition=Ready
fi

OPERATORS="openshift-cert-manager-operator kubernetes-nmstate-operator metallb-operator"

for operator in $OPERATORS; do
n=0
retries="${1:-20}" # Number of retries with a default value of 20
while true; do
oc get packagemanifests -n ${OPERATOR_NAMESPACE} | grep $operator
if [ $? -eq 0 ]; then
break
fi
n=$((n+1))
if (( n >= retries )); then
echo "Failed to get packagemanifest for operator $operator. Aborting"
exit 1
fi
sleep 10
done
done

0 comments on commit 02f0bc3

Please sign in to comment.