2023-05-30 21:01:12 +00:00
|
|
|
#!/bin/bash
|
2022-04-08 08:22:01 +00:00
|
|
|
set -euxo pipefail
|
|
|
|
|
2023-05-30 21:01:12 +00:00
|
|
|
# Ex: 21.0.0
|
2022-04-08 08:22:01 +00:00
|
|
|
VERSION=$1
|
2023-05-30 21:01:12 +00:00
|
|
|
# Ex: 20.0.0
|
|
|
|
# Ex: NONE [if no replaces]
|
2022-04-08 08:22:01 +00:00
|
|
|
REPLACES_VERSION=$2
|
2023-05-30 21:01:12 +00:00
|
|
|
# Ex: keycloak/keycloak-operator:999.0.0-SNAPSHOT
|
2022-04-08 08:22:01 +00:00
|
|
|
OPERATOR_DOCKER_IMAGE=$3
|
|
|
|
|
|
|
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
|
|
|
2023-05-30 21:01:12 +00:00
|
|
|
{ set +x; } 2>/dev/null
|
|
|
|
echo ""
|
2022-04-08 08:22:01 +00:00
|
|
|
echo "Creating OLM bundle for version $VERSION replacing version $REPLACES_VERSION"
|
2023-05-30 21:01:12 +00:00
|
|
|
echo ""
|
|
|
|
set -x
|
|
|
|
|
|
|
|
cd "$SCRIPT_DIR"
|
|
|
|
|
|
|
|
rm -rf ../olm/$VERSION
|
|
|
|
mkdir -p ../olm/$VERSION
|
|
|
|
|
|
|
|
# Extract the files generated by Quarkus during the maven build
|
|
|
|
unzip -q -d ../olm/$VERSION ../target/keycloak-operator-*-olm.zip
|
2022-04-08 08:22:01 +00:00
|
|
|
|
2023-05-30 21:01:12 +00:00
|
|
|
# Find the CSV YAML
|
|
|
|
CSV_PATH="$(find "../olm/$VERSION" -type f -name '*.clusterserviceversion.yaml')"
|
2022-04-08 08:22:01 +00:00
|
|
|
|
2023-05-30 21:01:12 +00:00
|
|
|
# Insert operator image coordinate
|
|
|
|
yq ea -i ".metadata.annotations.containerImage = \"$OPERATOR_DOCKER_IMAGE:$VERSION\"" "$CSV_PATH"
|
|
|
|
yq ea -i ".spec.install.spec.deployments[0].spec.template.spec.containers[0].image = \"$OPERATOR_DOCKER_IMAGE:$VERSION\"" "$CSV_PATH"
|
2022-04-08 08:22:01 +00:00
|
|
|
|
2023-05-30 21:01:12 +00:00
|
|
|
# Edit the CSV version, replaces, etc.
|
|
|
|
|
|
|
|
yq ea -i ".metadata.annotations.createdAt = \"$(date "+%D %T")\"" "$CSV_PATH"
|
|
|
|
yq ea -i ".spec.version = \"$VERSION\"" "$CSV_PATH"
|
|
|
|
yq ea -i ".metadata.name = \"keycloak-operator.v$VERSION\"" "$CSV_PATH"
|
|
|
|
yq ea -i '.metadata.namespace = "placeholder"' "$CSV_PATH"
|
2022-04-08 08:22:01 +00:00
|
|
|
|
|
|
|
if [[ $REPLACES_VERSION = "NONE" ]]
|
|
|
|
then
|
2023-05-30 21:01:12 +00:00
|
|
|
yq ea -i "del(.spec.replaces)" "$CSV_PATH"
|
2022-04-08 08:22:01 +00:00
|
|
|
else
|
2023-05-30 21:01:12 +00:00
|
|
|
yq ea -i ".spec.replaces = \"keycloak-operator.v$REPLACES_VERSION\"" "$CSV_PATH"
|
2022-04-08 08:22:01 +00:00
|
|
|
fi
|
|
|
|
|
2023-05-30 21:01:12 +00:00
|
|
|
# Mangle the YAML to make it look more like it did before. The bundle extension
|
|
|
|
# isn't configurable enough to do this itself. No one seems to have the
|
|
|
|
# expertise to say if the changes it makes are ok or not.
|
|
|
|
yq ea -i "del(.spec.install.spec.deployments[0].spec.selector.matchLabels)" "$CSV_PATH"
|
|
|
|
yq ea -i "del(.spec.install.spec.deployments[0].spec.template.metadata.labels)" "$CSV_PATH"
|
|
|
|
yq ea -i "del(.spec.install.spec.deployments[0].spec.template.metadata.annotations)" "$CSV_PATH"
|
|
|
|
yq ea -i "del(.spec.install.spec.deployments[0].spec.template.metadata.namespace)" "$CSV_PATH"
|
|
|
|
yq ea -i "del(.spec.install.spec.deployments[0].spec.template.namespace)" "$CSV_PATH"
|
|
|
|
yq ea -i "del(.spec.install.spec.deployments[0].spec.template.spec.containers[0].ports)" "$CSV_PATH"
|
|
|
|
yq ea -i "del(.spec.install.spec.deployments[0].spec.template.spec.containers[0].livenessProbe)" "$CSV_PATH"
|
|
|
|
yq ea -i "del(.spec.install.spec.deployments[0].spec.template.spec.containers[0].readinessProbe)" "$CSV_PATH"
|
|
|
|
yq ea -i "del(.spec.install.spec.deployments[0].spec.template.spec.containers[0].startupProbe)" "$CSV_PATH"
|
|
|
|
yq ea -i 'del(.spec.install.spec.deployments[0].spec.template.spec.containers[0].env[] | select(.name == "KUBERNETES_NAMESPACE"))' "$CSV_PATH"
|
|
|
|
|
|
|
|
yq ea -i '.spec.install.spec.deployments[0].spec.template.spec.containers[0].resources = {}' "$CSV_PATH"
|
|
|
|
yq ea -i '.spec.install.spec.deployments[0].spec.strategy = {}' "$CSV_PATH"
|
|
|
|
yq ea -i '.spec.apiservicedefinitions = {}' "$CSV_PATH"
|
|
|
|
|
|
|
|
yq ea -i '.spec.install.spec.deployments[0].spec.selector.matchLabels.name = "keycloak-operator"' "$CSV_PATH"
|
|
|
|
yq ea -i '.spec.install.spec.deployments[0].spec.template.metadata.labels.name = "keycloak-operator"' "$CSV_PATH"
|
|
|
|
|
|
|
|
yq ea -i '.spec.install.spec.deployments[0].spec.template.spec.containers[0].env += [{"name": "POD_NAME", "valueFrom": {"fieldRef": {"fieldPath": "metadata.name"}}}]' "$CSV_PATH"
|
|
|
|
yq ea -i '.spec.install.spec.deployments[0].spec.template.spec.containers[0].env += [{"name": "OPERATOR_NAME", "value": "keycloak-operator"}]' "$CSV_PATH"
|
2022-04-08 08:22:01 +00:00
|
|
|
|
2023-05-30 21:01:12 +00:00
|
|
|
{ set +x; } 2>/dev/null
|
|
|
|
echo ""
|
|
|
|
echo "Created OLM bundle ok!"
|