Skip to content

Commit

Permalink
chore: add helm flags from config to corresponding commands
Browse files Browse the repository at this point in the history
  • Loading branch information
renzodavid9 committed Dec 12, 2023
1 parent 6f8ad50 commit ab80d85
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
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
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

0 comments on commit ab80d85

Please sign in to comment.