From b02f574f530c0b9982b3d5cbe2365d0d001567ea Mon Sep 17 00:00:00 2001 From: Stacky McStackface <95074132+stackable-bot@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:59:34 +0200 Subject: [PATCH] chore: Generated commit to update templated files since the last template run up to stackabletech/operator-templating@1a3c00aedd85cf864881426a73daaa9b47317288 (#636) Reference-to: stackabletech/operator-templating@1a3c00a (Add KUBERNETES_CLUSTER_DOMAIN only if set) --- .../druid-operator/templates/deployment.yaml | 4 +- scripts/run-tests | 68 ++++++++++++++----- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/deploy/helm/druid-operator/templates/deployment.yaml b/deploy/helm/druid-operator/templates/deployment.yaml index a6074b16..39a90322 100644 --- a/deploy/helm/druid-operator/templates/deployment.yaml +++ b/deploy/helm/druid-operator/templates/deployment.yaml @@ -47,8 +47,10 @@ spec: valueFrom: fieldRef: fieldPath: metadata.annotations['internal.stackable.tech/image'] + {{- if .Values.kubernetesClusterDomain }} - name: KUBERNETES_CLUSTER_DOMAIN - value: {{ .Values.kubernetesClusterDomain | default "cluster.local" | quote }} + value: {{ .Values.kubernetesClusterDomain | quote }} + {{- end }} volumes: - name: config-spec configMap: diff --git a/scripts/run-tests b/scripts/run-tests index c331043b..3f41d2db 100755 --- a/scripts/run-tests +++ b/scripts/run-tests @@ -95,11 +95,18 @@ def parse_args(argv: list[str]) -> argparse.Namespace: parser.add_argument( "--operator", help="Patch operator version in release.yaml. Format =", - nargs="*", + action="append", type=cli_parse_operator_args, default=[], ) + parser.add_argument( + "--skip-operator", + help="Skip given operator(s) when installing a release.", + action="append", + default=[], + ) + parser.add_argument( "--test", help="Kuttl test to run.", @@ -138,7 +145,7 @@ def cli_parse_operator_args(args: str) -> tuple[str, str]: f"Invalid operator argument: {args}. Must be in format =" ) op, version = args.split("=", maxsplit=1) - return (op, version) + return op, version def cli_log_level(cli_arg: str) -> int: @@ -179,11 +186,13 @@ def have_requirements() -> None: @contextlib.contextmanager def release_file( - operators: list[tuple[str, str]] = [], + operators: list[tuple[str, str]], skip_ops: list[str] ) -> collections.abc.Generator[str, None, None]: - """Patch release.yaml with operator versions if needed. + """Generate a (possibly modified) copy of the release.yaml file. - If no --operator is set, the default release file is used. + Operator versions passed as --operator take precedence over the release.yaml contents. + + Operators passed as --skip-operator are excluded from the resulting release.yaml contents. If an invalid operator name is provided (i.e. one that doesn't exist in the original release file), a TestRunnerException is raised. @@ -194,36 +203,61 @@ def release_file( def _patch(): release_file = os.path.join("tests", "release.yaml") - # Make a copy so we can mutate it without affecting the original - ops_copy = operators.copy() + # A marker to validate that all ops were patched patched_release = [] with open(release_file, "r") as f: + patched_ops = [] patch_version = "" for line in f: if patch_version: line = re.sub(":.+$", f": {patch_version}", line) patch_version = "" else: - for op, version in ops_copy: + for op, version in operators: if op in line: patch_version = version - ops_copy.remove((op, version)) # found an operator to patch + patched_ops.append(op) break - patched_release.append(line) - if ops_copy: - # Some --operator args were not found in the release file. This is - # most likely a typo and CI pipelines should terminate early in such - # cases. + patched_release.append(line.rstrip("\n")) + + # Sanity test that cli didn't contain garbage that is silently discarded + ops_not_patched = set([op for op, _ in operators]) - set(patched_ops) + if ops_not_patched: + logging.error( + f"Patched operators [{', '.join(ops_not_patched)}] not found in {release_file}" + ) + raise TestRunnerException() + + # Filter out skip operators + release_contents = [] + skip_lines = 0 + valid_skip_ops = [] + for line in patched_release: + if skip_lines: + skip_lines -= 1 + continue + for op in skip_ops: + if op in line: + # Every product section has 1 line of additional config to skip + skip_lines = 1 + valid_skip_ops.append(op) + break + else: + release_contents.append(line) + # Sanity test that cli didn't contain garbage that is silently discarded + ops_not_skipped = set(skip_ops) - set(valid_skip_ops) + if ops_not_skipped: logging.error( - f"Operators {', '.join([op for op, _ in ops_copy])} not found in {release_file}" + f"Skipped operators [{', '.join(ops_not_skipped)}] not found in {release_file}" ) raise TestRunnerException() + with tempfile.NamedTemporaryFile( mode="w", delete=False, prefix="patched", ) as f: - pcontents = "".join(patched_release) + pcontents = "\n".join(release_contents) logging.debug(f"Writing patched release to {f.name}: {pcontents}\n") f.write(pcontents) return f.name @@ -353,7 +387,7 @@ def main(argv) -> int: logging.basicConfig(encoding="utf-8", level=opts.log_level) have_requirements() gen_tests(opts.test_suite) - with release_file(opts.operator) as f: + with release_file(opts.operator, opts.skip_operator) as f: maybe_install_release(opts.skip_release, f) if opts.skip_tests: logging.info("Skip running tests.")