Skip to content

Commit 601ade5

Browse files
committed
Rename SplitImageName => ParseDomainName
A better name based on what it actually does.
1 parent a0cf343 commit 601ade5

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

pkg/image/admission/imagequalify/api/validation/domain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const imageRefWithoutDomain = "foo/bar"
1010
// used as the domain component in a docker image reference. Returns
1111
// an error if domain is invalid.
1212
func validateDomain(domain string) error {
13-
matchedDomain, remainder, err := SplitImageName(domain + "/" + imageRefWithoutDomain)
13+
matchedDomain, remainder, err := ParseDomainName(domain + "/" + imageRefWithoutDomain)
1414
if err != nil {
1515
return err
1616
}

pkg/image/admission/imagequalify/api/validation/image.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"k8s.io/kubernetes/pkg/util/parsers"
77
)
88

9-
// SplitImageName splits a docker image reference into the domain
10-
// component and everything after the domain. An empty string is
11-
// returned if there is no domain component. This function will first
12-
// validate that image is a valid reference, returning an error if it
13-
// is not.
9+
// ParseDomainName parses a docker image reference into its domain
10+
// component, if any, and everything after the domain. An empty string
11+
// is returned if there is no domain component. This function will
12+
// first validate that image is a valid reference, returning an error
13+
// if it is not.
1414
//
1515
// Examples inputs and results for the domain component:
1616
//
@@ -23,7 +23,7 @@ import (
2323
// "docker.io/busybox" -> domain is "docker.io"
2424
// "docker.io/library/busybox" -> domain is "docker.io"
2525
// "library/busybox:v1" -> domain is ""
26-
func SplitImageName(image string) (string, string, error) {
26+
func ParseDomainName(image string) (string, string, error) {
2727
// Note: when we call ParseImageName() this gets normalized to
2828
// potentially include "docker.io", and/or "library/" and or
2929
// "latest". We are only interested in discerning the domain

pkg/image/admission/imagequalify/api/validation/image_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"testing"
55
)
66

7-
func TestImageSplitImageName(t *testing.T) {
7+
func TestImageParseDomainName(t *testing.T) {
88
for i, test := range []struct {
99
input string
1010
domain string
@@ -65,7 +65,7 @@ func TestImageSplitImageName(t *testing.T) {
6565
remainder: "foo/busybox:v1.2.3",
6666
}} {
6767
t.Logf("test #%v: %s", i, test.input)
68-
domain, remainder, err := SplitImageName(test.input)
68+
domain, remainder, err := ParseDomainName(test.input)
6969
if test.expectErr && err == nil {
7070
t.Errorf("test %#v: expected error", i)
7171
} else if !test.expectErr && err != nil {

pkg/image/admission/imagequalify/qualify.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,28 @@ func matchImage(image string, rules []api.ImageQualifyRule) *api.ImageQualifyRul
1919
}
2020

2121
func qualifyImage(image string, rules []api.ImageQualifyRule) (string, error) {
22-
domain, _, err := validation.SplitImageName(image)
22+
domain, _, err := validation.ParseDomainName(image)
2323
if err != nil {
2424
return "", err
2525
}
26+
2627
if domain != "" {
2728
// image is already qualified
2829
return image, nil
2930
}
30-
if matched := matchImage(image, rules); matched != nil {
31-
qname := matched.Domain + "/" + image
32-
// Revalidate qualified image
33-
_, _, err := validation.SplitImageName(qname)
34-
if err != nil {
35-
return "", err
36-
}
37-
return qname, nil
31+
32+
matched := matchImage(image, rules)
33+
if matched == nil {
34+
// no match, return as-is.
35+
return image, nil
3836
}
39-
return image, nil
37+
38+
qname := matched.Domain + "/" + image
39+
40+
// Revalidate qualified image
41+
if _, _, err := validation.ParseDomainName(qname); err != nil {
42+
return "", err
43+
}
44+
45+
return qname, nil
4046
}

0 commit comments

Comments
 (0)