diff --git a/README.md b/README.md index 5d07dca..643e220 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,8 @@ A _plugin descriptor_ specifying the helm repository, chart, version and values that should be used in a kubernetes-style resource can be referenced in the `generators` section of a `kustomization.yaml` and looks as follows: ``` -apiVersion: helm.mgoltzsche.github.com/v1 -kind: ChartInflator +apiVersion: helm.kustomize.mgoltzsche.github.com/v1 +kind: ChartRenderer metadata: name: namespace: diff --git a/example/jenkins/jenkins-chart.yaml b/example/jenkins/jenkins-chart.yaml index a09b3be..3d0303f 100644 --- a/example/jenkins/jenkins-chart.yaml +++ b/example/jenkins/jenkins-chart.yaml @@ -1,11 +1,11 @@ -apiVersion: helm.mgoltzsche.github.com/v1 -kind: ChartInflator +apiVersion: helm.kustomize.mgoltzsche.github.com/v1 +kind: ChartRenderer metadata: - name: jenkins-chart-inflator + name: myjenkins namespace: jenkins repository: https://kubernetes-charts.storage.googleapis.com chart: jenkins version: 0.32.4 -loadDependencies: true +#loadDependencies: true valueFiles: - - jenkins-values.yaml \ No newline at end of file + - values.yaml \ No newline at end of file diff --git a/example/jenkins/jenkins-values.yaml b/example/jenkins/values.yaml similarity index 100% rename from example/jenkins/jenkins-values.yaml rename to example/jenkins/values.yaml diff --git a/example/rook-ceph/operator/rook-ceph-chart.yaml b/example/rook-ceph/operator/rook-ceph-chart.yaml index c96583a..9946754 100644 --- a/example/rook-ceph/operator/rook-ceph-chart.yaml +++ b/example/rook-ceph/operator/rook-ceph-chart.yaml @@ -1,7 +1,7 @@ -apiVersion: helm.mgoltzsche.github.com/v1 -kind: ChartInflator +apiVersion: helm.kustomize.mgoltzsche.github.com/v1 +kind: ChartRenderer metadata: - name: ceph-chart-inflator + name: rook-ceph namespace: rook-ceph-system repository: https://charts.rook.io/stable chart: rook-ceph diff --git a/pkg/helm/chartwithextvalues.yaml b/pkg/helm/chartwithextvalues.yaml index a769ab5..dc46d42 100644 --- a/pkg/helm/chartwithextvalues.yaml +++ b/pkg/helm/chartwithextvalues.yaml @@ -1,11 +1,11 @@ -apiVersion: helm.mgoltzsche.github.com/v1 -kind: ChartInflator +apiVersion: helm.kustomize.mgoltzsche.github.com/v1 +kind: ChartRenderer metadata: - name: jenkins-chart-inflator + name: myjenkins namespace: jenkins repository: https://kubernetes-charts.storage.googleapis.com chart: jenkins version: 0.32.4 -loadDependencies: true +#loadDependencies: true valueFiles: - - ../../../example/jenkins/jenkins-values.yaml \ No newline at end of file + - ../../../example/jenkins/values.yaml \ No newline at end of file diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index da9b755..6685325 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -25,7 +25,11 @@ import ( "k8s.io/helm/pkg/repo" ) -const stableRepository = "stable" +const ( + stableRepository = "stable" + generatorAPIVersion = "helm.kustomize.mgoltzsche.github.com/v1" + generatorKind = "ChartRenderer" +) var ( whitespaceRegex = regexp.MustCompile(`^\s*$`) @@ -64,14 +68,15 @@ type LoadChartConfig struct { Repository string `yaml:"repository"` Chart string `yaml:"chart"` Version string `yaml:"version"` - Username string `yaml:"user,omitempty"` - Password string `yaml:"password,omitempty"` - DepUp bool `yaml:"loadDependencies,omitempty"` - Verify bool `yaml:"verify,omitempty"` - Keyring string `yaml:"keyring,omitempty"` - CertFile string `yaml:"certFile,omitempty"` - KeyFile string `yaml:"keyFile,omitempty"` - CaFile string `yaml:"caFile,omitempty"` + + // TODO: load from some local configuration + Username string `yaml:"user,omitempty"` + Password string `yaml:"password,omitempty"` + Verify bool `yaml:"verify,omitempty"` + Keyring string `yaml:"keyring,omitempty"` + CertFile string `yaml:"certFile,omitempty"` + KeyFile string `yaml:"keyFile,omitempty"` + CaFile string `yaml:"caFile,omitempty"` } // RenderConfig defines the configuration to render a chart @@ -101,13 +106,19 @@ func ReadGeneratorConfig(reader io.Reader) (cfg *GeneratorConfig, err error) { if cfg.Chart == "" { err = errors.New("chart not specified") } + if cfg.APIVersion != generatorAPIVersion { + err = errors.Errorf("expected apiVersion %s but was %s", generatorAPIVersion, cfg.APIVersion) + } + if cfg.Kind != generatorKind { + err = errors.Errorf("expected kind %s but was %s", generatorKind, cfg.Kind) + } } if cfg.Namespace == "" { cfg.Namespace = cfg.Metadata.Namespace } else if cfg.Metadata.Namespace != "" && err == nil { err = errors.New("both metadata.namespace and namespace defined") } - return cfg, errors.Wrap(err, "read chart inflator config") + return cfg, errors.Wrap(err, "read chart renderer config") } // Render manifest from helm chart configuration (shorthand) @@ -141,10 +152,10 @@ func NewHelm(home string, out io.Writer) *Helm { // Initialize initialize the helm home directory. // Derived from https://github.com/helm/helm/blob/v2.14.3/cmd/helm/installer/init.go func (h *Helm) Initialize() (err error) { - // TODO: - /*if _, e := os.Stat(h.settings.Home.String()); e == nil { + // TODO: create temporary helm home? + if _, e := os.Stat(h.settings.Home.String()); e == nil { return - }*/ + } log.Printf("Initializing helm home at %s\n", h.settings.Home) @@ -228,25 +239,21 @@ func (h *Helm) LoadChart(ref *LoadChartConfig) (c *chart.Chart, err error) { req, e := chartutil.LoadRequirements(c) if e == nil { if err = renderutil.CheckDependencies(c, req); err != nil { - if ref.DepUp { - man := &downloader.Manager{ - Out: h.out, - ChartPath: chartPath, - HelmHome: h.settings.Home, - Keyring: ref.Keyring, - SkipUpdate: false, - Getters: getter.All(h.settings), - } - if err = man.Update(); err != nil { - return - } - - // Update all dependencies which are present in /charts. - c, err = chartutil.Load(chartPath) - if err != nil { - return - } - } else { + man := &downloader.Manager{ + Out: h.out, + ChartPath: chartPath, + HelmHome: h.settings.Home, + Keyring: ref.Keyring, + SkipUpdate: true, + Getters: getter.All(h.settings), + } + if err = man.Update(); err != nil { + return + } + + // Update all dependencies which are present in /charts. + c, err = chartutil.Load(chartPath) + if err != nil { return } } diff --git a/pkg/helm/helm_test.go b/pkg/helm/helm_test.go index 945767e..c63a838 100644 --- a/pkg/helm/helm_test.go +++ b/pkg/helm/helm_test.go @@ -33,7 +33,7 @@ func TestRender(t *testing.T) { b := rendered.Bytes() l, err := readYaml(b) require.NoError(t, err, "rendered yaml:\n%s", b) - require.True(t, len(l) > 0, "rendered yaml is empty") + require.True(t, len(l) > 0, "%s: rendered yaml is empty", file) require.Contains(t, rendered.String(), "- host: jenkins.example.org\n") hasJenkinsNamespace := false for _, o := range l { @@ -42,7 +42,7 @@ func TestRender(t *testing.T) { break } } - require.True(t, hasJenkinsNamespace, "should have 'jenkins' namespace") + require.True(t, hasJenkinsNamespace, "%s: should have 'jenkins' namespace", file) } }