Skip to content

Commit b74c928

Browse files
authored
fix manifest generation from helm chart where version was not set correctly (#58)
Fix manifest generation from helm chart where version was not set correctly. This only affected the yaml manifests, not the actual helm charts. The fix is to use helm package generated manifests so they are all in-sync.
1 parent 21458bb commit b74c928

2 files changed

Lines changed: 27 additions & 19 deletions

File tree

.goreleaser.yaml

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,13 @@
66
# Docs: https://goreleaser.com/customization/ko/
77
version: 2
88

9-
env:
10-
- IMAGE_TAG={{ .Version }}
119
before:
1210
hooks:
13-
# Clean out stale chart tarballs so the `make release` helm push step only
14-
# sees the charts packaged for this version.
15-
- rm -rf ./_artifacts/helm
16-
- mkdir -p ./_artifacts/helm
17-
- >-
18-
helm package ./charts/cluster-api-provider-oxide
19-
--version {{ .Version }}
20-
--app-version {{ .Version }}
21-
--destination ./_artifacts/helm
22-
- >-
23-
helm package ./charts/cluster-api-provider-oxide-crds
24-
--version {{ .Version }}
25-
--app-version {{ .Version }}
26-
--destination ./_artifacts/helm
27-
- make manifests
11+
# Packages both charts (--version/--app-version) into _artifacts/helm and
12+
# renders infrastructure-components.yaml from the packaged chart. The
13+
# version is passed on the make command line because the top-level `env:`
14+
# section is evaluated before {{ .Version }} is computed.
15+
- make manifests VERSION={{ .Version }} IMAGE_TAG={{ .Version }}
2816

2917
# ko re-builds the binary itself using these settings (results are cached from
3018
# the build pipe). CGO is disabled so the image can run on the distroless base.

Makefile

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Release version: the current git tag without the "v" prefix (v0.1.2 ->
2+
# 0.1.2; between tags, git describe appends -<n>-g<sha>). goreleaser overrides
3+
# it on the make command line (see the before hook in .goreleaser.yaml) so the
4+
# Makefile and goreleaser always agree on one value.
5+
VERSION ?= $(shell git describe --tags | sed -e 's/^v//')
6+
17
# Image URL to use all building/pushing image targets
28
IMAGE_REPO ?= ghcr.io/oxidecomputer/cluster-api-provider-oxide
39
HELM_OCI_REPO ?= $(IMAGE_REPO)/helm-charts
@@ -235,12 +241,26 @@ run: generate ## Run a controller from your host.
235241

236242
.PHONY: manifests
237243
manifests: generate
238-
mkdir -p $(ARTIFACTS)
244+
# Package the charts at $(VERSION): helm template has no --app-version flag,
245+
# so the version-derived output (app.kubernetes.io/version) can only carry the
246+
# release version if the manifest is rendered from a packaged chart rather
247+
# than the chart dir (whose Chart.yaml holds a placeholder). The rm clears
248+
# stale tarballs so the `make release` helm push step only sees this version's.
249+
rm -rf $(ARTIFACTS)/helm
250+
mkdir -p $(ARTIFACTS)/helm
251+
$(HELM) package charts/cluster-api-provider-oxide \
252+
--version $(VERSION) \
253+
--app-version $(VERSION) \
254+
--destination $(ARTIFACTS)/helm
255+
$(HELM) package charts/cluster-api-provider-oxide-crds \
256+
--version $(VERSION) \
257+
--app-version $(VERSION) \
258+
--destination $(ARTIFACTS)/helm
239259
# helm never emits a Namespace object, so prepend one. The sed strips the
240260
# helm-specific labels the chart renders (helm.sh/chart, managed-by: Helm);
241261
# nothing in this manifest is managed by a helm release.
242262
printf 'apiVersion: v1\nkind: Namespace\nmetadata:\n name: $(NAMESPACE)\n---\n' > $(ARTIFACTS)/infrastructure-components.yaml
243-
$(HELM) template capox charts/cluster-api-provider-oxide \
263+
$(HELM) template capox $(ARTIFACTS)/helm/cluster-api-provider-oxide-$(VERSION).tgz \
244264
--namespace $(NAMESPACE) \
245265
--include-crds \
246266
--set image.repository=$(IMAGE_REPO) \

0 commit comments

Comments
 (0)