Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions pkg/kagent/install/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import (
releasev1 "helm.sh/helm/v4/pkg/release/v1"
"helm.sh/helm/v4/pkg/storage/driver"
"k8s.io/cli-runtime/pkg/genericclioptions"

"go.ate.dev/substrate/internal/version"
)

// release names a Helm release and the chart it installs.
Expand Down Expand Up @@ -219,7 +217,7 @@ func asV1(rel any, err error) (*releasev1.Release, error) {
}

// loadChart reads the chart in directory name of charts.
func loadChart(charts fs.FS, name string) (*chart.Chart, error) {
func loadChart(charts fs.FS, name, tag string) (*chart.Chart, error) {
var files []*archive.BufferedFile
err := fs.WalkDir(charts, name, func(p string, d fs.DirEntry, err error) error {
if err != nil || d.IsDir() {
Expand All @@ -239,7 +237,7 @@ func loadChart(charts fs.FS, name string) (*chart.Chart, error) {
if err != nil {
return nil, fmt.Errorf("while loading chart %s: %w", path.Base(name), err)
}
stampVersion(ch, version.Version)
stampVersion(ch, tag)
return ch, nil
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/kagent/install/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func TestStampVersion(t *testing.T) {
{"v1.2.3-rc.1", "1.2.3-rc.1", "v1.2.3-rc.1"},
{"dev", "0.1.0", "0.1.0"},
{"v1.2.3-4-gabcdef-dirty+meta", "0.1.0", "0.1.0"},
{"", "0.1.0", "0.1.0"},
}
for _, tc := range tests {
t.Run(tc.tag, func(t *testing.T) {
Expand All @@ -105,10 +106,13 @@ func TestStampVersion(t *testing.T) {
func TestLoadEmbeddedCharts(t *testing.T) {
for _, r := range allReleases {
t.Run(r.chart, func(t *testing.T) {
ch, err := loadChart(chartsfs.FS, r.chart)
ch, err := loadChart(chartsfs.FS, r.chart, "v1.2.3")
if err != nil {
t.Fatal(err)
}
if ch.Metadata.Version != "1.2.3" || ch.Metadata.AppVersion != "v1.2.3" {
t.Errorf("got version %q app %q, want 1.2.3 v1.2.3", ch.Metadata.Version, ch.Metadata.AppVersion)
}
if ch.Name() != r.chart {
t.Errorf("chart name = %q, want %q", ch.Name(), r.chart)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/kagent/install/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
chartsfs "go.ate.dev/substrate/charts"
"go.ate.dev/substrate/internal/ateclient"
"go.ate.dev/substrate/internal/installdefaults"
"go.ate.dev/substrate/internal/version"
)

const (
Expand Down Expand Up @@ -71,6 +72,10 @@ type Options struct {
Charts fs.FS
// HelmLog receives Helm's debug log. Nil discards it.
HelmLog io.Writer
// Version is the release tag, like v1.0.1, stamped on the charts. Their
// images default to it. Empty uses version.Version, which kubectl-ate sets
// at build time.
Version string
}

// Installer runs install steps against one cluster.
Expand Down Expand Up @@ -107,6 +112,9 @@ func New(opts Options, r Reporter) (*Installer, error) {
if err != nil {
return nil, fmt.Errorf("while creating Kubernetes client: %w", err)
}
if opts.Version == "" {
opts.Version = version.Version
}
charts := opts.Charts
if charts == nil {
charts = chartsfs.FS
Expand Down
2 changes: 1 addition & 1 deletion pkg/kagent/install/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func noValues(context.Context) (map[string]any, map[string]any, error) { return
// real upgrade.
func (in *Installer) helmStep(r release, vf valuesFunc) func(context.Context, func(string)) (string, error) {
return func(ctx context.Context, progress func(string)) (string, error) {
ch, err := loadChart(in.charts, r.chart)
ch, err := loadChart(in.charts, r.chart, in.opts.Version)
if err != nil {
return "", err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/kagent/install/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (in *Installer) checkVersions(_ context.Context, progress func(string)) (st
if st := cur.Info.Status; st.IsPending() {
return "", fmt.Errorf("release %s is %s; run helm rollback or helm uninstall on it, then retry", r.name, st)
}
ch, err := loadChart(in.charts, r.chart)
ch, err := loadChart(in.charts, r.chart, in.opts.Version)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func checkSkew(from, to string) error {
// checkCRDStorage refuses to drop a CRD version that objects are still
// stored in, which would make them unreadable.
func (in *Installer) checkCRDStorage(ctx context.Context, _ func(string)) (string, error) {
ch, err := loadChart(in.charts, crdsRelease.chart)
ch, err := loadChart(in.charts, crdsRelease.chart, in.opts.Version)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -234,7 +234,7 @@ func checkStoredVersions(ctx context.Context, c apiextclient.Interface, crds []a
// out.
func (in *Installer) diffStep(r release, vf valuesFunc, out io.Writer) func(context.Context, func(string)) (string, error) {
return func(ctx context.Context, _ func(string)) (string, error) {
ch, err := loadChart(in.charts, r.chart)
ch, err := loadChart(in.charts, r.chart, in.opts.Version)
if err != nil {
return "", err
}
Expand Down
Loading