Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deterministic TagPair assertion of custom registry #1183

Merged
merged 2 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/image/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func GetE2EImages(e2eRegistryConfig, version string) ([]string, error) {
return imageNames, nil
}

// GetE2EImagePairs gets a list of E2E image tag pairs from the default src to custom destination
// GetE2EImageTagPairs gets a list of E2E image tag pairs from the default src to custom destination
func GetE2EImageTagPairs(e2eRegistryConfig, version string) ([]TagPair, error) {
defaultImageRegistry, err := NewRegistryList("", version)
if err != nil {
Expand Down
30 changes: 20 additions & 10 deletions pkg/image/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,31 @@ func TestGetE2EImageTagPairs(t *testing.T) {
}
expectedDefaultRegistry := defaultRegistry.v1_17()
if len(imageTagPairs) != len(expectedDefaultRegistry) {
t.Fatalf("Unexpected number of image tag pairs returned, expected %v, got %v", len(expectedDefaultRegistry), len(imageTagPairs))
t.Fatalf("unexpected number of image tag pairs returned, expected %v, got %v", len(expectedDefaultRegistry), len(imageTagPairs))
}

// Check one of the returned image pairs to ensure correct format
imageTagPair := imageTagPairs[0]
if strings.HasPrefix(imageTagPair.Src, customRegistry) {
t.Errorf("Src image should not have custom registry prefix: %q", imageTagPair.Src)
// As a sample, check one of the images for E2E and assert their mapping
var e2eImageTagPair TagPair
for _, imageTagPair := range imageTagPairs {
if strings.Contains(imageTagPair.Src, "e2e") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this ensures the name of the image:tag contains e2e in the string ? Is that always the case ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ensures that what we validate is only the e2e in string, which should scope to gcr.io/kubernetes-e2e-test-images or k8s.gcr.io/e2e-test-images -- both are overridable with custom registry

e2eImageTagPair = imageTagPair
break
}
}

if e2eImageTagPair == (TagPair{}) {
t.Errorf("no e2eImageTagPair is found")
}
if strings.HasPrefix(e2eImageTagPair.Src, customRegistry) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if that loop never break (above) does that create any initializiation hazard for var e2eImageTagPair? It does not seem like it (since e2eimagetagpair is a struct) but check please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah that's a good point. I think e2e will always exist, but I also think it's valuable to have check to assert it.

t.Errorf("src image should not have custom registry prefix: %q", e2eImageTagPair.Src)
}

imageComponents := strings.SplitAfter(imageTagPair.Src, "/")
if !strings.HasPrefix(imageTagPair.Dst, customRegistry) {
t.Errorf("Expected Dst image to have prefix %q, got %q", customRegistry, imageTagPair.Dst)
imageComponents := strings.SplitAfter(e2eImageTagPair.Src, "/")
if !strings.HasPrefix(e2eImageTagPair.Dst, customRegistry) {
t.Errorf("expected Dst image to have prefix %q, got %q", customRegistry, e2eImageTagPair.Dst)
}
if !strings.HasSuffix(imageTagPair.Dst, imageComponents[len(imageComponents)-1]) {
t.Errorf("Expected Dst image to have suffix %q, got %q", imageComponents[len(imageComponents)-1], imageTagPair.Dst)
if !strings.HasSuffix(e2eImageTagPair.Dst, imageComponents[len(imageComponents)-1]) {
t.Errorf("expected Dst image to have suffix %q, got %q", imageComponents[len(imageComponents)-1], e2eImageTagPair.Dst)
}
}

Expand Down