From f30b82e19a602964fb20aec6b3ff9b378eb85fe1 Mon Sep 17 00:00:00 2001 From: Louis Murray Date: Mon, 4 Jun 2018 20:42:58 -0400 Subject: [PATCH 1/9] added code to handle overrides section --- pkg/skaffold/deploy/helm.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/skaffold/deploy/helm.go b/pkg/skaffold/deploy/helm.go index c92e72f818d..b7c5d12dcd1 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) } @@ -137,7 +152,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 { From 62eec65595d9f9845d377e19d2f115ab14646d59 Mon Sep 17 00:00:00 2001 From: Louis Murray Date: Mon, 4 Jun 2018 20:43:12 -0400 Subject: [PATCH 2/9] updated schema to handle new overrides field --- pkg/skaffold/schema/v1alpha2/config.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/skaffold/schema/v1alpha2/config.go b/pkg/skaffold/schema/v1alpha2/config.go index 5859fb22c03..bc7bc3d8c79 100644 --- a/pkg/skaffold/schema/v1alpha2/config.go +++ b/pkg/skaffold/schema/v1alpha2/config.go @@ -125,13 +125,14 @@ 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"` + 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"` + Overrides map[string]interface{} `yaml:"overrides"` } // Artifact represents items that need to be built, along with the context in which From eb44d88d4dcd6ea51ebfb2aee344823b0a57ad43 Mon Sep 17 00:00:00 2001 From: Louis Murray Date: Mon, 4 Jun 2018 20:43:34 -0400 Subject: [PATCH 3/9] updated test for overrides --- pkg/skaffold/deploy/helm_test.go | 3 +++ 1 file changed, 3 insertions(+) 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", }, From 91ea66c56a027163877ea6e19809922b6de1071c Mon Sep 17 00:00:00 2001 From: Louis Murray Date: Mon, 4 Jun 2018 20:45:08 -0400 Subject: [PATCH 4/9] updated helm example --- examples/helm-deployment/skaffold.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/helm-deployment/skaffold.yaml b/examples/helm-deployment/skaffold.yaml index d2ad1b498f0..4c01d3b14b8 100644 --- a/examples/helm-deployment/skaffold.yaml +++ b/examples/helm-deployment/skaffold.yaml @@ -14,6 +14,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 From 9f50e049b756584db2fbc2e6fb045a2dbb633f73 Mon Sep 17 00:00:00 2001 From: Louis Murray Date: Mon, 4 Jun 2018 21:07:25 -0400 Subject: [PATCH 5/9] fixed linter problems --- pkg/skaffold/schema/v1alpha2/config.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/skaffold/schema/v1alpha2/config.go b/pkg/skaffold/schema/v1alpha2/config.go index bc7bc3d8c79..334e28601a4 100644 --- a/pkg/skaffold/schema/v1alpha2/config.go +++ b/pkg/skaffold/schema/v1alpha2/config.go @@ -125,14 +125,14 @@ 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"` - Overrides map[string]interface{} `yaml:"overrides"` + 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"` + Overrides map[string]interface{} `yaml:"overrides"` } // Artifact represents items that need to be built, along with the context in which From 0b78983fae7c2d22a1fc4076a075079946086e8a Mon Sep 17 00:00:00 2001 From: Louis Murray Date: Mon, 4 Jun 2018 20:42:58 -0400 Subject: [PATCH 6/9] added code to handle overrides section --- pkg/skaffold/deploy/helm.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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 { From e3a5fc26e3b398a916162d840733d61c1d949128 Mon Sep 17 00:00:00 2001 From: Louis Murray Date: Mon, 4 Jun 2018 20:43:12 -0400 Subject: [PATCH 7/9] updated schema to handle new overrides field --- pkg/skaffold/schema/v1alpha2/config.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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 From 6e85d2d10ed0f5eb4ad8faa0ac7c0d4d1c664ee2 Mon Sep 17 00:00:00 2001 From: Louis Murray Date: Mon, 4 Jun 2018 20:43:34 -0400 Subject: [PATCH 8/9] updated test for overrides --- pkg/skaffold/deploy/helm_test.go | 3 +++ 1 file changed, 3 insertions(+) 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", }, From 83ac7743ee7d30ae56aa190de08a4a6b73ce37c4 Mon Sep 17 00:00:00 2001 From: Louis Murray Date: Mon, 4 Jun 2018 20:45:08 -0400 Subject: [PATCH 9/9] updated helm example --- examples/helm-deployment/skaffold.yaml | 4 ++++ 1 file changed, 4 insertions(+) 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