@@ -2,13 +2,9 @@ package images
22
33import (
44 "context"
5- "fmt"
6- "time"
75
86 corev1 "k8s.io/api/core/v1"
97 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10- "k8s.io/apimachinery/pkg/labels"
11- "k8s.io/apimachinery/pkg/types"
128
139 g "github.com/onsi/ginkgo/v2"
1410 o "github.com/onsi/gomega"
@@ -17,7 +13,6 @@ import (
1713 configclient "github.com/openshift/client-go/config/clientset/versioned"
1814 "github.com/openshift/library-go/pkg/image/imageutil"
1915 exutil "github.com/openshift/origin/test/extended/util"
20- "github.com/openshift/origin/test/extended/util/operator"
2116)
2217
2318var _ = g .Describe ("[sig-imageregistry][OCPFeatureGate:ImageStreamImportMode][Serial] ImageStream API" , func () {
@@ -27,46 +22,10 @@ var _ = g.Describe("[sig-imageregistry][OCPFeatureGate:ImageStreamImportMode][Se
2722 g .It ("import mode should be PreserveOriginal or Legacy depending on desired.architecture field in the CV [apigroup:image.openshift.io]" , func () {
2823 TestImageStreamImportMode (g .GinkgoT (), oc )
2924 })
30-
31- 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 () {
32- TestImageConfigImageStreamImportModeLegacy (g .GinkgoT (), oc )
33- })
34-
35- 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 () {
36- TestImageConfigImageStreamImportModePreserveOriginal (g .GinkgoT (), oc )
37- })
3825})
3926
40- func changeImportModeAndWaitForApiServer (ctx context.Context , t g.GinkgoTInterface , oc * exutil.CLI , importMode string ) error {
41- data := fmt .Sprintf (`{"spec":{"imageStreamImportMode":null}}` )
42- if len (importMode ) > 0 {
43- data = fmt .Sprintf (`{"spec":{"imageStreamImportMode":"%s"}}` , importMode )
44- }
45- _ , err := oc .AdminConfigClient ().ConfigV1 ().Images ().Patch (context .Background (), "cluster" , types .MergePatchType , []byte (data ), metav1.PatchOptions {})
46- if err != nil {
47- return err
48- }
49-
50- // when pods are pending it means the config has started to propagate
51- t .Log ("waiting for image controller configuration to propagate" )
52- _ , err = exutil .WaitForPods (oc .AdminKubeClient ().CoreV1 ().Pods ("openshift-apiserver" ), labels .Everything (), exutil .CheckPodIsPending , 1 , 5 * time .Minute )
53- if err != nil {
54- return fmt .Errorf ("error waiting for new apiserver pods: %s" , err )
55- }
56-
57- t .Log ("waiting for new openshift-apiserver operator to settle" )
58- if err := operator .WaitForOperatorsToSettle (ctx , oc .AdminConfigClient (), 10 ); err != nil {
59- return err
60- }
61- t .Log ("image controller configuration propagated" )
62- return nil
63- }
64-
6527func TestImageStreamImportMode (t g.GinkgoTInterface , oc * exutil.CLI ) {
6628 ctx := context .Background ()
67- if ! exutil .IsTechPreviewNoUpgrade (ctx , oc .AdminConfigClient ()) {
68- g .Skip ("skipping, this feature is only supported on TechPreviewNoUpgrade clusters" )
69- }
7029
7130 // Check desired.Architecture in the CV
7231 configClient , err := configclient .NewForConfig (oc .AdminConfig ())
@@ -101,109 +60,3 @@ func TestImageStreamImportMode(t g.GinkgoTInterface, oc *exutil.CLI) {
10160 o .Expect (ok ).To (o .BeTrue ())
10261 o .Expect (tag .ImportPolicy .ImportMode ).To (o .Equal (importmode ))
10362}
104-
105- func TestImageConfigImageStreamImportModeLegacy (t g.GinkgoTInterface , oc * exutil.CLI ) {
106- ctx := context .Background ()
107- if ! exutil .IsTechPreviewNoUpgrade (ctx , oc .AdminConfigClient ()) {
108- g .Skip ("skipping, this feature is only supported on TechPreviewNoUpgrade clusters" )
109- }
110- if isSNO , err := exutil .IsSingleNode (ctx , oc .AdminConfigClient ()); err == nil && isSNO {
111- g .Skip ("skipping this test for SNO as it involves an openshift-apiserver disruption" )
112- }
113-
114- clusterAdminConfigClient := oc .AdminConfigClient ().ConfigV1 ()
115- imageConfig , err := clusterAdminConfigClient .Images ().Get (ctx , "cluster" , metav1.GetOptions {})
116- o .Expect (err ).NotTo (o .HaveOccurred ())
117-
118- importModeNoChange := false
119- if imageConfig .Status .ImageStreamImportMode == configv1 .ImportModeLegacy {
120- importModeNoChange = true
121- }
122-
123- // If import mode is actually the same as the intended one, skip changing it
124- if ! importModeNoChange {
125- err = changeImportModeAndWaitForApiServer (ctx , t , oc , string (configv1 .ImportModeLegacy ))
126- o .Expect (err ).NotTo (o .HaveOccurred ())
127- }
128-
129- g .By ("creating an imagestream and imagestream tag" )
130- stream := & imagev1.ImageStream {ObjectMeta : metav1.ObjectMeta {Name : "test-importmode" }}
131-
132- clusterAdminImageClient := oc .AdminImageClient ().ImageV1 ()
133- expected , err := clusterAdminImageClient .ImageStreams (oc .Namespace ()).Create (ctx , stream , metav1.CreateOptions {})
134- o .Expect (err ).NotTo (o .HaveOccurred ())
135- o .Expect (expected .Name ).NotTo (o .BeEmpty ())
136-
137- _ , err = clusterAdminImageClient .ImageStreamTags (oc .Namespace ()).Create (ctx , & imagev1.ImageStreamTag {
138- ObjectMeta : metav1.ObjectMeta {Name : "test-importmode:2" },
139- Tag : & imagev1.TagReference {
140- From : & corev1.ObjectReference {Kind : "ImageStreamTag" , Namespace : "openshift" , Name : "tools:latest" },
141- },
142- }, metav1.CreateOptions {})
143- o .Expect (err ).ToNot (o .HaveOccurred ())
144-
145- is , err := clusterAdminImageClient .ImageStreams (oc .Namespace ()).Get (ctx , stream .Name , metav1.GetOptions {})
146- o .Expect (err ).NotTo (o .HaveOccurred ())
147- tag , ok := imageutil .SpecHasTag (is , "2" )
148- o .Expect (ok ).To (o .BeTrue ())
149- o .Expect (tag .ImportPolicy .ImportMode ).To (o .Equal (imagev1 .ImportModeLegacy ))
150-
151- // Revert back to original
152- if ! importModeNoChange {
153- err = changeImportModeAndWaitForApiServer (ctx , t , oc , "" )
154- o .Expect (err ).NotTo (o .HaveOccurred ())
155- }
156- }
157-
158- func TestImageConfigImageStreamImportModePreserveOriginal (t g.GinkgoTInterface , oc * exutil.CLI ) {
159- ctx := context .Background ()
160- if ! exutil .IsTechPreviewNoUpgrade (ctx , oc .AdminConfigClient ()) {
161- g .Skip ("skipping, this feature is only supported on TechPreviewNoUpgrade clusters" )
162- }
163- if isSNO , err := exutil .IsSingleNode (ctx , oc .AdminConfigClient ()); err == nil && isSNO {
164- g .Skip ("skipping this test for SNO as it involves an openshift-apiserver disruption" )
165- }
166-
167- clusterAdminConfigClient := oc .AdminConfigClient ().ConfigV1 ()
168- imageConfig , err := clusterAdminConfigClient .Images ().Get (ctx , "cluster" , metav1.GetOptions {})
169- o .Expect (err ).NotTo (o .HaveOccurred ())
170-
171- importModeNoChange := false
172- if imageConfig .Status .ImageStreamImportMode == configv1 .ImportModePreserveOriginal {
173- importModeNoChange = true
174- }
175-
176- // If import mode is actually the same as the intended one, skip changing it
177- if ! importModeNoChange {
178- err = changeImportModeAndWaitForApiServer (ctx , t , oc , string (configv1 .ImportModePreserveOriginal ))
179- o .Expect (err ).NotTo (o .HaveOccurred ())
180- }
181-
182- g .By ("creating an imagestream and imagestream tag" )
183- stream := & imagev1.ImageStream {ObjectMeta : metav1.ObjectMeta {Name : "test-importmode" }}
184-
185- clusterAdminImageClient := oc .AdminImageClient ().ImageV1 ()
186- expected , err := clusterAdminImageClient .ImageStreams (oc .Namespace ()).Create (ctx , stream , metav1.CreateOptions {})
187- o .Expect (err ).NotTo (o .HaveOccurred ())
188- o .Expect (expected .Name ).NotTo (o .BeEmpty ())
189-
190- _ , err = clusterAdminImageClient .ImageStreamTags (oc .Namespace ()).Create (ctx , & imagev1.ImageStreamTag {
191- ObjectMeta : metav1.ObjectMeta {Name : "test-importmode:3" },
192- Tag : & imagev1.TagReference {
193- From : & corev1.ObjectReference {Kind : "ImageStreamTag" , Namespace : "openshift" , Name : "tools:latest" },
194- },
195- }, metav1.CreateOptions {})
196- o .Expect (err ).ToNot (o .HaveOccurred ())
197-
198- is , err := clusterAdminImageClient .ImageStreams (oc .Namespace ()).Get (ctx , stream .Name , metav1.GetOptions {})
199- o .Expect (err ).NotTo (o .HaveOccurred ())
200- tag , ok := imageutil .SpecHasTag (is , "3" )
201- o .Expect (ok ).To (o .BeTrue ())
202- o .Expect (tag .ImportPolicy .ImportMode ).To (o .Equal (imagev1 .ImportModePreserveOriginal ))
203-
204- // Revert back to original
205- if ! importModeNoChange {
206- err = changeImportModeAndWaitForApiServer (ctx , t , oc , "" )
207- o .Expect (err ).NotTo (o .HaveOccurred ())
208- }
209- }
0 commit comments