-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdocker-entry.sh
executable file
·83 lines (70 loc) · 3.04 KB
/
docker-entry.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
#!/usr/bin/env bash
#
# Copyright DataStax, 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.
#
#
# Generates OLM bundle using existing CRDs
#
#
set -euox pipefail
. env.sh
BUNDLE_VERSION=${BUNDLE_VERSION}
BASEDIR="$(dirname "$(realpath "$0")")"
TARGET="${BASEDIR}/target"
BUNDLE="${TARGET}/${BUNDLE_VERSION}"
OPERATOR_IMG=${OPERATOR_IMG}
CHANNELS=alpha
PACKAGE_NAME=kaap
CSV_TEMPLATE_DIR="$(dirname "$(realpath "$0")")/csv-template"
# Base ClusterServiceVersion resource containing static information
CSV_TEMPLATE=${CSV_TEMPLATE_DIR}/bases/${PACKAGE_NAME}.clusterserviceversion.yaml
CRD_DIR="${BASEDIR}/helm/${PACKAGE_NAME}/crds"
MANIFESTS=${BUNDLE}/manifests
CRDDIR="${TARGET}/crds"
# CSV name may contain versioned or constant
# CSV_FILE="${MANIFESTS}/${PACKAGE_NAME}.v${BUNDLE_VERSION}.clusterserviceversion.yaml"
CSV_FILE="${MANIFESTS}/${PACKAGE_NAME}.clusterserviceversion.yaml"
# Generates bundle from existing CRDs and Resources
generate_olm_bundle() {
rm -rf "${BUNDLE}"
rm -rf "${CRDDIR}"
mkdir -p "${CRDDIR}"
cp -R "${CRD_DIR}" "${CRDDIR}"
helm template kaap helm/kaap > "$CRDDIR/template.yaml"
operator-sdk generate bundle \
--input-dir="$CRDDIR" \
--output-dir="$BUNDLE" \
--kustomize-dir="$CSV_TEMPLATE_DIR" \
--package="$PACKAGE_NAME" \
--version="$BUNDLE_VERSION" \
--channels="$CHANNELS"
# Remove Dockerfile generated by operator-sdk
rm ./bundle.Dockerfile
cp "${CSV_TEMPLATE_DIR}/bundle.Dockerfile" "${BUNDLE}"
yq ea -i 'select(fi==0).metadata.annotations = select(fi==1).metadata.annotations | select(fi==0)' "${CSV_FILE}" "${CSV_TEMPLATE}"
yq ea -i ".spec.install.spec.deployments[0].spec.template.spec.securityContext = {}" "${CSV_FILE}"
yq ea -i '.spec.install.spec.deployments[0].spec.template.spec.containers[0].resources = {"requests": {"cpu": "10m", "memory": "100Mi"}}' "${CSV_FILE}"
yq ea -i '(... | select(has("env"))).env += {"name": "WATCH_NAMESPACES", "valueFrom": {"fieldRef": {"fieldPath": "metadata.annotations['\''olm.targetNamespaces'\'']"}}}' "${CSV_FILE}"
yq ea -i "(... | select(has(\"image\"))).image =\"${OPERATOR_IMG}\"" "${CSV_FILE}"
yq ea -i ".metadata.annotations.createdAt = \"$(date +'%Y-%m-%d %H:%M:%S')\"" "${CSV_FILE}"
yq ea -i ".metadata.annotations.containerImage = \"${OPERATOR_IMG}\"" "${CSV_FILE}"
sed -i "s/RELEASE_VERSION/${BUNDLE_VERSION}/" "${CSV_FILE}"
}
validate_olm_bundle() {
operator-sdk bundle validate "${BUNDLE}" --select-optional name=operatorhub
operator-sdk bundle validate "${BUNDLE}" --select-optional suite=operatorframework
}
generate_olm_bundle
validate_olm_bundle