|
| 1 | +package cvo |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + configv1 "github.com/openshift/api/config/v1" |
| 6 | + "slices" |
| 7 | + |
| 8 | + g "github.com/onsi/ginkgo/v2" |
| 9 | + o "github.com/onsi/gomega" |
| 10 | + |
| 11 | + configclientv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1" |
| 12 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 13 | + "k8s.io/client-go/kubernetes" |
| 14 | + "k8s.io/client-go/rest" |
| 15 | + |
| 16 | + "github.com/openshift/cluster-version-operator/test/util" |
| 17 | +) |
| 18 | + |
| 19 | +var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator works well on accept risks.`, func() { |
| 20 | + |
| 21 | + var ( |
| 22 | + c *rest.Config |
| 23 | + kubeClient kubernetes.Interface |
| 24 | + configv1Client *configclientv1.ConfigV1Client |
| 25 | + err error |
| 26 | + |
| 27 | + isTechPreviewNoUpgrade bool |
| 28 | + isHypershift bool |
| 29 | + isMicroShiftCluster bool |
| 30 | + ) |
| 31 | + |
| 32 | + g.BeforeEach(func() { |
| 33 | + c, err = util.LoadRestConfig() |
| 34 | + o.Expect(err).To(o.BeNil()) |
| 35 | + kubeClient, err = kubernetes.NewForConfig(c) |
| 36 | + o.Expect(err).To(o.BeNil()) |
| 37 | + configv1Client, err = configclientv1.NewForConfig(c) |
| 38 | + o.Expect(err).To(o.BeNil()) |
| 39 | + isTechPreviewNoUpgrade = util.IsTechPreviewNoUpgrade(configv1Client) |
| 40 | + isHypershift, err = util.IsHypershift(configv1Client) |
| 41 | + o.Expect(err).To(o.BeNil()) |
| 42 | + isMicroShiftCluster, err = util.IsMicroShiftCluster(kubeClient, logger) |
| 43 | + o.Expect(err).To(o.BeNil()) |
| 44 | + |
| 45 | + if isHypershift { |
| 46 | + g.Skip("This test is skipped on a Hypershift cluster") |
| 47 | + } |
| 48 | + if isMicroShiftCluster { |
| 49 | + g.Skip("This test is skipped on a Microshift cluster") |
| 50 | + } |
| 51 | + if !isTechPreviewNoUpgrade { |
| 52 | + g.Skip("This test is skipped because the Tech Preview NoUpgrade is not enabled") |
| 53 | + } |
| 54 | + }) |
| 55 | + |
| 56 | + g.Describe("Cluster Version Operator", func() { |
| 57 | + g.It("can store accepted risks", func() { |
| 58 | + cv, err := configv1Client.ClusterVersions().Get(context.Background(), "cluster", metav1.GetOptions{}) |
| 59 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 60 | + |
| 61 | + bk := cv.Spec.DesiredUpdate |
| 62 | + if bk != nil { |
| 63 | + bk = bk.DeepCopy() |
| 64 | + } |
| 65 | + |
| 66 | + g.By("Checking that new risks can be saved") |
| 67 | + if cv.Spec.DesiredUpdate == nil { |
| 68 | + cv.Spec.DesiredUpdate = &configv1.Update{} |
| 69 | + } |
| 70 | + cv.Spec.DesiredUpdate.AcceptRisks = append(cv.Spec.DesiredUpdate.AcceptRisks, []configv1.AcceptRisk{ |
| 71 | + {Name: "riskA"}, |
| 72 | + {Name: "riskB"}, |
| 73 | + }...) |
| 74 | + |
| 75 | + cv, err = configv1Client.ClusterVersions().Update(context.Background(), cv, metav1.UpdateOptions{}) |
| 76 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 77 | + o.Expect(slices.Contains(cv.Spec.DesiredUpdate.AcceptRisks, configv1.AcceptRisk{Name: "riskA"})).To(o.BeTrue()) |
| 78 | + o.Expect(slices.Contains(cv.Spec.DesiredUpdate.AcceptRisks, configv1.AcceptRisk{Name: "riskB"})).To(o.BeTrue()) |
| 79 | + |
| 80 | + g.By("Checking that new risks can be removed") |
| 81 | + cv.Spec.DesiredUpdate = bk |
| 82 | + cv, err = configv1Client.ClusterVersions().Update(context.Background(), cv, metav1.UpdateOptions{}) |
| 83 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 84 | + o.Expect(slices.Contains(cv.Spec.DesiredUpdate.AcceptRisks, configv1.AcceptRisk{Name: "riskA"})).To(o.BeFalse()) |
| 85 | + o.Expect(slices.Contains(cv.Spec.DesiredUpdate.AcceptRisks, configv1.AcceptRisk{Name: "riskB"})).To(o.BeFalse()) |
| 86 | + }) |
| 87 | + |
| 88 | + g.It("should populate the fields about risks in status", func() { |
| 89 | + cv, err := configv1Client.ClusterVersions().Get(context.Background(), "cluster", metav1.GetOptions{}) |
| 90 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 91 | + |
| 92 | + g.By("Checking that each condition update has risk names") |
| 93 | + for _, cu := range cv.Status.ConditionalUpdates { |
| 94 | + o.Expect(cu.RiskNames).ShouldNot(o.BeEmpty(), "RiskNames should not be empty") |
| 95 | + } |
| 96 | + }) |
| 97 | + }) |
| 98 | +}) |
0 commit comments