-
Notifications
You must be signed in to change notification settings - Fork 4.8k
MULTIARCH-5318: Add tests for ImageStreamImportMode feature gate #29524
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
Merged
openshift-merge-bot
merged 2 commits into
openshift:master
from
Prashanth684:imagestreamimportmode
Feb 11, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| package images | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/labels" | ||
| "k8s.io/apimachinery/pkg/types" | ||
|
|
||
| g "github.com/onsi/ginkgo/v2" | ||
| o "github.com/onsi/gomega" | ||
| configv1 "github.com/openshift/api/config/v1" | ||
| imagev1 "github.com/openshift/api/image/v1" | ||
| configclient "github.com/openshift/client-go/config/clientset/versioned" | ||
| "github.com/openshift/library-go/pkg/image/imageutil" | ||
| exutil "github.com/openshift/origin/test/extended/util" | ||
| "github.com/openshift/origin/test/extended/util/operator" | ||
| ) | ||
|
|
||
| var _ = g.Describe("[sig-imageregistry][OCPFeatureGate:ImageStreamImportMode][Serial] ImageStream API", func() { | ||
| defer g.GinkgoRecover() | ||
| oc := exutil.NewCLI("imagestream-api") | ||
|
|
||
| g.It("import mode should be PreserveOriginal or Legacy depending on desired.architecture field in the CV [apigroup:image.openshift.io]", func() { | ||
| TestImageStreamImportMode(g.GinkgoT(), oc) | ||
| }) | ||
|
|
||
| g.It("import mode should be Legacy if the import mode specified in image.config.openshift.io config is Legacy [apigroup:image.openshift.io]", func() { | ||
| TestImageConfigImageStreamImportModeLegacy(g.GinkgoT(), oc) | ||
| }) | ||
|
|
||
| g.It("import mode should be PreserveOriginal if the import mode specified in image.config.openshift.io config is PreserveOriginal [apigroup:image.openshift.io]", func() { | ||
| TestImageConfigImageStreamImportModePreserveOriginal(g.GinkgoT(), oc) | ||
| }) | ||
| }) | ||
|
|
||
| func changeImportModeAndWaitForApiServer(ctx context.Context, t g.GinkgoTInterface, oc *exutil.CLI, importMode string) error { | ||
| data := fmt.Sprintf(`{"spec":{"imageStreamImportMode":null}}`) | ||
| if len(importMode) > 0 { | ||
| data = fmt.Sprintf(`{"spec":{"imageStreamImportMode":"%s"}}`, importMode) | ||
| } | ||
| _, err := oc.AdminConfigClient().ConfigV1().Images().Patch(context.Background(), "cluster", types.MergePatchType, []byte(data), metav1.PatchOptions{}) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // when pods are pending it means the config has started to propagate | ||
| t.Log("waiting for image controller configuration to propagate") | ||
| _, err = exutil.WaitForPods(oc.AdminKubeClient().CoreV1().Pods("openshift-apiserver"), labels.Everything(), exutil.CheckPodIsPending, 1, 5*time.Minute) | ||
| if err != nil { | ||
| return fmt.Errorf("error waiting for new apiserver pods: %s", err) | ||
| } | ||
|
|
||
| t.Log("waiting for new openshift-apiserver operator to settle") | ||
| if err := operator.WaitForOperatorsToSettle(ctx, oc.AdminConfigClient(), 10); err != nil { | ||
| return err | ||
| } | ||
| t.Log("image controller configuration propagated") | ||
| return nil | ||
| } | ||
|
|
||
| func TestImageStreamImportMode(t g.GinkgoTInterface, oc *exutil.CLI) { | ||
| ctx := context.Background() | ||
| if !exutil.IsTechPreviewNoUpgrade(ctx, oc.AdminConfigClient()) { | ||
| g.Skip("skipping, this feature is only supported on TechPreviewNoUpgrade clusters") | ||
| } | ||
|
|
||
| // Check desired.Architecture in the CV | ||
| configClient, err := configclient.NewForConfig(oc.AdminConfig()) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| clusterVersion, err := configClient.ConfigV1().ClusterVersions().Get(ctx, "version", metav1.GetOptions{}) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| importmode := imagev1.ImportModeLegacy | ||
| if clusterVersion.Status.Desired.Architecture == configv1.ClusterVersionArchitectureMulti { | ||
| importmode = imagev1.ImportModePreserveOriginal | ||
| } | ||
|
|
||
| clusterAdminImageClient := oc.AdminImageClient().ImageV1() | ||
| g.By("creating an imagestream and imagestream tag") | ||
| stream := &imagev1.ImageStream{ObjectMeta: metav1.ObjectMeta{Name: "test-importmode"}} | ||
|
|
||
| expected, err := clusterAdminImageClient.ImageStreams(oc.Namespace()).Create(ctx, stream, metav1.CreateOptions{}) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| o.Expect(expected.Name).NotTo(o.BeEmpty()) | ||
|
|
||
| _, err = clusterAdminImageClient.ImageStreamTags(oc.Namespace()).Create(ctx, &imagev1.ImageStreamTag{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "test-importmode:1"}, | ||
| Tag: &imagev1.TagReference{ | ||
| From: &corev1.ObjectReference{Kind: "ImageStreamTag", Namespace: "openshift", Name: "tools:latest"}, | ||
| }, | ||
| }, metav1.CreateOptions{}) | ||
| o.Expect(err).ToNot(o.HaveOccurred()) | ||
|
|
||
| is, err := clusterAdminImageClient.ImageStreams(oc.Namespace()).Get(ctx, stream.Name, metav1.GetOptions{}) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| tag, ok := imageutil.SpecHasTag(is, "1") | ||
| o.Expect(ok).To(o.BeTrue()) | ||
| o.Expect(tag.ImportPolicy.ImportMode).To(o.Equal(importmode)) | ||
| } | ||
|
|
||
| func TestImageConfigImageStreamImportModeLegacy(t g.GinkgoTInterface, oc *exutil.CLI) { | ||
| ctx := context.Background() | ||
| if !exutil.IsTechPreviewNoUpgrade(ctx, oc.AdminConfigClient()) { | ||
| g.Skip("skipping, this feature is only supported on TechPreviewNoUpgrade clusters") | ||
| } | ||
|
|
||
| clusterAdminConfigClient := oc.AdminConfigClient().ConfigV1() | ||
| imageConfig, err := clusterAdminConfigClient.Images().Get(ctx, "cluster", metav1.GetOptions{}) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| if imageConfig.Status.ImageStreamImportMode == configv1.ImportModeLegacy { | ||
| g.Skip("skipping, import mode is already Legacy") | ||
| } | ||
|
|
||
| err = changeImportModeAndWaitForApiServer(ctx, t, oc, string(configv1.ImportModeLegacy)) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("creating an imagestream and imagestream tag") | ||
| stream := &imagev1.ImageStream{ObjectMeta: metav1.ObjectMeta{Name: "test-importmode"}} | ||
|
|
||
| clusterAdminImageClient := oc.AdminImageClient().ImageV1() | ||
| expected, err := clusterAdminImageClient.ImageStreams(oc.Namespace()).Create(ctx, stream, metav1.CreateOptions{}) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| o.Expect(expected.Name).NotTo(o.BeEmpty()) | ||
|
|
||
| _, err = clusterAdminImageClient.ImageStreamTags(oc.Namespace()).Create(ctx, &imagev1.ImageStreamTag{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "test-importmode:2"}, | ||
| Tag: &imagev1.TagReference{ | ||
| From: &corev1.ObjectReference{Kind: "ImageStreamTag", Namespace: "openshift", Name: "tools:latest"}, | ||
| }, | ||
| }, metav1.CreateOptions{}) | ||
| o.Expect(err).ToNot(o.HaveOccurred()) | ||
|
|
||
| is, err := clusterAdminImageClient.ImageStreams(oc.Namespace()).Get(ctx, stream.Name, metav1.GetOptions{}) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| tag, ok := imageutil.SpecHasTag(is, "2") | ||
| o.Expect(ok).To(o.BeTrue()) | ||
| o.Expect(tag.ImportPolicy.ImportMode).To(o.Equal(imagev1.ImportModeLegacy)) | ||
|
|
||
| // Revert back to original | ||
| err = changeImportModeAndWaitForApiServer(ctx, t, oc, "") | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| } | ||
|
|
||
| func TestImageConfigImageStreamImportModePreserveOriginal(t g.GinkgoTInterface, oc *exutil.CLI) { | ||
| ctx := context.Background() | ||
| if !exutil.IsTechPreviewNoUpgrade(ctx, oc.AdminConfigClient()) { | ||
| g.Skip("skipping, this feature is only supported on TechPreviewNoUpgrade clusters") | ||
| } | ||
|
|
||
| clusterAdminConfigClient := oc.AdminConfigClient().ConfigV1() | ||
| imageConfig, err := clusterAdminConfigClient.Images().Get(ctx, "cluster", metav1.GetOptions{}) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| if imageConfig.Status.ImageStreamImportMode == configv1.ImportModePreserveOriginal { | ||
| g.Skip("skipping, import mode is already PreserveOriginal") | ||
| } | ||
|
|
||
| err = changeImportModeAndWaitForApiServer(ctx, t, oc, string(configv1.ImportModePreserveOriginal)) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("creating an imagestream and imagestream tag") | ||
| stream := &imagev1.ImageStream{ObjectMeta: metav1.ObjectMeta{Name: "test-importmode"}} | ||
|
|
||
| clusterAdminImageClient := oc.AdminImageClient().ImageV1() | ||
| expected, err := clusterAdminImageClient.ImageStreams(oc.Namespace()).Create(ctx, stream, metav1.CreateOptions{}) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| o.Expect(expected.Name).NotTo(o.BeEmpty()) | ||
|
|
||
| _, err = clusterAdminImageClient.ImageStreamTags(oc.Namespace()).Create(ctx, &imagev1.ImageStreamTag{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "test-importmode:3"}, | ||
| Tag: &imagev1.TagReference{ | ||
| From: &corev1.ObjectReference{Kind: "ImageStreamTag", Namespace: "openshift", Name: "tools:latest"}, | ||
| }, | ||
| }, metav1.CreateOptions{}) | ||
| o.Expect(err).ToNot(o.HaveOccurred()) | ||
|
|
||
| is, err := clusterAdminImageClient.ImageStreams(oc.Namespace()).Get(ctx, stream.Name, metav1.GetOptions{}) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| tag, ok := imageutil.SpecHasTag(is, "3") | ||
| o.Expect(ok).To(o.BeTrue()) | ||
| o.Expect(tag.ImportPolicy.ImportMode).To(o.Equal(imagev1.ImportModePreserveOriginal)) | ||
|
|
||
| // Revert back to original | ||
| err = changeImportModeAndWaitForApiServer(ctx, t, oc, "") | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
test/extended/util/annotate/generated/zz_generated.annotations.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 19 additions & 2 deletions
21
vendor/github.com/openshift/api/config/v1/types_cluster_version.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
28 changes: 21 additions & 7 deletions
28
vendor/github.com/openshift/api/config/v1/types_infrastructure.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the two test cases below cover both
LegacyandPreserveOriginal, do we really need this test case? I can't really see what value it's adding, though I may be missing something.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test case is actually the only "necessary" one in my opinion because it changes the default import mode based on the CV's architecture. The other two test cases are specifically for testing the knob to change the import mode which I don't see being used frequently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the main idea here is that we have these tests which are exercised behind the featuregate and once we let them run for a release (or maybe a few sprint cycles), we use that signal to promote the featuregate to default and then I was thinking we remove the two tests which change the import mode knob.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack, thanks for expanding!