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

chore: split helm render flags from helm deployer flags #9208

Closed
wants to merge 3 commits into from
Closed
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
58 changes: 54 additions & 4 deletions docs-v2/content/en/schemas/v4beta9.json
Original file line number Diff line number Diff line change
Expand Up @@ -2167,7 +2167,7 @@
],
"properties": {
"flags": {
"$ref": "#/definitions/HelmDeployFlags",
"$ref": "#/definitions/HelmRenderFlags",
"description": "additional option flags that are passed on the command line to `helm`.",
"x-intellij-html-description": "additional option flags that are passed on the command line to <code>helm</code>."
},
Expand All @@ -2191,6 +2191,15 @@
},
"HelmDeployFlags": {
"properties": {
"depBuild": {
"items": {
"type": "string"
},
"type": "array",
"description": "additional flags passed to (`helm dep build`).",
"x-intellij-html-description": "additional flags passed to (<code>helm dep build</code>).",
"default": "[]"
},
"global": {
"items": {
"type": "string"
Expand Down Expand Up @@ -2222,12 +2231,13 @@
"preferredOrder": [
"global",
"install",
"upgrade"
"upgrade",
"depBuild"
],
"additionalProperties": false,
"type": "object",
"description": "additional option flags that are passed on the command line to `helm`.",
"x-intellij-html-description": "additional option flags that are passed on the command line to <code>helm</code>."
"description": "additional option flags that are passed on the command line to `helm` on deploy.",
"x-intellij-html-description": "additional option flags that are passed on the command line to <code>helm</code> on deploy."
},
"HelmPackaged": {
"properties": {
Expand Down Expand Up @@ -2388,6 +2398,46 @@
"description": "describes a helm release to be deployed.",
"x-intellij-html-description": "describes a helm release to be deployed."
},
"HelmRenderFlags": {
"properties": {
"depBuild": {
"items": {
"type": "string"
},
"type": "array",
"description": "additional flags passed to (`helm dep build`).",
"x-intellij-html-description": "additional flags passed to (<code>helm dep build</code>).",
"default": "[]"
},
"global": {
"items": {
"type": "string"
},
"type": "array",
"description": "additional flags passed on every command.",
"x-intellij-html-description": "additional flags passed on every command.",
"default": "[]"
},
"template": {
"items": {
"type": "string"
},
"type": "array",
"description": "additional flags passed to (`helm template`).",
"x-intellij-html-description": "additional flags passed to (<code>helm template</code>).",
"default": "[]"
}
},
"preferredOrder": [
"global",
"template",
"depBuild"
],
"additionalProperties": false,
"type": "object",
"description": "additional option flags that are passed on the command line to `helm` on render.",
"x-intellij-html-description": "additional option flags that are passed on the command line to <code>helm</code> on render."
},
"HostHook": {
"required": [
"command"
Expand Down
17 changes: 9 additions & 8 deletions pkg/skaffold/deploy/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ func (h Deployer) ManifestOverrides() map[string]string {
return map[string]string{}
}

func (h Deployer) EnableDebug() bool { return h.enableDebug }
func (h Deployer) OverrideProtocols() []string { return h.overrideProtocols }
func (h Deployer) ConfigFile() string { return h.configFile }
func (h Deployer) KubeContext() string { return h.kubeContext }
func (h Deployer) KubeConfig() string { return h.kubeConfig }
func (h Deployer) Labels() map[string]string { return h.labels }
func (h Deployer) GlobalFlags() []string { return h.LegacyHelmDeploy.Flags.Global }
func (h Deployer) EnableDebug() bool { return h.enableDebug }
func (h Deployer) OverrideProtocols() []string { return h.overrideProtocols }
func (h Deployer) ConfigFile() string { return h.configFile }
func (h Deployer) KubeContext() string { return h.kubeContext }
func (h Deployer) KubeConfig() string { return h.kubeConfig }
func (h Deployer) Labels() map[string]string { return h.labels }
func (h Deployer) GlobalFlags() []string { return h.LegacyHelmDeploy.Flags.Global }
func (h Deployer) DependenciesBuildFlags() []string { return h.LegacyHelmDeploy.Flags.DepBuild }

type Config interface {
kubectl.Config
Expand Down Expand Up @@ -488,7 +489,7 @@ func (h *Deployer) deployRelease(ctx context.Context, out io.Writer, releaseName
if !r.SkipBuildDependencies && r.ChartPath != "" {
olog.Entry(ctx).Info("Building helm dependencies...")

if err := helm.Exec(ctx, h, out, false, nil, "dep", "build", r.ChartPath); err != nil {
if err := helm.BuildChartDependencies(ctx, out, out, h, nil, r.ChartPath); err != nil {
return nil, nil, helm.UserErr("building helm dependencies", err)
}
}
Expand Down
14 changes: 13 additions & 1 deletion pkg/skaffold/deploy/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,9 @@ func TestHelmRender(t *testing.T) {
helmRenderer, err := rhelm.New(&helmConfig{
namespace: test.namespace,
}, latest.RenderConfig{
Generate: latest.Generate{Helm: &latest.Helm{Flags: test.helm.Flags, Releases: test.helm.Releases}},
Generate: latest.Generate{
Helm: getHelmRendererConfig(t, test.helm),
},
}, labels, "default", nil)
t.RequireNoError(err)
_, err = helmRenderer.Render(context.Background(), io.Discard, test.builds, true)
Expand All @@ -1360,6 +1362,16 @@ func TestHelmRender(t *testing.T) {
}
}

func getHelmRendererConfig(t *testutil.T, helmDeployerCfg latest.LegacyHelmDeploy) *latest.Helm {
t.Helper()
return &latest.Helm{
Releases: helmDeployerCfg.Releases,
Flags: latest.HelmRenderFlags{
Global: helmDeployerCfg.Flags.Global,
},
}
}

func TestHelmHooks(t *testing.T) {
tests := []struct {
description string
Expand Down
8 changes: 8 additions & 0 deletions pkg/skaffold/helm/bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Client interface {
KubeContext() string
Labels() map[string]string
GlobalFlags() []string
DependenciesBuildFlags() []string
ManifestOverrides() map[string]string
}

Expand Down Expand Up @@ -151,3 +152,10 @@ func ExecWithStdoutAndStderr(ctx context.Context, h Client, stdout io.Writer, st

return util.RunCmd(ctx, cmd)
}

// BuildChartDependencies executes the helm command in charge of building the given chart dependencies
func BuildChartDependencies(ctx context.Context, stdout, stderr io.Writer, h Client, env []string, chartPath string) error {
args := []string{"dep", "build", chartPath}
args = append(args, h.DependenciesBuildFlags()...)
return ExecWithStdoutAndStderr(ctx, h, stdout, stderr, false, nil, args...)
}
16 changes: 9 additions & 7 deletions pkg/skaffold/helm/bin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,21 @@ type mockClient struct {
labels map[string]string
manifestsOverrides map[string]string
globalFlags []string
depBuildFlags []string
}

func (h mockClient) ManifestOverrides() map[string]string {
return h.manifestsOverrides
}

func (h mockClient) EnableDebug() bool { return h.enableDebug }
func (h mockClient) OverrideProtocols() []string { return h.overrideProtocols }
func (h mockClient) ConfigFile() string { return h.configFile }
func (h mockClient) KubeContext() string { return h.kubeContext }
func (h mockClient) KubeConfig() string { return h.kubeConfig }
func (h mockClient) Labels() map[string]string { return h.labels }
func (h mockClient) GlobalFlags() []string { return h.globalFlags }
func (h mockClient) EnableDebug() bool { return h.enableDebug }
func (h mockClient) OverrideProtocols() []string { return h.overrideProtocols }
func (h mockClient) ConfigFile() string { return h.configFile }
func (h mockClient) KubeContext() string { return h.kubeContext }
func (h mockClient) KubeConfig() string { return h.kubeConfig }
func (h mockClient) Labels() map[string]string { return h.labels }
func (h mockClient) GlobalFlags() []string { return h.globalFlags }
func (h mockClient) DependenciesBuildFlags() []string { return h.depBuildFlags }

func TestBinVer(t *testing.T) {
tests := []struct {
Expand Down
18 changes: 10 additions & 8 deletions pkg/skaffold/render/renderer/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ type Helm struct {
transformDenylist map[apimachinery.GroupKind]latest.ResourceFilter
}

func (h Helm) EnableDebug() bool { return h.enableDebug }
func (h Helm) OverrideProtocols() []string { return h.overrideProtocols }
func (h Helm) ConfigFile() string { return h.configFile }
func (h Helm) KubeContext() string { return h.kubeContext }
func (h Helm) KubeConfig() string { return h.kubeConfig }
func (h Helm) Labels() map[string]string { return h.labels }
func (h Helm) GlobalFlags() []string { return h.config.Flags.Global }
func (h Helm) EnableDebug() bool { return h.enableDebug }
func (h Helm) OverrideProtocols() []string { return h.overrideProtocols }
func (h Helm) ConfigFile() string { return h.configFile }
func (h Helm) KubeContext() string { return h.kubeContext }
func (h Helm) KubeConfig() string { return h.kubeConfig }
func (h Helm) Labels() map[string]string { return h.labels }
func (h Helm) GlobalFlags() []string { return h.config.Flags.Global }
func (h Helm) DependenciesBuildFlags() []string { return h.config.Flags.DepBuild }

func (h Helm) ManifestOverrides() map[string]string {
return h.manifestOverrides
Expand Down Expand Up @@ -207,12 +208,13 @@ func (h Helm) generateHelmManifest(ctx context.Context, builds []graph.Artifact,
// Build Chart dependencies, but allow a user to skip it.
if !release.SkipBuildDependencies && release.ChartPath != "" {
log.Entry(ctx).Info("Building helm dependencies...")
if err := helm.ExecWithStdoutAndStderr(ctx, h, io.Discard, errBuffer, false, env, "dep", "build", release.ChartPath); err != nil {
if err := helm.BuildChartDependencies(ctx, io.Discard, errBuffer, h, env, release.ChartPath); err != nil {
log.Entry(ctx).Infof(errBuffer.String())
return nil, helm.UserErr("building helm dependencies", err)
}
}

args = append(args, h.config.Flags.Template...)
err = helm.ExecWithStdoutAndStderr(ctx, h, outBuffer, errBuffer, false, env, args...)
errorMsg := errBuffer.String()

Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/runner/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func GetDeployer(ctx context.Context, runCtx *runcontext.RunContext, labeller *l
// copy relevant render config to legacy helm deployer
if r.Helm != nil {
d.LegacyHelmDeploy.Releases = r.Helm.Releases
d.LegacyHelmDeploy.Flags = r.Helm.Flags
d.LegacyHelmDeploy.Flags.Global = r.Helm.Flags.Global
}
h, err := helm.NewDeployer(ctx, dCtx, labeller, d.LegacyHelmDeploy, runCtx.Artifacts(), configName, gks)
if err != nil {
Expand Down
20 changes: 18 additions & 2 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ type Kustomize struct {
type Helm struct {
// Flags are additional option flags that are passed on the command
// line to `helm`.
Flags HelmDeployFlags `yaml:"flags,omitempty"`
Flags HelmRenderFlags `yaml:"flags,omitempty"`

// Releases is a list of Helm releases.
Releases []HelmRelease `yaml:"releases,omitempty" yamltags:"required"`
Expand Down Expand Up @@ -936,7 +936,7 @@ type LegacyHelmDeploy struct {
}

// HelmDeployFlags are additional option flags that are passed on the command
// line to `helm`.
// line to `helm` on deploy.
type HelmDeployFlags struct {
// Global are additional flags passed on every command.
Global []string `yaml:"global,omitempty"`
Expand All @@ -946,6 +946,22 @@ type HelmDeployFlags struct {

// Upgrade are additional flags passed to (`helm upgrade`).
Upgrade []string `yaml:"upgrade,omitempty"`

// DepBuild are additional flags passed to (`helm dep build`).
DepBuild []string `yaml:"depBuild,omitempty"`
}

// HelmRenderFlags are additional option flags that are passed on the command
// line to `helm` on render.
type HelmRenderFlags struct {
// Global are additional flags passed on every command.
Global []string `yaml:"global,omitempty"`

// Template are additional flags passed to (`helm template`).
Template []string `yaml:"template,omitempty"`

// DepBuild are additional flags passed to (`helm dep build`).
DepBuild []string `yaml:"depBuild,omitempty"`
}

// HelmRelease describes a helm release to be deployed.
Expand Down