watch.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. /*
  2. Copyright 2018 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 apimachinery
  14. import (
  15. "context"
  16. "fmt"
  17. "math/rand"
  18. "time"
  19. "k8s.io/api/core/v1"
  20. apiequality "k8s.io/apimachinery/pkg/api/equality"
  21. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  22. "k8s.io/apimachinery/pkg/runtime"
  23. "k8s.io/apimachinery/pkg/watch"
  24. "k8s.io/kubernetes/test/e2e/framework"
  25. "github.com/onsi/ginkgo"
  26. )
  27. const (
  28. watchConfigMapLabelKey = "watch-this-configmap"
  29. multipleWatchersLabelValueA = "multiple-watchers-A"
  30. multipleWatchersLabelValueB = "multiple-watchers-B"
  31. fromResourceVersionLabelValue = "from-resource-version"
  32. watchRestartedLabelValue = "watch-closed-and-restarted"
  33. toBeChangedLabelValue = "label-changed-and-restored"
  34. )
  35. var _ = SIGDescribe("Watchers", func() {
  36. f := framework.NewDefaultFramework("watch")
  37. /*
  38. Testname: watch-configmaps-with-multiple-watchers
  39. Description: Ensure that multiple watchers are able to receive all add,
  40. update, and delete notifications on configmaps that match a label selector and do
  41. not receive notifications for configmaps which do not match that label selector.
  42. */
  43. framework.ConformanceIt("should observe add, update, and delete watch notifications on configmaps", func() {
  44. c := f.ClientSet
  45. ns := f.Namespace.Name
  46. ginkgo.By("creating a watch on configmaps with label A")
  47. watchA, err := watchConfigMaps(f, "", multipleWatchersLabelValueA)
  48. framework.ExpectNoError(err, "failed to create a watch on configmaps with label: %s", multipleWatchersLabelValueA)
  49. ginkgo.By("creating a watch on configmaps with label B")
  50. watchB, err := watchConfigMaps(f, "", multipleWatchersLabelValueB)
  51. framework.ExpectNoError(err, "failed to create a watch on configmaps with label: %s", multipleWatchersLabelValueB)
  52. ginkgo.By("creating a watch on configmaps with label A or B")
  53. watchAB, err := watchConfigMaps(f, "", multipleWatchersLabelValueA, multipleWatchersLabelValueB)
  54. framework.ExpectNoError(err, "failed to create a watch on configmaps with label %s or %s", multipleWatchersLabelValueA, multipleWatchersLabelValueB)
  55. testConfigMapA := &v1.ConfigMap{
  56. ObjectMeta: metav1.ObjectMeta{
  57. Name: "e2e-watch-test-configmap-a",
  58. Labels: map[string]string{
  59. watchConfigMapLabelKey: multipleWatchersLabelValueA,
  60. },
  61. },
  62. }
  63. testConfigMapB := &v1.ConfigMap{
  64. ObjectMeta: metav1.ObjectMeta{
  65. Name: "e2e-watch-test-configmap-b",
  66. Labels: map[string]string{
  67. watchConfigMapLabelKey: multipleWatchersLabelValueB,
  68. },
  69. },
  70. }
  71. ginkgo.By("creating a configmap with label A and ensuring the correct watchers observe the notification")
  72. testConfigMapA, err = c.CoreV1().ConfigMaps(ns).Create(context.TODO(), testConfigMapA, metav1.CreateOptions{})
  73. framework.ExpectNoError(err, "failed to create a configmap with label %s in namespace: %s", multipleWatchersLabelValueA, ns)
  74. expectEvent(watchA, watch.Added, testConfigMapA)
  75. expectEvent(watchAB, watch.Added, testConfigMapA)
  76. expectNoEvent(watchB, watch.Added, testConfigMapA)
  77. ginkgo.By("modifying configmap A and ensuring the correct watchers observe the notification")
  78. testConfigMapA, err = updateConfigMap(c, ns, testConfigMapA.GetName(), func(cm *v1.ConfigMap) {
  79. setConfigMapData(cm, "mutation", "1")
  80. })
  81. framework.ExpectNoError(err, "failed to update configmap %s in namespace: %s", testConfigMapA.GetName(), ns)
  82. expectEvent(watchA, watch.Modified, testConfigMapA)
  83. expectEvent(watchAB, watch.Modified, testConfigMapA)
  84. expectNoEvent(watchB, watch.Modified, testConfigMapA)
  85. ginkgo.By("modifying configmap A again and ensuring the correct watchers observe the notification")
  86. testConfigMapA, err = updateConfigMap(c, ns, testConfigMapA.GetName(), func(cm *v1.ConfigMap) {
  87. setConfigMapData(cm, "mutation", "2")
  88. })
  89. framework.ExpectNoError(err, "failed to update configmap %s in namespace: %s", testConfigMapA.GetName(), ns)
  90. expectEvent(watchA, watch.Modified, testConfigMapA)
  91. expectEvent(watchAB, watch.Modified, testConfigMapA)
  92. expectNoEvent(watchB, watch.Modified, testConfigMapA)
  93. ginkgo.By("deleting configmap A and ensuring the correct watchers observe the notification")
  94. err = c.CoreV1().ConfigMaps(ns).Delete(context.TODO(), testConfigMapA.GetName(), nil)
  95. framework.ExpectNoError(err, "failed to delete configmap %s in namespace: %s", testConfigMapA.GetName(), ns)
  96. expectEvent(watchA, watch.Deleted, nil)
  97. expectEvent(watchAB, watch.Deleted, nil)
  98. expectNoEvent(watchB, watch.Deleted, nil)
  99. ginkgo.By("creating a configmap with label B and ensuring the correct watchers observe the notification")
  100. testConfigMapB, err = c.CoreV1().ConfigMaps(ns).Create(context.TODO(), testConfigMapB, metav1.CreateOptions{})
  101. framework.ExpectNoError(err, "failed to create configmap %s in namespace: %s", testConfigMapB, ns)
  102. expectEvent(watchB, watch.Added, testConfigMapB)
  103. expectEvent(watchAB, watch.Added, testConfigMapB)
  104. expectNoEvent(watchA, watch.Added, testConfigMapB)
  105. ginkgo.By("deleting configmap B and ensuring the correct watchers observe the notification")
  106. err = c.CoreV1().ConfigMaps(ns).Delete(context.TODO(), testConfigMapB.GetName(), nil)
  107. framework.ExpectNoError(err, "failed to delete configmap %s in namespace: %s", testConfigMapB.GetName(), ns)
  108. expectEvent(watchB, watch.Deleted, nil)
  109. expectEvent(watchAB, watch.Deleted, nil)
  110. expectNoEvent(watchA, watch.Deleted, nil)
  111. })
  112. /*
  113. Testname: watch-configmaps-from-resource-version
  114. Description: Ensure that a watch can be opened from a particular resource version
  115. in the past and only notifications happening after that resource version are observed.
  116. */
  117. framework.ConformanceIt("should be able to start watching from a specific resource version", func() {
  118. c := f.ClientSet
  119. ns := f.Namespace.Name
  120. testConfigMap := &v1.ConfigMap{
  121. ObjectMeta: metav1.ObjectMeta{
  122. Name: "e2e-watch-test-resource-version",
  123. Labels: map[string]string{
  124. watchConfigMapLabelKey: fromResourceVersionLabelValue,
  125. },
  126. },
  127. }
  128. ginkgo.By("creating a new configmap")
  129. testConfigMap, err := c.CoreV1().ConfigMaps(ns).Create(context.TODO(), testConfigMap, metav1.CreateOptions{})
  130. framework.ExpectNoError(err, "failed to create configmap %s in namespace: %s", testConfigMap.GetName(), ns)
  131. ginkgo.By("modifying the configmap once")
  132. testConfigMapFirstUpdate, err := updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) {
  133. setConfigMapData(cm, "mutation", "1")
  134. })
  135. framework.ExpectNoError(err, "failed to update configmap %s in namespace: %s", testConfigMap.GetName(), ns)
  136. ginkgo.By("modifying the configmap a second time")
  137. testConfigMapSecondUpdate, err := updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) {
  138. setConfigMapData(cm, "mutation", "2")
  139. })
  140. framework.ExpectNoError(err, "failed to update configmap %s in namespace %s a second time", testConfigMap.GetName(), ns)
  141. ginkgo.By("deleting the configmap")
  142. err = c.CoreV1().ConfigMaps(ns).Delete(context.TODO(), testConfigMap.GetName(), nil)
  143. framework.ExpectNoError(err, "failed to delete configmap %s in namespace: %s", testConfigMap.GetName(), ns)
  144. ginkgo.By("creating a watch on configmaps from the resource version returned by the first update")
  145. testWatch, err := watchConfigMaps(f, testConfigMapFirstUpdate.ObjectMeta.ResourceVersion, fromResourceVersionLabelValue)
  146. framework.ExpectNoError(err, "failed to create a watch on configmaps from the resource version %s returned by the first update", testConfigMapFirstUpdate.ObjectMeta.ResourceVersion)
  147. ginkgo.By("Expecting to observe notifications for all changes to the configmap after the first update")
  148. expectEvent(testWatch, watch.Modified, testConfigMapSecondUpdate)
  149. expectEvent(testWatch, watch.Deleted, nil)
  150. })
  151. /*
  152. Testname: watch-configmaps-closed-and-restarted
  153. Description: Ensure that a watch can be reopened from the last resource version
  154. observed by the previous watch, and it will continue delivering notifications from
  155. that point in time.
  156. */
  157. framework.ConformanceIt("should be able to restart watching from the last resource version observed by the previous watch", func() {
  158. c := f.ClientSet
  159. ns := f.Namespace.Name
  160. configMapName := "e2e-watch-test-watch-closed"
  161. testConfigMap := &v1.ConfigMap{
  162. ObjectMeta: metav1.ObjectMeta{
  163. Name: configMapName,
  164. Labels: map[string]string{
  165. watchConfigMapLabelKey: watchRestartedLabelValue,
  166. },
  167. },
  168. }
  169. ginkgo.By("creating a watch on configmaps")
  170. testWatchBroken, err := watchConfigMaps(f, "", watchRestartedLabelValue)
  171. framework.ExpectNoError(err, "failed to create a watch on configmap with label: %s", watchRestartedLabelValue)
  172. ginkgo.By("creating a new configmap")
  173. testConfigMap, err = c.CoreV1().ConfigMaps(ns).Create(context.TODO(), testConfigMap, metav1.CreateOptions{})
  174. framework.ExpectNoError(err, "failed to create configmap %s in namespace: %s", configMapName, ns)
  175. ginkgo.By("modifying the configmap once")
  176. _, err = updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) {
  177. setConfigMapData(cm, "mutation", "1")
  178. })
  179. framework.ExpectNoError(err, "failed to update configmap %s in namespace: %s", configMapName, ns)
  180. ginkgo.By("closing the watch once it receives two notifications")
  181. expectEvent(testWatchBroken, watch.Added, testConfigMap)
  182. lastEvent, ok := waitForEvent(testWatchBroken, watch.Modified, nil, 1*time.Minute)
  183. if !ok {
  184. framework.Failf("Timed out waiting for second watch notification")
  185. }
  186. testWatchBroken.Stop()
  187. ginkgo.By("modifying the configmap a second time, while the watch is closed")
  188. testConfigMapSecondUpdate, err := updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) {
  189. setConfigMapData(cm, "mutation", "2")
  190. })
  191. framework.ExpectNoError(err, "failed to update configmap %s in namespace %s a second time", configMapName, ns)
  192. ginkgo.By("creating a new watch on configmaps from the last resource version observed by the first watch")
  193. lastEventConfigMap, ok := lastEvent.Object.(*v1.ConfigMap)
  194. if !ok {
  195. framework.Failf("Expected last notification to refer to a configmap but got: %v", lastEvent)
  196. }
  197. testWatchRestarted, err := watchConfigMaps(f, lastEventConfigMap.ObjectMeta.ResourceVersion, watchRestartedLabelValue)
  198. framework.ExpectNoError(err, "failed to create a new watch on configmaps from the last resource version %s observed by the first watch", lastEventConfigMap.ObjectMeta.ResourceVersion)
  199. ginkgo.By("deleting the configmap")
  200. err = c.CoreV1().ConfigMaps(ns).Delete(context.TODO(), testConfigMap.GetName(), nil)
  201. framework.ExpectNoError(err, "failed to delete configmap %s in namespace: %s", configMapName, ns)
  202. ginkgo.By("Expecting to observe notifications for all changes to the configmap since the first watch closed")
  203. expectEvent(testWatchRestarted, watch.Modified, testConfigMapSecondUpdate)
  204. expectEvent(testWatchRestarted, watch.Deleted, nil)
  205. })
  206. /*
  207. Testname: watch-configmaps-label-changed
  208. Description: Ensure that a watched object stops meeting the requirements of
  209. a watch's selector, the watch will observe a delete, and will not observe
  210. notifications for that object until it meets the selector's requirements again.
  211. */
  212. framework.ConformanceIt("should observe an object deletion if it stops meeting the requirements of the selector", func() {
  213. c := f.ClientSet
  214. ns := f.Namespace.Name
  215. configMapName := "e2e-watch-test-label-changed"
  216. testConfigMap := &v1.ConfigMap{
  217. ObjectMeta: metav1.ObjectMeta{
  218. Name: configMapName,
  219. Labels: map[string]string{
  220. watchConfigMapLabelKey: toBeChangedLabelValue,
  221. },
  222. },
  223. }
  224. ginkgo.By("creating a watch on configmaps with a certain label")
  225. testWatch, err := watchConfigMaps(f, "", toBeChangedLabelValue)
  226. framework.ExpectNoError(err, "failed to create a watch on configmap with label: %s", toBeChangedLabelValue)
  227. ginkgo.By("creating a new configmap")
  228. testConfigMap, err = c.CoreV1().ConfigMaps(ns).Create(context.TODO(), testConfigMap, metav1.CreateOptions{})
  229. framework.ExpectNoError(err, "failed to create configmap %s in namespace: %s", configMapName, ns)
  230. ginkgo.By("modifying the configmap once")
  231. testConfigMapFirstUpdate, err := updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) {
  232. setConfigMapData(cm, "mutation", "1")
  233. })
  234. framework.ExpectNoError(err, "failed to update configmap %s in namespace: %s", configMapName, ns)
  235. ginkgo.By("changing the label value of the configmap")
  236. _, err = updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) {
  237. cm.ObjectMeta.Labels[watchConfigMapLabelKey] = "wrong-value"
  238. })
  239. framework.ExpectNoError(err, "failed to update configmap %s in namespace %s by changing label value", configMapName, ns)
  240. ginkgo.By("Expecting to observe a delete notification for the watched object")
  241. expectEvent(testWatch, watch.Added, testConfigMap)
  242. expectEvent(testWatch, watch.Modified, testConfigMapFirstUpdate)
  243. expectEvent(testWatch, watch.Deleted, nil)
  244. ginkgo.By("modifying the configmap a second time")
  245. testConfigMapSecondUpdate, err := updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) {
  246. setConfigMapData(cm, "mutation", "2")
  247. })
  248. framework.ExpectNoError(err, "failed to update configmap %s in namespace %s a second time", configMapName, ns)
  249. ginkgo.By("Expecting not to observe a notification because the object no longer meets the selector's requirements")
  250. expectNoEvent(testWatch, watch.Modified, testConfigMapSecondUpdate)
  251. ginkgo.By("changing the label value of the configmap back")
  252. testConfigMapLabelRestored, err := updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) {
  253. cm.ObjectMeta.Labels[watchConfigMapLabelKey] = toBeChangedLabelValue
  254. })
  255. framework.ExpectNoError(err, "failed to update configmap %s in namespace %s by changing label value back", configMapName, ns)
  256. ginkgo.By("modifying the configmap a third time")
  257. testConfigMapThirdUpdate, err := updateConfigMap(c, ns, testConfigMap.GetName(), func(cm *v1.ConfigMap) {
  258. setConfigMapData(cm, "mutation", "3")
  259. })
  260. framework.ExpectNoError(err, "failed to update configmap %s in namespace %s a third time", configMapName, ns)
  261. ginkgo.By("deleting the configmap")
  262. err = c.CoreV1().ConfigMaps(ns).Delete(context.TODO(), testConfigMap.GetName(), nil)
  263. framework.ExpectNoError(err, "failed to delete configmap %s in namespace: %s", configMapName, ns)
  264. ginkgo.By("Expecting to observe an add notification for the watched object when the label value was restored")
  265. expectEvent(testWatch, watch.Added, testConfigMapLabelRestored)
  266. expectEvent(testWatch, watch.Modified, testConfigMapThirdUpdate)
  267. expectEvent(testWatch, watch.Deleted, nil)
  268. })
  269. /*
  270. Testname: watch-consistency
  271. Release : v1.15
  272. Description: Ensure that concurrent watches are consistent with each other by initiating an additional watch
  273. for events received from the first watch, initiated at the resource version of the event, and checking that all
  274. resource versions of all events match. Events are produced from writes on a background goroutine.
  275. */
  276. framework.ConformanceIt("should receive events on concurrent watches in same order", func() {
  277. c := f.ClientSet
  278. ns := f.Namespace.Name
  279. iterations := 100
  280. ginkgo.By("starting a background goroutine to produce watch events")
  281. donec := make(chan struct{})
  282. stopc := make(chan struct{})
  283. go func() {
  284. defer ginkgo.GinkgoRecover()
  285. defer close(donec)
  286. produceConfigMapEvents(f, stopc, 5*time.Millisecond)
  287. }()
  288. ginkgo.By("creating watches starting from each resource version of the events produced and verifying they all receive resource versions in the same order")
  289. wcs := []watch.Interface{}
  290. resourceVersion := "0"
  291. for i := 0; i < iterations; i++ {
  292. wc, err := c.CoreV1().ConfigMaps(ns).Watch(context.TODO(), metav1.ListOptions{ResourceVersion: resourceVersion})
  293. framework.ExpectNoError(err, "Failed to watch configmaps in the namespace %s", ns)
  294. wcs = append(wcs, wc)
  295. resourceVersion = waitForNextConfigMapEvent(wcs[0]).ResourceVersion
  296. for _, wc := range wcs[1:] {
  297. e := waitForNextConfigMapEvent(wc)
  298. if resourceVersion != e.ResourceVersion {
  299. framework.Failf("resource version mismatch, expected %s but got %s", resourceVersion, e.ResourceVersion)
  300. }
  301. }
  302. }
  303. close(stopc)
  304. for _, wc := range wcs {
  305. wc.Stop()
  306. }
  307. <-donec
  308. })
  309. })
  310. func watchConfigMaps(f *framework.Framework, resourceVersion string, labels ...string) (watch.Interface, error) {
  311. c := f.ClientSet
  312. ns := f.Namespace.Name
  313. opts := metav1.ListOptions{
  314. ResourceVersion: resourceVersion,
  315. LabelSelector: metav1.FormatLabelSelector(&metav1.LabelSelector{
  316. MatchExpressions: []metav1.LabelSelectorRequirement{
  317. {
  318. Key: watchConfigMapLabelKey,
  319. Operator: metav1.LabelSelectorOpIn,
  320. Values: labels,
  321. },
  322. },
  323. }),
  324. }
  325. return c.CoreV1().ConfigMaps(ns).Watch(context.TODO(), opts)
  326. }
  327. func int64ptr(i int) *int64 {
  328. i64 := int64(i)
  329. return &i64
  330. }
  331. func setConfigMapData(cm *v1.ConfigMap, key, value string) {
  332. if cm.Data == nil {
  333. cm.Data = make(map[string]string)
  334. }
  335. cm.Data[key] = value
  336. }
  337. func expectEvent(w watch.Interface, eventType watch.EventType, object runtime.Object) {
  338. if event, ok := waitForEvent(w, eventType, object, 1*time.Minute); !ok {
  339. framework.Failf("Timed out waiting for expected watch notification: %v", event)
  340. }
  341. }
  342. func expectNoEvent(w watch.Interface, eventType watch.EventType, object runtime.Object) {
  343. if event, ok := waitForEvent(w, eventType, object, 10*time.Second); ok {
  344. framework.Failf("Unexpected watch notification observed: %v", event)
  345. }
  346. }
  347. func waitForEvent(w watch.Interface, expectType watch.EventType, expectObject runtime.Object, duration time.Duration) (watch.Event, bool) {
  348. stopTimer := time.NewTimer(duration)
  349. defer stopTimer.Stop()
  350. for {
  351. select {
  352. case actual, ok := <-w.ResultChan():
  353. if ok {
  354. framework.Logf("Got : %v %v", actual.Type, actual.Object)
  355. } else {
  356. framework.Failf("Watch closed unexpectedly")
  357. }
  358. if expectType == actual.Type && (expectObject == nil || apiequality.Semantic.DeepEqual(expectObject, actual.Object)) {
  359. return actual, true
  360. }
  361. case <-stopTimer.C:
  362. expected := watch.Event{
  363. Type: expectType,
  364. Object: expectObject,
  365. }
  366. return expected, false
  367. }
  368. }
  369. }
  370. func waitForNextConfigMapEvent(watch watch.Interface) *v1.ConfigMap {
  371. select {
  372. case event := <-watch.ResultChan():
  373. if configMap, ok := event.Object.(*v1.ConfigMap); ok {
  374. return configMap
  375. }
  376. framework.Failf("expected config map")
  377. case <-time.After(10 * time.Second):
  378. framework.Failf("timed out waiting for watch event")
  379. }
  380. return nil // should never happen
  381. }
  382. const (
  383. createEvent = iota
  384. updateEvent
  385. deleteEvent
  386. )
  387. func produceConfigMapEvents(f *framework.Framework, stopc <-chan struct{}, minWaitBetweenEvents time.Duration) {
  388. c := f.ClientSet
  389. ns := f.Namespace.Name
  390. name := func(i int) string {
  391. return fmt.Sprintf("cm-%d", i)
  392. }
  393. existing := []int{}
  394. tc := time.NewTicker(minWaitBetweenEvents)
  395. defer tc.Stop()
  396. i := 0
  397. for range tc.C {
  398. op := rand.Intn(3)
  399. if len(existing) == 0 {
  400. op = createEvent
  401. }
  402. cm := &v1.ConfigMap{}
  403. switch op {
  404. case createEvent:
  405. cm.Name = name(i)
  406. _, err := c.CoreV1().ConfigMaps(ns).Create(context.TODO(), cm, metav1.CreateOptions{})
  407. framework.ExpectNoError(err, "Failed to create configmap %s in namespace %s", cm.Name, ns)
  408. existing = append(existing, i)
  409. i++
  410. case updateEvent:
  411. idx := rand.Intn(len(existing))
  412. cm.Name = name(existing[idx])
  413. _, err := c.CoreV1().ConfigMaps(ns).Update(context.TODO(), cm, metav1.UpdateOptions{})
  414. framework.ExpectNoError(err, "Failed to update configmap %s in namespace %s", cm.Name, ns)
  415. case deleteEvent:
  416. idx := rand.Intn(len(existing))
  417. err := c.CoreV1().ConfigMaps(ns).Delete(context.TODO(), name(existing[idx]), &metav1.DeleteOptions{})
  418. framework.ExpectNoError(err, "Failed to delete configmap %s in namespace %s", name(existing[idx]), ns)
  419. existing = append(existing[:idx], existing[idx+1:]...)
  420. default:
  421. framework.Failf("Unsupported event operation: %d", op)
  422. }
  423. select {
  424. case <-stopc:
  425. return
  426. default:
  427. }
  428. }
  429. }