Skip to content
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

simple deploy_marketplace.sh #409

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy/deploy_imageregistry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CLUSTER="${CLUSTER:-OPENSHIFT}"
GLOBAL_NAMESPACE="${GLOBAL_NAMESPACE:-$globalNamespace}"

APPROVAL="${APPROVAL:-Manual}"
CONTENT_ONLY="${CONTENT_ONLY:-}"
CONTENT_ONLY="${CONTENT_ONLY:-Y}"
KVM_EMULATION="${KVM_EMULATION:-false}"

RETRIES="${RETRIES:-10}"
Expand Down
214 changes: 36 additions & 178 deletions deploy/deploy_marketplace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,215 +2,73 @@

set -ex

RED='\033[0;31m'
NO_COLOR='\033[0m'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change is irrelevant. If you think that this should be dropped, please do it in a separate PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because when you have a cluster (clean one), you already have 3 catalogsources: redhat-operators, community, and certified-operators. So no need for preparation.
In case of QE/Dev, custom catalogsources are prepared earlier, and already used for other operators (not just CNV)

Should someone, needs a custom catsrc, then he can't use the "full" script as it's not supporting the creation of a plain catalogSource (ONLY by operatorSource, from QUAY).

IMO, an OLM catalogSource creation script, should be added to repo as an extra utility, and to support plain/opsrc catsrc creation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like long scripts myself. If you want to split out some logic to another script, please do it. But please take care of existing use cases

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned before, for 99.99% of deploy_marketplace.sh, creation of catalogSOurce is not required. For other cases, the split is in a new script (with old content) deploy_operatoSource.sh.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we already have deploy_imageregistry.sh (to consume the bundle image as a local registry) and deploy_marketplace.sh (to deploy pointing to a remote app-registry) and we want to unify them (to avoid having to duplicate each fix to both of them).
Introducing a third script is definitively not an option.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deploy_imageregistry is creating catalogSource not an operatorSource from QUAY.
Also this one should be splitted..
Sure, it's a good idea to unify them (just for catsrc/opsrc creation)


globalNamespace=`oc -n openshift-operator-lifecycle-manager get deployments catalog-operator -o jsonpath='{.spec.template.spec.containers[].args[1]}'`
echo "Global Namespace: ${globalNamespace}"

APP_REGISTRY="${APP_REGISTRY:-kubevirt-hyperconverged}"
APP_REGISTRY="${APP_REGISTRY:-redhat-operators}"
PACKAGE="${PACKAGE:-kubevirt-hyperconverged}"
CSC_SOURCE="${CSC_SOURCE:-hco-catalogsource-config}"
TARGET_NAMESPACE="${TARGET_NAMESPACE:-kubevirt-hyperconverged}"
OPERATOR="hyperconverged-cluster-operator"
TARGET_NAMESPACE="${TARGET_NAMESPACE:-openshift-cnv}"
CLUSTER="${CLUSTER:-OPENSHIFT}"
MARKETPLACE_NAMESPACE="${MARKETPLACE_NAMESPACE:-openshift-marketplace}"
GLOBAL_NAMESPACE="${GLOBAL_NAMESPACE:-$globalNamespace}"
HCO_VERSION="${HCO_VERSION:-1.0.0}"
HCO_CHANNEL="${HCO_CHANNEL:-1.0.0}"
APPROVAL="${APPROVAL:-Manual}"
CONTENT_ONLY="${CONTENT_ONLY:-}"
KVM_EMULATION="${KVM_EMULATION:-false}"
PRIVATE_REPO="${PRIVATE_REPO:-false}"
QUAY_USERNAME="${QUAY_USERNAME:-}"
QUAY_PASSWORD="${QUAY_PASSWORD:-}"
QUAY_TOKEN="${QUAY_TOKEN:-}"

RETRIES="${RETRIES:-10}"

oc create ns $TARGET_NAMESPACE || true
HCO_VERSION="${HCO_VERSION:-2.1.0}"
HCO_CHANNEL="${HCO_CHANNEL:-2.1}"

