Skip to content

Commit 650e04a

Browse files
author
Casey Morton
committed
Comverted all instances of app.Spec.Source to normalize on app.Spec.GetSources[0] instead
Signed-off-by: Casey Morton <cmorton@exiger.com>
1 parent 82d59ef commit 650e04a

File tree

2 files changed

+91
-29
lines changed

2 files changed

+91
-29
lines changed

pkg/argocd/argocd.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -425,15 +425,15 @@ func SetHelmImage(app *v1alpha1.Application, newImage *image.ContainerImage) err
425425
}
426426
}
427427

428-
if app.Spec.Source.Helm == nil {
429-
app.Spec.Source.Helm = &v1alpha1.ApplicationSourceHelm{}
428+
if app.Spec.GetSources()[0].Helm == nil {
429+
app.Spec.GetSources()[0].Helm = &v1alpha1.ApplicationSourceHelm{}
430430
}
431431

432-
if app.Spec.Source.Helm.Parameters == nil {
433-
app.Spec.Source.Helm.Parameters = make([]v1alpha1.HelmParameter, 0)
432+
if app.Spec.GetSources()[0].Helm.Parameters == nil {
433+
app.Spec.GetSources()[0].Helm.Parameters = make([]v1alpha1.HelmParameter, 0)
434434
}
435435

436-
app.Spec.Source.Helm.Parameters = mergeHelmParams(app.Spec.Source.Helm.Parameters, mergeParams)
436+
app.Spec.GetSources()[0].Helm.Parameters = mergeHelmParams(app.Spec.GetSources()[0].Helm.Parameters, mergeParams)
437437

438438
return nil
439439
}
@@ -454,22 +454,29 @@ func SetKustomizeImage(app *v1alpha1.Application, newImage *image.ContainerImage
454454

455455
log.WithContext().AddField("application", app.GetName()).Tracef("Setting Kustomize parameter %s", ksImageParam)
456456

457-
if app.Spec.Source.Kustomize == nil {
458-
app.Spec.Source.Kustomize = &v1alpha1.ApplicationSourceKustomize{}
457+
var source = app.Spec.GetSources()[0]
458+
if source.Kustomize == nil {
459+
source.Kustomize = &v1alpha1.ApplicationSourceKustomize{}
459460
}
460461

461-
for i, kImg := range app.Spec.Source.Kustomize.Images {
462+
for i, kImg := range source.Kustomize.Images {
462463
curr := image.NewFromIdentifier(string(kImg))
463464
override := image.NewFromIdentifier(ksImageParam)
464465

465466
if curr.ImageName == override.ImageName {
466467
curr.ImageAlias = override.ImageAlias
467-
app.Spec.Source.Kustomize.Images[i] = v1alpha1.KustomizeImage(override.String())
468+
source.Kustomize.Images[i] = v1alpha1.KustomizeImage(override.String())
468469
}
469470

470471
}
471472

472-
app.Spec.Source.Kustomize.MergeImage(v1alpha1.KustomizeImage(ksImageParam))
473+
source.Kustomize.MergeImage(v1alpha1.KustomizeImage(ksImageParam))
474+
475+
if app.Spec.HasMultipleSources() {
476+
app.Spec.Sources[0] = source
477+
} else {
478+
app.Spec.Source = &source
479+
}
473480

474481
return nil
475482
}

pkg/argocd/argocd_test.go

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,9 @@ func Test_SetKustomizeImage(t *testing.T) {
468468
img := image.NewFromIdentifier("jannfis/foobar:1.0.1")
469469
err := SetKustomizeImage(app, img)
470470
require.NoError(t, err)
471-
require.NotNil(t, app.Spec.Source.Kustomize)
472-
assert.Len(t, app.Spec.Source.Kustomize.Images, 1)
473-
assert.Equal(t, v1alpha1.KustomizeImage("jannfis/foobar:1.0.1"), app.Spec.Source.Kustomize.Images[0])
471+
require.NotNil(t, app.Spec.GetSources()[0].Kustomize)
472+
assert.Len(t, app.Spec.GetSources()[0].Kustomize.Images, 1)
473+
assert.Equal(t, v1alpha1.KustomizeImage("jannfis/foobar:1.0.1"), app.Spec.GetSources()[0].Kustomize.Images[0])
474474
})
475475

476476
t.Run("Test set Kustomize image parameters on Kustomize app with no params set", func(t *testing.T) {
@@ -494,9 +494,9 @@ func Test_SetKustomizeImage(t *testing.T) {
494494
img := image.NewFromIdentifier("jannfis/foobar:1.0.1")
495495
err := SetKustomizeImage(app, img)
496496
require.NoError(t, err)
497-
require.NotNil(t, app.Spec.Source.Kustomize)
498-
assert.Len(t, app.Spec.Source.Kustomize.Images, 1)
499-
assert.Equal(t, v1alpha1.KustomizeImage("jannfis/foobar:1.0.1"), app.Spec.Source.Kustomize.Images[0])
497+
require.NotNil(t, app.Spec.GetSources()[0].Kustomize)
498+
assert.Len(t, app.Spec.GetSources()[0].Kustomize.Images, 1)
499+
assert.Equal(t, v1alpha1.KustomizeImage("jannfis/foobar:1.0.1"), app.Spec.GetSources()[0].Kustomize.Images[0])
500500
})
501501

502502
t.Run("Test set Kustomize image parameters on non-Kustomize app", func(t *testing.T) {
@@ -558,9 +558,9 @@ func Test_SetKustomizeImage(t *testing.T) {
558558
img := image.NewFromIdentifier("foobar=jannfis/foobar:1.0.1")
559559
err := SetKustomizeImage(app, img)
560560
require.NoError(t, err)
561-
require.NotNil(t, app.Spec.Source.Kustomize)
562-
assert.Len(t, app.Spec.Source.Kustomize.Images, 1)
563-
assert.Equal(t, v1alpha1.KustomizeImage("foobar=jannfis/foobar:1.0.1"), app.Spec.Source.Kustomize.Images[0])
561+
require.NotNil(t, app.Spec.GetSources()[0].Kustomize)
562+
assert.Len(t, app.Spec.GetSources()[0].Kustomize.Images, 1)
563+
assert.Equal(t, v1alpha1.KustomizeImage("foobar=jannfis/foobar:1.0.1"), app.Spec.GetSources()[0].Kustomize.Images[0])
564564
})
565565

566566
}
@@ -606,12 +606,12 @@ func Test_SetHelmImage(t *testing.T) {
606606

607607
err := SetHelmImage(app, img)
608608
require.NoError(t, err)
609-
require.NotNil(t, app.Spec.Source.Helm)
610-
assert.Len(t, app.Spec.Source.Helm.Parameters, 2)
609+
require.NotNil(t, app.Spec.GetSources()[0].Helm)
610+
assert.Len(t, app.Spec.GetSources()[0].Helm.Parameters, 2)
611611

612612
// Find correct parameter
613613
var tagParam v1alpha1.HelmParameter
614-
for _, p := range app.Spec.Source.Helm.Parameters {
614+
for _, p := range app.Spec.GetSources()[0].Helm.Parameters {
615615
if p.Name == "image.tag" {
616616
tagParam = p
617617
break
@@ -649,12 +649,67 @@ func Test_SetHelmImage(t *testing.T) {
649649

650650
err := SetHelmImage(app, img)
651651
require.NoError(t, err)
652-
require.NotNil(t, app.Spec.Source.Helm)
653-
assert.Len(t, app.Spec.Source.Helm.Parameters, 2)
652+
require.NotNil(t, app.Spec.GetSources()[0].Helm)
653+
assert.Len(t, app.Spec.GetSources()[0].Helm.Parameters, 2)
654654

655655
// Find correct parameter
656656
var tagParam v1alpha1.HelmParameter
657-
for _, p := range app.Spec.Source.Helm.Parameters {
657+
for _, p := range app.Spec.GetSources()[0].Helm.Parameters {
658+
if p.Name == "image.tag" {
659+
tagParam = p
660+
break
661+
}
662+
}
663+
assert.Equal(t, "1.0.1", tagParam.Value)
664+
})
665+
666+
t.Run("Test set Helm image parameters on Helm app with multiple sources but existing parameters", func(t *testing.T) {
667+
app := &v1alpha1.Application{
668+
ObjectMeta: v1.ObjectMeta{
669+
Name: "test-app",
670+
Namespace: "testns",
671+
Annotations: map[string]string{
672+
fmt.Sprintf(common.HelmParamImageNameAnnotation, "foobar"): "image.name",
673+
fmt.Sprintf(common.HelmParamImageTagAnnotation, "foobar"): "image.tag",
674+
fmt.Sprintf(common.HelmParamImageNameAnnotation, "baz"): "image.name",
675+
fmt.Sprintf(common.HelmParamImageTagAnnotation, "baz"): "image.tag",
676+
},
677+
},
678+
Spec: v1alpha1.ApplicationSpec{
679+
Sources: v1alpha1.ApplicationSources{
680+
v1alpha1.ApplicationSource{
681+
Helm: &v1alpha1.ApplicationSourceHelm{},
682+
},
683+
v1alpha1.ApplicationSource{
684+
Helm: &v1alpha1.ApplicationSourceHelm{},
685+
},
686+
},
687+
},
688+
Status: v1alpha1.ApplicationStatus{
689+
SourceTypes: []v1alpha1.ApplicationSourceType{
690+
v1alpha1.ApplicationSourceTypeHelm,
691+
v1alpha1.ApplicationSourceTypeHelm,
692+
},
693+
SourceType: v1alpha1.ApplicationSourceTypeHelm,
694+
Summary: v1alpha1.ApplicationSummary{
695+
Images: []string{
696+
"jannfis/foobar:1.0.0",
697+
"cjm/baz:2.0.0",
698+
},
699+
},
700+
},
701+
}
702+
703+
img := image.NewFromIdentifier("foobar=jannfis/foobar:1.0.1")
704+
705+
err := SetHelmImage(app, img)
706+
require.NoError(t, err)
707+
require.NotNil(t, app.Spec.GetSources()[0].Helm)
708+
assert.Len(t, app.Spec.GetSources()[0].Helm.Parameters, 2)
709+
710+
// Find correct parameter
711+
var tagParam v1alpha1.HelmParameter
712+
for _, p := range app.Spec.GetSources()[0].Helm.Parameters {
658713
if p.Name == "image.tag" {
659714
tagParam = p
660715
break
@@ -703,12 +758,12 @@ func Test_SetHelmImage(t *testing.T) {
703758

704759
err := SetHelmImage(app, img)
705760
require.NoError(t, err)
706-
require.NotNil(t, app.Spec.Source.Helm)
707-
assert.Len(t, app.Spec.Source.Helm.Parameters, 4)
761+
require.NotNil(t, app.Spec.GetSources()[0].Helm)
762+
assert.Len(t, app.Spec.GetSources()[0].Helm.Parameters, 4)
708763

709764
// Find correct parameter
710765
var tagParam v1alpha1.HelmParameter
711-
for _, p := range app.Spec.Source.Helm.Parameters {
766+
for _, p := range app.Spec.GetSources()[0].Helm.Parameters {
712767
if p.Name == "foobar.image.tag" {
713768
tagParam = p
714769
break
@@ -818,7 +873,7 @@ func TestKubernetesClient_UpdateSpec_Conflict(t *testing.T) {
818873

819874
require.NoError(t, err)
820875

821-
assert.Equal(t, "https://github.com/argoproj/argocd-example-apps", spec.Source.RepoURL)
876+
assert.Equal(t, "https://github.com/argoproj/argocd-example-apps", spec.GetSources()[0].RepoURL)
822877
}
823878

824879
func Test_parseImageList(t *testing.T) {

0 commit comments

Comments
 (0)