Skip to content

Commit

Permalink
Keep only 1 historical helm release per app on cluster
Browse files Browse the repository at this point in the history
   Currently, we don't specify MaxHistory and a number of helm releases
keeps growing meaning ketch creates lots of secrets named
"sh.helm.release.v1.<app-name>.v<version>".
  • Loading branch information
aleksej-paschenko committed Dec 21, 2021
1 parent 5c19952 commit 3ba5649
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ci/limits.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"github.com/theketchio/ketch/internal/api/v1beta1": 33.2,
"github.com/theketchio/ketch/internal/api/v1beta1/mocks": 0,
"github.com/theketchio/ketch/internal/build": 92.3,
"github.com/theketchio/ketch/internal/chart": 67.8,
"github.com/theketchio/ketch/internal/chart": 67.7,
"github.com/theketchio/ketch/internal/controllers": 55.7,
"github.com/theketchio/ketch/internal/deploy": 26.5,
"github.com/theketchio/ketch/internal/errors": 50,
Expand Down
15 changes: 11 additions & 4 deletions internal/chart/helm_client.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package chart

import (
"errors"
"log"
"os"

"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/storage/driver"
"k8s.io/cli-runtime/pkg/genericclioptions"
"log"
"os"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -73,7 +76,7 @@ func (c HelmClient) UpdateChart(tv TemplateValuer, config ChartConfig, opts ...I
getValuesClient := action.NewGetValues(c.cfg)
getValuesClient.AllValues = true
_, err = getValuesClient.Run(appName)
if err != nil && err.Error() == "release: not found" {
if err != nil && errors.Is(err, driver.ErrReleaseNotFound) {
clientInstall := action.NewInstall(c.cfg)
clientInstall.ReleaseName = appName
clientInstall.Namespace = c.namespace
Expand All @@ -91,6 +94,10 @@ func (c HelmClient) UpdateChart(tv TemplateValuer, config ChartConfig, opts ...I
}
updateClient := action.NewUpgrade(c.cfg)
updateClient.Namespace = c.namespace
// MaxHistory=0 means there is an unlimited number of k8s secrets per application,
// and the number keeps growing.
// Let's set it to minimal.
updateClient.MaxHistory = 1
updateClient.PostRenderer = &postRender{
namespace: c.namespace,
cli: c.c,
Expand All @@ -102,7 +109,7 @@ func (c HelmClient) UpdateChart(tv TemplateValuer, config ChartConfig, opts ...I
func (c HelmClient) DeleteChart(appName string) error {
uninstall := action.NewUninstall(c.cfg)
_, err := uninstall.Run(appName)
if err != nil && err.Error() == "release: not found" {
if err != nil && errors.Is(err, driver.ErrReleaseNotFound) {
return nil
}
return err
Expand Down

0 comments on commit 3ba5649

Please sign in to comment.