retain_keys_test.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. Copyright 2017 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 strategy_test
  14. import (
  15. . "github.com/onsi/ginkgo"
  16. "k8s.io/kubernetes/pkg/kubectl/apply/strategy"
  17. )
  18. var _ = Describe("Merging fields with the retainkeys strategy", func() {
  19. Context("where some fields are only defined remotely", func() {
  20. It("should drop those fields ", func() {
  21. recorded := create(`
  22. apiVersion: apps/v1
  23. kind: Deployment
  24. spec:
  25. strategy:
  26. `)
  27. local := create(`
  28. apiVersion: apps/v1
  29. kind: Deployment
  30. spec:
  31. strategy:
  32. type: Recreate
  33. `)
  34. remote := create(`
  35. apiVersion: apps/v1
  36. kind: Deployment
  37. spec:
  38. strategy:
  39. type: RollingUpdate
  40. rollingUpdate:
  41. maxUnavailable: 1
  42. maxSurge: 1
  43. `)
  44. expected := create(`
  45. apiVersion: apps/v1
  46. kind: Deployment
  47. spec:
  48. strategy:
  49. type: Recreate
  50. `)
  51. run(strategy.Create(strategy.Options{}), recorded, local, remote, expected)
  52. })
  53. })
  54. Context("where some fields are defined both locally and remotely", func() {
  55. It("should merge those fields", func() {
  56. recorded := create(`
  57. apiVersion: apps/v1
  58. kind: Deployment
  59. spec:
  60. strategy:
  61. `)
  62. local := create(`
  63. apiVersion: apps/v1
  64. kind: Deployment
  65. spec:
  66. strategy:
  67. type: RollingUpdate
  68. rollingUpdate:
  69. maxUnavailable: 2
  70. `)
  71. remote := create(`
  72. apiVersion: apps/v1
  73. kind: Deployment
  74. spec:
  75. strategy:
  76. type: RollingUpdate
  77. rollingUpdate:
  78. maxSurge: 1
  79. `)
  80. expected := create(`
  81. apiVersion: apps/v1
  82. kind: Deployment
  83. spec:
  84. strategy:
  85. type: RollingUpdate
  86. rollingUpdate:
  87. maxUnavailable: 2
  88. maxSurge: 1
  89. `)
  90. run(strategy.Create(strategy.Options{}), recorded, local, remote, expected)
  91. })
  92. })
  93. Context("where the elements are in a list and some fields are only defined remotely", func() {
  94. It("should drop those fields ", func() {
  95. recorded := create(`
  96. apiVersion: apps/v1
  97. kind: Deployment
  98. spec:
  99. template:
  100. spec:
  101. `)
  102. local := create(`
  103. apiVersion: apps/v1
  104. kind: Deployment
  105. spec:
  106. template:
  107. spec:
  108. volumes:
  109. - name: cache-volume
  110. emptyDir:
  111. `)
  112. remote := create(`
  113. apiVersion: apps/v1
  114. kind: Deployment
  115. spec:
  116. template:
  117. spec:
  118. volumes:
  119. - name: cache-volume
  120. hostPath:
  121. path: /tmp/cache-volume
  122. `)
  123. expected := create(`
  124. apiVersion: apps/v1
  125. kind: Deployment
  126. spec:
  127. template:
  128. spec:
  129. volumes:
  130. - name: cache-volume
  131. emptyDir:
  132. `)
  133. run(strategy.Create(strategy.Options{}), recorded, local, remote, expected)
  134. })
  135. })
  136. Context("where the elements are in a list", func() {
  137. It("the fields defined both locally and remotely should be merged", func() {
  138. recorded := create(`
  139. apiVersion: apps/v1
  140. kind: Deployment
  141. spec:
  142. template:
  143. spec:
  144. `)
  145. local := create(`
  146. apiVersion: apps/v1
  147. kind: Deployment
  148. spec:
  149. template:
  150. spec:
  151. volumes:
  152. - name: cache-volume
  153. hostPath:
  154. path: /tmp/cache-volume
  155. emptyDir:
  156. `)
  157. remote := create(`
  158. apiVersion: apps/v1
  159. kind: Deployment
  160. spec:
  161. template:
  162. spec:
  163. volumes:
  164. - name: cache-volume
  165. hostPath:
  166. path: /tmp/cache-volume
  167. type: Directory
  168. `)
  169. expected := create(`
  170. apiVersion: apps/v1
  171. kind: Deployment
  172. spec:
  173. template:
  174. spec:
  175. volumes:
  176. - name: cache-volume
  177. hostPath:
  178. path: /tmp/cache-volume
  179. type: Directory
  180. emptyDir:
  181. `)
  182. run(strategy.Create(strategy.Options{}), recorded, local, remote, expected)
  183. })
  184. })
  185. })