@@ -15,6 +15,8 @@ import (
1515 g "github.com/onsi/ginkgo/v2"
1616 o "github.com/onsi/gomega"
1717 configv1 "github.com/openshift/api/config/v1"
18+ "github.com/openshift/api/features"
19+ configv1client "github.com/openshift/client-go/config/clientset/versioned"
1820 exutil "github.com/openshift/origin/test/extended/util"
1921 "github.com/openshift/origin/test/extended/util/image"
2022 appsv1 "k8s.io/api/apps/v1"
@@ -31,7 +33,7 @@ var _ = g.Describe("[Serial][sig-cli] oc adm upgrade recommend", g.Ordered, func
3133 f := framework .NewDefaultFramework ("oc-adm-upgrade-recommend" )
3234 oc := exutil .NewCLIWithFramework (f ).AsAdmin ()
3335 var cv * configv1.ClusterVersion
34- var restoreChannel , restoreUpstream bool
36+ var restoreChannel , restoreUpstream , alertsByCVO , isHyperShift bool
3537 var caBundleFilePath string
3638
3739 g .BeforeAll (func () {
@@ -43,6 +45,12 @@ var _ = g.Describe("[Serial][sig-cli] oc adm upgrade recommend", g.Ordered, func
4345
4446 cv , err = oc .AdminConfigClient ().ConfigV1 ().ClusterVersions ().Get (ctx , "version" , metav1.GetOptions {})
4547 o .Expect (err ).NotTo (o .HaveOccurred ())
48+
49+ isHyperShift , err = exutil .IsHypershift (ctx , oc .AdminConfigClient ())
50+ o .Expect (err ).NotTo (o .HaveOccurred ())
51+
52+ alertsByCVO , err = alertsEvaluatedByCVO (ctx , cv , isHyperShift , oc .AdminConfigClient ())
53+ o .Expect (err ).NotTo (o .HaveOccurred ())
4654 })
4755
4856 g .AfterAll (func () {
@@ -121,8 +129,6 @@ No updates available. You may still upgrade to a specific release image.*`)
121129 var token string
122130
123131 g .BeforeAll (func () {
124- isHyperShift , err := exutil .IsHypershift (ctx , oc .AdminConfigClient ())
125- o .Expect (err ).NotTo (o .HaveOccurred ())
126132 if isHyperShift {
127133 g .Skip ("HyperShift does not support configuring the upstream OpenShift Update Service directoly via ClusterVersion (it must be configured via HostedCluster on the management cluster)" )
128134 }
@@ -134,7 +140,7 @@ No updates available. You may still upgrade to a specific release image.*`)
134140 }
135141
136142 var buf strings.Builder
137- err = template .Must (template .New ("letter" ).Parse (`{
143+ err : = template .Must (template .New ("letter" ).Parse (`{
138144 "nodes": [
139145 {"version": "{{.CurrentVersion}}","payload": "{{.CurrentImage}}", "metadata": {"io.openshift.upgrades.graph.release.channels": "test-channel,other-channel"}},
140146 {"version": "4.{{.CurrentMinor}}.998","payload": "example.com/test@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
@@ -216,6 +222,10 @@ No updates available. You may still upgrade to a specific release image.*`)
216222 o .Expect (oc .Run ("config" , "set-context" ).Args ("--current" , "--user" , "test" ).Execute ()).To (o .Succeed ())
217223
218224 out , err := oc .Run ("--certificate-authority" , caBundleFilePath , "adm" , "upgrade" , "recommend" ).EnvVar ("OC_ENABLE_CMD_UPGRADE_RECOMMEND" , "true" ).EnvVar ("OC_ENABLE_CMD_UPGRADE_RECOMMEND_PRECHECK" , "true" ).EnvVar ("OC_ENABLE_CMD_UPGRADE_RECOMMEND_ACCEPT" , "true" ).Output ()
225+ if alertsByCVO {
226+ g .Skip ("Skip temporarily until the implementation lands" )
227+ // TODO: define the new pattern for the implementation
228+ }
219229 o .Expect (err ).NotTo (o .HaveOccurred ())
220230 err = matchRegexp (out , `The following conditions found no cause for concern in updating this cluster to later releases.*
221231
@@ -243,7 +253,11 @@ Updates to 4[.][0-9]*:
243253 o .Expect (oc .Run ("config" , "set-context" ).Args ("--current" , "--user" , "test" ).Execute ()).To (o .Succeed ())
244254
245255 out , err := oc .Run ("--certificate-authority" , caBundleFilePath , "adm" , "upgrade" , "recommend" , "--version" , fmt .Sprintf ("4.%d.0" , currentVersion .Minor + 1 ), "--accept" , "ConditionalUpdateRisk,Failing" ).EnvVar ("OC_ENABLE_CMD_UPGRADE_RECOMMEND" , "true" ).EnvVar ("OC_ENABLE_CMD_UPGRADE_RECOMMEND_PRECHECK" , "true" ).EnvVar ("OC_ENABLE_CMD_UPGRADE_RECOMMEND_ACCEPT" , "true" ).Output ()
246-
256+ if alertsByCVO {
257+ g .Skip ("Skip temporarily until the implementation lands" )
258+ // TODO: expect an error to occur
259+ // the error directs the user to use `oc adm upgrade accept command`.
260+ }
247261 o .Expect (err ).NotTo (o .HaveOccurred ())
248262 err = matchRegexp (out , `The following conditions found no cause for concern in updating this cluster to later releases.*
249263
@@ -262,6 +276,30 @@ Update to 4[.][0-9]*[.]0 has no known issues relevant to this cluster other than
262276 })
263277})
264278
279+ // alertsEvaluatedByCVO returns true if features.FeatureGateClusterUpdateAcceptRisks is enabled, and it is not a hosted cluster
280+ // ref. https://github.com/openshift/cluster-version-operator/blob/97a5bd23f73a649f1ca8d0364eca57318f3ed274/pkg/cvo/cvo.go#L1235
281+ func alertsEvaluatedByCVO (ctx context.Context , cv * configv1.ClusterVersion , isHyperShift bool , client configv1client.Interface ) (bool , error ) {
282+ if isHyperShift {
283+ return false , nil
284+ }
285+ featureGate , err := client .ConfigV1 ().FeatureGates ().Get (ctx , "cluster" , metav1.GetOptions {})
286+ if err != nil {
287+ return false , err
288+ }
289+
290+ for _ , fg := range featureGate .Status .FeatureGates {
291+ if fg .Version == cv .Status .Desired .Version {
292+ for _ , enabledGate := range fg .Enabled {
293+ if enabledGate .Name == features .FeatureGateClusterUpdateAcceptRisks {
294+ return true , nil
295+ }
296+ }
297+ }
298+ }
299+
300+ return false , nil
301+ }
302+
265303func runUpdateService (ctx context.Context , oc * exutil.CLI , graph string ) (* url.URL , error ) {
266304 deployment , err := oc .AdminKubeClient ().AppsV1 ().Deployments (oc .Namespace ()).Create (ctx ,
267305 & appsv1.Deployment {
0 commit comments