File: helm_api.go

package info (click to toggle)
gitlab-agent 16.1.3-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 6,324 kB
  • sloc: makefile: 175; sh: 52; ruby: 3
file content (52 lines) | stat: -rw-r--r-- 1,660 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package chartops

import (
	"context"

	"helm.sh/helm/v3/pkg/action"
	"helm.sh/helm/v3/pkg/chart"
	"helm.sh/helm/v3/pkg/release"
)

type ChartValues map[string]interface{}

type Helm interface {
	History(name string) ([]*release.Release, error)
	Upgrade(ctx context.Context, name string, chart *chart.Chart, vals ChartValues, cfg UpgradeConfig) (*release.Release, error)
	Install(ctx context.Context, chart *chart.Chart, vals ChartValues, cfg InstallConfig) (*release.Release, error)
}

type UpgradeConfig struct {
	// Namespace is the namespace in which this operation should be performed.
	Namespace string
	// MaxHistory limits the maximum number of revisions saved per release
	MaxHistory int
}

type InstallConfig struct {
	// Namespace is the namespace in which this operation should be performed.
	Namespace   string
	ReleaseName string
}

type HelmActions struct {
	ActionCfg *action.Configuration
}

func (h *HelmActions) History(name string) ([]*release.Release, error) {
	return action.NewHistory(h.ActionCfg).Run(name)
}

func (h *HelmActions) Upgrade(ctx context.Context, name string, chart *chart.Chart, vals ChartValues, cfg UpgradeConfig) (*release.Release, error) {
	upgrade := action.NewUpgrade(h.ActionCfg)
	upgrade.Namespace = cfg.Namespace
	upgrade.MaxHistory = cfg.MaxHistory
	return upgrade.RunWithContext(ctx, name, chart, vals)
}

func (h *HelmActions) Install(ctx context.Context, chart *chart.Chart, vals ChartValues, cfg InstallConfig) (*release.Release, error) {
	install := action.NewInstall(h.ActionCfg)
	install.Namespace = cfg.Namespace
	install.ReleaseName = cfg.ReleaseName
	return install.RunWithContext(ctx, chart, vals)
}