Browse Source

chore(makefile): enhance Helm schema plugin management logic (#5212)

Improved logic for installing and updating the Helm schema plugin to ensure version consistency and avoid unnecessary reinstallation.

This avoids a silent failure with `|| true` when the isntall breaks which can cause make `check-diff` to break

test by switching HELM_SCHEMA_VER around:

```shell
make helm.schema.plugin HELM_SCHEMA_VER=2.2.0
make helm.schema.plugin HELM_SCHEMA_VER=2.2.1
make helm.schema.plugin
```

Signed-off-by: Jakob Möller <jakob.moeller@sap.com>
Jakob Möller 7 months ago
parent
commit
527e7965a4
1 changed files with 17 additions and 3 deletions
  1. 17 3
      Makefile

+ 17 - 3
Makefile

@@ -189,10 +189,24 @@ helm.build: helm.generate ## Build helm chart
 	@mv $(OUTPUT_DIR)/chart/external-secrets-$(HELM_VERSION).tgz $(OUTPUT_DIR)/chart/external-secrets.tgz
 	@$(OK) helm package
 
+HELM_SCHEMA_NAME := schema
+HELM_SCHEMA_VER  := 2.2.1
+HELM_SCHEMA_URL  := https://github.com/losisin/helm-values-schema-json.git
+
 helm.schema.plugin:
-	@$(INFO) Installing helm-values-schema-json plugin
-	@helm plugin install --version v2.2.1 https://github.com/losisin/helm-values-schema-json.git || true
-	@$(OK) Installed helm-values-schema-json plugin
+	@v=$$(helm plugin list | awk '$$1=="$(HELM_SCHEMA_NAME)"{print $$2}'); \
+	if [ -z "$$v" ]; then \
+		$(INFO) "Installing $(HELM_SCHEMA_NAME) v$(HELM_SCHEMA_VER)"; \
+		helm plugin install --version $(HELM_SCHEMA_VER) $(HELM_SCHEMA_URL); \
+		$(OK) "Installed $(HELM_SCHEMA_NAME) v$(HELM_SCHEMA_VER)"; \
+	elif [ "$$v" != "$(HELM_SCHEMA_VER)" ]; then \
+		$(INFO) "Found $(HELM_SCHEMA_NAME) $$v. Reinstalling v$(HELM_SCHEMA_VER)"; \
+		helm plugin remove $(HELM_SCHEMA_NAME); \
+		helm plugin install --version $(HELM_SCHEMA_VER) $(HELM_SCHEMA_URL); \
+		$(OK) "Reinstalled $(HELM_SCHEMA_NAME) v$(HELM_SCHEMA_VER)"; \
+	else \
+		$(OK) "$(HELM_SCHEMA_NAME) already at v$(HELM_SCHEMA_VER)"; \
+	fi
 
 helm.schema.update: helm.schema.plugin
 	@$(INFO) Generating values.schema.json