@@ -25,8 +25,8 @@ import (
25
25
"sync"
26
26
"time"
27
27
28
- . "github.com/onsi/ginkgo"
29
- . "github.com/onsi/gomega"
28
+ "github.com/onsi/ginkgo"
29
+ "github.com/onsi/gomega"
30
30
31
31
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32
32
"k8s.io/apimachinery/pkg/util/version"
@@ -37,14 +37,17 @@ import (
37
37
38
38
const manifestPath = "test/e2e/testing-manifests/statefulset/etcd"
39
39
40
+ // EtcdUpgradeTest tests that etcd is writable before and after a cluster upgrade.
40
41
type EtcdUpgradeTest struct {
41
42
ip string
42
43
successfulWrites int
43
44
ssTester * framework.StatefulSetTester
44
45
}
45
46
47
+ // Name returns the tracking name of the test.
46
48
func (EtcdUpgradeTest ) Name () string { return "etcd-upgrade" }
47
49
50
+ // Skip returns true when this test can be skipped.
48
51
func (EtcdUpgradeTest ) Skip (upgCtx UpgradeContext ) bool {
49
52
minVersion := version .MustParseSemantic ("1.6.0" )
50
53
for _ , vCtx := range upgCtx .Versions {
@@ -56,26 +59,27 @@ func (EtcdUpgradeTest) Skip(upgCtx UpgradeContext) bool {
56
59
}
57
60
58
61
func kubectlCreate (ns , file string ) {
59
- input := string (testfiles .ReadOrDie (filepath .Join (manifestPath , file ), Fail ))
62
+ input := string (testfiles .ReadOrDie (filepath .Join (manifestPath , file ), ginkgo . Fail ))
60
63
framework .RunKubectlOrDieInput (input , "create" , "-f" , "-" , fmt .Sprintf ("--namespace=%s" , ns ))
61
64
}
62
65
66
+ // Setup creates etcd statefulset and then verifies that the etcd is writable.
63
67
func (t * EtcdUpgradeTest ) Setup (f * framework.Framework ) {
64
68
ns := f .Namespace .Name
65
69
statefulsetPoll := 30 * time .Second
66
70
statefulsetTimeout := 10 * time .Minute
67
71
t .ssTester = framework .NewStatefulSetTester (f .ClientSet )
68
72
69
- By ("Creating a PDB" )
73
+ ginkgo . By ("Creating a PDB" )
70
74
kubectlCreate (ns , "pdb.yaml" )
71
75
72
- By ("Creating an etcd StatefulSet" )
76
+ ginkgo . By ("Creating an etcd StatefulSet" )
73
77
t .ssTester .CreateStatefulSet (manifestPath , ns )
74
78
75
- By ("Creating an etcd--test-server deployment" )
79
+ ginkgo . By ("Creating an etcd--test-server deployment" )
76
80
kubectlCreate (ns , "tester.yaml" )
77
81
78
- By ("Getting the ingress IPs from the services" )
82
+ ginkgo . By ("Getting the ingress IPs from the services" )
79
83
err := wait .PollImmediate (statefulsetPoll , statefulsetTimeout , func () (bool , error ) {
80
84
if t .ip = t .getServiceIP (f , ns , "test-server" ); t .ip == "" {
81
85
return false , nil
@@ -86,18 +90,18 @@ func (t *EtcdUpgradeTest) Setup(f *framework.Framework) {
86
90
}
87
91
return true , nil
88
92
})
89
- Expect (err ).NotTo (HaveOccurred ())
93
+ gomega . Expect (err ).NotTo (gomega . HaveOccurred ())
90
94
framework .Logf ("Service endpoint is up" )
91
95
92
- By ("Adding 2 dummy users" )
93
- Expect (t .addUser ("Alice" )).NotTo (HaveOccurred ())
94
- Expect (t .addUser ("Bob" )).NotTo (HaveOccurred ())
96
+ ginkgo . By ("Adding 2 dummy users" )
97
+ gomega . Expect (t .addUser ("Alice" )).NotTo (gomega . HaveOccurred ())
98
+ gomega . Expect (t .addUser ("Bob" )).NotTo (gomega . HaveOccurred ())
95
99
t .successfulWrites = 2
96
100
97
- By ("Verifying that the users exist" )
101
+ ginkgo . By ("Verifying that the users exist" )
98
102
users , err := t .listUsers ()
99
- Expect (err ).NotTo (HaveOccurred ())
100
- Expect (len (users )).To (Equal (2 ))
103
+ gomega . Expect (err ).NotTo (gomega . HaveOccurred ())
104
+ gomega . Expect (len (users )).To (gomega . Equal (2 ))
101
105
}
102
106
103
107
func (t * EtcdUpgradeTest ) listUsers () ([]string , error ) {
@@ -139,16 +143,17 @@ func (t *EtcdUpgradeTest) addUser(name string) error {
139
143
140
144
func (t * EtcdUpgradeTest ) getServiceIP (f * framework.Framework , ns , svcName string ) string {
141
145
svc , err := f .ClientSet .CoreV1 ().Services (ns ).Get (svcName , metav1.GetOptions {})
142
- Expect (err ).NotTo (HaveOccurred ())
146
+ gomega . Expect (err ).NotTo (gomega . HaveOccurred ())
143
147
ingress := svc .Status .LoadBalancer .Ingress
144
148
if len (ingress ) == 0 {
145
149
return ""
146
150
}
147
151
return ingress [0 ].IP
148
152
}
149
153
154
+ // Test waits for upgrade to complete and verifies if etcd is writable.
150
155
func (t * EtcdUpgradeTest ) Test (f * framework.Framework , done <- chan struct {}, upgrade UpgradeType ) {
151
- By ("Continuously polling the database during upgrade." )
156
+ ginkgo . By ("Continuously polling the database during upgrade." )
152
157
var (
153
158
success , failures , writeAttempts , lastUserCount int
154
159
mu sync.Mutex
@@ -182,19 +187,19 @@ func (t *EtcdUpgradeTest) Test(f *framework.Framework, done <-chan struct{}, upg
182
187
}, 10 * time .Millisecond , done )
183
188
framework .Logf ("got %d users; want >=%d" , lastUserCount , t .successfulWrites )
184
189
185
- Expect (lastUserCount >= t .successfulWrites ).To (BeTrue ())
190
+ gomega . Expect (lastUserCount >= t .successfulWrites ).To (gomega . BeTrue ())
186
191
ratio := float64 (success ) / float64 (success + failures )
187
192
framework .Logf ("Successful gets %d/%d=%v" , success , success + failures , ratio )
188
193
ratio = float64 (t .successfulWrites ) / float64 (writeAttempts )
189
194
framework .Logf ("Successful writes %d/%d=%v" , t .successfulWrites , writeAttempts , ratio )
190
195
framework .Logf ("Errors: %v" , errors )
191
196
// TODO(maisem): tweak this value once we have a few test runs.
192
- Expect (ratio > 0.75 ).To (BeTrue ())
197
+ gomega . Expect (ratio > 0.75 ).To (gomega . BeTrue ())
193
198
}
194
199
195
200
// Teardown does one final check of the data's availability.
196
201
func (t * EtcdUpgradeTest ) Teardown (f * framework.Framework ) {
197
202
users , err := t .listUsers ()
198
- Expect (err ).NotTo (HaveOccurred ())
199
- Expect (len (users ) >= t .successfulWrites ).To (BeTrue ())
203
+ gomega . Expect (err ).NotTo (gomega . HaveOccurred ())
204
+ gomega . Expect (len (users ) >= t .successfulWrites ).To (gomega . BeTrue ())
200
205
}
0 commit comments