Skip to content

Commit b97be22

Browse files
author
Cristhian Castaneda
authored
feat(health-check): increase timeout and validate ready replicas for status. (#219) (#221)
* feat(health-check): increase timeout and validate ready replicas for status. * feat(health-check): fix unit tests. * fix(build): set up Go in github action. (cherry picked from commit 3d409c8)
1 parent ded0135 commit b97be22

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ jobs:
1616
- name: Fetch full history
1717
run: git fetch --prune --tags --unshallow
1818

19+
- name: Set up Go 1.13.15
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: 1.13.15
23+
1924
- name: Determine build type
2025
id: build_type
2126
run: |

pkg/controller/spinnakerservice/status.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func (s *statusChecker) checks(instance interfaces.SpinnakerService) error {
4646
}
4747

4848
var pods []v1.Pod
49+
var replicasReady []bool
4950

5051
for i := range deployments {
5152
deployment := deployments[i]
@@ -56,7 +57,7 @@ func (s *statusChecker) checks(instance interfaces.SpinnakerService) error {
5657
ReadyReplicas: deployment.Status.ReadyReplicas,
5758
Image: s.k8sLookup.GetSpinnakerServiceImageFromDeployment(deployment.Spec.Template.Spec),
5859
}
59-
60+
replicasReady = append(replicasReady, deployment.Status.Replicas == deployment.Status.ReadyReplicas)
6061
pd, err := s.k8sLookup.GetPodsByDeployment(instance, deployment)
6162
if err != nil {
6263
return err
@@ -69,6 +70,12 @@ func (s *statusChecker) checks(instance interfaces.SpinnakerService) error {
6970
if err != nil {
7071
return err
7172
}
73+
if spinsvcStatus == Updating {
74+
areReplicasReady := s.replicasReady(replicasReady)
75+
if areReplicasReady {
76+
spinsvcStatus = Ok
77+
}
78+
}
7279
status.Status = spinsvcStatus
7380
status.Services = svcs
7481
status.ServiceCount = len(status.Services)
@@ -82,6 +89,16 @@ func (s *statusChecker) checks(instance interfaces.SpinnakerService) error {
8289
return nil
8390
}
8491

92+
// getStatus check spinnaker status
93+
func (s *statusChecker) replicasReady(replicasReady []bool) bool {
94+
for _, v := range replicasReady {
95+
if !v {
96+
return false
97+
}
98+
}
99+
return true
100+
}
101+
85102
// getStatus check spinnaker status
86103
func (s *statusChecker) getStatus(instance interfaces.SpinnakerService, pods []v1.Pod) (string, error) {
87104
status := Ok

pkg/controller/spinnakerservice/status_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ func Test_statusChecker_checks(t *testing.T) {
101101
},
102102
},
103103
}},
104-
mockedDeployments: []appsv1.Deployment{{}},
104+
mockedDeployments: []appsv1.Deployment{{
105+
Status: appsv1.DeploymentStatus{
106+
Replicas: int32(1),
107+
ReadyReplicas: int32(0),
108+
},
109+
}},
105110
mockedExceededTime: false,
106111
},
107112
wantErr: false,
@@ -174,7 +179,12 @@ func Test_statusChecker_checks(t *testing.T) {
174179
},
175180
},
176181
},
177-
mockedDeployments: []appsv1.Deployment{{}},
182+
mockedDeployments: []appsv1.Deployment{{
183+
Status: appsv1.DeploymentStatus{
184+
Replicas: int32(1),
185+
ReadyReplicas: int32(0),
186+
},
187+
}},
178188
mockedExceededTime: false,
179189
},
180190
wantErr: false,

pkg/util/k8s_lookup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
//go:generate mockgen -destination=k8s_lookup_mocks.go -package util -source k8s_lookup.go
1414

15-
const MaxChecksWaitingForSpinnakerStability = 1
15+
const MaxChecksWaitingForSpinnakerStability = 2
1616

1717
type Ik8sLookup interface {
1818
GetSpinnakerDeployments(instance interfaces.SpinnakerService) ([]appsv1.Deployment, error)

0 commit comments

Comments
 (0)