statefulset.go 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  1. /*
  2. Copyright 2014 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package apps
  14. import (
  15. "context"
  16. "fmt"
  17. "strings"
  18. "time"
  19. "github.com/onsi/ginkgo"
  20. "github.com/onsi/gomega"
  21. appsv1 "k8s.io/api/apps/v1"
  22. v1 "k8s.io/api/core/v1"
  23. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  24. klabels "k8s.io/apimachinery/pkg/labels"
  25. "k8s.io/apimachinery/pkg/types"
  26. "k8s.io/apimachinery/pkg/util/intstr"
  27. "k8s.io/apimachinery/pkg/util/wait"
  28. "k8s.io/apimachinery/pkg/watch"
  29. clientset "k8s.io/client-go/kubernetes"
  30. watchtools "k8s.io/client-go/tools/watch"
  31. "k8s.io/kubernetes/test/e2e/framework"
  32. e2enode "k8s.io/kubernetes/test/e2e/framework/node"
  33. e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
  34. e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
  35. e2eservice "k8s.io/kubernetes/test/e2e/framework/service"
  36. e2esset "k8s.io/kubernetes/test/e2e/framework/statefulset"
  37. imageutils "k8s.io/kubernetes/test/utils/image"
  38. )
  39. const (
  40. zookeeperManifestPath = "test/e2e/testing-manifests/statefulset/zookeeper"
  41. mysqlGaleraManifestPath = "test/e2e/testing-manifests/statefulset/mysql-galera"
  42. redisManifestPath = "test/e2e/testing-manifests/statefulset/redis"
  43. cockroachDBManifestPath = "test/e2e/testing-manifests/statefulset/cockroachdb"
  44. // We don't restart MySQL cluster regardless of restartCluster, since MySQL doesn't handle restart well
  45. restartCluster = true
  46. // Timeout for reads from databases running on stateful pods.
  47. readTimeout = 60 * time.Second
  48. // statefulSetPoll is a poll interval for StatefulSet tests
  49. statefulSetPoll = 10 * time.Second
  50. // statefulSetTimeout is a timeout interval for StatefulSet operations
  51. statefulSetTimeout = 10 * time.Minute
  52. // statefulPodTimeout is a timeout for stateful pods to change state
  53. statefulPodTimeout = 5 * time.Minute
  54. )
  55. var httpProbe = &v1.Probe{
  56. Handler: v1.Handler{
  57. HTTPGet: &v1.HTTPGetAction{
  58. Path: "/index.html",
  59. Port: intstr.IntOrString{IntVal: 80},
  60. },
  61. },
  62. PeriodSeconds: 1,
  63. SuccessThreshold: 1,
  64. FailureThreshold: 1,
  65. }
  66. // GCE Quota requirements: 3 pds, one per stateful pod manifest declared above.
  67. // GCE Api requirements: nodes and master need storage r/w permissions.
  68. var _ = SIGDescribe("StatefulSet", func() {
  69. f := framework.NewDefaultFramework("statefulset")
  70. var ns string
  71. var c clientset.Interface
  72. ginkgo.BeforeEach(func() {
  73. c = f.ClientSet
  74. ns = f.Namespace.Name
  75. })
  76. framework.KubeDescribe("Basic StatefulSet functionality [StatefulSetBasic]", func() {
  77. ssName := "ss"
  78. labels := map[string]string{
  79. "foo": "bar",
  80. "baz": "blah",
  81. }
  82. headlessSvcName := "test"
  83. var statefulPodMounts, podMounts []v1.VolumeMount
  84. var ss *appsv1.StatefulSet
  85. ginkgo.BeforeEach(func() {
  86. statefulPodMounts = []v1.VolumeMount{{Name: "datadir", MountPath: "/data/"}}
  87. podMounts = []v1.VolumeMount{{Name: "home", MountPath: "/home"}}
  88. ss = e2esset.NewStatefulSet(ssName, ns, headlessSvcName, 2, statefulPodMounts, podMounts, labels)
  89. ginkgo.By("Creating service " + headlessSvcName + " in namespace " + ns)
  90. headlessService := e2eservice.CreateServiceSpec(headlessSvcName, "", true, labels)
  91. _, err := c.CoreV1().Services(ns).Create(context.TODO(), headlessService, metav1.CreateOptions{})
  92. framework.ExpectNoError(err)
  93. })
  94. ginkgo.AfterEach(func() {
  95. if ginkgo.CurrentGinkgoTestDescription().Failed {
  96. framework.DumpDebugInfo(c, ns)
  97. }
  98. framework.Logf("Deleting all statefulset in ns %v", ns)
  99. e2esset.DeleteAllStatefulSets(c, ns)
  100. })
  101. // This can't be Conformance yet because it depends on a default
  102. // StorageClass and a dynamic provisioner.
  103. ginkgo.It("should provide basic identity", func() {
  104. ginkgo.By("Creating statefulset " + ssName + " in namespace " + ns)
  105. e2epv.SkipIfNoDefaultStorageClass(c)
  106. *(ss.Spec.Replicas) = 3
  107. e2esset.PauseNewPods(ss)
  108. _, err := c.AppsV1().StatefulSets(ns).Create(context.TODO(), ss, metav1.CreateOptions{})
  109. framework.ExpectNoError(err)
  110. ginkgo.By("Saturating stateful set " + ss.Name)
  111. e2esset.Saturate(c, ss)
  112. ginkgo.By("Verifying statefulset mounted data directory is usable")
  113. framework.ExpectNoError(e2esset.CheckMount(c, ss, "/data"))
  114. ginkgo.By("Verifying statefulset provides a stable hostname for each pod")
  115. framework.ExpectNoError(e2esset.CheckHostname(c, ss))
  116. ginkgo.By("Verifying statefulset set proper service name")
  117. framework.ExpectNoError(e2esset.CheckServiceName(ss, headlessSvcName))
  118. cmd := "echo $(hostname) | dd of=/data/hostname conv=fsync"
  119. ginkgo.By("Running " + cmd + " in all stateful pods")
  120. framework.ExpectNoError(e2esset.ExecInStatefulPods(c, ss, cmd))
  121. ginkgo.By("Restarting statefulset " + ss.Name)
  122. e2esset.Restart(c, ss)
  123. e2esset.WaitForRunningAndReady(c, *ss.Spec.Replicas, ss)
  124. ginkgo.By("Verifying statefulset mounted data directory is usable")
  125. framework.ExpectNoError(e2esset.CheckMount(c, ss, "/data"))
  126. cmd = "if [ \"$(cat /data/hostname)\" = \"$(hostname)\" ]; then exit 0; else exit 1; fi"
  127. ginkgo.By("Running " + cmd + " in all stateful pods")
  128. framework.ExpectNoError(e2esset.ExecInStatefulPods(c, ss, cmd))
  129. })
  130. // This can't be Conformance yet because it depends on a default
  131. // StorageClass and a dynamic provisioner.
  132. ginkgo.It("should adopt matching orphans and release non-matching pods", func() {
  133. ginkgo.By("Creating statefulset " + ssName + " in namespace " + ns)
  134. e2epv.SkipIfNoDefaultStorageClass(c)
  135. *(ss.Spec.Replicas) = 1
  136. e2esset.PauseNewPods(ss)
  137. // Replace ss with the one returned from Create() so it has the UID.
  138. // Save Kind since it won't be populated in the returned ss.
  139. kind := ss.Kind
  140. ss, err := c.AppsV1().StatefulSets(ns).Create(context.TODO(), ss, metav1.CreateOptions{})
  141. framework.ExpectNoError(err)
  142. ss.Kind = kind
  143. ginkgo.By("Saturating stateful set " + ss.Name)
  144. e2esset.Saturate(c, ss)
  145. pods := e2esset.GetPodList(c, ss)
  146. gomega.Expect(pods.Items).To(gomega.HaveLen(int(*ss.Spec.Replicas)))
  147. ginkgo.By("Checking that stateful set pods are created with ControllerRef")
  148. pod := pods.Items[0]
  149. controllerRef := metav1.GetControllerOf(&pod)
  150. gomega.Expect(controllerRef).ToNot(gomega.BeNil())
  151. framework.ExpectEqual(controllerRef.Kind, ss.Kind)
  152. framework.ExpectEqual(controllerRef.Name, ss.Name)
  153. framework.ExpectEqual(controllerRef.UID, ss.UID)
  154. ginkgo.By("Orphaning one of the stateful set's pods")
  155. f.PodClient().Update(pod.Name, func(pod *v1.Pod) {
  156. pod.OwnerReferences = nil
  157. })
  158. ginkgo.By("Checking that the stateful set readopts the pod")
  159. gomega.Expect(e2epod.WaitForPodCondition(c, pod.Namespace, pod.Name, "adopted", statefulSetTimeout,
  160. func(pod *v1.Pod) (bool, error) {
  161. controllerRef := metav1.GetControllerOf(pod)
  162. if controllerRef == nil {
  163. return false, nil
  164. }
  165. if controllerRef.Kind != ss.Kind || controllerRef.Name != ss.Name || controllerRef.UID != ss.UID {
  166. return false, fmt.Errorf("pod has wrong controllerRef: %v", controllerRef)
  167. }
  168. return true, nil
  169. },
  170. )).To(gomega.Succeed(), "wait for pod %q to be readopted", pod.Name)
  171. ginkgo.By("Removing the labels from one of the stateful set's pods")
  172. prevLabels := pod.Labels
  173. f.PodClient().Update(pod.Name, func(pod *v1.Pod) {
  174. pod.Labels = nil
  175. })
  176. ginkgo.By("Checking that the stateful set releases the pod")
  177. gomega.Expect(e2epod.WaitForPodCondition(c, pod.Namespace, pod.Name, "released", statefulSetTimeout,
  178. func(pod *v1.Pod) (bool, error) {
  179. controllerRef := metav1.GetControllerOf(pod)
  180. if controllerRef != nil {
  181. return false, nil
  182. }
  183. return true, nil
  184. },
  185. )).To(gomega.Succeed(), "wait for pod %q to be released", pod.Name)
  186. // If we don't do this, the test leaks the Pod and PVC.
  187. ginkgo.By("Readding labels to the stateful set's pod")
  188. f.PodClient().Update(pod.Name, func(pod *v1.Pod) {
  189. pod.Labels = prevLabels
  190. })
  191. ginkgo.By("Checking that the stateful set readopts the pod")
  192. gomega.Expect(e2epod.WaitForPodCondition(c, pod.Namespace, pod.Name, "adopted", statefulSetTimeout,
  193. func(pod *v1.Pod) (bool, error) {
  194. controllerRef := metav1.GetControllerOf(pod)
  195. if controllerRef == nil {
  196. return false, nil
  197. }
  198. if controllerRef.Kind != ss.Kind || controllerRef.Name != ss.Name || controllerRef.UID != ss.UID {
  199. return false, fmt.Errorf("pod has wrong controllerRef: %v", controllerRef)
  200. }
  201. return true, nil
  202. },
  203. )).To(gomega.Succeed(), "wait for pod %q to be readopted", pod.Name)
  204. })
  205. // This can't be Conformance yet because it depends on a default
  206. // StorageClass and a dynamic provisioner.
  207. ginkgo.It("should not deadlock when a pod's predecessor fails", func() {
  208. ginkgo.By("Creating statefulset " + ssName + " in namespace " + ns)
  209. e2epv.SkipIfNoDefaultStorageClass(c)
  210. *(ss.Spec.Replicas) = 2
  211. e2esset.PauseNewPods(ss)
  212. _, err := c.AppsV1().StatefulSets(ns).Create(context.TODO(), ss, metav1.CreateOptions{})
  213. framework.ExpectNoError(err)
  214. e2esset.WaitForRunning(c, 1, 0, ss)
  215. ginkgo.By("Resuming stateful pod at index 0.")
  216. e2esset.ResumeNextPod(c, ss)
  217. ginkgo.By("Waiting for stateful pod at index 1 to enter running.")
  218. e2esset.WaitForRunning(c, 2, 1, ss)
  219. // Now we have 1 healthy and 1 unhealthy stateful pod. Deleting the healthy stateful pod should *not*
  220. // create a new stateful pod till the remaining stateful pod becomes healthy, which won't happen till
  221. // we set the healthy bit.
  222. ginkgo.By("Deleting healthy stateful pod at index 0.")
  223. deleteStatefulPodAtIndex(c, 0, ss)
  224. ginkgo.By("Confirming stateful pod at index 0 is recreated.")
  225. e2esset.WaitForRunning(c, 2, 1, ss)
  226. ginkgo.By("Resuming stateful pod at index 1.")
  227. e2esset.ResumeNextPod(c, ss)
  228. ginkgo.By("Confirming all stateful pods in statefulset are created.")
  229. e2esset.WaitForRunningAndReady(c, *ss.Spec.Replicas, ss)
  230. })
  231. // This can't be Conformance yet because it depends on a default
  232. // StorageClass and a dynamic provisioner.
  233. ginkgo.It("should perform rolling updates and roll backs of template modifications with PVCs", func() {
  234. ginkgo.By("Creating a new StatefulSet with PVCs")
  235. e2epv.SkipIfNoDefaultStorageClass(c)
  236. *(ss.Spec.Replicas) = 3
  237. rollbackTest(c, ns, ss)
  238. })
  239. /*
  240. Release : v1.9
  241. Testname: StatefulSet, Rolling Update
  242. Description: StatefulSet MUST support the RollingUpdate strategy to automatically replace Pods one at a time when the Pod template changes. The StatefulSet's status MUST indicate the CurrentRevision and UpdateRevision. If the template is changed to match a prior revision, StatefulSet MUST detect this as a rollback instead of creating a new revision. This test does not depend on a preexisting default StorageClass or a dynamic provisioner.
  243. */
  244. framework.ConformanceIt("should perform rolling updates and roll backs of template modifications", func() {
  245. ginkgo.By("Creating a new StatefulSet")
  246. ss := e2esset.NewStatefulSet("ss2", ns, headlessSvcName, 3, nil, nil, labels)
  247. rollbackTest(c, ns, ss)
  248. })
  249. /*
  250. Release : v1.9
  251. Testname: StatefulSet, Rolling Update with Partition
  252. Description: StatefulSet's RollingUpdate strategy MUST support the Partition parameter for canaries and phased rollouts. If a Pod is deleted while a rolling update is in progress, StatefulSet MUST restore the Pod without violating the Partition. This test does not depend on a preexisting default StorageClass or a dynamic provisioner.
  253. */
  254. framework.ConformanceIt("should perform canary updates and phased rolling updates of template modifications", func() {
  255. ginkgo.By("Creating a new StatefulSet")
  256. ss := e2esset.NewStatefulSet("ss2", ns, headlessSvcName, 3, nil, nil, labels)
  257. setHTTPProbe(ss)
  258. ss.Spec.UpdateStrategy = appsv1.StatefulSetUpdateStrategy{
  259. Type: appsv1.RollingUpdateStatefulSetStrategyType,
  260. RollingUpdate: func() *appsv1.RollingUpdateStatefulSetStrategy {
  261. return &appsv1.RollingUpdateStatefulSetStrategy{
  262. Partition: func() *int32 {
  263. i := int32(3)
  264. return &i
  265. }()}
  266. }(),
  267. }
  268. ss, err := c.AppsV1().StatefulSets(ns).Create(context.TODO(), ss, metav1.CreateOptions{})
  269. framework.ExpectNoError(err)
  270. e2esset.WaitForRunningAndReady(c, *ss.Spec.Replicas, ss)
  271. ss = waitForStatus(c, ss)
  272. currentRevision, updateRevision := ss.Status.CurrentRevision, ss.Status.UpdateRevision
  273. framework.ExpectEqual(currentRevision, updateRevision, fmt.Sprintf("StatefulSet %s/%s created with update revision %s not equal to current revision %s",
  274. ss.Namespace, ss.Name, updateRevision, currentRevision))
  275. pods := e2esset.GetPodList(c, ss)
  276. for i := range pods.Items {
  277. framework.ExpectEqual(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel], currentRevision, fmt.Sprintf("Pod %s/%s revision %s is not equal to currentRevision %s",
  278. pods.Items[i].Namespace,
  279. pods.Items[i].Name,
  280. pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel],
  281. currentRevision))
  282. }
  283. newImage := NewWebserverImage
  284. oldImage := ss.Spec.Template.Spec.Containers[0].Image
  285. ginkgo.By(fmt.Sprintf("Updating stateful set template: update image from %s to %s", oldImage, newImage))
  286. framework.ExpectNotEqual(oldImage, newImage, "Incorrect test setup: should update to a different image")
  287. ss, err = updateStatefulSetWithRetries(c, ns, ss.Name, func(update *appsv1.StatefulSet) {
  288. update.Spec.Template.Spec.Containers[0].Image = newImage
  289. })
  290. framework.ExpectNoError(err)
  291. ginkgo.By("Creating a new revision")
  292. ss = waitForStatus(c, ss)
  293. currentRevision, updateRevision = ss.Status.CurrentRevision, ss.Status.UpdateRevision
  294. framework.ExpectNotEqual(currentRevision, updateRevision, "Current revision should not equal update revision during rolling update")
  295. ginkgo.By("Not applying an update when the partition is greater than the number of replicas")
  296. for i := range pods.Items {
  297. framework.ExpectEqual(pods.Items[i].Spec.Containers[0].Image, oldImage, fmt.Sprintf("Pod %s/%s has image %s not equal to current image %s",
  298. pods.Items[i].Namespace,
  299. pods.Items[i].Name,
  300. pods.Items[i].Spec.Containers[0].Image,
  301. oldImage))
  302. framework.ExpectEqual(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel], currentRevision, fmt.Sprintf("Pod %s/%s has revision %s not equal to current revision %s",
  303. pods.Items[i].Namespace,
  304. pods.Items[i].Name,
  305. pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel],
  306. currentRevision))
  307. }
  308. ginkgo.By("Performing a canary update")
  309. ss.Spec.UpdateStrategy = appsv1.StatefulSetUpdateStrategy{
  310. Type: appsv1.RollingUpdateStatefulSetStrategyType,
  311. RollingUpdate: func() *appsv1.RollingUpdateStatefulSetStrategy {
  312. return &appsv1.RollingUpdateStatefulSetStrategy{
  313. Partition: func() *int32 {
  314. i := int32(2)
  315. return &i
  316. }()}
  317. }(),
  318. }
  319. ss, err = updateStatefulSetWithRetries(c, ns, ss.Name, func(update *appsv1.StatefulSet) {
  320. update.Spec.UpdateStrategy = appsv1.StatefulSetUpdateStrategy{
  321. Type: appsv1.RollingUpdateStatefulSetStrategyType,
  322. RollingUpdate: func() *appsv1.RollingUpdateStatefulSetStrategy {
  323. return &appsv1.RollingUpdateStatefulSetStrategy{
  324. Partition: func() *int32 {
  325. i := int32(2)
  326. return &i
  327. }()}
  328. }(),
  329. }
  330. })
  331. framework.ExpectNoError(err)
  332. ss, pods = waitForPartitionedRollingUpdate(c, ss)
  333. for i := range pods.Items {
  334. if i < int(*ss.Spec.UpdateStrategy.RollingUpdate.Partition) {
  335. framework.ExpectEqual(pods.Items[i].Spec.Containers[0].Image, oldImage, fmt.Sprintf("Pod %s/%s has image %s not equal to current image %s",
  336. pods.Items[i].Namespace,
  337. pods.Items[i].Name,
  338. pods.Items[i].Spec.Containers[0].Image,
  339. oldImage))
  340. framework.ExpectEqual(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel], currentRevision, fmt.Sprintf("Pod %s/%s has revision %s not equal to current revision %s",
  341. pods.Items[i].Namespace,
  342. pods.Items[i].Name,
  343. pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel],
  344. currentRevision))
  345. } else {
  346. framework.ExpectEqual(pods.Items[i].Spec.Containers[0].Image, newImage, fmt.Sprintf("Pod %s/%s has image %s not equal to new image %s",
  347. pods.Items[i].Namespace,
  348. pods.Items[i].Name,
  349. pods.Items[i].Spec.Containers[0].Image,
  350. newImage))
  351. framework.ExpectEqual(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel], updateRevision, fmt.Sprintf("Pod %s/%s has revision %s not equal to new revision %s",
  352. pods.Items[i].Namespace,
  353. pods.Items[i].Name,
  354. pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel],
  355. updateRevision))
  356. }
  357. }
  358. ginkgo.By("Restoring Pods to the correct revision when they are deleted")
  359. deleteStatefulPodAtIndex(c, 0, ss)
  360. deleteStatefulPodAtIndex(c, 2, ss)
  361. e2esset.WaitForRunningAndReady(c, 3, ss)
  362. ss = getStatefulSet(c, ss.Namespace, ss.Name)
  363. pods = e2esset.GetPodList(c, ss)
  364. for i := range pods.Items {
  365. if i < int(*ss.Spec.UpdateStrategy.RollingUpdate.Partition) {
  366. framework.ExpectEqual(pods.Items[i].Spec.Containers[0].Image, oldImage, fmt.Sprintf("Pod %s/%s has image %s not equal to current image %s",
  367. pods.Items[i].Namespace,
  368. pods.Items[i].Name,
  369. pods.Items[i].Spec.Containers[0].Image,
  370. oldImage))
  371. framework.ExpectEqual(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel], currentRevision, fmt.Sprintf("Pod %s/%s has revision %s not equal to current revision %s",
  372. pods.Items[i].Namespace,
  373. pods.Items[i].Name,
  374. pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel],
  375. currentRevision))
  376. } else {
  377. framework.ExpectEqual(pods.Items[i].Spec.Containers[0].Image, newImage, fmt.Sprintf("Pod %s/%s has image %s not equal to new image %s",
  378. pods.Items[i].Namespace,
  379. pods.Items[i].Name,
  380. pods.Items[i].Spec.Containers[0].Image,
  381. newImage))
  382. framework.ExpectEqual(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel], updateRevision, fmt.Sprintf("Pod %s/%s has revision %s not equal to new revision %s",
  383. pods.Items[i].Namespace,
  384. pods.Items[i].Name,
  385. pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel],
  386. updateRevision))
  387. }
  388. }
  389. ginkgo.By("Performing a phased rolling update")
  390. for i := int(*ss.Spec.UpdateStrategy.RollingUpdate.Partition) - 1; i >= 0; i-- {
  391. ss, err = updateStatefulSetWithRetries(c, ns, ss.Name, func(update *appsv1.StatefulSet) {
  392. update.Spec.UpdateStrategy = appsv1.StatefulSetUpdateStrategy{
  393. Type: appsv1.RollingUpdateStatefulSetStrategyType,
  394. RollingUpdate: func() *appsv1.RollingUpdateStatefulSetStrategy {
  395. j := int32(i)
  396. return &appsv1.RollingUpdateStatefulSetStrategy{
  397. Partition: &j,
  398. }
  399. }(),
  400. }
  401. })
  402. framework.ExpectNoError(err)
  403. ss, pods = waitForPartitionedRollingUpdate(c, ss)
  404. for i := range pods.Items {
  405. if i < int(*ss.Spec.UpdateStrategy.RollingUpdate.Partition) {
  406. framework.ExpectEqual(pods.Items[i].Spec.Containers[0].Image, oldImage, fmt.Sprintf("Pod %s/%s has image %s not equal to current image %s",
  407. pods.Items[i].Namespace,
  408. pods.Items[i].Name,
  409. pods.Items[i].Spec.Containers[0].Image,
  410. oldImage))
  411. framework.ExpectEqual(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel], currentRevision, fmt.Sprintf("Pod %s/%s has revision %s not equal to current revision %s",
  412. pods.Items[i].Namespace,
  413. pods.Items[i].Name,
  414. pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel],
  415. currentRevision))
  416. } else {
  417. framework.ExpectEqual(pods.Items[i].Spec.Containers[0].Image, newImage, fmt.Sprintf("Pod %s/%s has image %s not equal to new image %s",
  418. pods.Items[i].Namespace,
  419. pods.Items[i].Name,
  420. pods.Items[i].Spec.Containers[0].Image,
  421. newImage))
  422. framework.ExpectEqual(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel], updateRevision, fmt.Sprintf("Pod %s/%s has revision %s not equal to new revision %s",
  423. pods.Items[i].Namespace,
  424. pods.Items[i].Name,
  425. pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel],
  426. updateRevision))
  427. }
  428. }
  429. }
  430. framework.ExpectEqual(ss.Status.CurrentRevision, updateRevision, fmt.Sprintf("StatefulSet %s/%s current revision %s does not equal update revision %s on update completion",
  431. ss.Namespace,
  432. ss.Name,
  433. ss.Status.CurrentRevision,
  434. updateRevision))
  435. })
  436. // Do not mark this as Conformance.
  437. // The legacy OnDelete strategy only exists for backward compatibility with pre-v1 APIs.
  438. ginkgo.It("should implement legacy replacement when the update strategy is OnDelete", func() {
  439. ginkgo.By("Creating a new StatefulSet")
  440. ss := e2esset.NewStatefulSet("ss2", ns, headlessSvcName, 3, nil, nil, labels)
  441. setHTTPProbe(ss)
  442. ss.Spec.UpdateStrategy = appsv1.StatefulSetUpdateStrategy{
  443. Type: appsv1.OnDeleteStatefulSetStrategyType,
  444. }
  445. ss, err := c.AppsV1().StatefulSets(ns).Create(context.TODO(), ss, metav1.CreateOptions{})
  446. framework.ExpectNoError(err)
  447. e2esset.WaitForRunningAndReady(c, *ss.Spec.Replicas, ss)
  448. ss = waitForStatus(c, ss)
  449. currentRevision, updateRevision := ss.Status.CurrentRevision, ss.Status.UpdateRevision
  450. framework.ExpectEqual(currentRevision, updateRevision, fmt.Sprintf("StatefulSet %s/%s created with update revision %s not equal to current revision %s",
  451. ss.Namespace, ss.Name, updateRevision, currentRevision))
  452. pods := e2esset.GetPodList(c, ss)
  453. for i := range pods.Items {
  454. framework.ExpectEqual(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel], currentRevision, fmt.Sprintf("Pod %s/%s revision %s is not equal to current revision %s",
  455. pods.Items[i].Namespace,
  456. pods.Items[i].Name,
  457. pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel],
  458. currentRevision))
  459. }
  460. ginkgo.By("Restoring Pods to the current revision")
  461. deleteStatefulPodAtIndex(c, 0, ss)
  462. deleteStatefulPodAtIndex(c, 1, ss)
  463. deleteStatefulPodAtIndex(c, 2, ss)
  464. e2esset.WaitForRunningAndReady(c, 3, ss)
  465. ss = getStatefulSet(c, ss.Namespace, ss.Name)
  466. pods = e2esset.GetPodList(c, ss)
  467. for i := range pods.Items {
  468. framework.ExpectEqual(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel], currentRevision, fmt.Sprintf("Pod %s/%s revision %s is not equal to current revision %s",
  469. pods.Items[i].Namespace,
  470. pods.Items[i].Name,
  471. pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel],
  472. currentRevision))
  473. }
  474. newImage := NewWebserverImage
  475. oldImage := ss.Spec.Template.Spec.Containers[0].Image
  476. ginkgo.By(fmt.Sprintf("Updating stateful set template: update image from %s to %s", oldImage, newImage))
  477. framework.ExpectNotEqual(oldImage, newImage, "Incorrect test setup: should update to a different image")
  478. ss, err = updateStatefulSetWithRetries(c, ns, ss.Name, func(update *appsv1.StatefulSet) {
  479. update.Spec.Template.Spec.Containers[0].Image = newImage
  480. })
  481. framework.ExpectNoError(err)
  482. ginkgo.By("Creating a new revision")
  483. ss = waitForStatus(c, ss)
  484. currentRevision, updateRevision = ss.Status.CurrentRevision, ss.Status.UpdateRevision
  485. framework.ExpectNotEqual(currentRevision, updateRevision, "Current revision should not equal update revision during rolling update")
  486. ginkgo.By("Recreating Pods at the new revision")
  487. deleteStatefulPodAtIndex(c, 0, ss)
  488. deleteStatefulPodAtIndex(c, 1, ss)
  489. deleteStatefulPodAtIndex(c, 2, ss)
  490. e2esset.WaitForRunningAndReady(c, 3, ss)
  491. ss = getStatefulSet(c, ss.Namespace, ss.Name)
  492. pods = e2esset.GetPodList(c, ss)
  493. for i := range pods.Items {
  494. framework.ExpectEqual(pods.Items[i].Spec.Containers[0].Image, newImage, fmt.Sprintf("Pod %s/%s has image %s not equal to new image %s",
  495. pods.Items[i].Namespace,
  496. pods.Items[i].Name,
  497. pods.Items[i].Spec.Containers[0].Image,
  498. newImage))
  499. framework.ExpectEqual(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel], updateRevision, fmt.Sprintf("Pod %s/%s has revision %s not equal to current revision %s",
  500. pods.Items[i].Namespace,
  501. pods.Items[i].Name,
  502. pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel],
  503. updateRevision))
  504. }
  505. })
  506. /*
  507. Release : v1.9
  508. Testname: StatefulSet, Scaling
  509. Description: StatefulSet MUST create Pods in ascending order by ordinal index when scaling up, and delete Pods in descending order when scaling down. Scaling up or down MUST pause if any Pods belonging to the StatefulSet are unhealthy. This test does not depend on a preexisting default StorageClass or a dynamic provisioner.
  510. */
  511. framework.ConformanceIt("Scaling should happen in predictable order and halt if any stateful pod is unhealthy [Slow]", func() {
  512. psLabels := klabels.Set(labels)
  513. ginkgo.By("Initializing watcher for selector " + psLabels.String())
  514. watcher, err := f.ClientSet.CoreV1().Pods(ns).Watch(context.TODO(), metav1.ListOptions{
  515. LabelSelector: psLabels.AsSelector().String(),
  516. })
  517. framework.ExpectNoError(err)
  518. ginkgo.By("Creating stateful set " + ssName + " in namespace " + ns)
  519. ss := e2esset.NewStatefulSet(ssName, ns, headlessSvcName, 1, nil, nil, psLabels)
  520. setHTTPProbe(ss)
  521. ss, err = c.AppsV1().StatefulSets(ns).Create(context.TODO(), ss, metav1.CreateOptions{})
  522. framework.ExpectNoError(err)
  523. ginkgo.By("Waiting until all stateful set " + ssName + " replicas will be running in namespace " + ns)
  524. e2esset.WaitForRunningAndReady(c, *ss.Spec.Replicas, ss)
  525. ginkgo.By("Confirming that stateful set scale up will halt with unhealthy stateful pod")
  526. breakHTTPProbe(c, ss)
  527. waitForRunningAndNotReady(c, *ss.Spec.Replicas, ss)
  528. e2esset.WaitForStatusReadyReplicas(c, ss, 0)
  529. e2esset.UpdateReplicas(c, ss, 3)
  530. confirmStatefulPodCount(c, 1, ss, 10*time.Second, true)
  531. ginkgo.By("Scaling up stateful set " + ssName + " to 3 replicas and waiting until all of them will be running in namespace " + ns)
  532. restoreHTTPProbe(c, ss)
  533. e2esset.WaitForRunningAndReady(c, 3, ss)
  534. ginkgo.By("Verifying that stateful set " + ssName + " was scaled up in order")
  535. expectedOrder := []string{ssName + "-0", ssName + "-1", ssName + "-2"}
  536. ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), statefulSetTimeout)
  537. defer cancel()
  538. _, err = watchtools.UntilWithoutRetry(ctx, watcher, func(event watch.Event) (bool, error) {
  539. if event.Type != watch.Added {
  540. return false, nil
  541. }
  542. pod := event.Object.(*v1.Pod)
  543. if pod.Name == expectedOrder[0] {
  544. expectedOrder = expectedOrder[1:]
  545. }
  546. return len(expectedOrder) == 0, nil
  547. })
  548. framework.ExpectNoError(err)
  549. ginkgo.By("Scale down will halt with unhealthy stateful pod")
  550. watcher, err = f.ClientSet.CoreV1().Pods(ns).Watch(context.TODO(), metav1.ListOptions{
  551. LabelSelector: psLabels.AsSelector().String(),
  552. })
  553. framework.ExpectNoError(err)
  554. breakHTTPProbe(c, ss)
  555. e2esset.WaitForStatusReadyReplicas(c, ss, 0)
  556. waitForRunningAndNotReady(c, 3, ss)
  557. e2esset.UpdateReplicas(c, ss, 0)
  558. confirmStatefulPodCount(c, 3, ss, 10*time.Second, true)
  559. ginkgo.By("Scaling down stateful set " + ssName + " to 0 replicas and waiting until none of pods will run in namespace" + ns)
  560. restoreHTTPProbe(c, ss)
  561. e2esset.Scale(c, ss, 0)
  562. ginkgo.By("Verifying that stateful set " + ssName + " was scaled down in reverse order")
  563. expectedOrder = []string{ssName + "-2", ssName + "-1", ssName + "-0"}
  564. ctx, cancel = watchtools.ContextWithOptionalTimeout(context.Background(), statefulSetTimeout)
  565. defer cancel()
  566. _, err = watchtools.UntilWithoutRetry(ctx, watcher, func(event watch.Event) (bool, error) {
  567. if event.Type != watch.Deleted {
  568. return false, nil
  569. }
  570. pod := event.Object.(*v1.Pod)
  571. if pod.Name == expectedOrder[0] {
  572. expectedOrder = expectedOrder[1:]
  573. }
  574. return len(expectedOrder) == 0, nil
  575. })
  576. framework.ExpectNoError(err)
  577. })
  578. /*
  579. Release : v1.9
  580. Testname: StatefulSet, Burst Scaling
  581. Description: StatefulSet MUST support the Parallel PodManagementPolicy for burst scaling. This test does not depend on a preexisting default StorageClass or a dynamic provisioner.
  582. */
  583. framework.ConformanceIt("Burst scaling should run to completion even with unhealthy pods [Slow]", func() {
  584. psLabels := klabels.Set(labels)
  585. ginkgo.By("Creating stateful set " + ssName + " in namespace " + ns)
  586. ss := e2esset.NewStatefulSet(ssName, ns, headlessSvcName, 1, nil, nil, psLabels)
  587. ss.Spec.PodManagementPolicy = appsv1.ParallelPodManagement
  588. setHTTPProbe(ss)
  589. ss, err := c.AppsV1().StatefulSets(ns).Create(context.TODO(), ss, metav1.CreateOptions{})
  590. framework.ExpectNoError(err)
  591. ginkgo.By("Waiting until all stateful set " + ssName + " replicas will be running in namespace " + ns)
  592. e2esset.WaitForRunningAndReady(c, *ss.Spec.Replicas, ss)
  593. ginkgo.By("Confirming that stateful set scale up will not halt with unhealthy stateful pod")
  594. breakHTTPProbe(c, ss)
  595. waitForRunningAndNotReady(c, *ss.Spec.Replicas, ss)
  596. e2esset.WaitForStatusReadyReplicas(c, ss, 0)
  597. e2esset.UpdateReplicas(c, ss, 3)
  598. confirmStatefulPodCount(c, 3, ss, 10*time.Second, false)
  599. ginkgo.By("Scaling up stateful set " + ssName + " to 3 replicas and waiting until all of them will be running in namespace " + ns)
  600. restoreHTTPProbe(c, ss)
  601. e2esset.WaitForRunningAndReady(c, 3, ss)
  602. ginkgo.By("Scale down will not halt with unhealthy stateful pod")
  603. breakHTTPProbe(c, ss)
  604. e2esset.WaitForStatusReadyReplicas(c, ss, 0)
  605. waitForRunningAndNotReady(c, 3, ss)
  606. e2esset.UpdateReplicas(c, ss, 0)
  607. confirmStatefulPodCount(c, 0, ss, 10*time.Second, false)
  608. ginkgo.By("Scaling down stateful set " + ssName + " to 0 replicas and waiting until none of pods will run in namespace" + ns)
  609. restoreHTTPProbe(c, ss)
  610. e2esset.Scale(c, ss, 0)
  611. e2esset.WaitForStatusReplicas(c, ss, 0)
  612. })
  613. /*
  614. Release : v1.9
  615. Testname: StatefulSet, Recreate Failed Pod
  616. Description: StatefulSet MUST delete and recreate Pods it owns that go into a Failed state, such as when they are rejected or evicted by a Node. This test does not depend on a preexisting default StorageClass or a dynamic provisioner.
  617. */
  618. framework.ConformanceIt("Should recreate evicted statefulset", func() {
  619. podName := "test-pod"
  620. statefulPodName := ssName + "-0"
  621. ginkgo.By("Looking for a node to schedule stateful set and pod")
  622. node, err := e2enode.GetRandomReadySchedulableNode(f.ClientSet)
  623. framework.ExpectNoError(err)
  624. ginkgo.By("Creating pod with conflicting port in namespace " + f.Namespace.Name)
  625. conflictingPort := v1.ContainerPort{HostPort: 21017, ContainerPort: 21017, Name: "conflict"}
  626. pod := &v1.Pod{
  627. ObjectMeta: metav1.ObjectMeta{
  628. Name: podName,
  629. },
  630. Spec: v1.PodSpec{
  631. Containers: []v1.Container{
  632. {
  633. Name: "webserver",
  634. Image: imageutils.GetE2EImage(imageutils.Httpd),
  635. Ports: []v1.ContainerPort{conflictingPort},
  636. },
  637. },
  638. NodeName: node.Name,
  639. },
  640. }
  641. pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), pod, metav1.CreateOptions{})
  642. framework.ExpectNoError(err)
  643. ginkgo.By("Creating statefulset with conflicting port in namespace " + f.Namespace.Name)
  644. ss := e2esset.NewStatefulSet(ssName, f.Namespace.Name, headlessSvcName, 1, nil, nil, labels)
  645. statefulPodContainer := &ss.Spec.Template.Spec.Containers[0]
  646. statefulPodContainer.Ports = append(statefulPodContainer.Ports, conflictingPort)
  647. ss.Spec.Template.Spec.NodeName = node.Name
  648. _, err = f.ClientSet.AppsV1().StatefulSets(f.Namespace.Name).Create(context.TODO(), ss, metav1.CreateOptions{})
  649. framework.ExpectNoError(err)
  650. ginkgo.By("Waiting until pod " + podName + " will start running in namespace " + f.Namespace.Name)
  651. if err := f.WaitForPodRunning(podName); err != nil {
  652. framework.Failf("Pod %v did not start running: %v", podName, err)
  653. }
  654. var initialStatefulPodUID types.UID
  655. ginkgo.By("Waiting until stateful pod " + statefulPodName + " will be recreated and deleted at least once in namespace " + f.Namespace.Name)
  656. w, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Watch(context.TODO(), metav1.SingleObject(metav1.ObjectMeta{Name: statefulPodName}))
  657. framework.ExpectNoError(err)
  658. ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), statefulPodTimeout)
  659. defer cancel()
  660. // we need to get UID from pod in any state and wait until stateful set controller will remove pod at least once
  661. _, err = watchtools.UntilWithoutRetry(ctx, w, func(event watch.Event) (bool, error) {
  662. pod := event.Object.(*v1.Pod)
  663. switch event.Type {
  664. case watch.Deleted:
  665. framework.Logf("Observed delete event for stateful pod %v in namespace %v", pod.Name, pod.Namespace)
  666. if initialStatefulPodUID == "" {
  667. return false, nil
  668. }
  669. return true, nil
  670. }
  671. framework.Logf("Observed stateful pod in namespace: %v, name: %v, uid: %v, status phase: %v. Waiting for statefulset controller to delete.",
  672. pod.Namespace, pod.Name, pod.UID, pod.Status.Phase)
  673. initialStatefulPodUID = pod.UID
  674. return false, nil
  675. })
  676. if err != nil {
  677. framework.Failf("Pod %v expected to be re-created at least once", statefulPodName)
  678. }
  679. ginkgo.By("Removing pod with conflicting port in namespace " + f.Namespace.Name)
  680. err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(context.TODO(), pod.Name, metav1.NewDeleteOptions(0))
  681. framework.ExpectNoError(err)
  682. ginkgo.By("Waiting when stateful pod " + statefulPodName + " will be recreated in namespace " + f.Namespace.Name + " and will be in running state")
  683. // we may catch delete event, that's why we are waiting for running phase like this, and not with watchtools.UntilWithoutRetry
  684. gomega.Eventually(func() error {
  685. statefulPod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(context.TODO(), statefulPodName, metav1.GetOptions{})
  686. if err != nil {
  687. return err
  688. }
  689. if statefulPod.Status.Phase != v1.PodRunning {
  690. return fmt.Errorf("pod %v is not in running phase: %v", statefulPod.Name, statefulPod.Status.Phase)
  691. } else if statefulPod.UID == initialStatefulPodUID {
  692. return fmt.Errorf("pod %v wasn't recreated: %v == %v", statefulPod.Name, statefulPod.UID, initialStatefulPodUID)
  693. }
  694. return nil
  695. }, statefulPodTimeout, 2*time.Second).Should(gomega.BeNil())
  696. })
  697. /*
  698. Release : v1.16
  699. Testname: StatefulSet resource Replica scaling
  700. Description: Create a StatefulSet resource.
  701. Newly created StatefulSet resource MUST have a scale of one.
  702. Bring the scale of the StatefulSet resource up to two. StatefulSet scale MUST be at two replicas.
  703. */
  704. framework.ConformanceIt("should have a working scale subresource", func() {
  705. ginkgo.By("Creating statefulset " + ssName + " in namespace " + ns)
  706. ss := e2esset.NewStatefulSet(ssName, ns, headlessSvcName, 1, nil, nil, labels)
  707. setHTTPProbe(ss)
  708. ss, err := c.AppsV1().StatefulSets(ns).Create(context.TODO(), ss, metav1.CreateOptions{})
  709. framework.ExpectNoError(err)
  710. e2esset.WaitForRunningAndReady(c, *ss.Spec.Replicas, ss)
  711. ss = waitForStatus(c, ss)
  712. ginkgo.By("getting scale subresource")
  713. scale, err := c.AppsV1().StatefulSets(ns).GetScale(context.TODO(), ssName, metav1.GetOptions{})
  714. if err != nil {
  715. framework.Failf("Failed to get scale subresource: %v", err)
  716. }
  717. framework.ExpectEqual(scale.Spec.Replicas, int32(1))
  718. framework.ExpectEqual(scale.Status.Replicas, int32(1))
  719. ginkgo.By("updating a scale subresource")
  720. scale.ResourceVersion = "" // indicate the scale update should be unconditional
  721. scale.Spec.Replicas = 2
  722. scaleResult, err := c.AppsV1().StatefulSets(ns).UpdateScale(context.TODO(), ssName, scale, metav1.UpdateOptions{})
  723. if err != nil {
  724. framework.Failf("Failed to put scale subresource: %v", err)
  725. }
  726. framework.ExpectEqual(scaleResult.Spec.Replicas, int32(2))
  727. ginkgo.By("verifying the statefulset Spec.Replicas was modified")
  728. ss, err = c.AppsV1().StatefulSets(ns).Get(context.TODO(), ssName, metav1.GetOptions{})
  729. if err != nil {
  730. framework.Failf("Failed to get statefulset resource: %v", err)
  731. }
  732. framework.ExpectEqual(*(ss.Spec.Replicas), int32(2))
  733. })
  734. })
  735. framework.KubeDescribe("Deploy clustered applications [Feature:StatefulSet] [Slow]", func() {
  736. var appTester *clusterAppTester
  737. ginkgo.BeforeEach(func() {
  738. appTester = &clusterAppTester{client: c, ns: ns}
  739. })
  740. ginkgo.AfterEach(func() {
  741. if ginkgo.CurrentGinkgoTestDescription().Failed {
  742. framework.DumpDebugInfo(c, ns)
  743. }
  744. framework.Logf("Deleting all statefulset in ns %v", ns)
  745. e2esset.DeleteAllStatefulSets(c, ns)
  746. })
  747. // Do not mark this as Conformance.
  748. // StatefulSet Conformance should not be dependent on specific applications.
  749. ginkgo.It("should creating a working zookeeper cluster", func() {
  750. appTester.statefulPod = &zookeeperTester{client: c}
  751. appTester.run()
  752. })
  753. // Do not mark this as Conformance.
  754. // StatefulSet Conformance should not be dependent on specific applications.
  755. ginkgo.It("should creating a working redis cluster", func() {
  756. appTester.statefulPod = &redisTester{client: c}
  757. appTester.run()
  758. })
  759. // Do not mark this as Conformance.
  760. // StatefulSet Conformance should not be dependent on specific applications.
  761. ginkgo.It("should creating a working mysql cluster", func() {
  762. appTester.statefulPod = &mysqlGaleraTester{client: c}
  763. appTester.run()
  764. })
  765. // Do not mark this as Conformance.
  766. // StatefulSet Conformance should not be dependent on specific applications.
  767. ginkgo.It("should creating a working CockroachDB cluster", func() {
  768. appTester.statefulPod = &cockroachDBTester{client: c}
  769. appTester.run()
  770. })
  771. })
  772. })
  773. func kubectlExecWithRetries(ns string, args ...string) (out string) {
  774. var err error
  775. for i := 0; i < 3; i++ {
  776. if out, err = framework.RunKubectl(ns, args...); err == nil {
  777. return
  778. }
  779. framework.Logf("Retrying %v:\nerror %v\nstdout %v", args, err, out)
  780. }
  781. framework.Failf("Failed to execute \"%v\" with retries: %v", args, err)
  782. return
  783. }
  784. type statefulPodTester interface {
  785. deploy(ns string) *appsv1.StatefulSet
  786. write(statefulPodIndex int, kv map[string]string)
  787. read(statefulPodIndex int, key string) string
  788. name() string
  789. }
  790. type clusterAppTester struct {
  791. ns string
  792. statefulPod statefulPodTester
  793. client clientset.Interface
  794. }
  795. func (c *clusterAppTester) run() {
  796. ginkgo.By("Deploying " + c.statefulPod.name())
  797. ss := c.statefulPod.deploy(c.ns)
  798. ginkgo.By("Creating foo:bar in member with index 0")
  799. c.statefulPod.write(0, map[string]string{"foo": "bar"})
  800. switch c.statefulPod.(type) {
  801. case *mysqlGaleraTester:
  802. // Don't restart MySQL cluster since it doesn't handle restarts well
  803. default:
  804. if restartCluster {
  805. ginkgo.By("Restarting stateful set " + ss.Name)
  806. e2esset.Restart(c.client, ss)
  807. e2esset.WaitForRunningAndReady(c.client, *ss.Spec.Replicas, ss)
  808. }
  809. }
  810. ginkgo.By("Reading value under foo from member with index 2")
  811. if err := pollReadWithTimeout(c.statefulPod, 2, "foo", "bar"); err != nil {
  812. framework.Failf("%v", err)
  813. }
  814. }
  815. type zookeeperTester struct {
  816. ss *appsv1.StatefulSet
  817. client clientset.Interface
  818. }
  819. func (z *zookeeperTester) name() string {
  820. return "zookeeper"
  821. }
  822. func (z *zookeeperTester) deploy(ns string) *appsv1.StatefulSet {
  823. z.ss = e2esset.CreateStatefulSet(z.client, zookeeperManifestPath, ns)
  824. return z.ss
  825. }
  826. func (z *zookeeperTester) write(statefulPodIndex int, kv map[string]string) {
  827. name := fmt.Sprintf("%v-%d", z.ss.Name, statefulPodIndex)
  828. ns := fmt.Sprintf("--namespace=%v", z.ss.Namespace)
  829. for k, v := range kv {
  830. cmd := fmt.Sprintf("/opt/zookeeper/bin/zkCli.sh create /%v %v", k, v)
  831. framework.Logf(framework.RunKubectlOrDie(z.ss.Namespace, "exec", ns, name, "--", "/bin/sh", "-c", cmd))
  832. }
  833. }
  834. func (z *zookeeperTester) read(statefulPodIndex int, key string) string {
  835. name := fmt.Sprintf("%v-%d", z.ss.Name, statefulPodIndex)
  836. ns := fmt.Sprintf("--namespace=%v", z.ss.Namespace)
  837. cmd := fmt.Sprintf("/opt/zookeeper/bin/zkCli.sh get /%v", key)
  838. return lastLine(framework.RunKubectlOrDie(z.ss.Namespace, "exec", ns, name, "--", "/bin/sh", "-c", cmd))
  839. }
  840. type mysqlGaleraTester struct {
  841. ss *appsv1.StatefulSet
  842. client clientset.Interface
  843. }
  844. func (m *mysqlGaleraTester) name() string {
  845. return "mysql: galera"
  846. }
  847. func (m *mysqlGaleraTester) mysqlExec(cmd, ns, podName string) string {
  848. cmd = fmt.Sprintf("/usr/bin/mysql -u root -B -e '%v'", cmd)
  849. // TODO: Find a readiness probe for mysql that guarantees writes will
  850. // succeed and ditch retries. Current probe only reads, so there's a window
  851. // for a race.
  852. return kubectlExecWithRetries(ns, fmt.Sprintf("--namespace=%v", ns), "exec", podName, "--", "/bin/sh", "-c", cmd)
  853. }
  854. func (m *mysqlGaleraTester) deploy(ns string) *appsv1.StatefulSet {
  855. m.ss = e2esset.CreateStatefulSet(m.client, mysqlGaleraManifestPath, ns)
  856. framework.Logf("Deployed statefulset %v, initializing database", m.ss.Name)
  857. for _, cmd := range []string{
  858. "create database statefulset;",
  859. "use statefulset; create table foo (k varchar(20), v varchar(20));",
  860. } {
  861. framework.Logf(m.mysqlExec(cmd, ns, fmt.Sprintf("%v-0", m.ss.Name)))
  862. }
  863. return m.ss
  864. }
  865. func (m *mysqlGaleraTester) write(statefulPodIndex int, kv map[string]string) {
  866. name := fmt.Sprintf("%v-%d", m.ss.Name, statefulPodIndex)
  867. for k, v := range kv {
  868. cmd := fmt.Sprintf("use statefulset; insert into foo (k, v) values (\"%v\", \"%v\");", k, v)
  869. framework.Logf(m.mysqlExec(cmd, m.ss.Namespace, name))
  870. }
  871. }
  872. func (m *mysqlGaleraTester) read(statefulPodIndex int, key string) string {
  873. name := fmt.Sprintf("%v-%d", m.ss.Name, statefulPodIndex)
  874. return lastLine(m.mysqlExec(fmt.Sprintf("use statefulset; select v from foo where k=\"%v\";", key), m.ss.Namespace, name))
  875. }
  876. type redisTester struct {
  877. ss *appsv1.StatefulSet
  878. client clientset.Interface
  879. }
  880. func (m *redisTester) name() string {
  881. return "redis: master/slave"
  882. }
  883. func (m *redisTester) redisExec(cmd, ns, podName string) string {
  884. cmd = fmt.Sprintf("/opt/redis/redis-cli -h %v %v", podName, cmd)
  885. return framework.RunKubectlOrDie(ns, fmt.Sprintf("--namespace=%v", ns), "exec", podName, "--", "/bin/sh", "-c", cmd)
  886. }
  887. func (m *redisTester) deploy(ns string) *appsv1.StatefulSet {
  888. m.ss = e2esset.CreateStatefulSet(m.client, redisManifestPath, ns)
  889. return m.ss
  890. }
  891. func (m *redisTester) write(statefulPodIndex int, kv map[string]string) {
  892. name := fmt.Sprintf("%v-%d", m.ss.Name, statefulPodIndex)
  893. for k, v := range kv {
  894. framework.Logf(m.redisExec(fmt.Sprintf("SET %v %v", k, v), m.ss.Namespace, name))
  895. }
  896. }
  897. func (m *redisTester) read(statefulPodIndex int, key string) string {
  898. name := fmt.Sprintf("%v-%d", m.ss.Name, statefulPodIndex)
  899. return lastLine(m.redisExec(fmt.Sprintf("GET %v", key), m.ss.Namespace, name))
  900. }
  901. type cockroachDBTester struct {
  902. ss *appsv1.StatefulSet
  903. client clientset.Interface
  904. }
  905. func (c *cockroachDBTester) name() string {
  906. return "CockroachDB"
  907. }
  908. func (c *cockroachDBTester) cockroachDBExec(cmd, ns, podName string) string {
  909. cmd = fmt.Sprintf("/cockroach/cockroach sql --insecure --host %s.cockroachdb -e \"%v\"", podName, cmd)
  910. return framework.RunKubectlOrDie(ns, fmt.Sprintf("--namespace=%v", ns), "exec", podName, "--", "/bin/sh", "-c", cmd)
  911. }
  912. func (c *cockroachDBTester) deploy(ns string) *appsv1.StatefulSet {
  913. c.ss = e2esset.CreateStatefulSet(c.client, cockroachDBManifestPath, ns)
  914. framework.Logf("Deployed statefulset %v, initializing database", c.ss.Name)
  915. for _, cmd := range []string{
  916. "CREATE DATABASE IF NOT EXISTS foo;",
  917. "CREATE TABLE IF NOT EXISTS foo.bar (k STRING PRIMARY KEY, v STRING);",
  918. } {
  919. framework.Logf(c.cockroachDBExec(cmd, ns, fmt.Sprintf("%v-0", c.ss.Name)))
  920. }
  921. return c.ss
  922. }
  923. func (c *cockroachDBTester) write(statefulPodIndex int, kv map[string]string) {
  924. name := fmt.Sprintf("%v-%d", c.ss.Name, statefulPodIndex)
  925. for k, v := range kv {
  926. cmd := fmt.Sprintf("UPSERT INTO foo.bar VALUES ('%v', '%v');", k, v)
  927. framework.Logf(c.cockroachDBExec(cmd, c.ss.Namespace, name))
  928. }
  929. }
  930. func (c *cockroachDBTester) read(statefulPodIndex int, key string) string {
  931. name := fmt.Sprintf("%v-%d", c.ss.Name, statefulPodIndex)
  932. return lastLine(c.cockroachDBExec(fmt.Sprintf("SELECT v FROM foo.bar WHERE k='%v';", key), c.ss.Namespace, name))
  933. }
  934. func lastLine(out string) string {
  935. outLines := strings.Split(strings.Trim(out, "\n"), "\n")
  936. return outLines[len(outLines)-1]
  937. }
  938. func pollReadWithTimeout(statefulPod statefulPodTester, statefulPodNumber int, key, expectedVal string) error {
  939. err := wait.PollImmediate(time.Second, readTimeout, func() (bool, error) {
  940. val := statefulPod.read(statefulPodNumber, key)
  941. if val == "" {
  942. return false, nil
  943. } else if val != expectedVal {
  944. return false, fmt.Errorf("expected value %v, found %v", expectedVal, val)
  945. }
  946. return true, nil
  947. })
  948. if err == wait.ErrWaitTimeout {
  949. return fmt.Errorf("timed out when trying to read value for key %v from stateful pod %d", key, statefulPodNumber)
  950. }
  951. return err
  952. }
  953. // This function is used by two tests to test StatefulSet rollbacks: one using
  954. // PVCs and one using no storage.
  955. func rollbackTest(c clientset.Interface, ns string, ss *appsv1.StatefulSet) {
  956. setHTTPProbe(ss)
  957. ss, err := c.AppsV1().StatefulSets(ns).Create(context.TODO(), ss, metav1.CreateOptions{})
  958. framework.ExpectNoError(err)
  959. e2esset.WaitForRunningAndReady(c, *ss.Spec.Replicas, ss)
  960. ss = waitForStatus(c, ss)
  961. currentRevision, updateRevision := ss.Status.CurrentRevision, ss.Status.UpdateRevision
  962. framework.ExpectEqual(currentRevision, updateRevision, fmt.Sprintf("StatefulSet %s/%s created with update revision %s not equal to current revision %s",
  963. ss.Namespace, ss.Name, updateRevision, currentRevision))
  964. pods := e2esset.GetPodList(c, ss)
  965. for i := range pods.Items {
  966. framework.ExpectEqual(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel], currentRevision, fmt.Sprintf("Pod %s/%s revision %s is not equal to current revision %s",
  967. pods.Items[i].Namespace,
  968. pods.Items[i].Name,
  969. pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel],
  970. currentRevision))
  971. }
  972. e2esset.SortStatefulPods(pods)
  973. err = breakPodHTTPProbe(ss, &pods.Items[1])
  974. framework.ExpectNoError(err)
  975. ss, pods = waitForPodNotReady(c, ss, pods.Items[1].Name)
  976. newImage := NewWebserverImage
  977. oldImage := ss.Spec.Template.Spec.Containers[0].Image
  978. ginkgo.By(fmt.Sprintf("Updating StatefulSet template: update image from %s to %s", oldImage, newImage))
  979. framework.ExpectNotEqual(oldImage, newImage, "Incorrect test setup: should update to a different image")
  980. ss, err = updateStatefulSetWithRetries(c, ns, ss.Name, func(update *appsv1.StatefulSet) {
  981. update.Spec.Template.Spec.Containers[0].Image = newImage
  982. })
  983. framework.ExpectNoError(err)
  984. ginkgo.By("Creating a new revision")
  985. ss = waitForStatus(c, ss)
  986. currentRevision, updateRevision = ss.Status.CurrentRevision, ss.Status.UpdateRevision
  987. framework.ExpectNotEqual(currentRevision, updateRevision, "Current revision should not equal update revision during rolling update")
  988. ginkgo.By("Updating Pods in reverse ordinal order")
  989. pods = e2esset.GetPodList(c, ss)
  990. e2esset.SortStatefulPods(pods)
  991. err = restorePodHTTPProbe(ss, &pods.Items[1])
  992. framework.ExpectNoError(err)
  993. ss, pods = e2esset.WaitForPodReady(c, ss, pods.Items[1].Name)
  994. ss, pods = waitForRollingUpdate(c, ss)
  995. framework.ExpectEqual(ss.Status.CurrentRevision, updateRevision, fmt.Sprintf("StatefulSet %s/%s current revision %s does not equal update revision %s on update completion",
  996. ss.Namespace,
  997. ss.Name,
  998. ss.Status.CurrentRevision,
  999. updateRevision))
  1000. for i := range pods.Items {
  1001. framework.ExpectEqual(pods.Items[i].Spec.Containers[0].Image, newImage, fmt.Sprintf(" Pod %s/%s has image %s not have new image %s",
  1002. pods.Items[i].Namespace,
  1003. pods.Items[i].Name,
  1004. pods.Items[i].Spec.Containers[0].Image,
  1005. newImage))
  1006. framework.ExpectEqual(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel], updateRevision, fmt.Sprintf("Pod %s/%s revision %s is not equal to update revision %s",
  1007. pods.Items[i].Namespace,
  1008. pods.Items[i].Name,
  1009. pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel],
  1010. updateRevision))
  1011. }
  1012. ginkgo.By("Rolling back to a previous revision")
  1013. err = breakPodHTTPProbe(ss, &pods.Items[1])
  1014. framework.ExpectNoError(err)
  1015. ss, pods = waitForPodNotReady(c, ss, pods.Items[1].Name)
  1016. priorRevision := currentRevision
  1017. currentRevision, updateRevision = ss.Status.CurrentRevision, ss.Status.UpdateRevision
  1018. ss, err = updateStatefulSetWithRetries(c, ns, ss.Name, func(update *appsv1.StatefulSet) {
  1019. update.Spec.Template.Spec.Containers[0].Image = oldImage
  1020. })
  1021. framework.ExpectNoError(err)
  1022. ss = waitForStatus(c, ss)
  1023. currentRevision, updateRevision = ss.Status.CurrentRevision, ss.Status.UpdateRevision
  1024. framework.ExpectEqual(priorRevision, updateRevision, "Prior revision should equal update revision during roll back")
  1025. framework.ExpectNotEqual(currentRevision, updateRevision, "Current revision should not equal update revision during roll back")
  1026. ginkgo.By("Rolling back update in reverse ordinal order")
  1027. pods = e2esset.GetPodList(c, ss)
  1028. e2esset.SortStatefulPods(pods)
  1029. restorePodHTTPProbe(ss, &pods.Items[1])
  1030. ss, pods = e2esset.WaitForPodReady(c, ss, pods.Items[1].Name)
  1031. ss, pods = waitForRollingUpdate(c, ss)
  1032. framework.ExpectEqual(ss.Status.CurrentRevision, priorRevision, fmt.Sprintf("StatefulSet %s/%s current revision %s does not equal prior revision %s on rollback completion",
  1033. ss.Namespace,
  1034. ss.Name,
  1035. ss.Status.CurrentRevision,
  1036. updateRevision))
  1037. for i := range pods.Items {
  1038. framework.ExpectEqual(pods.Items[i].Spec.Containers[0].Image, oldImage, fmt.Sprintf("Pod %s/%s has image %s not equal to previous image %s",
  1039. pods.Items[i].Namespace,
  1040. pods.Items[i].Name,
  1041. pods.Items[i].Spec.Containers[0].Image,
  1042. oldImage))
  1043. framework.ExpectEqual(pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel], priorRevision, fmt.Sprintf("Pod %s/%s revision %s is not equal to prior revision %s",
  1044. pods.Items[i].Namespace,
  1045. pods.Items[i].Name,
  1046. pods.Items[i].Labels[appsv1.StatefulSetRevisionLabel],
  1047. priorRevision))
  1048. }
  1049. }
  1050. // confirmStatefulPodCount asserts that the current number of Pods in ss is count, waiting up to timeout for ss to
  1051. // to scale to count.
  1052. func confirmStatefulPodCount(c clientset.Interface, count int, ss *appsv1.StatefulSet, timeout time.Duration, hard bool) {
  1053. start := time.Now()
  1054. deadline := start.Add(timeout)
  1055. for t := time.Now(); t.Before(deadline); t = time.Now() {
  1056. podList := e2esset.GetPodList(c, ss)
  1057. statefulPodCount := len(podList.Items)
  1058. if statefulPodCount != count {
  1059. e2epod.LogPodStates(podList.Items)
  1060. if hard {
  1061. framework.Failf("StatefulSet %v scaled unexpectedly scaled to %d -> %d replicas", ss.Name, count, len(podList.Items))
  1062. } else {
  1063. framework.Logf("StatefulSet %v has not reached scale %d, at %d", ss.Name, count, statefulPodCount)
  1064. }
  1065. time.Sleep(1 * time.Second)
  1066. continue
  1067. }
  1068. framework.Logf("Verifying statefulset %v doesn't scale past %d for another %+v", ss.Name, count, deadline.Sub(t))
  1069. time.Sleep(1 * time.Second)
  1070. }
  1071. }
  1072. // setHTTPProbe sets the pod template's ReadinessProbe for Webserver StatefulSet containers.
  1073. // This probe can then be controlled with BreakHTTPProbe() and RestoreHTTPProbe().
  1074. // Note that this cannot be used together with PauseNewPods().
  1075. func setHTTPProbe(ss *appsv1.StatefulSet) {
  1076. ss.Spec.Template.Spec.Containers[0].ReadinessProbe = httpProbe
  1077. }
  1078. // breakHTTPProbe breaks the readiness probe for Nginx StatefulSet containers in ss.
  1079. func breakHTTPProbe(c clientset.Interface, ss *appsv1.StatefulSet) error {
  1080. path := httpProbe.HTTPGet.Path
  1081. if path == "" {
  1082. return fmt.Errorf("path expected to be not empty: %v", path)
  1083. }
  1084. // Ignore 'mv' errors to make this idempotent.
  1085. cmd := fmt.Sprintf("mv -v /usr/local/apache2/htdocs%v /tmp/ || true", path)
  1086. return e2esset.ExecInStatefulPods(c, ss, cmd)
  1087. }
  1088. // breakPodHTTPProbe breaks the readiness probe for Nginx StatefulSet containers in one pod.
  1089. func breakPodHTTPProbe(ss *appsv1.StatefulSet, pod *v1.Pod) error {
  1090. path := httpProbe.HTTPGet.Path
  1091. if path == "" {
  1092. return fmt.Errorf("path expected to be not empty: %v", path)
  1093. }
  1094. // Ignore 'mv' errors to make this idempotent.
  1095. cmd := fmt.Sprintf("mv -v /usr/local/apache2/htdocs%v /tmp/ || true", path)
  1096. stdout, err := framework.RunHostCmdWithRetries(pod.Namespace, pod.Name, cmd, statefulSetPoll, statefulPodTimeout)
  1097. framework.Logf("stdout of %v on %v: %v", cmd, pod.Name, stdout)
  1098. return err
  1099. }
  1100. // restoreHTTPProbe restores the readiness probe for Nginx StatefulSet containers in ss.
  1101. func restoreHTTPProbe(c clientset.Interface, ss *appsv1.StatefulSet) error {
  1102. path := httpProbe.HTTPGet.Path
  1103. if path == "" {
  1104. return fmt.Errorf("path expected to be not empty: %v", path)
  1105. }
  1106. // Ignore 'mv' errors to make this idempotent.
  1107. cmd := fmt.Sprintf("mv -v /tmp%v /usr/local/apache2/htdocs/ || true", path)
  1108. return e2esset.ExecInStatefulPods(c, ss, cmd)
  1109. }
  1110. // restorePodHTTPProbe restores the readiness probe for Nginx StatefulSet containers in pod.
  1111. func restorePodHTTPProbe(ss *appsv1.StatefulSet, pod *v1.Pod) error {
  1112. path := httpProbe.HTTPGet.Path
  1113. if path == "" {
  1114. return fmt.Errorf("path expected to be not empty: %v", path)
  1115. }
  1116. // Ignore 'mv' errors to make this idempotent.
  1117. cmd := fmt.Sprintf("mv -v /tmp%v /usr/local/apache2/htdocs/ || true", path)
  1118. stdout, err := framework.RunHostCmdWithRetries(pod.Namespace, pod.Name, cmd, statefulSetPoll, statefulPodTimeout)
  1119. framework.Logf("stdout of %v on %v: %v", cmd, pod.Name, stdout)
  1120. return err
  1121. }
  1122. // deleteStatefulPodAtIndex deletes the Pod with ordinal index in ss.
  1123. func deleteStatefulPodAtIndex(c clientset.Interface, index int, ss *appsv1.StatefulSet) {
  1124. name := getStatefulSetPodNameAtIndex(index, ss)
  1125. noGrace := int64(0)
  1126. if err := c.CoreV1().Pods(ss.Namespace).Delete(context.TODO(), name, &metav1.DeleteOptions{GracePeriodSeconds: &noGrace}); err != nil {
  1127. framework.Failf("Failed to delete stateful pod %v for StatefulSet %v/%v: %v", name, ss.Namespace, ss.Name, err)
  1128. }
  1129. }
  1130. // getStatefulSetPodNameAtIndex gets formated pod name given index.
  1131. func getStatefulSetPodNameAtIndex(index int, ss *appsv1.StatefulSet) string {
  1132. // TODO: we won't use "-index" as the name strategy forever,
  1133. // pull the name out from an identity mapper.
  1134. return fmt.Sprintf("%v-%v", ss.Name, index)
  1135. }
  1136. type updateStatefulSetFunc func(*appsv1.StatefulSet)
  1137. // updateStatefulSetWithRetries updates statfulset template with retries.
  1138. func updateStatefulSetWithRetries(c clientset.Interface, namespace, name string, applyUpdate updateStatefulSetFunc) (statefulSet *appsv1.StatefulSet, err error) {
  1139. statefulSets := c.AppsV1().StatefulSets(namespace)
  1140. var updateErr error
  1141. pollErr := wait.Poll(10*time.Millisecond, 1*time.Minute, func() (bool, error) {
  1142. if statefulSet, err = statefulSets.Get(context.TODO(), name, metav1.GetOptions{}); err != nil {
  1143. return false, err
  1144. }
  1145. // Apply the update, then attempt to push it to the apiserver.
  1146. applyUpdate(statefulSet)
  1147. if statefulSet, err = statefulSets.Update(context.TODO(), statefulSet, metav1.UpdateOptions{}); err == nil {
  1148. framework.Logf("Updating stateful set %s", name)
  1149. return true, nil
  1150. }
  1151. updateErr = err
  1152. return false, nil
  1153. })
  1154. if pollErr == wait.ErrWaitTimeout {
  1155. pollErr = fmt.Errorf("couldn't apply the provided updated to stateful set %q: %v", name, updateErr)
  1156. }
  1157. return statefulSet, pollErr
  1158. }
  1159. // getStatefulSet gets the StatefulSet named name in namespace.
  1160. func getStatefulSet(c clientset.Interface, namespace, name string) *appsv1.StatefulSet {
  1161. ss, err := c.AppsV1().StatefulSets(namespace).Get(context.TODO(), name, metav1.GetOptions{})
  1162. if err != nil {
  1163. framework.Failf("Failed to get StatefulSet %s/%s: %v", namespace, name, err)
  1164. }
  1165. return ss
  1166. }