Skip to content

Commit 73c2431

Browse files
authored
fix: preserve existing repoURL if new URL is placeholder (#658)
We do not want to re-introduce the placeholder in case it was already removed in previous reconciliations and instead use whatever value was in the unstructured resource beforehand. Refers to: #656 On-behalf-of: @SAP florian.wuermseer@sap.com
1 parent a3be26e commit 73c2431

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

pkg/subroutines/deployment_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (r *DeploymentSubroutine) preserveExistingArgoSourceFields(
312312
if source, ok := spec["source"].(map[string]interface{}); ok {
313313
if newRepoURL == argoPlaceholderRepoURL {
314314
// Never apply the placeholder — always strip it so ResourceSubroutine owns the field.
315-
source["repoURL"] = argoPlaceholderRepoURL
315+
source["repoURL"] = existingRepoURL
316316
if found && existingRepoURL != "" && existingRepoURL != argoPlaceholderRepoURL {
317317
log.Debug().Str("app", name).Msg("Preserving existing repoURL from ResourceSubroutine")
318318
}

pkg/subroutines/deployment_helpers_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,11 @@ func (s *DeploymentHelpersTestSuite) Test_templateFuncMap_not() {
458458

459459
func (s *DeploymentHelpersTestSuite) Test_preserveExistingArgoSourceFields() {
460460
tests := []struct {
461-
name string
462-
existingApp *unstructured.Unstructured
463-
objMap map[string]interface{}
464-
expectedRepoURL string
465-
expectedRevPreserved bool
466-
expectedTargetRevisionDeleted bool
461+
name string
462+
existingApp *unstructured.Unstructured
463+
objMap map[string]interface{}
464+
expectedRepoURL string
465+
expectedTargetRevision string
467466
}{
468467
{
469468
name: "app does not exist - nothing to preserve",
@@ -476,7 +475,8 @@ func (s *DeploymentHelpersTestSuite) Test_preserveExistingArgoSourceFields() {
476475
},
477476
},
478477
},
479-
expectedRepoURL: "https://new-repo.git",
478+
expectedRepoURL: "https://new-repo.git",
479+
expectedTargetRevision: "v1.0.0",
480480
},
481481
{
482482
name: "existing app has placeholder values - should not preserve",
@@ -504,7 +504,8 @@ func (s *DeploymentHelpersTestSuite) Test_preserveExistingArgoSourceFields() {
504504
},
505505
},
506506
},
507-
expectedRepoURL: "https://new-repo.git",
507+
expectedRepoURL: "https://new-repo.git",
508+
expectedTargetRevision: "v1.0.0",
508509
},
509510
{
510511
name: "existing app has real values different from new - should preserve",
@@ -532,8 +533,8 @@ func (s *DeploymentHelpersTestSuite) Test_preserveExistingArgoSourceFields() {
532533
},
533534
},
534535
},
535-
expectedRepoURL: "https://existing-repo.git",
536-
expectedTargetRevisionDeleted: true,
536+
expectedRepoURL: "https://existing-repo.git",
537+
expectedTargetRevision: "", // deleted so ResourceSubroutine's value is preserved
537538
},
538539
{
539540
name: "existing app has same values as new - no preservation needed",
@@ -561,7 +562,8 @@ func (s *DeploymentHelpersTestSuite) Test_preserveExistingArgoSourceFields() {
561562
},
562563
},
563564
},
564-
expectedRepoURL: "https://same-repo.git",
565+
expectedRepoURL: "https://same-repo.git",
566+
expectedTargetRevision: "v1.0.0",
565567
},
566568
{
567569
name: "existing app has empty repoURL - should not preserve",
@@ -589,7 +591,8 @@ func (s *DeploymentHelpersTestSuite) Test_preserveExistingArgoSourceFields() {
589591
},
590592
},
591593
},
592-
expectedRepoURL: "https://new-repo.git",
594+
expectedRepoURL: "https://new-repo.git",
595+
expectedTargetRevision: "v1.0.0",
593596
},
594597
}
595598

@@ -622,17 +625,14 @@ func (s *DeploymentHelpersTestSuite) Test_preserveExistingArgoSourceFields() {
622625
spec := tt.objMap["spec"].(map[string]interface{})
623626
source := spec["source"].(map[string]interface{})
624627

625-
if tt.expectedRevPreserved {
626-
_, hasRepoURL := source["repoURL"]
627-
_, hasTargetRevision := source["targetRevision"]
628-
s.False(hasRepoURL, "repoURL should have been deleted to preserve existing")
629-
s.False(hasTargetRevision, "targetRevision should have been deleted to preserve existing")
630-
} else if tt.expectedRepoURL != "" {
631-
s.Equal(tt.expectedRepoURL, source["repoURL"])
632-
}
633-
if tt.expectedTargetRevisionDeleted {
634-
_, hasTargetRevision := source["targetRevision"]
628+
s.Equal(tt.expectedRepoURL, source["repoURL"])
629+
630+
actualTargetRevision, hasTargetRevision := source["targetRevision"]
631+
if tt.expectedTargetRevision == "" {
635632
s.False(hasTargetRevision, "targetRevision should have been deleted to preserve existing")
633+
} else {
634+
s.True(hasTargetRevision, "targetRevision should be present")
635+
s.Equal(tt.expectedTargetRevision, actualTargetRevision)
636636
}
637637
})
638638
}
@@ -675,7 +675,7 @@ func (s *DeploymentHelpersTestSuite) Test_mergeImageVersionsIntoHelmReleaseValue
675675
tests := []struct {
676676
name string
677677
isUnsuspended bool
678-
specSuspend *bool // nil = field absent from template
678+
specSuspend *bool // nil = field absent from template
679679
expectSuspend interface{} // nil = key absent
680680
}{
681681
{

0 commit comments

Comments
 (0)