diff --git a/examples/helm-deployment/skaffold.yaml b/examples/helm-deployment/skaffold.yaml index 5e37951dd5b..cc54dd5b1ae 100644 --- a/examples/helm-deployment/skaffold.yaml +++ b/examples/helm-deployment/skaffold.yaml @@ -15,6 +15,10 @@ deploy: #valuesFilePath: helm-skaffold-values.yaml values: image: skaffold-helm + #overrides builds an override values.yaml file to run with the helm deploy + #overrides: + # some: + # key: someValue #setValues get appended to the helm deploy with --set. #setValues: #some.key: someValue diff --git a/pkg/skaffold/deploy/helm.go b/pkg/skaffold/deploy/helm.go index c0f4000a898..448ad042880 100644 --- a/pkg/skaffold/deploy/helm.go +++ b/pkg/skaffold/deploy/helm.go @@ -28,6 +28,7 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/pkg/errors" "github.com/sirupsen/logrus" + yaml "gopkg.in/yaml.v2" ) type HelmDeployer struct { @@ -122,6 +123,20 @@ func (h *HelmDeployer) deployRelease(out io.Writer, r v1alpha2.HelmRelease, buil if ns != "" { args = append(args, "--namespace", ns) } + if len(r.Overrides) != 0 { + overrides, err := yaml.Marshal(r.Overrides) + if err != nil { + return errors.Wrap(err, "cannot marshal overrides to create overrides values.yaml") + } + overridesFile, err := os.Create("skaffold-overrides.yaml") + if err != nil { + return errors.Wrap(err, "cannot create file skaffold-overrides.yaml") + } + if _, err := overridesFile.WriteString(string(overrides)); err != nil { + return errors.Wrap(err, "failed to write file skaffold-overrides.yaml") + } + args = append(args, "-f", "skaffold-overrides.yaml") + } if r.ValuesFilePath != "" { args = append(args, "-f", r.ValuesFilePath) } @@ -140,7 +155,11 @@ func (h *HelmDeployer) deployRelease(out io.Writer, r v1alpha2.HelmRelease, buil } args = append(args, setOpts...) - return h.helm(out, args...) + helmErr := h.helm(out, args...) + if len(r.Overrides) != 0 { + os.Remove("skaffold-overrides.yaml") + } + return helmErr } func (h *HelmDeployer) deleteRelease(out io.Writer, r v1alpha2.HelmRelease) error { diff --git a/pkg/skaffold/deploy/helm_test.go b/pkg/skaffold/deploy/helm_test.go index c11dda5284e..92fc05f0d8d 100644 --- a/pkg/skaffold/deploy/helm_test.go +++ b/pkg/skaffold/deploy/helm_test.go @@ -46,6 +46,9 @@ var testDeployConfig = &v1alpha2.DeployConfig{ Values: map[string]string{ "image.tag": "skaffold-helm", }, + Overrides: map[string]interface{}{ + "foo": "bar", + }, SetValues: map[string]string{ "some.key": "somevalue", }, diff --git a/pkg/skaffold/schema/v1alpha2/config.go b/pkg/skaffold/schema/v1alpha2/config.go index d32d9887f79..743e35df5be 100644 --- a/pkg/skaffold/schema/v1alpha2/config.go +++ b/pkg/skaffold/schema/v1alpha2/config.go @@ -125,14 +125,15 @@ type HelmDeploy struct { } type HelmRelease struct { - Name string `yaml:"name"` - ChartPath string `yaml:"chartPath"` - ValuesFilePath string `yaml:"valuesFilePath"` - Values map[string]string `yaml:"values,omitempty"` - Namespace string `yaml:"namespace"` - Version string `yaml:"version"` - SetValues map[string]string `yaml:"setValues"` - Wait bool `yaml:"wait"` + Name string `yaml:"name"` + ChartPath string `yaml:"chartPath"` + ValuesFilePath string `yaml:"valuesFilePath"` + Values map[string]string `yaml:"values,omitempty"` + Namespace string `yaml:"namespace"` + Version string `yaml:"version"` + SetValues map[string]string `yaml:"setValues"` + Wait bool `yaml:"wait"` + Overrides map[string]interface{} `yaml:"overrides"` } // Artifact represents items that need to be built, along with the context in which