Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to generate override values.yaml based on data passed into skaffold.yaml #632

Merged
merged 10 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/helm-deployment/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 20 additions & 1 deletion pkg/skaffold/deploy/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/deploy/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
17 changes: 9 additions & 8 deletions pkg/skaffold/schema/v1alpha2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down