diff --git a/CHANGELOG.md b/CHANGELOG.md index b8258e5fb..7703bf947 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - (Feature) Helm Lint - (Bugfix) Helm Lint Indent fix - (Feature) Add CA Certificates +- (Feature) Chart By Tag filter ## [1.3.0](https://github.com/arangodb/kube-arangodb/tree/1.3.0) (2025-08-01) - (Feature) (Platform) Storage Debug diff --git a/pkg/util/constants/helm.go b/pkg/util/constants/helm.go index 05c2f4e9f..e686eef17 100644 --- a/pkg/util/constants/helm.go +++ b/pkg/util/constants/helm.go @@ -34,4 +34,6 @@ const ( // HelmLabelArangoDBType set to platform or service HelmLabelArangoDBType = HelmLabelInstallationBase + "/type" + + HelmLabelTag = HelmLabelBase + "/tag" ) diff --git a/pkg/util/k8sutil/helm/chart_manager_repo.go b/pkg/util/k8sutil/helm/chart_manager_repo.go index 12e0b9d30..b8a9ac67a 100644 --- a/pkg/util/k8sutil/helm/chart_manager_repo.go +++ b/pkg/util/k8sutil/helm/chart_manager_repo.go @@ -25,12 +25,16 @@ import ( "sort" "helm.sh/helm/v3/pkg/repo" + + "github.com/arangodb/kube-arangodb/pkg/util" + utilConstants "github.com/arangodb/kube-arangodb/pkg/util/constants" ) type ChartManagerRepo interface { Versions() []string Get(version string) (ChartManagerRepoVersion, bool) + GetByTag(version string) (ChartManagerRepoVersion, bool) Latest() (ChartManagerRepoVersion, bool) } @@ -63,6 +67,34 @@ func (c chartManagerRepo) Versions() []string { return s } +func (c chartManagerRepo) GetByTag(version string) (ChartManagerRepoVersion, bool) { + r, ok := c.manager.index.Entries[c.name] + if !ok { + return nil, false + } + + r = util.FilterList(r, func(v *repo.ChartVersion) bool { + if v, ok := v.Annotations[utilConstants.HelmLabelTag]; ok && v == version { + return true + } + return false + }) + + r = util.Sort(r, func(i, j *repo.ChartVersion) bool { + return i.Created.After(j.Created) + }) + + if len(r) == 0 { + return nil, false + } + + return chartManagerRepoVersion{ + version: r[0].Version, + manager: c.manager, + chart: r[0], + }, true +} + func (c chartManagerRepo) Get(version string) (ChartManagerRepoVersion, bool) { if version == "latest" { return c.Latest() diff --git a/pkg/util/k8sutil/helm/chart_manager_test.go b/pkg/util/k8sutil/helm/chart_manager_test.go index de4dafb61..4eba05dc0 100644 --- a/pkg/util/k8sutil/helm/chart_manager_test.go +++ b/pkg/util/k8sutil/helm/chart_manager_test.go @@ -92,3 +92,13 @@ func Test_Manager(t *testing.T) { require.NoError(t, mgr.Reload(context.Background())) } + +func Test_Manager_Tag(t *testing.T) { + mgr, err := NewChartManager(context.Background(), nil, "https://arangodb-platform-dev-chart-registry.s3.amazonaws.com/index.yaml") + require.NoError(t, err) + + repo, ok := mgr.Get("platform_test_example") + require.True(t, ok) + + repo.GetByTag("dev") +}