@@ -15,17 +15,26 @@ import (
1515 "sigs.k8s.io/controller-runtime/pkg/client"
1616)
1717
18- var _ = Describe ("Application health deployment controller " , func () {
18+ var _ = Describe ("Deployment status on health status changed " , func () {
1919 var app argocdv1alpha1.Application
20+ var deploymentStatus githubmock.DeploymentStatus
2021
2122 BeforeEach (func (ctx context.Context ) {
23+ By ("Setting up a deployment status endpoint" )
24+ deploymentStatus = githubmock.DeploymentStatus {}
25+ githubServer .AddHandlers (map [string ]http.Handler {
26+ "GET /api/v3/repos/test/health-deployment/deployments/101/statuses" : deploymentStatus .ListEndpoint (),
27+ "POST /api/v3/repos/test/health-deployment/deployments/101/statuses" : deploymentStatus .CreateEndpoint (),
28+ })
29+
30+ By ("Creating an application" )
2231 app = argocdv1alpha1.Application {
2332 TypeMeta : metav1.TypeMeta {
2433 APIVersion : "argoproj.io/v1alpha1" ,
2534 Kind : "Application" ,
2635 },
2736 ObjectMeta : metav1.ObjectMeta {
28- GenerateName : "fixture-" ,
37+ GenerateName : "fixture-deployment-status-health- " ,
2938 Namespace : "default" ,
3039 },
3140 Spec : argocdv1alpha1.ApplicationSpec {
@@ -43,6 +52,7 @@ var _ = Describe("Application health deployment controller", func() {
4352 }
4453 Expect (k8sClient .Create (ctx , & app )).Should (Succeed ())
4554
55+ By ("Updating the application to progressing" )
4656 app .Status = argocdv1alpha1.ApplicationStatus {
4757 Health : argocdv1alpha1.HealthStatus {
4858 Status : health .HealthStatusProgressing ,
@@ -61,12 +71,6 @@ var _ = Describe("Application health deployment controller", func() {
6171
6272 Context ("When an application is healthy" , func () {
6373 It ("Should notify a deployment status once" , func (ctx context.Context ) {
64- var deploymentStatus githubmock.DeploymentStatus
65- githubServer .AddHandlers (map [string ]http.Handler {
66- "GET /api/v3/repos/test/health-deployment/deployments/101/statuses" : deploymentStatus .ListEndpoint (),
67- "POST /api/v3/repos/test/health-deployment/deployments/101/statuses" : deploymentStatus .CreateEndpoint (),
68- })
69-
7074 By ("Updating the deployment annotation" )
7175 app .Annotations = map [string ]string {
7276 "argocd-commenter.int128.github.io/deployment-url" : "https://api.github.com/repos/test/health-deployment/deployments/101" ,
@@ -96,12 +100,6 @@ var _ = Describe("Application health deployment controller", func() {
96100
97101 Context ("When the deployment annotation is updated and then the application becomes healthy" , func () {
98102 It ("Should notify a deployment status" , func (ctx context.Context ) {
99- var deploymentStatus githubmock.DeploymentStatus
100- githubServer .AddHandlers (map [string ]http.Handler {
101- "GET /api/v3/repos/test/health-deployment/deployments/102/statuses" : deploymentStatus .ListEndpoint (),
102- "POST /api/v3/repos/test/health-deployment/deployments/102/statuses" : deploymentStatus .CreateEndpoint (),
103- })
104-
105103 By ("Updating the deployment annotation" )
106104 app .Annotations = map [string ]string {
107105 "argocd-commenter.int128.github.io/deployment-url" : "https://api.github.com/repos/test/health-deployment/deployments/999" ,
@@ -114,7 +112,7 @@ var _ = Describe("Application health deployment controller", func() {
114112
115113 By ("Updating the deployment annotation" )
116114 app .Annotations = map [string ]string {
117- "argocd-commenter.int128.github.io/deployment-url" : "https://api.github.com/repos/test/health-deployment/deployments/102 " ,
115+ "argocd-commenter.int128.github.io/deployment-url" : "https://api.github.com/repos/test/health-deployment/deployments/101 " ,
118116 }
119117 Expect (k8sClient .Update (ctx , & app )).Should (Succeed ())
120118 Consistently (func () int { return deploymentStatus .CreateCount () }, "100ms" ).Should (BeZero ())
@@ -132,14 +130,6 @@ var _ = Describe("Application health deployment controller", func() {
132130
133131 Context ("When an application became healthy before the deployment annotation is updated" , func () {
134132 It ("Should notify a deployment status when the deployment annotation is valid" , func (ctx context.Context ) {
135- var deploymentStatusOld , deploymentStatusNew githubmock.DeploymentStatus
136- githubServer .AddHandlers (map [string ]http.Handler {
137- "GET /api/v3/repos/test/health-deployment/deployments/103/statuses" : deploymentStatusOld .ListEndpoint (),
138- "POST /api/v3/repos/test/health-deployment/deployments/103/statuses" : deploymentStatusOld .CreateEndpoint (),
139- "GET /api/v3/repos/test/health-deployment/deployments/104/statuses" : deploymentStatusNew .ListEndpoint (),
140- "POST /api/v3/repos/test/health-deployment/deployments/104/statuses" : deploymentStatusNew .CreateEndpoint (),
141- })
142-
143133 By ("Updating the deployment annotation" )
144134 app .Annotations = map [string ]string {
145135 "argocd-commenter.int128.github.io/deployment-url" : "https://api.github.com/repos/test/health-deployment/deployments/999" ,
@@ -149,17 +139,24 @@ var _ = Describe("Application health deployment controller", func() {
149139 By ("Updating the application to healthy" )
150140 app .Status .Health .Status = health .HealthStatusHealthy
151141 Expect (k8sClient .Update (ctx , & app )).Should (Succeed ())
152- Consistently (func () int { return deploymentStatusOld .CreateCount () }, "100ms" ).Should (BeZero ())
142+ Consistently (func () int { return deploymentStatus .CreateCount () }, "100ms" ).Should (BeZero ())
153143
154144 By ("Updating the deployment annotation" )
155145 app .Annotations = map [string ]string {
156- "argocd-commenter.int128.github.io/deployment-url" : "https://api.github.com/repos/test/health-deployment/deployments/103 " ,
146+ "argocd-commenter.int128.github.io/deployment-url" : "https://api.github.com/repos/test/health-deployment/deployments/101 " ,
157147 }
158148 Expect (k8sClient .Update (ctx , & app )).Should (Succeed ())
159- Eventually (func () int { return deploymentStatusOld .CreateCount () }).Should (Equal (1 ))
149+ Eventually (func () int { return deploymentStatus .CreateCount () }).Should (Equal (1 ))
160150
161151 By ("Deleting the old deployment" )
162- deploymentStatusOld .NotFound = true
152+ deploymentStatus .NotFound = true
153+
154+ By ("Setting up the new deployment status endpoint" )
155+ var newDeploymentStatus githubmock.DeploymentStatus
156+ githubServer .AddHandlers (map [string ]http.Handler {
157+ "GET /api/v3/repos/test/health-deployment/deployments/102/statuses" : newDeploymentStatus .ListEndpoint (),
158+ "POST /api/v3/repos/test/health-deployment/deployments/102/statuses" : newDeploymentStatus .CreateEndpoint (),
159+ })
163160
164161 By ("Updating the application to progressing" )
165162 app .Status .Health .Status = health .HealthStatusProgressing
@@ -168,15 +165,15 @@ var _ = Describe("Application health deployment controller", func() {
168165 By ("Updating the application to healthy" )
169166 app .Status .Health .Status = health .HealthStatusHealthy
170167 Expect (k8sClient .Update (ctx , & app )).Should (Succeed ())
171- Consistently (func () int { return deploymentStatusNew .CreateCount () }, "100ms" ).Should (BeZero ())
168+ Consistently (func () int { return newDeploymentStatus .CreateCount () }, "100ms" ).Should (BeZero ())
172169
173170 By ("Updating the deployment annotation" )
174171 app .Annotations = map [string ]string {
175- "argocd-commenter.int128.github.io/deployment-url" : "https://api.github.com/repos/test/health-deployment/deployments/104 " ,
172+ "argocd-commenter.int128.github.io/deployment-url" : "https://api.github.com/repos/test/health-deployment/deployments/102 " ,
176173 }
177174 Expect (k8sClient .Update (ctx , & app )).Should (Succeed ())
178- Eventually (func () int { return deploymentStatusNew .CreateCount () }).Should (Equal (1 ))
179- Expect (deploymentStatusOld .CreateCount ()).Should (Equal (1 ))
175+ Eventually (func () int { return newDeploymentStatus .CreateCount () }).Should (Equal (1 ))
176+ Expect (deploymentStatus .CreateCount ()).Should (Equal (1 ))
180177 }, SpecTimeout (3 * time .Second ))
181178
182179 It ("Should retry a deployment status until timeout" , func (ctx context.Context ) {
0 commit comments