|
| 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/sets" |
| 15 | + "k8s.io/apimachinery/pkg/util/wait" |
| 16 | + "k8s.io/client-go/rest" |
| 17 | + |
| 18 | + "github.com/openshift/cluster-version-operator/pkg/external" |
| 19 | + "github.com/openshift/cluster-version-operator/test/util" |
| 20 | +) |
| 21 | + |
| 22 | +var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator`, func() { |
| 23 | + |
| 24 | + var ( |
| 25 | + c *rest.Config |
| 26 | + configClient *configv1client.ConfigV1Client |
| 27 | + err error |
| 28 | + |
| 29 | + ctx = context.TODO() |
| 30 | + backup configv1.ClusterVersionSpec |
| 31 | + ) |
| 32 | + |
| 33 | + g.BeforeEach(func() { |
| 34 | + c, err = util.GetRestConfig() |
| 35 | + o.Expect(err).To(o.BeNil()) |
| 36 | + configClient, err = configv1client.NewForConfig(c) |
| 37 | + o.Expect(err).To(o.BeNil()) |
| 38 | + |
| 39 | + util.SkipIfNotTechPreviewNoUpgrade(ctx, c) |
| 40 | + o.Expect(util.SkipIfHypershift(ctx, c)).To(o.BeNil()) |
| 41 | + o.Expect(util.SkipIfMicroshift(ctx, c)).To(o.BeNil()) |
| 42 | + |
| 43 | + cv, err := configClient.ClusterVersions().Get(ctx, external.DefaultClusterVersionName, metav1.GetOptions{}) |
| 44 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 45 | + if du := cv.Spec.DesiredUpdate; du != nil { |
| 46 | + logger.WithValues("AcceptRisks", du.AcceptRisks).Info("Accept risks before testing") |
| 47 | + o.Expect(du.AcceptRisks).To(o.BeEmpty(), "found accept risks") |
| 48 | + } |
| 49 | + backup = *cv.Spec.DeepCopy() |
| 50 | + }) |
| 51 | + |
| 52 | + g.AfterEach(func() { |
| 53 | + cv, err := configClient.ClusterVersions().Get(ctx, external.DefaultClusterVersionName, metav1.GetOptions{}) |
| 54 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 55 | + cv.Spec = backup |
| 56 | + _, err = configClient.ClusterVersions().Update(ctx, cv, metav1.UpdateOptions{}) |
| 57 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 58 | + }) |
| 59 | + |
| 60 | + g.It("should work with accept risks", g.Label("Serial"), func() { |
| 61 | + cv, err := configClient.ClusterVersions().Get(ctx, external.DefaultClusterVersionName, metav1.GetOptions{}) |
| 62 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 63 | + |
| 64 | + g.By("Using fauxinnati as the upstream and its risks-always channel") |
| 65 | + cv.Spec.Upstream = util.FauxinnatiAPIURL |
| 66 | + cv.Spec.Channel = "risks-always" |
| 67 | + |
| 68 | + _, err = configClient.ClusterVersions().Update(ctx, cv, metav1.UpdateOptions{}) |
| 69 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 70 | + |
| 71 | + g.By("Checking that conditional updates shows up in status") |
| 72 | + // waiting for the conditional updates to show up |
| 73 | + o.Expect(wait.PollUntilContextTimeout(ctx, 30*time.Second, 5*time.Minute, true, func(ctx context.Context) (done bool, err error) { |
| 74 | + cv, err = configClient.ClusterVersions().Get(ctx, external.DefaultClusterVersionName, metav1.GetOptions{}) |
| 75 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 76 | + if len(cv.Status.ConditionalUpdates) == 0 { |
| 77 | + return false, nil |
| 78 | + } |
| 79 | + return true, nil |
| 80 | + })).NotTo(o.HaveOccurred(), "no conditional updates found in status") |
| 81 | + |
| 82 | + g.By("Checking that no conditional updates are recommended") |
| 83 | + conditionalUpdatesLength := len(cv.Status.ConditionalUpdates) |
| 84 | + var acceptRisks []configv1.AcceptRisk |
| 85 | + var releases []configv1.Release |
| 86 | + names := sets.New[string]() |
| 87 | + for _, cu := range cv.Status.ConditionalUpdates { |
| 88 | + releases = append(releases, cu.Release) |
| 89 | + o.Expect(cu.RiskNames).NotTo(o.BeEmpty()) |
| 90 | + for _, name := range cu.RiskNames { |
| 91 | + if names.Has(name) { |
| 92 | + continue |
| 93 | + } |
| 94 | + names.Insert(name) |
| 95 | + acceptRisks = append(acceptRisks, configv1.AcceptRisk{Name: name}) |
| 96 | + } |
| 97 | + o.Expect(cu.Risks).NotTo(o.BeEmpty()) |
| 98 | + recommendedCondition := meta.FindStatusCondition(cu.Conditions, external.ConditionalUpdateConditionTypeRecommended) |
| 99 | + o.Expect(recommendedCondition).NotTo(o.BeNil()) |
| 100 | + o.Expect(recommendedCondition.Status).To(o.Equal(metav1.ConditionFalse)) |
| 101 | + } |
| 102 | + |
| 103 | + g.By("Accepting all risks") |
| 104 | + o.Expect(acceptRisks).NotTo(o.BeEmpty()) |
| 105 | + if cv.Spec.DesiredUpdate == nil { |
| 106 | + cv.Spec.DesiredUpdate = &configv1.Update{ |
| 107 | + Image: cv.Status.Desired.Image, |
| 108 | + Version: cv.Status.Desired.Version, |
| 109 | + Architecture: cv.Status.Desired.Architecture, |
| 110 | + } |
| 111 | + } |
| 112 | + cv.Spec.DesiredUpdate.AcceptRisks = acceptRisks |
| 113 | + |
| 114 | + _, err = configClient.ClusterVersions().Update(ctx, cv, metav1.UpdateOptions{}) |
| 115 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 116 | + |
| 117 | + g.By("Checking that all conditional updates are recommended") |
| 118 | + var releasesNow []configv1.Release |
| 119 | + // waiting for the conditional updates to be refreshed |
| 120 | + o.Expect(wait.PollUntilContextTimeout(ctx, 30*time.Second, 5*time.Minute, true, func(ctx context.Context) (done bool, err error) { |
| 121 | + cv, err = configClient.ClusterVersions().Get(ctx, external.DefaultClusterVersionName, metav1.GetOptions{}) |
| 122 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 123 | + o.Expect(cv.Status.ConditionalUpdates).NotTo(o.BeEmpty()) |
| 124 | + releasesNow = nil |
| 125 | + for _, cu := range cv.Status.ConditionalUpdates { |
| 126 | + releasesNow = append(releasesNow, cu.Release) |
| 127 | + recommendedCondition := meta.FindStatusCondition(cu.Conditions, external.ConditionalUpdateConditionTypeRecommended) |
| 128 | + o.Expect(recommendedCondition).NotTo(o.BeNil()) |
| 129 | + if recommendedCondition.Status != metav1.ConditionTrue { |
| 130 | + return false, nil |
| 131 | + } |
| 132 | + } |
| 133 | + return true, nil |
| 134 | + })).NotTo(o.HaveOccurred(), "no conditional updates are recommended in status after accepting risks") |
| 135 | + |
| 136 | + o.Expect(cv.Spec.DesiredUpdate.AcceptRisks).To(o.Equal(acceptRisks)) |
| 137 | + o.Expect(cv.Status.ConditionalUpdates).To(o.HaveLen(conditionalUpdatesLength)) |
| 138 | + o.Expect(releasesNow).To(o.Equal(releases)) |
| 139 | + }) |
| 140 | +}) |
0 commit comments