diff --git a/.helm/starter/Chart.yaml b/.helm/starter/Chart.yaml index efc98d55..929291e8 100644 --- a/.helm/starter/Chart.yaml +++ b/.helm/starter/Chart.yaml @@ -1,7 +1,9 @@ --- apiVersion: v2 -appVersion: 0.1.0 -description: A Helm chart for Kubernetes -name: starter +description: The community-supported AWX Operator Helm Chart +name: awx-operator type: application +# the current version of this helm chart version: 0.1.0 +# The version of the awx-operator to install +appVersion: 2.19.1 diff --git a/Makefile b/Makefile index bb5febe1..3d9615ac 100644 --- a/Makefile +++ b/Makefile @@ -11,12 +11,13 @@ endif # Helm variables CHART_NAME ?= awx-operator -CHART_DESCRIPTION ?= A Helm chart for the AWX Operator CHART_OWNER ?= $(GH_REPO_OWNER) CHART_REPO ?= awx-operator CHART_BRANCH ?= gh-pages CHART_DIR ?= gh-pages CHART_INDEX ?= index.yaml +# use python3 if python isn't in the path +PYTHON ?= $(shell which python >/dev/null 2>&1 && echo python || echo python3) .PHONY: kustomize KUSTOMIZE = $(shell pwd)/bin/kustomize @@ -67,6 +68,10 @@ YQ = $(shell which yq) endif endif +.PHONY: chart-version +chart-version: yq +CHART_VERSION = $(shell cat .helm/starter/Chart.yaml | $(YQ) '.version') + .PHONY: helm HELM = $(shell pwd)/bin/helm helm: ## Download helm locally if necessary. @@ -111,7 +116,7 @@ helm-chart: helm-chart-generate helm-chart-generate: kustomize helm kubectl-slice yq charts @echo "== Clone the AWX Operator repository ==" - python clone-awx-operator.py + $(PYTHON) clone-awx-operator.py @echo "== KUSTOMIZE: Set image and chart label ==" cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} @@ -120,13 +125,11 @@ helm-chart-generate: kustomize helm kubectl-slice yq charts @echo "== Gather Helm Chart Metadata ==" # remove the existing chart if it exists + # edit and copy the Chart.yaml ourselves since helm doesn't do it: https://github.com/helm/helm/issues/9551#issuecomment-811217822 rm -rf charts/$(CHART_NAME) - # create new chart metadata in Chart.yaml cd charts && \ $(HELM) create $(CHART_NAME) --starter $(shell pwd)/.helm/starter ;\ - $(YQ) -i '.version = "$(VERSION)"' $(CHART_NAME)/Chart.yaml ;\ - $(YQ) -i '.appVersion = "$(VERSION)" | .appVersion style="double"' $(CHART_NAME)/Chart.yaml ;\ - $(YQ) -i '.description = "$(CHART_DESCRIPTION)"' $(CHART_NAME)/Chart.yaml ;\ + $(YQ) '.name = "$(CHART_NAME)"' $(shell pwd)/.helm/starter/Chart.yaml > $(CHART_NAME)/Chart.yaml;\ @echo "Generated chart metadata:" @cat charts/$(CHART_NAME)/Chart.yaml @@ -174,17 +177,17 @@ helm-chart-generate: kustomize helm kubectl-slice yq charts rm -rf charts/$(CHART_NAME)/raw-files # create and populate NOTES.txt - @echo "AWX Operator installed with Helm Chart version $(VERSION)" > charts/$(CHART_NAME)/templates/NOTES.txt + @echo "AWX Operator installed with Helm Chart version {{ .Chart.Version }}" > charts/$(CHART_NAME)/templates/NOTES.txt - @echo "Helm chart successfully configured for $(CHART_NAME) version $(VERSION)" + @echo "Helm chart successfully configured for $(CHART_NAME)" .PHONY: helm-package -helm-package: helm-chart +helm-package: helm-chart chart-version @echo "== Package Current Chart Version ==" mkdir -p .cr-release-packages # package the chart and put it in .cr-release-packages dir - $(HELM) package ./charts/$(CHART_NAME) -d .cr-release-packages/$(VERSION) + $(HELM) package ./charts/$(CHART_NAME) -d .cr-release-packages/$(CHART_VERSION) # List all tags oldest to newest. TAGS := $(shell git ls-remote --tags --sort=version:refname --refs -q | cut -d/ -f3) diff --git a/clone-awx-operator.py b/clone-awx-operator.py old mode 100644 new mode 100755 index 065afce4..fcfcb3aa --- a/clone-awx-operator.py +++ b/clone-awx-operator.py @@ -14,10 +14,28 @@ import sys import tempfile -DEFAULT_BRANCH = "devel" DEFAULT_AWX_OPERATOR_REPO = "https://github.com/ansible/awx-operator" +# get the appVersion configured in Chart.yaml +def get_app_version(): + try: + chart_yaml_path = "./.helm/starter/Chart.yaml" + with open(chart_yaml_path, "r", encoding="utf-8") as chart: + for line in chart: + if line.startswith("appVersion:"): + result = line.split(":", 1) + if len(result) != 2: + raise KeyError("Malformed appVersion in Chart.yaml") + app_version = result[1].strip() + if not app_version: + raise KeyError("No appVersion value found") + return app_version + except FileNotFoundError as e: + raise FileNotFoundError("Failed to open Chart.yaml") from e + raise KeyError("Could not find appVersion in Chart.yaml") + + @dataclasses.dataclass() class Args: branch: str | None @@ -30,8 +48,8 @@ def parse_args(args: list[str] | None = None) -> Args: "-b", "--branch", help="Set the branch of awx-operator to clone." - " Defaults to current branch (%(default)s)", - default=DEFAULT_BRANCH, + " Defaults to configured appVersion", + default=get_app_version(), ) parser.add_argument( "--no-branch", @@ -65,7 +83,13 @@ def main(args: Args) -> None: ] with tempfile.TemporaryDirectory() as temp_dir: - cmd: list[str] = ["git", "clone", args.repo, "--depth=1"] + cmd: list[str] = [ + "git", + "clone", + args.repo, + "--depth=1", + "-c advice.detachedHead=false", + ] if args.branch is not None: cmd.append(f"--branch={args.branch}") cmd.append(temp_dir) @@ -86,7 +110,7 @@ def main(args: Args) -> None: for keep_file in keep_files: src = pathlib.Path(temp_dir, keep_file) - if keep_file == 'Makefile': + if keep_file == "Makefile": dst = pathlib.Path.cwd() / "Makefile.awx-operator" else: dst = pathlib.Path.cwd() / keep_file