Skip to content

Commit

Permalink
fix: Make generated manifests compatible with various Yaml parsers (a…
Browse files Browse the repository at this point in the history
…rgoproj#20532)

Can help with argoproj#20532

The manifests often used the plain style of strings, which could move a part of value to a new line, which could cause some parsers fail to parse. Using this style is not recommended. It was switched to the literal style when relevant and manifests were updated. To make sure next updates are good, the helper script to fix manifests is a part of the script to update manifests. It's in Python, but it's run only locally.

There's one weird value for haproxy.cfg which is rendered as a quotes-enclosed string, but it was correct when I tried to load yamls from upstream and updated ones. In any case, it's more readable now.

Let's cherry pick to 2.13, as the apply of install manifests is currently broken.

Signed-off-by: Andrii Korotkov <[email protected]>
  • Loading branch information
andrii-korotkov-verkada committed Nov 10, 2024
1 parent 5d0a3e6 commit 0a34e0a
Show file tree
Hide file tree
Showing 10 changed files with 7,715 additions and 7,631 deletions.
2 changes: 1 addition & 1 deletion hack/installers/install-codegen-tools.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
set -eux -o pipefail

KUSTOMIZE_VERSION=4.5.7 "$(dirname $0)/../install.sh" kustomize protoc
KUSTOMIZE_VERSION=5.4.3 "$(dirname $0)/../install.sh" kustomize protoc
23 changes: 23 additions & 0 deletions hack/update-manifests-normalizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import math
import sys
import yaml

def represent_str(dumper, data):
use_literal_style = '\n' in data or ' ' in data or '\\' in data
if use_literal_style:
data = data.replace("\\", "\\\\")
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
return dumper.represent_str(data)

yaml.add_representer(str, represent_str, Dumper=yaml.SafeDumper)

# Technically we can write to the same file, but that can erase the file if dump fails.
input_filename = sys.argv[1]
output_filename = sys.argv[2]

with open(input_filename, "r") as input_file:
data = yaml.safe_load_all(input_file.read())

with open(output_filename, "w") as output_file:
# Without large width the multiline strings enclosed in "..." are rendered weirdly.
yaml.safe_dump_all(data, output_file, width=math.inf)
46 changes: 36 additions & 10 deletions hack/update-manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ AUTOGENMSG="# This is an auto-generated file. DO NOT EDIT"

KUSTOMIZE=kustomize
[ -f "$SRCROOT/dist/kustomize" ] && KUSTOMIZE="$SRCROOT/dist/kustomize"
# Really need advanced Yaml tools to fix https://github.com/argoproj/argo-cd/issues/20532.
# The script is only used locally and everyone has Python3 installed, right?
PYTHON=python3
NORMALIZER="$SRCROOT/hack/update-manifests-normalizer.py"
TEMP_FILE=/tmp/argocd-normalized-manifest.yaml

cd ${SRCROOT}/manifests/ha/base/redis-ha && ./generate.sh

Expand All @@ -35,17 +40,38 @@ cd ${SRCROOT}/manifests/base && $KUSTOMIZE edit set image quay.io/argoproj/argoc
cd ${SRCROOT}/manifests/ha/base && $KUSTOMIZE edit set image quay.io/argoproj/argocd=${IMAGE_NAMESPACE}/argocd:${IMAGE_TAG}
cd ${SRCROOT}/manifests/core-install && $KUSTOMIZE edit set image quay.io/argoproj/argocd=${IMAGE_NAMESPACE}/argocd:${IMAGE_TAG}

echo "${AUTOGENMSG}" > "${SRCROOT}/manifests/install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/cluster-install" >> "${SRCROOT}/manifests/install.yaml"
OUTPUT_FILE="${SRCROOT}/manifests/install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/cluster-install" > $OUTPUT_FILE
$PYTHON $NORMALIZER $OUTPUT_FILE $TEMP_FILE
# Avoid printing the whole file contents
set +x
echo -e "${AUTOGENMSG}\n$(cat $TEMP_FILE)" > $OUTPUT_FILE
set -x

echo "${AUTOGENMSG}" > "${SRCROOT}/manifests/namespace-install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/namespace-install" >> "${SRCROOT}/manifests/namespace-install.yaml"
OUTPUT_FILE="${SRCROOT}/manifests/namespace-install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/namespace-install" > $OUTPUT_FILE
$PYTHON $NORMALIZER $OUTPUT_FILE $TEMP_FILE
set +x
echo -e "${AUTOGENMSG}\n$(cat $TEMP_FILE)" > $OUTPUT_FILE
set -x

echo "${AUTOGENMSG}" > "${SRCROOT}/manifests/ha/install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/ha/cluster-install" >> "${SRCROOT}/manifests/ha/install.yaml"
OUTPUT_FILE="${SRCROOT}/manifests/ha/install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/ha/cluster-install" > $OUTPUT_FILE
$PYTHON $NORMALIZER $OUTPUT_FILE $TEMP_FILE
set +x
echo -e "${AUTOGENMSG}\n$(cat $TEMP_FILE)" > $OUTPUT_FILE
set -x

echo "${AUTOGENMSG}" > "${SRCROOT}/manifests/ha/namespace-install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/ha/namespace-install" >> "${SRCROOT}/manifests/ha/namespace-install.yaml"
OUTPUT_FILE="${SRCROOT}/manifests/ha/namespace-install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/ha/namespace-install" > $OUTPUT_FILE
$PYTHON $NORMALIZER $OUTPUT_FILE $TEMP_FILE
set +x
echo -e "${AUTOGENMSG}\n$(cat $TEMP_FILE)" > $OUTPUT_FILE
set -x

echo "${AUTOGENMSG}" > "${SRCROOT}/manifests/core-install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/core-install" >> "${SRCROOT}/manifests/core-install.yaml"
OUTPUT_FILE="${SRCROOT}/manifests/core-install.yaml"
$KUSTOMIZE build "${SRCROOT}/manifests/core-install" > $OUTPUT_FILE
$PYTHON $NORMALIZER $OUTPUT_FILE $TEMP_FILE
set +x
echo -e "${AUTOGENMSG}\n$(cat $TEMP_FILE)" > $OUTPUT_FILE
set -x
3,734 changes: 1,859 additions & 1,875 deletions manifests/core-install.yaml

Large diffs are not rendered by default.

3,528 changes: 1,754 additions & 1,774 deletions manifests/crds/application-crd.yaml

Large diffs are not rendered by default.

185 changes: 94 additions & 91 deletions manifests/crds/appproject-crd.yaml

Large diffs are not rendered by default.

3,881 changes: 1,957 additions & 1,924 deletions manifests/ha/install.yaml

Large diffs are not rendered by default.

158 changes: 104 additions & 54 deletions manifests/ha/namespace-install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0a34e0a

Please sign in to comment.