if [ "${CLUSTER}" == "KUBERNETES" ]; then
MARKETPLACE_NAMESPACE="marketplace"
OPERATOR="hco-operator"
APP_REGISTRY="kubevirt-hyperconverged"
HCO_VERSION="${HCO_VERSION:-1.0.0}"
HCO_CHANNEL="${HCO_CHANNEL:-1.0.0}"
TARGET_NAMESPACE="${TARGET_NAMESPACE:-kubevirt-hyperconverged}"
fi

TMP_DIR=$(mktemp -d)

function cleanup_tmp {
rm -rf $TMP_DIR
}

trap cleanup_tmp EXIT

cleanup_tmp

AUTH_TOKEN=""

if [ "$PRIVATE_REPO" = true ]; then
if [ -z "${QUAY_TOKEN}" ]; then
if [ -z "${QUAY_USERNAME}" ]; then
echo "QUAY_USERNAME is unset"
exit 1
fi

if [ -z "${QUAY_PASSWORD}" ]; then
echo "QUAY_PASSWORD is unset"
exit 1
fi

QUAY_TOKEN=$(curl -sH "Content-Type: application/json" -XPOST https://quay.io/cnr/api/v1/users/login -d '
{
"user": {
"username": "'"${QUAY_USERNAME}"'",
"password": "'"${QUAY_PASSWORD}"'"
}
}' | jq -r '.token')

echo $QUAY_TOKEN
if [ "${QUAY_TOKEN}" == "null" ]; then
echo "QUAY_TOKEN was 'null'. Did you enter the correct quay Username & Password?"
exit 1
fi
fi

echo "Creating registry secret"
cat <<EOF | oc create -f -
apiVersion: v1
kind: Secret
metadata:
name: "quay-registry-${APP_REGISTRY}"
namespace: "${MARKETPLACE_NAMESPACE}"
type: Opaque
stringData:
token: "$QUAY_TOKEN"
EOF

AUTH_TOKEN=$(cat <<EOF
authorizationToken:
secretName: "quay-registry-${APP_REGISTRY}"
EOF
)

fi

if [ `oc get OperatorSource "${APP_REGISTRY}" -n "${MARKETPLACE_NAMESPACE}" --no-headers 2> /dev/null | wc -l` -eq 0 ]; then
echo "Creating OperatorSource"
cat <<EOF | oc create -f -
apiVersion: operators.coreos.com/v1
kind: OperatorSource
metadata:
name: "${APP_REGISTRY}"
namespace: "${MARKETPLACE_NAMESPACE}"
spec:
type: appregistry
endpoint: https://quay.io/cnr
registryNamespace: "${APP_REGISTRY}"
displayName: "${APP_REGISTRY}"
publisher: "Kubevirt"
${AUTH_TOKEN}
EOF
fi

echo "Give the cluster 30 seconds to create the catalogSourceConfig..."
sleep 30

cat <<EOF | oc apply -f -
apiVersion: operators.coreos.com/v1
kind: CatalogSourceConfig
metadata:
name: "${CSC_SOURCE}"
namespace: "${MARKETPLACE_NAMESPACE}"
spec:
source: "${APP_REGISTRY}"
targetNamespace: "${GLOBAL_NAMESPACE}"
packages: "${PACKAGE}"
csDisplayName: "HCO Operator"
csPublisher: "Red Hat"
EOF

echo "Give the cluster 30 seconds to process catalogSourceConfig..."
sleep 30
oc wait deploy $CSC_SOURCE --for condition=available -n $MARKETPLACE_NAMESPACE --timeout="360s"

for i in $(seq 1 $RETRIES); do
echo "Waiting for packagemanifest '${PACKAGE}' to be created in namespace '${TARGET_NAMESPACE}'..."
oc get packagemanifest -n "${TARGET_NAMESPACE}" "${PACKAGE}" && break
sleep $i
if [ "$i" -eq "${RETRIES}" ]; then
echo "packagemanifest '${PACKAGE}' was never created in namespace '${TARGET_NAMESPACE}'"
exit 1
fi
done

SUBSCRIPTION_CONFIG=""
if [ "$KVM_EMULATION" = true ]; then
SUBSCRIPTION_CONFIG=$(cat <<EOF
config:
selector:
matchLabels:
name: hyperconverged-cluster-operator
env:
- name: KVM_EMULATION
value: "true"
EOF
)
fi
oc create ns $TARGET_NAMESPACE || true

echo "Content Successfully Created"
if [ -z "${CONTENT_ONLY}" ]; then
oc -n "${TARGET_NAMESPACE}" delete og ${PACKAGE}-operatorgroup || true
oc -n "${TARGET_NAMESPACE}" delete sub ${PACKAGE}-subscription || true
oc -n "${TARGET_NAMESPACE}" delete csv --all || true
oc -n "${TARGET_NAMESPACE}" delete ip --all || true

if [ `oc get operatorgroup -n "${TARGET_NAMESPACE}" --no-headers 2> /dev/null | wc -l` -eq 0 ]; then
echo "Creating OperatorGroup"
cat <<EOF | oc create -f -
cat << __EOF__ | oc create -f -
---
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: "${TARGET_NAMESPACE}-group"
name: "${PACKAGE}-operatorgroup"
namespace: "${TARGET_NAMESPACE}"
spec:
serviceAccount:
metadata:
creationTimestamp: null
targetNamespaces:
- "${TARGET_NAMESPACE}"
EOF
fi

echo "Creating Subscription"
cat <<EOF | oc create -f -
---
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: hco-operatorhub
name: "${PACKAGE}-subscription"
namespace: "${TARGET_NAMESPACE}"
spec:
source: "${CSC_SOURCE}"
sourceNamespace: "${GLOBAL_NAMESPACE}"
name: kubevirt-hyperconverged
startingCSV: "kubevirt-hyperconverged-operator.v${HCO_VERSION}"
channel: "${HCO_CHANNEL}"
installPlanApproval: "${APPROVAL}"
${SUBSCRIPTION_CONFIG}
EOF

echo "Give OLM 60 seconds to process the subscription..."
sleep 60
sourceNamespace: "${MARKETPLACE_NAMESPACE}"
source: "${APP_REGISTRY}"
name: "${PACKAGE}"
channel: "${HCO_CHANNEL}"
startingCSV: "${PACKAGE}-operator.v${HCO_VERSION}"
__EOF__
#wait for it
retries=0; while [ $retries -lt 200 ] && ! oc wait --for condition=ready pod -l name=${OPERATOR} -n ${TARGET_NAMESPACE} --timeout=1m ; do sleep 15; let retries=$retries+1; done

oc get installplan -o yaml -n "${TARGET_NAMESPACE}" $(oc get installplan -n "${TARGET_NAMESPACE}" --no-headers | grep "kubevirt-hyperconverged-operator.v${HCO_VERSION}" | awk '{print $1}') | sed 's/approved: false/approved: true/' | oc apply -n "${TARGET_NAMESPACE}" -f -

echo "Give OLM 60 seconds to process the installplan..."
sleep 60
oc -n "${TARGET_NAMESPACE}" delete hco --all || true

oc wait pod $(oc get pods -n ${TARGET_NAMESPACE} | grep hco-operator | head -1 | awk '{ print $1 }') --for condition=Ready -n ${TARGET_NAMESPACE} --timeout="360s"

echo "Creating the HCO's Custom Resource"
cat <<EOF | oc create -f -
cat << __EOF__ | oc create -f -
apiVersion: hco.kubevirt.io/v1alpha1
kind: HyperConverged
metadata:
name: hyperconverged-cluster
namespace: "${TARGET_NAMESPACE}"
spec:
BareMetalPlatform: true
EOF
__EOF__
#wait for it
retries=0; while [ $retries -lt 200 ] && ! oc wait --for condition=Available hyperconverged hyperconverged-cluster -n ${TARGET_NAMESPACE} --timeout=2m ; do sleep 15; let retries=$retries+1; done

echo "Waiting for HCO to get fully deployed"
oc wait -n ${TARGET_NAMESPACE} hyperconverged hyperconverged-cluster --for condition=Available --timeout=15m
oc wait "$(oc get pods -n ${TARGET_NAMESPACE} -l name=hyperconverged-cluster-operator -o name)" -n "${TARGET_NAMESPACE}" --for condition=Ready --timeout=15m
fi
Loading