@@ -10,6 +10,7 @@ import (
10
10
. "github.com/onsi/gomega"
11
11
appsv1 "k8s.io/api/apps/v1"
12
12
batchv1 "k8s.io/api/batch/v1"
13
+ v1 "k8s.io/api/core/v1"
13
14
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
15
"k8s.io/client-go/kubernetes"
15
16
)
@@ -36,6 +37,9 @@ var _ = Describe("Redis", Ordered, func() {
36
37
getAvailableReplicas := func (ss * appsv1.StatefulSet ) int32 { return ss .Status .AvailableReplicas }
37
38
getSucceededJobs := func (j * batchv1.Job ) int32 { return j .Status .Succeeded }
38
39
getOpts := metav1.GetOptions {}
40
+ restartKey := "kubectl.kubernetes.io/restartedAt"
41
+ restartAnnotation := map [string ]string {restartKey : time .Now ().Format (time .RFC3339 )}
42
+ getRestartedAtAnnotation := func (pod * v1.Pod ) string { return pod .Annotations [restartKey ] }
39
43
40
44
By ("checking all the replicas are available" )
41
45
ss , err := c .AppsV1 ().StatefulSets (namespace ).Get (ctx , stsName , getOpts )
@@ -71,17 +75,16 @@ var _ = Describe("Redis", Ordered, func() {
71
75
return c .BatchV1 ().Jobs (namespace ).Get (ctx , createKEYJobName , getOpts )
72
76
}, timeout , PollingInterval ).Should (WithTransform (getSucceededJobs , Equal (int32 (1 ))))
73
77
74
- By ("scaling down to 0 replicas " )
75
- ss , err = utils . StsScale ( ctx , c , ss , 0 )
76
- Expect ( err ). NotTo ( HaveOccurred () )
78
+ By ("running rollout restart " )
79
+ // Annotate pods to force a rollout restart
80
+ ss , err = utils . StsAnnotateTemplate ( ctx , c , ss , restartAnnotation )
77
81
78
- Eventually (func () (* appsv1.StatefulSet , error ) {
79
- return c .AppsV1 ().StatefulSets (namespace ).Get (ctx , stsName , getOpts )
80
- }, timeout , PollingInterval ).Should (WithTransform (getAvailableReplicas , BeZero ()))
81
-
82
- By ("scaling up to the original replicas" )
83
- ss , err = utils .StsScale (ctx , c , ss , origReplicas )
84
- Expect (err ).NotTo (HaveOccurred ())
82
+ // Wait for the new annotation in the existing pods
83
+ for i := int (origReplicas ) - 1 ; i >= 0 ; i -- {
84
+ Eventually (func () (* v1.Pod , error ) {
85
+ return c .CoreV1 ().Pods (namespace ).Get (ctx , fmt .Sprintf ("%s-%d" , stsName , i ), getOpts )
86
+ }, timeout , PollingInterval ).Should (WithTransform (getRestartedAtAnnotation , Equal (restartAnnotation [restartKey ])))
87
+ }
85
88
86
89
Eventually (func () (* appsv1.StatefulSet , error ) {
87
90
return c .AppsV1 ().StatefulSets (namespace ).Get (ctx , stsName , getOpts )
0 commit comments