From 9f77a35a564bd442804b50590847b342c9ccea53 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Wed, 27 Sep 2023 16:36:29 -0700 Subject: [PATCH] Fix Chart.yaml for new applications Helm completely ignores the contents of Chart.yaml in starters so far as I can tell, so load the Chart.yaml from the starter and template the key parts of it ourselves, overwriting the generated Chart.yaml for the application with that. --- src/phalanx/services/application.py | 14 ++++++++-- starters/web-service/README.md | 27 ------------------- tests/cli/application_test.py | 13 ++++++++- .../input/starters/web-service/Chart.yaml | 3 ++- 4 files changed, 26 insertions(+), 31 deletions(-) delete mode 100644 starters/web-service/README.md diff --git a/src/phalanx/services/application.py b/src/phalanx/services/application.py index fc849059d6..b2cd629145 100644 --- a/src/phalanx/services/application.py +++ b/src/phalanx/services/application.py @@ -68,9 +68,19 @@ def create_application( raise ApplicationExistsError(name) self._helm.create(name, starter) - # Replace the description in the chart with the provided one. - chart = yaml.safe_load((path / "Chart.yaml").read_text()) + # Unfortunately, Helm completely ignores the Chart.yaml in a starter + # so far as I can tell, so we have to load the starter Chart.yaml + # ourselves and replace the generated Chart.yaml with it, but + # preserving the substitutions that Helm does make. + starter_path = self._config.get_starter_path(starter) + chart = yaml.safe_load((starter_path / "Chart.yaml").read_text()) + helm_chart = yaml.safe_load((path / "Chart.yaml").read_text()) + chart["name"] = helm_chart["name"] chart["description"] = description + if "sources" in chart: + chart["sources"] = [ + s.replace("", name) for s in chart["sources"] + ] with (path / "Chart.yaml").open("w") as fh: yaml.dump(chart, fh) diff --git a/starters/web-service/README.md b/starters/web-service/README.md deleted file mode 100644 index 6e0e4b91e0..0000000000 --- a/starters/web-service/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# - -Helm starter chart for a new RSP service. - -**Homepage:** > - -## Values - -| Key | Type | Default | Description | -|-----|------|---------|-------------| -| affinity | object | `{}` | Affinity rules for the deployment pod | -| autoscaling.enabled | bool | `false` | Enable autoscaling of deployment | -| autoscaling.maxReplicas | int | `100` | Maximum number of deployment pods | -| autoscaling.minReplicas | int | `1` | Minimum number of deployment pods | -| autoscaling.targetCPUUtilizationPercentage | int | `80` | Target CPU utilization of deployment pods | -| global.baseUrl | string | Set by Argo CD | Base URL for the environment | -| global.host | string | Set by Argo CD | Host name for ingress | -| global.vaultSecretsPath | string | Set by Argo CD | Base path for Vault secrets | -| image.pullPolicy | string | `"IfNotPresent"` | Pull policy for the image | -| image.repository | string | `"ghcr.io/lsst-sqre/"` | Image to use in the deployment | -| image.tag | string | `""` | Overrides the image tag whose default is the chart appVersion. | -| ingress.annotations | object | `{}` | Additional annotations for the ingress rule | -| nodeSelector | object | `{}` | Node selection rules for the deployment pod | -| podAnnotations | object | `{}` | Annotations for the deployment pod | -| replicaCount | int | `1` | Number of web deployment pods to start | -| resources | object | `{}` | Resource limits and requests for the deployment pod | -| tolerations | list | `[]` | Tolerations for the deployment pod | diff --git a/tests/cli/application_test.py b/tests/cli/application_test.py index 818202252b..b19be99328 100644 --- a/tests/cli/application_test.py +++ b/tests/cli/application_test.py @@ -91,7 +91,7 @@ def test_create(tmp_path: Path) -> None: (apps_path / "zzz-other-app" / "values-minikube.yaml").write_text("") # Load the environment, make sure the new apps are enabled, and check that - # the chart descriptions are correct. + # the chart metadata is correct. factory = Factory(config_path) config_storage = factory.create_config_storage() environment = config_storage.load_environment("minikube") @@ -104,6 +104,17 @@ def test_create(tmp_path: Path) -> None: ("zzz-other-app", "Last new app"), ): assert environment.applications[app].chart["description"] == expected + assert environment.applications[app].chart["version"] == "1.0.0" + + # Charts created from the empty starter should not have appVersion. Charts + # using the web-service starter should, set to 0.1.0. + assert "appVersion" not in environment.applications["aaa-new-app"].chart + assert "appVersion" not in environment.applications["zzz-other-app"].chart + assert environment.applications["hips"].chart["appVersion"] == "0.1.0" + + # Charts using the web-service starter should have a default sources. + expected = "https://github.com/lsst-sqre/hips" + assert environment.applications["hips"].chart["sources"][0] == expected def test_create_prompt(tmp_path: Path) -> None: diff --git a/tests/data/input/starters/web-service/Chart.yaml b/tests/data/input/starters/web-service/Chart.yaml index c1854534d6..3731096fe3 100644 --- a/tests/data/input/starters/web-service/Chart.yaml +++ b/tests/data/input/starters/web-service/Chart.yaml @@ -2,6 +2,7 @@ apiVersion: v2 name: version: 1.0.0 description: "Helm starter chart for a new RSP service" -home: "https://github.com/lsst-sqre/" +sources: + - "https://github.com/lsst-sqre/" type: application appVersion: "0.1.0"