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