From e5ae5e0bd29d8dce96fb64b3b7378988e57d39c8 Mon Sep 17 00:00:00 2001 From: Sergio Arroutbi Date: Tue, 8 Aug 2023 12:04:46 +0200 Subject: [PATCH] Add index tools (catalog, subscription) Resolves: #144 Signed-off-by: Sergio Arroutbi --- .../tang_catalog_source_template.yaml | 11 ++++ tools/index_tools/tang_index.sh | 53 +++++++++++++++++++ tools/index_tools/tang_install_catalog.sh | 49 +++++++++++++++++ tools/index_tools/tang_subscription.yaml | 13 +++++ tools/index_tools/tang_uninstall_catalog.sh | 3 ++ 5 files changed, 129 insertions(+) create mode 100644 tools/index_tools/tang_catalog_source_template.yaml create mode 100755 tools/index_tools/tang_index.sh create mode 100755 tools/index_tools/tang_install_catalog.sh create mode 100644 tools/index_tools/tang_subscription.yaml create mode 100755 tools/index_tools/tang_uninstall_catalog.sh diff --git a/tools/index_tools/tang_catalog_source_template.yaml b/tools/index_tools/tang_catalog_source_template.yaml new file mode 100644 index 0000000..9a22ce4 --- /dev/null +++ b/tools/index_tools/tang_catalog_source_template.yaml @@ -0,0 +1,11 @@ +apiVersion: operators.coreos.com/v1alpha1 +kind: CatalogSource +metadata: + name: tang-operator + namespace: openshift-operators +spec: + displayName: tang-operator + publisher: Red Hat + sourceType: grpc + image: quay.io/sec-eng-special/tang-operator-index:VERSION_HERE + diff --git a/tools/index_tools/tang_index.sh b/tools/index_tools/tang_index.sh new file mode 100755 index 0000000..e9170f9 --- /dev/null +++ b/tools/index_tools/tang_index.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Parameters: +# 1 - sync image to quay.io// or registry-proxy.engineering.redhat.com/rh-osbs/tang-operator-bundle@sha256:fceb6d82cea8fd14be1b0ebc0333d314ec5bd2c88199c0aa63377d12c6f4db6e +# 2 - two parameters, $1 is for bundle; $2 is for release, format like 0.0.25-1 +# Example: +# $0 "registry-proxy.engineering.redhat.com/rh-osbs/tang-operator-bundle:0.2.0-6" +# ./tang_index.sh registry-proxy.engineering.redhat.com/rh-osbs/tang-operator-bundle@sha256:a69a44c15bb0ca40a382dcd551f2e7ed06fe8ae8007df55feeeb8a1c33de6e7d 0.2.0-6 +# +# +CONTAINER_MGR='docker' + +usage() { +### echo './tang_index.sh registry-proxy.engineering.redhat.com/rh-osbs/tang-operator-bundle@sha256:a69a44c15bb0ca40a382dcd551f2e7ed06fe8ae8007df55feeeb8a1c33de6e7d 0.2.0-6' + echo './tang_index.sh quay.io/sec-eng-special/tang-operator-bundle:v0.2.0-6 0.2.0-6' + exit "$2" +} + +while getopts "h" arg +do + case "${arg}" in + h) usage "$0" 0 + ;; + *) usage "$0" 1 + ;; + esac +done + +CO_image_with_digest=$1 +version=$2 + +digest=$(echo "${CO_image_with_digest}" | awk -F: '{print $2}') +sub_digest="${digest:0:12}" + +"${CONTAINER_MGR}" login quay.io -u sarroutb +echo "sub_digest:${sub_digest}" + +#1. Mirror bundle container image +echo -e "step 1 \n\n" + +oc image mirror --filter-by-os=".*" --keep-manifest-list "${CO_image_with_digest}" quay.io/sec-eng-special/tang-operator-bundle-container:"${sub_digest}" +oc image mirror --filter-by-os=".*" --keep-manifest-list "${CO_image_with_digest}" quay.io/sec-eng-special/tang-operator-bundle-container:latest + +#2. Build index image +echo -e "step 2 \n\n" +opm index add --bundles "${CO_image_with_digest}" --tag quay.io/sec-eng-special/tang-operator-index:v"${version}" -c ${CONTAINER_MGR} + +#3. Push image index to quay.io/sec-eng-special/ +echo -e "step 3 \n\n" +echo -e "${CONTAINER_MGR} push quay.io/sec-eng-special/tang-operator-index:v$version \n" +${CONTAINER_MGR} push quay.io/sec-eng-special/tang-operator-index:v"${version}" + +#4. Substitute version in catalog source +sed -e "s@VERSION_HERE@v${version}@g" < tang_catalog_source_template.yaml > tang_catalog_source.yaml diff --git a/tools/index_tools/tang_install_catalog.sh b/tools/index_tools/tang_install_catalog.sh new file mode 100755 index 0000000..5f1b8e7 --- /dev/null +++ b/tools/index_tools/tang_install_catalog.sh @@ -0,0 +1,49 @@ +#!/bin/bash +echo "-------------------------------------" +echo "oc status" +oc status +echo "-------------------------------------" +sleep 1 +echo "oc create -f tang_catalog_source.yaml" +oc create -f tang_catalog_source.yaml +echo "-------------------------------------" +sleep 1 +echo "oc get catsrc -nopenshift-marketplace" +oc get catsrc -nopenshift-marketplace +echo "-------------------------------------" +sleep 1 +echo "oc get pods -nopenshift-marketplace" +oc get pods -nopenshift-marketplace +echo "-------------------------------------" +sleep 1 +echo "oc create -f tang_subscription.yaml" +oc create -f tang_subscription.yaml +echo "-------------------------------------" +echo "oc project" +oc project +echo "-------------------------------------" +sleep 1 +echo "oc get sub" +oc get sub +echo "-------------------------------------" +sleep 1 +echo "oc get ip" +oc get ip +echo "-------------------------------------" +sleep 1 +echo "oc get jobs -nopenshift-marketplace" +oc get jobs -nopenshift-marketplace +echo "-------------------------------------" +sleep 1 +echo "oc get pods -nopenshift-marketplace" +oc get pods -nopenshift-marketplace +echo "-------------------------------------" +sleep 1 +echo "oc get csv" +oc get csv +echo "-------------------------------------" +sleep 1 +echo "oc get pods" +oc get pods +echo "-------------------------------------" +sleep 1 diff --git a/tools/index_tools/tang_subscription.yaml b/tools/index_tools/tang_subscription.yaml new file mode 100644 index 0000000..9b63175 --- /dev/null +++ b/tools/index_tools/tang_subscription.yaml @@ -0,0 +1,13 @@ +apiVersion: operators.coreos.com/v1alpha1 +kind: Subscription +metadata: + labels: + operators.coreos.com/tang-operator.openshift-operators: "" + name: tang-operator + namespace: openshift-operators +spec: + channel: "alpha" + installPlanApproval: Automatic + name: tang-operator + source: tang-operator + sourceNamespace: openshift-marketplace diff --git a/tools/index_tools/tang_uninstall_catalog.sh b/tools/index_tools/tang_uninstall_catalog.sh new file mode 100755 index 0000000..646e7d8 --- /dev/null +++ b/tools/index_tools/tang_uninstall_catalog.sh @@ -0,0 +1,3 @@ +#!/bin/bash +oc delete -f tang_subscription.yaml +oc delete -f tang_catalog_source.yaml