Skip to content

Commit d1ca9a7

Browse files
Merge pull request #17315 from pravisankar/fix-diag-imagepath
Automatic merge from submit-queue. Fix network diagnostic default image path - variable.DefaultImagePrefix is populated from {node,master}-config.yaml (imageConfig.format) and if this value is not specified in the config, openshift ansible defaults it to 'registry.access.redhat.com'. - Network diagnostics is run as a admin CLI command so there is no config for variable.DefaultImagePrefix and it defaults to 'registry.access.redhat.com' which may not be true for AWS or some other openshift environments. - This change will remove the registry path from the default image so that it defaults to registry configured on the openshift node. Example: Earlier image path: registry.access.redhat.com/openshift3/ose New image path: openshift3/ose On AWS node, this will resolve to registry.reg-aws.openshift.com:443/openshift3/ose
2 parents 4765c46 + fe892c5 commit d1ca9a7

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

pkg/oc/admin/diagnostics/diagnostics/networkpod/util/util.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,29 @@ const (
3737
NetworkDiagDefaultTestPodPort = 8080
3838
)
3939

40+
func trimRegistryPath(image string) string {
41+
// Image format could be: [<dns-name>/]openshift/origin-deployer[:<tag>]
42+
// Return image without registry dns: openshift/origin-deployer[:<tag>]
43+
tokens := strings.Split(image, "/")
44+
sz := len(tokens)
45+
trimmedImage := image
46+
if sz >= 2 {
47+
trimmedImage = fmt.Sprintf("%s/%s", tokens[sz-2], tokens[sz-1])
48+
}
49+
return trimmedImage
50+
}
51+
4052
func GetNetworkDiagDefaultPodImage() string {
4153
imageTemplate := variable.NewDefaultImageTemplate()
4254
imageTemplate.Format = variable.DefaultImagePrefix + ":${version}"
43-
return imageTemplate.ExpandOrDie("")
55+
image := imageTemplate.ExpandOrDie("")
56+
return trimRegistryPath(image)
4457
}
4558

4659
func GetNetworkDiagDefaultTestPodImage() string {
4760
imageTemplate := variable.NewDefaultImageTemplate()
48-
return imageTemplate.ExpandOrDie("deployer")
61+
image := imageTemplate.ExpandOrDie("deployer")
62+
return trimRegistryPath(image)
4963
}
5064

5165
func GetOpenShiftNetworkPlugin(clusterNetworkClient networktypedclient.ClusterNetworksGetter) (string, bool, error) {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package util
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestTrimRegistryPath(t *testing.T) {
8+
testcases := map[string]struct {
9+
image string
10+
expectedImage string
11+
}{
12+
"Empty image": {
13+
image: "",
14+
expectedImage: "",
15+
},
16+
"Image with no slashes, no tags": {
17+
image: "origin",
18+
expectedImage: "origin",
19+
},
20+
"Image with no slashes": {
21+
image: "origin:v1.2.3",
22+
expectedImage: "origin:v1.2.3",
23+
},
24+
"Image with one slash, no tags": {
25+
image: "openshift/origin",
26+
expectedImage: "openshift/origin",
27+
},
28+
"Image with one slash": {
29+
image: "openshift/origin:v1.2.3",
30+
expectedImage: "openshift/origin:v1.2.3",
31+
},
32+
"Image with dns path, no port, no tags": {
33+
image: "registry.access.redhat.com/openshift3/ose",
34+
expectedImage: "openshift3/ose",
35+
},
36+
"Image with dns path, no port": {
37+
image: "registry.access.redhat.com/openshift3/ose:v1.2.3",
38+
expectedImage: "openshift3/ose:v1.2.3",
39+
},
40+
"Image with dns path": {
41+
image: "registry.reg-aws.openshift.com:443/openshift3/ose:v1.2.3",
42+
expectedImage: "openshift3/ose:v1.2.3",
43+
},
44+
}
45+
46+
for name, tc := range testcases {
47+
trimmedImage := trimRegistryPath(tc.image)
48+
if trimmedImage != tc.expectedImage {
49+
t.Fatalf("[%s] failed: expected %s but got %s", name, tc.expectedImage, trimmedImage)
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)