Skip to content

Commit 9353408

Browse files
committed
fix(imageupdateautomation_controller.go): fixed tag parsing logic misinterpreting [host:port] registry url
Signed-off-by: lukas8219 <[email protected]>
1 parent ba238df commit 9353408

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

internal/controller/imageupdateautomation_controller.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,18 +557,26 @@ func getPolicies(ctx context.Context, kclient client.Client, namespace string, s
557557
func observedPolicies(policies []imagev1_reflect.ImagePolicy) (imagev1.ObservedPolicies, error) {
558558
observedPolicies := imagev1.ObservedPolicies{}
559559
for _, policy := range policies {
560-
parts := strings.SplitN(policy.Status.LatestImage, ":", 2)
561-
if len(parts) != 2 {
560+
name, tag := splitByLastColon(policy.Status.LatestImage)
561+
if name == "" || tag == "" {
562562
return nil, fmt.Errorf("failed parsing image: %s", policy.Status.LatestImage)
563563
}
564564
observedPolicies[policy.Name] = imagev1.ImageRef{
565-
Name: parts[0],
566-
Tag: parts[1],
565+
Name: name,
566+
Tag: tag,
567567
}
568568
}
569569
return observedPolicies, nil
570570
}
571571

572+
func splitByLastColon(latestImage string) (string, string) {
573+
idx := strings.LastIndex(latestImage, ":")
574+
if idx == -1 {
575+
return latestImage, ""
576+
}
577+
return latestImage[:idx], latestImage[idx+1:]
578+
}
579+
572580
// observedPoliciesChanged returns if the previous and current observedPolicies
573581
// have changed.
574582
func observedPoliciesChanged(previous, current imagev1.ObservedPolicies) bool {

internal/controller/update_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,13 +1568,13 @@ func Test_observedPolicies(t *testing.T) {
15681568
"p1": "aaa:bbb",
15691569
"p2": "ccc:ddd",
15701570
"p3": "eee:latest",
1571-
"p4": "fff:ggg:hhh",
1571+
"p4": "registry.localhost:5000/sample-web:0.1.0",
15721572
},
15731573
want: imagev1.ObservedPolicies{
15741574
"p1": imagev1.ImageRef{Name: "aaa", Tag: "bbb"},
15751575
"p2": imagev1.ImageRef{Name: "ccc", Tag: "ddd"},
15761576
"p3": imagev1.ImageRef{Name: "eee", Tag: "latest"},
1577-
"p4": imagev1.ImageRef{Name: "fff", Tag: "ggg:hhh"},
1577+
"p4": imagev1.ImageRef{Name: "registry.localhost:5000/sample-web", Tag: "0.1.0"},
15781578
},
15791579
},
15801580
{

0 commit comments

Comments
 (0)