Skip to content

Commit

Permalink
Auto-gen mutating-webhook, validation-webhook and manager-role files
Browse files Browse the repository at this point in the history
  • Loading branch information
super-harsh committed May 29, 2024
1 parent d7c2f20 commit b0964b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,8 @@ tasks:
controller:package-helm-manifest:
desc: Package helm manifest for the release
dir: "{{.CONTROLLER_ROOT}}"
deps:
- controller:generate-kustomize
cmds:
- "{{.SCRIPTS_ROOT}}/package-helm-manifest.sh {{.LOCAL_REGISTRY_CONTROLLER_DOCKER_IMAGE}} {{.PUBLIC_REGISTRY}} {{.LATEST_VERSION_TAG}} `pwd`/"
- task: controller:validate-helm
Expand Down
32 changes: 19 additions & 13 deletions scripts/v2/package-helm-manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,35 @@ DIR=$4

ASO_CHART="$DIR"charts/azure-service-operator
GEN_FILES_DIR="$ASO_CHART"/templates/generated
TEMP_DIR="$GEN_FILES_DIR"/temp
IF_CLUSTER="{{- if or (eq .Values.multitenant.enable false) (eq .Values.azureOperatorMode \"webhooks\") }}"
IF_TENANT="{{- if or (eq .Values.multitenant.enable false) (eq .Values.azureOperatorMode \"watchers\") }}"
IF_CRDS="{{- if and (eq .Values.installCRDs true) (or (eq .Values.multitenant.enable false) (eq .Values.azureOperatorMode \"webhooks\")) }}"

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# Matches and adds helm flow control to a file
flow_control(){
MATCHER_IF=$1
MATCHER_END=$2
IF_CLAUSE=$3
TARGET=$4

sed -i "/$MATCHER_IF/i \ \ $IF_CLAUSE" "$TARGET"
sed -i "/$MATCHER_END/a \ \ {{- end }}" "$TARGET"
}

echo "Updating helm chart manifest"
sed -i "s@\($PUBLIC_REGISTRY\)\(.*\)@\1azureserviceoperator:$VERSION@g" "$ASO_CHART"/values.yaml

# Chart replacements
sed -i "s/\(version: \)\(.*\)/\1${VERSION//v}/g" "$ASO_CHART"/Chart.yaml # find version key and update the value with the current version

mkdir "$TEMP_DIR"
${SCRIPT_DIR}/kustomize-build.sh -v "$VERSION" -k operator -o "$TEMP_DIR"

echo "Making sed replacements and copying generated yamls"
for file in $(find "$TEMP_DIR" -type f)
do
# Append cluster or tenant guards to each file
if [[ $file == *"mutating-webhook-configuration"* ]] ||
[[ $file == *"validating-webhook-configuration"* ]] ||
[[ $file == *"azureserviceoperator-manager-role.yaml" ]] ; then
sed -i "1 s/^/$IF_CLUSTER\n/;$ a {{- end }}" "$file"
sed -i 's/azureserviceoperator-system/{{ .Release.Namespace }}/g' "$file"
mv -f "$file" "$GEN_FILES_DIR"
fi
done

rm -rf "$TEMP_DIR"

# Helm chart packaging, indexing and updating dependencies
echo "Packaging helm charts"
helm package "$ASO_CHART" -d "$DIR"charts # package the ASOv2 helm files into a tar file
Expand Down

0 comments on commit b0964b3

Please sign in to comment.