Skip to content

Commit e3d753b

Browse files
author
Diego Alfonso
committed
fix: Update subpath from DeepCopy instead of pointer
Signed-off-by: Diego Alfonso <[email protected]>
1 parent fd35b06 commit e3d753b

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

pkg/apis/cartographer/v1alpha1/workload_helpers.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ func (w *WorkloadSpec) Merge(updates *WorkloadSpec) {
222222
if updates.Image != "" {
223223
w.MergeImage(updates.Image)
224224
}
225-
if s := updates.Source; s != nil {
225+
if updates.Source != nil {
226+
s := updates.Source.DeepCopy()
226227
if s.Git != nil {
227228
w.MergeGit(*s.Git)
228229
}
@@ -326,7 +327,7 @@ func (w *WorkloadSpec) ResetSource() {
326327
}
327328

328329
func (w *WorkloadSpec) MergeGit(git GitSource) {
329-
stash := w.Source
330+
stash := w.Source.DeepCopy()
330331
image := w.Image
331332
w.ResetSource()
332333

@@ -348,13 +349,13 @@ func (w *WorkloadSpec) MergeGit(git GitSource) {
348349
}
349350

350351
func (w *WorkloadSpec) MergeSourceImage(image string) {
351-
stash := w.Source
352+
stash := w.Source.DeepCopy()
352353
w.ResetSource()
353354

354355
w.Source = &Source{
355356
Image: image,
356357
}
357-
if stash != nil && stash.Image != "" {
358+
if stash != nil && stash.Subpath != "" {
358359
w.Source.Subpath = stash.Subpath
359360
}
360361
}

pkg/apis/cartographer/v1alpha1/workload_test.go

-19
Original file line numberDiff line numberDiff line change
@@ -1884,25 +1884,6 @@ func TestWorkloadSpec_MergeSourceImage(t *testing.T) {
18841884
Subpath: "my-subpath",
18851885
},
18861886
},
1887-
}, {
1888-
name: "update deleting subpath",
1889-
seed: &WorkloadSpec{
1890-
Source: &Source{
1891-
Git: &GitSource{
1892-
URL: "[email protected]:example/repo.git",
1893-
Ref: GitRef{
1894-
Branch: "main",
1895-
},
1896-
},
1897-
Subpath: "my-subpath",
1898-
},
1899-
},
1900-
sourceImage: "my-registry.nip.io/my-folder/my-image:latest@sha:my-sha1234567890",
1901-
want: &WorkloadSpec{
1902-
Source: &Source{
1903-
Image: "my-registry.nip.io/my-folder/my-image:latest@sha:my-sha1234567890",
1904-
},
1905-
},
19061887
}}
19071888

19081889
for _, test := range tests {

0 commit comments

Comments
 (0)