Skip to content

Commit aeaecfb

Browse files
authored
Merge pull request #826 from bivas/fix-issue-360
add support for helm image convention vs fqn setting
2 parents 40af64d + 6e72f84 commit aeaecfb

File tree

4 files changed

+107
-14
lines changed

4 files changed

+107
-14
lines changed

examples/helm-deployment/skaffold-helm/values.yaml

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
# This is a YAML-formatted file.
33
# Declare variables to be passed into your templates.
44
replicaCount: 1
5-
image:
6-
repository: nginx
7-
tag: stable
8-
pullPolicy: IfNotPresent
5+
image: nginx:stable
6+
# This is the helm convention on declaring images
7+
# image:
8+
# repository: nginx
9+
# tag: stable
10+
# pullPolicy: IfNotPresent
911
service:
1012
name: nginx
1113
type: ClusterIP

pkg/skaffold/deploy/helm.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,13 @@ func (h *HelmDeployer) deployRelease(out io.Writer, r v1alpha2.HelmRelease, buil
129129
var setOpts []string
130130
for k, v := range params {
131131
setOpts = append(setOpts, "--set")
132-
setOpts = append(setOpts, fmt.Sprintf("%s=%s", k, v.Tag))
132+
if r.ImageStrategy.HelmImageConfig.HelmConventionConfig != nil {
133+
tagSplit := strings.Split(v.Tag, ":")
134+
imageRepositoryTag := fmt.Sprintf("%s.repository=%s,%s.tag=%s", k, tagSplit[0], k, tagSplit[1])
135+
setOpts = append(setOpts, imageRepositoryTag)
136+
} else {
137+
setOpts = append(setOpts, fmt.Sprintf("%s=%s", k, v.Tag))
138+
}
133139
}
134140

135141
// First build dependencies.

pkg/skaffold/deploy/helm_test.go

+75-9
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var testDeployConfig = &v1alpha2.HelmDeploy{
5454
Name: "skaffold-helm",
5555
ChartPath: "examples/test",
5656
Values: map[string]string{
57-
"image.tag": "skaffold-helm",
57+
"image": "skaffold-helm",
5858
},
5959
Overrides: map[string]interface{}{
6060
"foo": "bar",
@@ -66,13 +66,36 @@ var testDeployConfig = &v1alpha2.HelmDeploy{
6666
},
6767
}
6868

69+
var testDeployHelmStyleConfig = &v1alpha2.HelmDeploy{
70+
Releases: []v1alpha2.HelmRelease{
71+
{
72+
Name: "skaffold-helm",
73+
ChartPath: "examples/test",
74+
Values: map[string]string{
75+
"image": "skaffold-helm",
76+
},
77+
Overrides: map[string]interface{}{
78+
"foo": "bar",
79+
},
80+
SetValues: map[string]string{
81+
"some.key": "somevalue",
82+
},
83+
ImageStrategy: v1alpha2.HelmImageStrategy{
84+
HelmImageConfig: v1alpha2.HelmImageConfig{
85+
HelmConventionConfig: &v1alpha2.HelmConventionConfig{},
86+
},
87+
},
88+
},
89+
},
90+
}
91+
6992
var testDeployConfigParameterUnmatched = &v1alpha2.HelmDeploy{
7093
Releases: []v1alpha2.HelmRelease{
7194
{
7295
Name: "skaffold-helm",
7396
ChartPath: "examples/test",
7497
Values: map[string]string{
75-
"image.tag": "skaffold-helm-unmatched",
98+
"image": "skaffold-helm-unmatched",
7699
},
77100
},
78101
},
@@ -84,7 +107,7 @@ var testDeployFooWithPackaged = &v1alpha2.HelmDeploy{
84107
Name: "foo",
85108
ChartPath: "testdata/foo",
86109
Values: map[string]string{
87-
"image.tag": "foo",
110+
"image": "foo",
88111
},
89112
Packaged: &v1alpha2.HelmPackaged{
90113
Version: "0.1.2",
@@ -222,13 +245,42 @@ func TestHelmDeploy(t *testing.T) {
222245
{
223246
description: "get failure should install not upgrade",
224247
cmd: &MockHelm{
225-
t: t,
226-
getResult: fmt.Errorf("not found"),
248+
t: t,
249+
getResult: fmt.Errorf("not found"),
250+
installMatcher: func(cmd *exec.Cmd) bool {
251+
expected := map[string]bool{fmt.Sprintf("image=%s", testBuilds[0].Tag): true}
252+
for _, arg := range cmd.Args {
253+
if expected[arg] {
254+
return true
255+
}
256+
}
257+
return false
258+
},
227259
upgradeResult: fmt.Errorf("should not have called upgrade"),
228260
},
229261
deployer: NewHelmDeployer(testDeployConfig, testKubeContext, testNamespace),
230262
builds: testBuilds,
231263
},
264+
{
265+
description: "get failure should install not upgrade with helm image strategy",
266+
cmd: &MockHelm{
267+
t: t,
268+
getResult: fmt.Errorf("not found"),
269+
installMatcher: func(cmd *exec.Cmd) bool {
270+
builds := strings.Split(testBuilds[0].Tag, ":")
271+
expected := map[string]bool{fmt.Sprintf("image.repository=%s,image.tag=%s", builds[0], builds[1]): true}
272+
for _, arg := range cmd.Args {
273+
if expected[arg] {
274+
return true
275+
}
276+
}
277+
return false
278+
},
279+
upgradeResult: fmt.Errorf("should not have called upgrade"),
280+
},
281+
deployer: NewHelmDeployer(testDeployHelmStyleConfig, testKubeContext, testNamespace),
282+
builds: testBuilds,
283+
},
232284
{
233285
description: "get success should upgrade not install",
234286
cmd: &MockHelm{
@@ -305,13 +357,18 @@ func TestHelmDeploy(t *testing.T) {
305357
}
306358
}
307359

360+
type CommandMatcher func(*exec.Cmd) bool
361+
308362
type MockHelm struct {
309363
t *testing.T
310364

311-
getResult error
312-
installResult error
313-
upgradeResult error
314-
depResult error
365+
getResult error
366+
getMatcher CommandMatcher
367+
installResult error
368+
installMatcher CommandMatcher
369+
upgradeResult error
370+
upgradeMatcher CommandMatcher
371+
depResult error
315372

316373
packageOut io.Reader
317374
packageResult error
@@ -339,10 +396,19 @@ func (m *MockHelm) RunCmd(c *exec.Cmd) error {
339396

340397
switch c.Args[3] {
341398
case "get":
399+
if m.getMatcher != nil && !m.getMatcher(c) {
400+
m.t.Errorf("get matcher failed to match cmd")
401+
}
342402
return m.getResult
343403
case "install":
404+
if m.installMatcher != nil && !m.installMatcher(c) {
405+
m.t.Errorf("install matcher failed to match cmd")
406+
}
344407
return m.installResult
345408
case "upgrade":
409+
if m.upgradeMatcher != nil && !m.upgradeMatcher(c) {
410+
m.t.Errorf("upgrade matcher failed to match cmd")
411+
}
346412
return m.upgradeResult
347413
case "dep":
348414
return m.depResult

pkg/skaffold/schema/v1alpha2/config.go

+19
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ type HelmRelease struct {
152152
Wait bool `yaml:"wait"`
153153
Overrides map[string]interface{} `yaml:"overrides"`
154154
Packaged *HelmPackaged `yaml:"packaged"`
155+
ImageStrategy HelmImageStrategy `yaml:"imageStrategy"`
155156
}
156157

157158
// HelmPackaged represents parameters for packaging helm chart.
@@ -163,6 +164,24 @@ type HelmPackaged struct {
163164
AppVersion string `yaml:"appVersion"`
164165
}
165166

167+
type HelmImageStrategy struct {
168+
HelmImageConfig `yaml:",inline"`
169+
}
170+
171+
type HelmImageConfig struct {
172+
HelmFQNConfig *HelmFQNConfig `yaml:"fqn"`
173+
HelmConventionConfig *HelmConventionConfig `yaml:"helm"`
174+
}
175+
176+
// HelmFQNConfig represents image config to use the FullyQualifiedImageName as param to set
177+
type HelmFQNConfig struct {
178+
Property string `yaml:"property"`
179+
}
180+
181+
// HelmConventionConfig represents image config in the syntax of image.repository and image.tag
182+
type HelmConventionConfig struct {
183+
}
184+
166185
// Artifact represents items that need to be built, along with the context in which
167186
// they should be built.
168187
type Artifact struct {

0 commit comments

Comments
 (0)