forked from minio/directpv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release-operator.sh
executable file
·178 lines (154 loc) · 6.54 KB
/
release-operator.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/bash
# This file is part of MinIO DirectPV
# Copyright (c) 2023 MinIO, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
ME=$(basename "$0"); export ME
cd "$(dirname "$0")" || exit 255
set -o errexit
set -o nounset
set -o pipefail
declare BUILD_VERSION KUBECTL_DIRECTPV PODMAN OPERATOR_SDK KUSTOMIZE
function init() {
if [ "$#" -ne 1 ]; then
cat <<EOF
USAGE:
${ME} <VERSION>
EXAMPLE:
$ ${ME} 4.0.8
EOF
exit 255
fi
# assign after trimming 'v'
BUILD_VERSION="${1/v/}"
kubectl_directpv="kubectl-directpv_${BUILD_VERSION}_$(go env GOOS)_$(go env GOARCH)"
KUBECTL_DIRECTPV="${PWD}/${kubectl_directpv}"
if [ ! -f "${KUBECTL_DIRECTPV}" ]; then
echo "Downloading ${kubectl_directpv}"
curl --silent --location --insecure --fail --output "${kubectl_directpv}" "https://github.com/minio/directpv/releases/download/v${BUILD_VERSION}/${kubectl_directpv}"
chmod a+x "${kubectl_directpv}"
fi
if which podman >/dev/null 2>&1; then
PODMAN=podman
elif which docker >/dev/null 2>&1; then
PODMAN=docker
else
echo "no podman or docker found; please install"
exit 255
fi
if which operator-sdk >/dev/null 2>&1; then
OPERATOR_SDK=operator-sdk
fi
if [ -f "operator-sdk" ]; then
OPERATOR_SDK="${PWD}/operator-sdk"
fi
if [ -z "${OPERATOR_SDK=}" ]; then
OPERATOR_SDK="${PWD}/operator-sdk"
echo "Downloading operator-sdk"
release=$(curl -sfL "https://api.github.com/repos/operator-framework/operator-sdk/releases/latest" | awk '/tag_name/ { print substr($2, 2, length($2)-3) }')
curl -sfLo operator-sdk "https://github.com/operator-framework/operator-sdk/releases/download/${release}/operator-sdk_$(go env GOOS)_$(go env GOARCH)"
chmod a+x operator-sdk
fi
if which kustomize >/dev/null 2>&1; then
KUSTOMIZE=kustomize
fi
if [ -f ./kustomize ]; then
KUSTOMIZE="${PWD}/kustomize"
fi
if [ -z "${KUSTOMIZE=}" ]; then
KUSTOMIZE="${PWD}/kustomize"
echo "Downloading kustomize"
release=$(curl -sfL "https://api.github.com/repos/kubernetes-sigs/kustomize/releases/latest" | awk '/tag_name/ { print substr($2, 12, length($2)-13) }')
curl --silent --location --insecure --fail "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F${release}/kustomize_${release}_$(go env GOOS)_$(go env GOARCH).tar.gz" | tar -zxf -
fi
}
function git_commit() {
case "$(git describe --always --dirty)" in
*dirty)
git commit --quiet --all -m "$*"
git push --quiet
;;
esac
}
function update_charts() {
sed -i -e "/^appVersion: /c appVersion: \"${BUILD_VERSION}\"" "${PWD}/operator/helm-charts/directpv-chart/Chart.yaml"
"${KUBECTL_DIRECTPV}" install -o yaml | sed -e 's/^---/~~~/g' | awk '{f="file" NR; print $0 > f}' RS='~~~'
for file in file*; do
name=$(awk '/^kind:/ { print $NF }' "${file}")
if [ "${name}" == "CustomResourceDefinition" ]; then
name=$(awk '/^ name:/ { print $NF }' "${file}")
fi
if [ -n "${name}" ]; then
mv "${file}" "${PWD}/operator/helm-charts/directpv-chart/templates/${name}.yaml"
else
rm "${file}"
fi
done
git_commit "Update Helm charts for v${BUILD_VERSION}"
}
function make_release() {
export IMAGE_TAG_BASE=quay.io/minio/directpv-operator
export IMG="${IMAGE_TAG_BASE}:${BUILD_VERSION}"
cd operator
"${PODMAN}" buildx build --platform linux/amd64 --tag "${IMG}" .
"${PODMAN}" push "${IMG}"
git_commit "Update operator for v${BUILD_VERSION}"
# Package is intended for certified operators only not for rhmp anymore.
"${OPERATOR_SDK}" generate kustomize manifests --quiet --package minio-directpv-operator
}
### subsequent_steps() objective:
#
# To add additional things once images has been pushed in make_release()
#
### Reasoning:
#
# We can't add these additional things until images are pushed.
# This is why we need this function, similar to what we are doing at
# Operator repo: https://github.com/minio/operator/blob/master/olm-post-script.sh
#
function subsequent_steps() {
export IMAGE_TAG_BASE=quay.io/minio/directpv-operator
# Package is intended for certified operators only not for rhmp anymore.
# --use-image-digests flag will create relatedImages section by digest
# there is no need for any further modification if using --use-image-digests flag to get the digest form.
export BUNDLE_GEN_FLAGS="-q --overwrite --version ${BUILD_VERSION} --package minio-directpv-operator --use-image-digests"
export BUNDLE_IMG="${IMAGE_TAG_BASE}-bundle:v${BUILD_VERSION}"
export CONTROLLER_IMAGE="${IMAGE_TAG_BASE}:${BUILD_VERSION}"
# Controller image, should be in SHA Digest form for certification to pass test:
# verify-pinned-digest where all your container images should use SHA digests instead of tags.
# Example:
# (cd config/manager && kustomize edit set image controller=quay.io/minio/directpv-operator@sha256:04fec2fbd0d17f449a17c0f509b359c18d6c662e0a22e84cd625b538ca2a1af2)
(cd config/manager && "${KUSTOMIZE}" edit set image controller="${CONTROLLER_IMAGE}")
# shellcheck disable=SC2086
"${KUSTOMIZE}" build config/manifests | "${OPERATOR_SDK}" generate bundle ${BUNDLE_GEN_FLAGS}
# Since above line overwrites our redhat annotation,
# it will be added back:
{
echo " # Annotations to specify OCP versions compatibility."
echo " com.redhat.openshift.versions: v4.8-v4.13"
} >> bundle/metadata/annotations.yaml
"${OPERATOR_SDK}" bundle validate ./bundle
git_commit "Update operator bundle for v${BUILD_VERSION}"
"${PODMAN}" build -f bundle.Dockerfile --tag "${BUNDLE_IMG}" .
"${PODMAN}" push "${BUNDLE_IMG}"
git_commit "Update operator bundle image for v${BUILD_VERSION}"
cd -
}
function main() {
update_charts
make_release
subsequent_steps
}
init "$@"
main "$@"