github.com/redhat-appstudio/e2e-tests@v0.0.0-20240520140907-9709f6f59323/tests/release/service/release_plan_and_admission_matched.go (about) 1 package service 2 3 import ( 4 "fmt" 5 6 tektonutils "github.com/redhat-appstudio/release-service/tekton/utils" 7 "k8s.io/apimachinery/pkg/api/meta" 8 9 . "github.com/onsi/ginkgo/v2" 10 . "github.com/onsi/gomega" 11 "github.com/redhat-appstudio/e2e-tests/pkg/framework" 12 "github.com/redhat-appstudio/e2e-tests/pkg/utils" 13 releasecommon "github.com/redhat-appstudio/e2e-tests/tests/release" 14 releaseApi "github.com/redhat-appstudio/release-service/api/v1alpha1" 15 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 16 ) 17 18 var _ = framework.ReleaseServiceSuiteDescribe("ReleasePlan and ReleasePlanAdmission match", Label("release-service", "release_plan_and_admission", "HACBS"), func() { 19 defer GinkgoRecover() 20 21 var fw *framework.Framework 22 var err error 23 var devNamespace string 24 var managedNamespace = utils.GetGeneratedNamespace("plan-and-admission-managed") 25 26 var releasePlanCR, secondReleasePlanCR *releaseApi.ReleasePlan 27 var releasePlanAdmissionCR *releaseApi.ReleasePlanAdmission 28 AfterEach(framework.ReportFailure(&fw)) 29 30 BeforeAll(func() { 31 // Initialize the tests controllers 32 fw, err = framework.NewFramework(utils.GetGeneratedNamespace("rel-plan-admis")) 33 Expect(err).NotTo(HaveOccurred()) 34 devNamespace = fw.UserNamespace 35 36 _, err = fw.AsKubeAdmin.CommonController.CreateTestNamespace(managedNamespace) 37 Expect(err).NotTo(HaveOccurred(), "Error when creating managedNamespace: %v", err) 38 39 _, err = fw.AsKubeAdmin.HasController.CreateApplication(releasecommon.ApplicationNameDefault, devNamespace) 40 Expect(err).NotTo(HaveOccurred()) 41 42 //Create ReleasePlan 43 _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(releasecommon.SourceReleasePlanName, devNamespace, releasecommon.ApplicationNameDefault, managedNamespace, "true", nil) 44 Expect(err).NotTo(HaveOccurred()) 45 }) 46 47 AfterAll(func() { 48 if !CurrentSpecReport().Failed() { 49 Expect(fw.AsKubeAdmin.CommonController.DeleteNamespace(managedNamespace)).NotTo(HaveOccurred()) 50 Expect(fw.SandboxController.DeleteUserSignup(fw.UserName)).To(BeTrue()) 51 } 52 }) 53 54 var _ = Describe("RP and PRA status change verification", func() { 55 It("verifies that the ReleasePlan CR is unmatched in the beginning", func() { 56 var condition *metav1.Condition 57 Eventually(func() error { 58 releasePlanCR, err = fw.AsKubeAdmin.ReleaseController.GetReleasePlan(releasecommon.SourceReleasePlanName, devNamespace) 59 Expect(err).NotTo(HaveOccurred()) 60 condition = meta.FindStatusCondition(releasePlanCR.Status.Conditions, releaseApi.MatchedConditionType.String()) 61 if condition == nil { 62 return fmt.Errorf("the MatchedConditon of %s is still not set", releasePlanCR.Name) 63 } 64 return nil 65 }, releasecommon.ReleasePlanStatusUpdateTimeout, releasecommon.DefaultInterval).Should(Succeed()) 66 condition = meta.FindStatusCondition(releasePlanCR.Status.Conditions, releaseApi.MatchedConditionType.String()) 67 Expect(condition.Status).To(Equal(metav1.ConditionFalse)) 68 }) 69 70 It("Creates ReleasePlanAdmission CR in corresponding managed namespace", func() { 71 _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlanAdmission(releasecommon.TargetReleasePlanAdmissionName, managedNamespace, "", devNamespace, releasecommon.ReleaseStrategyPolicyDefault, releasecommon.ReleasePipelineServiceAccountDefault, []string{releasecommon.ApplicationNameDefault}, true, &tektonutils.PipelineRef{ 72 Resolver: "git", 73 Params: []tektonutils.Param{ 74 {Name: "url", Value: releasecommon.RelSvcCatalogURL}, 75 {Name: "revision", Value: releasecommon.RelSvcCatalogRevision}, 76 {Name: "pathInRepo", Value: "pipelines/e2e/e2e.yaml"}, 77 }, 78 }, nil) 79 Expect(err).NotTo(HaveOccurred()) 80 }) 81 82 When("ReleasePlanAdmission CR is created in managed namespace", func() { 83 It("verifies that the ReleasePlan CR is set to matched", func() { 84 var condition *metav1.Condition 85 Eventually(func() error { 86 releasePlanCR, err = fw.AsKubeAdmin.ReleaseController.GetReleasePlan(releasecommon.SourceReleasePlanName, devNamespace) 87 Expect(err).NotTo(HaveOccurred()) 88 condition = meta.FindStatusCondition(releasePlanCR.Status.Conditions, releaseApi.MatchedConditionType.String()) 89 if condition == nil { 90 return fmt.Errorf("the MatchedConditon of %s is still not set", releasePlanCR.Name) 91 } 92 // it may need a period of time for the ReleasePlanCR to be reconciled 93 if condition.Status == metav1.ConditionFalse { 94 return fmt.Errorf("the MatchedConditon of %s has not reconciled yet", releasePlanCR.Name) 95 } 96 return nil 97 }, releasecommon.ReleasePlanStatusUpdateTimeout, releasecommon.DefaultInterval).Should(Succeed()) 98 Expect(condition.Status).To(Equal(metav1.ConditionTrue)) 99 Expect(releasePlanCR.Status.ReleasePlanAdmission.Name).To(Equal(managedNamespace + "/" + releasecommon.TargetReleasePlanAdmissionName)) 100 Expect(releasePlanCR.Status.ReleasePlanAdmission.Active).To(BeTrue()) 101 }) 102 103 It("verifies that the ReleasePlanAdmission CR is set to matched", func() { 104 var condition *metav1.Condition 105 Eventually(func() error { 106 releasePlanAdmissionCR, err = fw.AsKubeAdmin.ReleaseController.GetReleasePlanAdmission(releasecommon.TargetReleasePlanAdmissionName, managedNamespace) 107 Expect(err).NotTo(HaveOccurred()) 108 condition = meta.FindStatusCondition(releasePlanAdmissionCR.Status.Conditions, releaseApi.MatchedConditionType.String()) 109 if condition.Status == metav1.ConditionFalse { 110 return fmt.Errorf("the MatchedConditon of %s has not reconciled yet", releasePlanCR.Name) 111 } 112 return nil 113 }, releasecommon.ReleasePlanStatusUpdateTimeout, releasecommon.DefaultInterval).Should(Succeed(), "time out when waiting for ReleasePlanAdmission being reconciled to matched") 114 Expect(condition).NotTo(BeNil()) 115 Expect(condition.Status).To(Equal(metav1.ConditionTrue)) 116 Expect(releasePlanAdmissionCR.Status.ReleasePlans).To(HaveLen(1)) 117 Expect(releasePlanAdmissionCR.Status.ReleasePlans).To(Equal([]releaseApi.MatchedReleasePlan{{Name: devNamespace + "/" + releasecommon.SourceReleasePlanName, Active: true}})) 118 }) 119 }) 120 121 It("Creates a manual release ReleasePlan CR in devNamespace", func() { 122 _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(releasecommon.SecondReleasePlanName, devNamespace, releasecommon.ApplicationNameDefault, managedNamespace, "false", nil) 123 Expect(err).NotTo(HaveOccurred()) 124 }) 125 126 When("the second ReleasePlan CR is created", func() { 127 It("verifies that the second ReleasePlan CR is set to matched", func() { 128 var condition *metav1.Condition 129 Eventually(func() error { 130 secondReleasePlanCR, err = fw.AsKubeAdmin.ReleaseController.GetReleasePlan(releasecommon.SecondReleasePlanName, devNamespace) 131 Expect(err).NotTo(HaveOccurred()) 132 condition = meta.FindStatusCondition(secondReleasePlanCR.Status.Conditions, releaseApi.MatchedConditionType.String()) 133 134 if condition == nil { 135 return fmt.Errorf("the MatchedConditon of %s is still not set", secondReleasePlanCR.Name) 136 } 137 // it may need a period of time for the secondReleasePlanCR to be reconciled 138 if condition.Status == metav1.ConditionFalse { 139 return fmt.Errorf("the MatchedConditon of %s has not reconciled yet", secondReleasePlanCR.Name) 140 } 141 return nil 142 }, releasecommon.ReleasePlanStatusUpdateTimeout, releasecommon.DefaultInterval).Should(Succeed()) 143 Expect(condition.Status).To(Equal(metav1.ConditionTrue)) 144 Expect(secondReleasePlanCR.Status.ReleasePlanAdmission.Name).To(Equal(managedNamespace + "/" + releasecommon.TargetReleasePlanAdmissionName)) 145 Expect(secondReleasePlanCR.Status.ReleasePlanAdmission.Active).To(BeTrue()) 146 }) 147 148 It("verifies that the ReleasePlanAdmission CR has two matched ReleasePlan CRs", func() { 149 Eventually(func() error { 150 releasePlanAdmissionCR, err = fw.AsKubeAdmin.ReleaseController.GetReleasePlanAdmission(releasecommon.TargetReleasePlanAdmissionName, managedNamespace) 151 Expect(err).NotTo(HaveOccurred()) 152 condition := meta.FindStatusCondition(releasePlanAdmissionCR.Status.Conditions, releaseApi.MatchedConditionType.String()) 153 if condition == nil { 154 return fmt.Errorf("failed to get the MatchedConditon of RPA %s ", releasePlanAdmissionCR.Name) 155 } 156 157 if len(releasePlanAdmissionCR.Status.ReleasePlans) < 2 { 158 return fmt.Errorf("the second ReleasePlan CR has not being added to %s", releasePlanAdmissionCR.Name) 159 } 160 Expect(condition).NotTo(BeNil()) 161 Expect(condition.Status).To(Equal(metav1.ConditionTrue)) 162 return nil 163 }, releasecommon.ReleasePlanStatusUpdateTimeout, releasecommon.DefaultInterval).Should(Succeed(), fmt.Sprintf("time out when waiting for ReleasePlanAdmission %s being reconciled to matched", releasePlanAdmissionCR.Name)) 164 Expect(releasePlanAdmissionCR.Status.ReleasePlans).To(HaveLen(2)) 165 Expect(releasePlanAdmissionCR.Status.ReleasePlans).To(Equal([]releaseApi.MatchedReleasePlan{{Name: devNamespace + "/" + releasecommon.SourceReleasePlanName, Active: true}, {Name: devNamespace + "/" + releasecommon.SecondReleasePlanName, Active: false}})) 166 }) 167 }) 168 169 It("deletes one ReleasePlan CR", func() { 170 err = fw.AsKubeAdmin.ReleaseController.DeleteReleasePlan(releasecommon.SourceReleasePlanName, devNamespace, true) 171 Expect(err).NotTo(HaveOccurred()) 172 }) 173 174 When("One ReleasePlan CR is deleted in managed namespace", func() { 175 It("verifies that the ReleasePlanAdmission CR has only one matching ReleasePlan", func() { 176 Eventually(func() error { 177 releasePlanAdmissionCR, err = fw.AsKubeAdmin.ReleaseController.GetReleasePlanAdmission(releasecommon.TargetReleasePlanAdmissionName, managedNamespace) 178 Expect(err).NotTo(HaveOccurred()) 179 condition := meta.FindStatusCondition(releasePlanAdmissionCR.Status.Conditions, releaseApi.MatchedConditionType.String()) 180 if condition == nil { 181 return fmt.Errorf("failed to find the MatchedConditon of %s", releasePlanAdmissionCR.Name) 182 } 183 184 if len(releasePlanAdmissionCR.Status.ReleasePlans) > 1 { 185 return fmt.Errorf("ReleasePlan CR is deleted, but ReleasePlanAdmission CR %s has not been reconciled", releasePlanAdmissionCR.Name) 186 } 187 Expect(condition).NotTo(BeNil()) 188 Expect(condition.Status).To(Equal(metav1.ConditionTrue)) 189 return nil 190 }, releasecommon.ReleasePlanStatusUpdateTimeout, releasecommon.DefaultInterval).Should(Succeed(), fmt.Sprintf("time out when waiting for ReleasePlanAdmission %s being reconciled after one ReleasePlan is deleted", releasePlanAdmissionCR.Name)) 191 Expect(releasePlanAdmissionCR.Status.ReleasePlans).To(HaveLen(1)) 192 Expect(releasePlanAdmissionCR.Status.ReleasePlans).To(Equal([]releaseApi.MatchedReleasePlan{{Name: devNamespace + "/" + releasecommon.SecondReleasePlanName, Active: false}})) 193 }) 194 }) 195 196 It("deletes the ReleasePlanAdmission CR", func() { 197 err = fw.AsKubeAdmin.ReleaseController.DeleteReleasePlanAdmission(releasecommon.TargetReleasePlanAdmissionName, managedNamespace, true) 198 Expect(err).NotTo(HaveOccurred()) 199 }) 200 201 When("ReleasePlanAdmission CR is deleted in managed namespace", func() { 202 It("verifies that the ReleasePlan CR has no matched ReleasePlanAdmission", func() { 203 Eventually(func() error { 204 secondReleasePlanCR, err = fw.AsKubeAdmin.ReleaseController.GetReleasePlan(releasecommon.SecondReleasePlanName, devNamespace) 205 Expect(err).NotTo(HaveOccurred()) 206 condition := meta.FindStatusCondition(secondReleasePlanCR.Status.Conditions, releaseApi.MatchedConditionType.String()) 207 if condition == nil { 208 return fmt.Errorf("failed to get the MatchedConditon of %s", secondReleasePlanCR.Name) 209 } 210 211 // it may need a period of time for the secondReleasePlanCR to be reconciled 212 if condition.Status == metav1.ConditionTrue { 213 return fmt.Errorf("the MatchedConditon of %s has not reconciled yet", secondReleasePlanCR.Name) 214 } 215 return nil 216 }, releasecommon.ReleasePlanStatusUpdateTimeout, releasecommon.DefaultInterval).Should(Succeed()) 217 Expect(secondReleasePlanCR.Status.ReleasePlanAdmission).To(Equal(releaseApi.MatchedReleasePlanAdmission{})) 218 }) 219 }) 220 }) 221 })