-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(helm): add depBuild and template flags to HelmDeployFlags schema
- Loading branch information
1 parent
acad129
commit 0fd151a
Showing
5 changed files
with
245 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
Copyright 2022 The Skaffold Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package helm | ||
|
||
import ( | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/graph" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/helm" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/schema/latest" | ||
) | ||
|
||
func (h Helm) depBuildArgs(chartPath string) []string { | ||
args := []string{"dep", "build", chartPath} | ||
args = append(args, h.config.Flags.DepBuild...) | ||
return args | ||
} | ||
|
||
func (h Helm) templateArgs(releaseName string, release latest.HelmRelease, builds []graph.Artifact, namespace string, additionalArgs []string) ([]string, error) { | ||
var err error | ||
args := []string{"template", releaseName, helm.ChartSource(release)} | ||
args = append(args, h.config.Flags.Template...) | ||
args = append(args, additionalArgs...) | ||
|
||
if release.Packaged == nil && release.Version != "" { | ||
args = append(args, "--version", release.Version) | ||
} | ||
|
||
args, err = helm.ConstructOverrideArgs(&release, builds, args, h.manifestOverrides) | ||
if err != nil { | ||
return nil, helm.UserErr("construct override args", err) | ||
} | ||
|
||
if namespace != "" { | ||
args = append(args, "--namespace", namespace) | ||
} | ||
if release.Repo != "" { | ||
args = append(args, "--repo") | ||
args = append(args, release.Repo) | ||
} | ||
if release.SkipTests { | ||
args = append(args, "--skip-tests") | ||
} | ||
|
||
return args, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
Copyright 2022 The Skaffold Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package helm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/graph" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/schema/latest" | ||
"github.com/GoogleContainerTools/skaffold/v2/testutil" | ||
) | ||
|
||
func TestDepBuildArgs(t *testing.T) { | ||
tests := []struct { | ||
description string | ||
chartPath string | ||
flags latest.HelmDeployFlags | ||
expected []string | ||
}{ | ||
{ | ||
description: "basic", | ||
chartPath: "chart/path", | ||
expected: []string{"dep", "build", "chart/path"}, | ||
}, | ||
{ | ||
description: "with flags", | ||
chartPath: "chart/path", | ||
flags: latest.HelmDeployFlags{ | ||
DepBuild: []string{"--skip-refresh"}, | ||
}, | ||
expected: []string{"dep", "build", "chart/path", "--skip-refresh"}, | ||
}, | ||
{ | ||
description: "with multiple flags", | ||
chartPath: "chart/path", | ||
flags: latest.HelmDeployFlags{ | ||
DepBuild: []string{"--skip-refresh", "--debug"}, | ||
}, | ||
expected: []string{"dep", "build", "chart/path", "--skip-refresh", "--debug"}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
testutil.Run(t, test.description, func(t *testutil.T) { | ||
h := Helm{ | ||
config: &latest.Helm{ | ||
Flags: test.flags, | ||
}, | ||
} | ||
args := h.depBuildArgs(test.chartPath) | ||
t.CheckDeepEqual(test.expected, args) | ||
}) | ||
} | ||
} | ||
|
||
func TestTemplateArgs(t *testing.T) { | ||
tests := []struct { | ||
description string | ||
releaseName string | ||
release latest.HelmRelease | ||
builds []graph.Artifact | ||
namespace string | ||
additionalArgs []string | ||
flags latest.HelmDeployFlags | ||
expected []string | ||
shouldErr bool | ||
}{ | ||
{ | ||
description: "basic template", | ||
releaseName: "release", | ||
release: latest.HelmRelease{ | ||
ChartPath: "chart/path", | ||
}, | ||
expected: []string{"template", "release", "chart/path"}, | ||
}, | ||
{ | ||
description: "with version", | ||
releaseName: "release", | ||
release: latest.HelmRelease{ | ||
ChartPath: "chart/path", | ||
Version: "1.2.3", | ||
}, | ||
expected: []string{"template", "release", "chart/path", "--version", "1.2.3"}, | ||
}, | ||
{ | ||
description: "with namespace", | ||
releaseName: "release", | ||
release: latest.HelmRelease{ | ||
ChartPath: "chart/path", | ||
}, | ||
namespace: "namespace", | ||
expected: []string{"template", "release", "chart/path", "--namespace", "namespace"}, | ||
}, | ||
{ | ||
description: "with repo", | ||
releaseName: "release", | ||
release: latest.HelmRelease{ | ||
ChartPath: "chart/path", | ||
Repo: "repo-url", | ||
}, | ||
expected: []string{"template", "release", "chart/path", "--repo", "repo-url"}, | ||
}, | ||
{ | ||
description: "with skipTests", | ||
releaseName: "release", | ||
release: latest.HelmRelease{ | ||
ChartPath: "chart/path", | ||
SkipTests: true, | ||
}, | ||
expected: []string{"template", "release", "chart/path", "--skip-tests"}, | ||
}, | ||
{ | ||
description: "with additional args", | ||
releaseName: "release", | ||
release: latest.HelmRelease{ChartPath: "chart/path"}, | ||
additionalArgs: []string{"--foo", "bar"}, | ||
expected: []string{"template", "release", "chart/path", "--foo", "bar"}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
testutil.Run(t, test.description, func(t *testutil.T) { | ||
h := Helm{ | ||
config: &latest.Helm{ | ||
Flags: test.flags, | ||
}, | ||
} | ||
args, err := h.templateArgs(test.releaseName, test.release, test.builds, test.namespace, test.additionalArgs) | ||
if test.shouldErr { | ||
t.CheckError(true, err) | ||
} else { | ||
t.CheckError(false, err) | ||
t.CheckDeepEqual(test.expected, args) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters