forked from minio/operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
olm.sh
executable file
·144 lines (121 loc) · 6.87 KB
/
olm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
set -e
#binary versions
OPERATOR_SDK_VERSION=v1.22.2
TMP_BIN_DIR="$(mktemp -d)"
function install_binaries() {
if ! operator-sdk version; then
echo "Installing temporary Binaries into: $TMP_BIN_DIR";
echo "Installing temporary operator-sdk binary: $OPERATOR_SDK_VERSION"
ARCH=`{ case "$(uname -m)" in "x86_64") echo -n "amd64";; "aarch64") echo -n "arm64";; *) echo -n "$(uname -m)";; esac; }`
OS=$(uname | awk '{print tolower($0)}')
OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/$OPERATOR_SDK_VERSION
curl -L ${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH} -o ${TMP_BIN_DIR}/operator-sdk
OPERATOR_SDK_BIN=${TMP_BIN_DIR}/operator-sdk
chmod +x $OPERATOR_SDK_BIN
else
OPERATOR_SDK_BIN="$(which operator-sdk)"
fi
}
install_binaries
# get the minio version
minioVersionInExample=$(kustomize build examples/kustomization/tenant-openshift | yq eval-all '.spec.image' | tail -1)
echo "minioVersionInExample: ${minioVersionInExample}"
# Get sha form of minio version
minioVersionDigest=$(docker pull $minioVersionInExample | grep Digest | awk -F ' ' '{print $2}')
minioVersionDigest="quay.io/minio/minio@${minioVersionDigest}"
echo "minioVersionDigest: ${minioVersionDigest}"
# There are 4 catalogs in Red Hat, we are interested in two of them:
# https://docs.openshift.com/container-platform/4.7/operators/understanding/olm-rh-catalogs.html
# 1. redhat-operators <------------ Supported by Red Hat.
# 2. certified-operators <--------- Supported by the ISV (independent software vendors) <------------- We want this!
# 3. redhat-marketplace <---------- an be purchased from Red Hat Marketplace. <----------------------- We want this!
# 4. community-operators <--------- No official support.
redhatCatalogs=("certified-operators" "redhat-marketplace" "community-operators")
# This constants are supported Openshift versions
minOpenshiftVersion=4.8
maxOpenshiftVersion=4.14
for catalog in "${redhatCatalogs[@]}"; do
echo " "
echo $catalog
package=minio-operator
if [[ "$catalog" == "redhat-marketplace" ]]
then
package=minio-operator-rhmp
fi
echo "package: ${package}"
kustomize build config/manifests | $OPERATOR_SDK_BIN generate bundle \
--package $package \
--version $RELEASE \
--manifests \
--metadata \
--output-dir bundles/$catalog/$RELEASE \
--channels stable \
--overwrite \
--kustomize-dir config/manifests
# Set the version, later in olm-post-script.sh we change for Digest form.
containerImage="quay.io/minio/operator:v${RELEASE}"
echo "containerImage: ${containerImage}"
operatorImageDigest="quay.io/minio/operator:v${RELEASE}"
yq -i ".metadata.annotations.containerImage |= (\"${operatorImageDigest}\")" bundles/$catalog/$RELEASE/manifests/$package.clusterserviceversion.yaml
yq -i ".spec.install.spec.deployments[0].spec.template.spec.containers[0].image |= (\"${operatorImageDigest}\")" bundles/$catalog/$RELEASE/manifests/$package.clusterserviceversion.yaml
yq -i ".spec.install.spec.deployments[1].spec.template.spec.containers[0].image |= (\"${operatorImageDigest}\")" bundles/$catalog/$RELEASE/manifests/$package.clusterserviceversion.yaml
# Will query if a previous version of the CSV was published to the catalog of the latest supported Openshift version.
# It will help to prevent add the `spec.replaces` annotation when there is no preexisting CSV in the catalog to replace.
# See support case https://connect.redhat.com/support/technology-partner/#/case/03671253
prev=$(curl -s "https://catalog.redhat.com/api/containers/v1/operators/bundles?channel_name=stable&package=${package}&organization=${catalog}&ocp_version=${maxOpenshiftVersion}&include=data.version,data.csv_name,data.ocp_version" | jq '.data | length' -r)
# only add `spec.replaces` if at least one version have been published to the catalog
if [ "$prev" -gt 0 ]; then
# To provide channel for upgrade where we tell what versions can be replaced by the new version we offer
# You can read the documentation at link below:
# https://access.redhat.com/documentation/en-us/openshift_container_platform/4.2/html/operators/understanding-the-operator-lifecycle-manager-olm#olm-upgrades_olm-understanding-olm
echo "To provide replacement for upgrading Operator..."
PREV_VERSION=$(curl -s "https://catalog.redhat.com/api/containers/v1/operators/bundles?channel_name=stable&package=${package}&organization=${catalog}&ocp_version=${maxOpenshiftVersion}&include=data.version,data.csv_name,data.ocp_version" | jq '.data | max_by(.version).csv_name' -r)
echo "replaces: $PREV_VERSION"
yq -i e ".spec.replaces |= \"${PREV_VERSION}\"" bundles/$catalog/$RELEASE/manifests/$package.clusterserviceversion.yaml
else
echo "no previous published in catalog ${maxOpenshiftVersion}, removing spec.replaces"
yq -i "del(.spec.replaces) " bundles/$catalog/$RELEASE/manifests/$package.clusterserviceversion.yaml
fi
# Now promote the latest release to the root of the repository
rm -Rf manifests
rm -Rf metadata
mkdir -p $catalog
cp -R bundles/$catalog/$RELEASE/manifests $catalog
cp -R bundles/$catalog/$RELEASE/metadata $catalog
sed -i -e '/metrics/d' bundle.Dockerfile
sed -i -e '/scorecard/d' bundle.Dockerfile
sed -i -e '/testing/d' bundle.Dockerfile
echo "clean released annotations"
sed -i -e '/metrics/d' bundles/$catalog/$RELEASE/metadata/annotations.yaml
sed -i -e '/scorecard/d' bundles/$catalog/$RELEASE/metadata/annotations.yaml
sed -i -e '/testing/d' bundles/$catalog/$RELEASE/metadata/annotations.yaml
# Add openshift supported version & default channel
# It needs to be added, since you have to declare both the potential eligible
# channels for an operator via operators.operatorframework.io.bundle.channels
# as well as the default.
{
echo " # Annotations to specify OCP versions compatibility."
echo " com.redhat.openshift.versions: v${minOpenshiftVersion}-v${maxOpenshiftVersion}"
echo " # Annotation to add default bundle channel as potential is declared"
echo " operators.operatorframework.io.bundle.channel.default.v1: stable"
echo " operatorframework.io/suggested-namespace: minio-operator"
} >> bundles/$catalog/$RELEASE/metadata/annotations.yaml
echo "clean root level annotations.yaml"
sed -i -e '/metrics/d' bundles/$catalog/$RELEASE/metadata/annotations.yaml
sed -i -e '/scorecard/d' bundles/$catalog/$RELEASE/metadata/annotations.yaml
sed -i -e '/testing/d' bundles/$catalog/$RELEASE/metadata/annotations.yaml
done
echo " "
echo "clean -e files"
rm -vf $(git ls-files --others | grep -e "-e$" | awk '{print $1}')
echo "Copying latest bundle to root"
cp -R bundles/redhat-marketplace/$RELEASE/manifests manifests
cp -R bundles/redhat-marketplace/$RELEASE/metadata metadata
echo "Commit all assets"
#git add -u
#git add bundles
#git add community-operators
#git add helm-releases
echo "Removing temporary binaries in: $TMP_BIN_DIR"
rm -rf $TMP_BIN_DIR