Skip to content

Commit a4b7547

Browse files
committed
Add a serial e2e for accept-risks
1 parent bdd3553 commit a4b7547

5 files changed

Lines changed: 161 additions & 2 deletions

File tree

.openshift-tests-extension/openshift_payload_cluster-version-operator.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
[
2+
{
3+
"name": "[Jira:\"Cluster Version Operator\"] cluster-version-operator should work with accept risks [Serial]",
4+
"labels": {},
5+
"resources": {
6+
"isolation": {}
7+
},
8+
"source": "openshift:payload:cluster-version-operator",
9+
"lifecycle": "blocking",
10+
"environmentSelector": {}
11+
},
212
{
313
"name": "[Jira:\"Cluster Version Operator\"] cluster-version-operator-tests should support passing tests",
414
"labels": {},

test/cvo/accept_risks.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package cvo
2+
3+
import (
4+
"context"
5+
"time"
6+
7+
g "github.com/onsi/ginkgo/v2"
8+
o "github.com/onsi/gomega"
9+
10+
configv1 "github.com/openshift/api/config/v1"
11+
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
12+
"k8s.io/apimachinery/pkg/api/meta"
13+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14+
"k8s.io/apimachinery/pkg/util/wait"
15+
"k8s.io/client-go/rest"
16+
17+
"github.com/openshift/cluster-version-operator/test/util"
18+
)
19+
20+
var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator`, func() {
21+
22+
var (
23+
c *rest.Config
24+
configClient *configv1client.ConfigV1Client
25+
err error
26+
27+
ctx = context.TODO()
28+
backup configv1.ClusterVersionSpec
29+
)
30+
31+
g.BeforeEach(func() {
32+
c, err = util.GetRestConfig()
33+
o.Expect(err).To(o.BeNil())
34+
configClient, err = configv1client.NewForConfig(c)
35+
o.Expect(err).To(o.BeNil())
36+
37+
util.SkipIfNotTechPreviewNoUpgrade(ctx, c)
38+
o.Expect(util.SkipIfHypershift(ctx, c)).To(o.BeNil())
39+
o.Expect(util.SkipIfMicroshift(ctx, c)).To(o.BeNil())
40+
41+
cv, err := configClient.ClusterVersions().Get(ctx, "version", metav1.GetOptions{})
42+
backup = *cv.Spec.DeepCopy()
43+
o.Expect(err).NotTo(o.HaveOccurred())
44+
})
45+
46+
g.AfterEach(func() {
47+
cv, err := configClient.ClusterVersions().Get(ctx, "version", metav1.GetOptions{})
48+
o.Expect(err).NotTo(o.HaveOccurred())
49+
cv.Spec = backup
50+
_, err = configClient.ClusterVersions().Update(ctx, cv, metav1.UpdateOptions{})
51+
o.Expect(err).NotTo(o.HaveOccurred())
52+
})
53+
54+
g.It("should work with accept risks [Serial]", func() {
55+
cv, err := configClient.ClusterVersions().Get(ctx, "version", metav1.GetOptions{})
56+
o.Expect(err).NotTo(o.HaveOccurred())
57+
58+
g.By("Using fauxinnati as the upstream and its risks-always channel")
59+
cv.Spec.Upstream = util.FauxinnatiAPIURL
60+
cv.Spec.Channel = "risks-always"
61+
62+
_, err = configClient.ClusterVersions().Update(ctx, cv, metav1.UpdateOptions{})
63+
o.Expect(err).NotTo(o.HaveOccurred())
64+
65+
g.By("Checking that conditional updates shows up in status")
66+
// waiting for the conditional updates to show up
67+
o.Expect(wait.PollUntilContextTimeout(ctx, 30*time.Second, 5*time.Minute, true, func(ctx context.Context) (done bool, err error) {
68+
cv, err = configClient.ClusterVersions().Get(ctx, "version", metav1.GetOptions{})
69+
o.Expect(err).NotTo(o.HaveOccurred())
70+
if len(cv.Status.ConditionalUpdates) == 0 {
71+
return false, nil
72+
}
73+
return true, nil
74+
})).NotTo(o.HaveOccurred(), "no conditional updates found in status")
75+
76+
g.By("Checking that no conditional updates are recommended")
77+
var acceptRisks []configv1.AcceptRisk
78+
for _, cu := range cv.Status.ConditionalUpdates {
79+
o.Expect(cu.RiskNames).NotTo(o.BeEmpty())
80+
for _, name := range cu.RiskNames {
81+
acceptRisks = append(acceptRisks, configv1.AcceptRisk{Name: name})
82+
}
83+
o.Expect(cu.Risks).NotTo(o.BeEmpty())
84+
recommendedCondition := meta.FindStatusCondition(cu.Conditions, conditionalUpdateConditionTypeRecommended)
85+
o.Expect(recommendedCondition).NotTo(o.BeNil())
86+
o.Expect(recommendedCondition.Status).To(o.Equal(metav1.ConditionFalse))
87+
}
88+
89+
g.By("Accepting all risks")
90+
if cv.Spec.DesiredUpdate == nil {
91+
cv.Spec.DesiredUpdate = &configv1.Update{
92+
Image: cv.Status.Desired.Image,
93+
Version: cv.Status.Desired.Version,
94+
Architecture: cv.Status.Desired.Architecture,
95+
}
96+
}
97+
cv.Spec.DesiredUpdate.AcceptRisks = acceptRisks
98+
99+
_, err = configClient.ClusterVersions().Update(ctx, cv, metav1.UpdateOptions{})
100+
o.Expect(err).NotTo(o.HaveOccurred())
101+
102+
g.By("Checking that all conditional updates are recommended")
103+
// waiting for the conditional updates to show up
104+
o.Expect(wait.PollUntilContextTimeout(ctx, 30*time.Second, 5*time.Minute, true, func(ctx context.Context) (done bool, err error) {
105+
cv, err = configClient.ClusterVersions().Get(ctx, "version", metav1.GetOptions{})
106+
o.Expect(err).NotTo(o.HaveOccurred())
107+
o.Expect(cv.Status.ConditionalUpdates).NotTo(o.BeEmpty())
108+
for _, cu := range cv.Status.ConditionalUpdates {
109+
recommendedCondition := meta.FindStatusCondition(cu.Conditions, conditionalUpdateConditionTypeRecommended)
110+
o.Expect(recommendedCondition).NotTo(o.BeNil())
111+
if recommendedCondition.Status != metav1.ConditionTrue {
112+
return false, nil
113+
}
114+
}
115+
return true, nil
116+
})).NotTo(o.HaveOccurred(), "no conditional updates are recommended in status after accepting risks")
117+
})
118+
})

test/cvo/constants.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package cvo
2+
3+
// Those constants are defined in the core CVO code already
4+
// For some reason (mostly technical debts) they are re-defined here for e2e tests
5+
const (
6+
cvoNamespace = "openshift-cluster-version"
7+
conditionalUpdateConditionTypeRecommended = "Recommended"
8+
)

test/cvo/cvo.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717

1818
var logger = g.GinkgoLogr.WithName("cluster-version-operator-tests")
1919

20-
const cvoNamespace = "openshift-cluster-version"
21-
2220
var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator-tests`, func() {
2321
g.It("should support passing tests", func() {
2422
o.Expect(true).To(o.BeTrue())

test/util/util.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"time"
66

77
g "github.com/onsi/ginkgo/v2"
8+
o "github.com/onsi/gomega"
9+
810
configv1 "github.com/openshift/api/config/v1"
911
clientconfigv1 "github.com/openshift/client-go/config/clientset/versioned"
1012
corev1 "k8s.io/api/core/v1"
@@ -106,3 +108,26 @@ func GetKubeClient(restConfig *rest.Config) (kubernetes.Interface, error) {
106108
func GetConfigClient(restConfig *rest.Config) (clientconfigv1.Interface, error) {
107109
return clientconfigv1.NewForConfig(restConfig)
108110
}
111+
112+
// IsTechPreviewNoUpgrade checks if a cluster is a TechPreviewNoUpgrade cluster
113+
func IsTechPreviewNoUpgrade(ctx context.Context, restConfig *rest.Config) bool {
114+
configClient, err := GetConfigClient(restConfig)
115+
o.Expect(err).NotTo(o.HaveOccurred())
116+
featureGate, err := configClient.ConfigV1().FeatureGates().Get(ctx, "cluster", metav1.GetOptions{})
117+
if err != nil {
118+
if apierrors.IsNotFound(err) {
119+
return false
120+
}
121+
o.Expect(err).NotTo(o.HaveOccurred(), "could not retrieve feature-gate: %v", err)
122+
}
123+
return featureGate.Spec.FeatureSet == configv1.TechPreviewNoUpgrade
124+
}
125+
126+
// SkipIfNotTechPreviewNoUpgrade skips the test if a cluster is not a TechPreviewNoUpgrade cluster
127+
func SkipIfNotTechPreviewNoUpgrade(ctx context.Context, restConfig *rest.Config) {
128+
if !IsTechPreviewNoUpgrade(ctx, restConfig) {
129+
g.Skip("This test is skipped because the Tech Preview NoUpgrade is not enabled")
130+
}
131+
}
132+
133+
const FauxinnatiAPIURL = "https://fauxinnati-fauxinnati.apps.ota-stage.q2z4.p1.openshiftapps.com/api/upgrades_info/graph"

0 commit comments

Comments
 (0)