1
16
17 package v1_test
18
19 import (
20 "testing"
21
22 appsv1 "k8s.io/api/apps/v1"
23 v1 "k8s.io/api/core/v1"
24 apiequality "k8s.io/apimachinery/pkg/api/equality"
25 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26 "k8s.io/apimachinery/pkg/util/intstr"
27 "k8s.io/kubernetes/pkg/api/legacyscheme"
28 "k8s.io/kubernetes/pkg/apis/apps"
29 api "k8s.io/kubernetes/pkg/apis/core"
30 utilpointer "k8s.io/utils/pointer"
31 )
32
33 func TestV12StatefulSetSpecConversion(t *testing.T) {
34 replicas := utilpointer.Int32(2)
35 selector := &metav1.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}}
36 appsv1Template := v1.PodTemplateSpec{
37 ObjectMeta: metav1.ObjectMeta{Name: "foo"},
38 Spec: v1.PodSpec{
39 RestartPolicy: v1.RestartPolicy("bar"),
40 SecurityContext: new(v1.PodSecurityContext),
41 },
42 }
43 apiTemplate := api.PodTemplateSpec{
44 ObjectMeta: metav1.ObjectMeta{Name: "foo"},
45 Spec: api.PodSpec{
46 RestartPolicy: api.RestartPolicy("bar"),
47 SecurityContext: new(api.PodSecurityContext),
48 },
49 }
50 testcases := map[string]struct {
51 stsSpec1 *apps.StatefulSetSpec
52 stsSepc2 *appsv1.StatefulSetSpec
53 }{
54 "StatefulSetSpec Conversion 1": {
55 stsSpec1: &apps.StatefulSetSpec{
56 Replicas: *replicas,
57 Template: apiTemplate,
58 },
59 stsSepc2: &appsv1.StatefulSetSpec{
60 Replicas: replicas,
61 Template: appsv1Template,
62 },
63 },
64 "StatefulSetSpec Conversion 2": {
65 stsSpec1: &apps.StatefulSetSpec{
66 Replicas: *replicas,
67 Selector: selector,
68 Template: apiTemplate,
69 ServiceName: "foo",
70 PodManagementPolicy: apps.PodManagementPolicyType("bar"),
71 },
72 stsSepc2: &appsv1.StatefulSetSpec{
73 Replicas: replicas,
74 Selector: selector,
75 Template: appsv1Template,
76 ServiceName: "foo",
77 PodManagementPolicy: appsv1.PodManagementPolicyType("bar"),
78 },
79 },
80 }
81
82 for k, tc := range testcases {
83
84 internal1 := &appsv1.StatefulSetSpec{}
85 if err := legacyscheme.Scheme.Convert(tc.stsSpec1, internal1, nil); err != nil {
86 t.Errorf("%q - %q: unexpected error: %v", k, "from apps to appsv1", err)
87 }
88
89 if !apiequality.Semantic.DeepEqual(internal1, tc.stsSepc2) {
90 t.Errorf("%q - %q: expected\n\t%#v, got \n\t%#v", k, "from apps to appsv1", tc.stsSepc2, internal1)
91 }
92
93
94 internal2 := &apps.StatefulSetSpec{}
95 if err := legacyscheme.Scheme.Convert(tc.stsSepc2, internal2, nil); err != nil {
96 t.Errorf("%q - %q: unexpected error: %v", k, "from appsv1 to apps", err)
97 }
98 if !apiequality.Semantic.DeepEqual(internal2, tc.stsSpec1) {
99 t.Errorf("%q- %q: expected\n\t%#v, got \n\t%#v", k, "from appsv1 to apps", tc.stsSpec1, internal2)
100 }
101 }
102 }
103
104 func TestV1StatefulSetStatusConversion(t *testing.T) {
105 observedGeneration := new(int64)
106 *observedGeneration = 2
107 collisionCount := new(int32)
108 *collisionCount = 1
109 testcases := map[string]struct {
110 stsStatus1 *apps.StatefulSetStatus
111 stsStatus2 *appsv1.StatefulSetStatus
112 }{
113 "StatefulSetStatus Conversion 1": {
114 stsStatus1: &apps.StatefulSetStatus{
115 Replicas: int32(3),
116 ReadyReplicas: int32(1),
117 CurrentReplicas: int32(3),
118 UpdatedReplicas: int32(3),
119 CurrentRevision: "12345",
120 UpdateRevision: "23456",
121 ObservedGeneration: observedGeneration,
122 },
123 stsStatus2: &appsv1.StatefulSetStatus{
124 Replicas: int32(3),
125 ReadyReplicas: int32(1),
126 CurrentReplicas: int32(3),
127 UpdatedReplicas: int32(3),
128 CurrentRevision: "12345",
129 UpdateRevision: "23456",
130 ObservedGeneration: *observedGeneration,
131 },
132 },
133 "StatefulSetStatus Conversion 2": {
134 stsStatus1: &apps.StatefulSetStatus{
135 ObservedGeneration: observedGeneration,
136 Replicas: int32(3),
137 ReadyReplicas: int32(1),
138 CurrentReplicas: int32(3),
139 UpdatedReplicas: int32(3),
140 CurrentRevision: "12345",
141 UpdateRevision: "23456",
142 CollisionCount: collisionCount,
143 },
144 stsStatus2: &appsv1.StatefulSetStatus{
145 ObservedGeneration: *observedGeneration,
146 Replicas: int32(3),
147 ReadyReplicas: int32(1),
148 CurrentReplicas: int32(3),
149 UpdatedReplicas: int32(3),
150 CurrentRevision: "12345",
151 UpdateRevision: "23456",
152 CollisionCount: collisionCount,
153 },
154 },
155 }
156
157 for k, tc := range testcases {
158
159 internal1 := &appsv1.StatefulSetStatus{}
160 if err := legacyscheme.Scheme.Convert(tc.stsStatus1, internal1, nil); err != nil {
161 t.Errorf("%q - %q: unexpected error: %v", k, "from apps to appsv1", err)
162 }
163
164 if !apiequality.Semantic.DeepEqual(internal1, tc.stsStatus2) {
165 t.Errorf("%q - %q: expected\n\t%#v, got \n\t%#v", k, "from apps to appsv1", tc.stsStatus2, internal1)
166 }
167
168
169 internal2 := &apps.StatefulSetStatus{}
170 if err := legacyscheme.Scheme.Convert(tc.stsStatus2, internal2, nil); err != nil {
171 t.Errorf("%q - %q: unexpected error: %v", k, "from appsv1 to apps", err)
172 }
173 if !apiequality.Semantic.DeepEqual(internal2, tc.stsStatus1) {
174 t.Errorf("%q - %q: expected\n\t%#v, got \n\t%#v", k, "from appsv1 to apps", tc.stsStatus1, internal2)
175 }
176 }
177 }
178
179 func TestV1StatefulSetUpdateStrategyConversion(t *testing.T) {
180 partition := utilpointer.Int32(2)
181 appsv1rollingUpdate := new(appsv1.RollingUpdateStatefulSetStrategy)
182 appsv1rollingUpdate.Partition = partition
183 appsrollingUpdate := new(apps.RollingUpdateStatefulSetStrategy)
184 appsrollingUpdate.Partition = *partition
185 testcases := map[string]struct {
186 stsUpdateStrategy1 *apps.StatefulSetUpdateStrategy
187 stsUpdateStrategy2 *appsv1.StatefulSetUpdateStrategy
188 }{
189 "StatefulSetUpdateStrategy Conversion 1": {
190 stsUpdateStrategy1: &apps.StatefulSetUpdateStrategy{Type: apps.StatefulSetUpdateStrategyType("foo")},
191 stsUpdateStrategy2: &appsv1.StatefulSetUpdateStrategy{Type: appsv1.StatefulSetUpdateStrategyType("foo")},
192 },
193 "StatefulSetUpdateStrategy Conversion 2": {
194 stsUpdateStrategy1: &apps.StatefulSetUpdateStrategy{
195 Type: apps.StatefulSetUpdateStrategyType("foo"),
196 RollingUpdate: appsrollingUpdate,
197 },
198 stsUpdateStrategy2: &appsv1.StatefulSetUpdateStrategy{
199 Type: appsv1.StatefulSetUpdateStrategyType("foo"),
200 RollingUpdate: appsv1rollingUpdate,
201 },
202 },
203 }
204
205 for k, tc := range testcases {
206
207 internal1 := &appsv1.StatefulSetUpdateStrategy{}
208 if err := legacyscheme.Scheme.Convert(tc.stsUpdateStrategy1, internal1, nil); err != nil {
209 t.Errorf("%q - %q: unexpected error: %v", "apps -> appsv1", k, err)
210 }
211
212 if !apiequality.Semantic.DeepEqual(internal1, tc.stsUpdateStrategy2) {
213 t.Errorf("%q - %q: expected\n\t%#v, got \n\t%#v", "apps -> appsv1", k, tc.stsUpdateStrategy2, internal1)
214 }
215
216
217 internal2 := &apps.StatefulSetUpdateStrategy{}
218 if err := legacyscheme.Scheme.Convert(tc.stsUpdateStrategy2, internal2, nil); err != nil {
219 t.Errorf("%q - %q: unexpected error: %v", "appsv1 -> apps", k, err)
220 }
221 if !apiequality.Semantic.DeepEqual(internal2, tc.stsUpdateStrategy1) {
222 t.Errorf("%q - %q: expected\n\t%#v, got \n\t%#v", "appsv1 -> apps", k, tc.stsUpdateStrategy1, internal2)
223 }
224 }
225 }
226
227 func TestV1RollingUpdateDaemonSetConversion(t *testing.T) {
228 intorstr := intstr.FromInt32(1)
229 maxSurge := intstr.FromInt32(0)
230 testcases := map[string]struct {
231 rollingUpdateDs1 *apps.RollingUpdateDaemonSet
232 rollingUpdateDs2 *appsv1.RollingUpdateDaemonSet
233 }{
234 "RollingUpdateDaemonSet Conversion 2": {
235 rollingUpdateDs1: &apps.RollingUpdateDaemonSet{MaxUnavailable: intorstr, MaxSurge: maxSurge},
236 rollingUpdateDs2: &appsv1.RollingUpdateDaemonSet{MaxUnavailable: &intorstr, MaxSurge: &maxSurge},
237 },
238 }
239
240 for k, tc := range testcases {
241
242 internal1 := &appsv1.RollingUpdateDaemonSet{}
243 if err := legacyscheme.Scheme.Convert(tc.rollingUpdateDs1, internal1, nil); err != nil {
244 t.Errorf("%q - %q: unexpected error: %v", k, "from apps to v1", err)
245 }
246 if !apiequality.Semantic.DeepEqual(internal1, tc.rollingUpdateDs2) {
247 t.Errorf("%q - %q: expected\n\t%#v, got \n\t%#v", k, "from apps to v1", tc.rollingUpdateDs2, internal1)
248 }
249
250
251 internal2 := &apps.RollingUpdateDaemonSet{}
252 if err := legacyscheme.Scheme.Convert(tc.rollingUpdateDs2, internal2, nil); err != nil {
253 t.Errorf("%q - %q: unexpected error: %v", k, "from v1 to apps", err)
254 }
255 if !apiequality.Semantic.DeepEqual(internal2, tc.rollingUpdateDs1) {
256 t.Errorf("%q - %q: expected\n\t%#v, got \n\t%#v", k, "from v1 to apps", tc.rollingUpdateDs1, internal2)
257 }
258 }
259 }
260
261 func TestV1DeploymentConversion(t *testing.T) {
262 replica := utilpointer.Int32(2)
263 rollbackTo := new(apps.RollbackConfig)
264 rollbackTo.Revision = int64(2)
265 testcases := map[string]struct {
266 deployment1 *apps.Deployment
267 deployment2 *appsv1.Deployment
268 }{
269 "Deployment Conversion 1": {
270 deployment1: &apps.Deployment{
271 Spec: apps.DeploymentSpec{
272 Replicas: *replica,
273 RollbackTo: rollbackTo,
274 Template: api.PodTemplateSpec{
275 Spec: api.PodSpec{
276 SecurityContext: new(api.PodSecurityContext),
277 },
278 },
279 },
280 },
281 deployment2: &appsv1.Deployment{
282 ObjectMeta: metav1.ObjectMeta{
283 Annotations: map[string]string{appsv1.DeprecatedRollbackTo: "2"},
284 },
285 Spec: appsv1.DeploymentSpec{
286 Replicas: replica,
287 Template: v1.PodTemplateSpec{
288 Spec: v1.PodSpec{
289 SecurityContext: new(v1.PodSecurityContext),
290 },
291 },
292 },
293 },
294 },
295 "Deployment Conversion 2": {
296 deployment1: &apps.Deployment{
297 Spec: apps.DeploymentSpec{
298 Replicas: *replica,
299 Template: api.PodTemplateSpec{
300 Spec: api.PodSpec{
301 SecurityContext: new(api.PodSecurityContext),
302 },
303 },
304 },
305 },
306 deployment2: &appsv1.Deployment{
307 Spec: appsv1.DeploymentSpec{
308 Replicas: replica,
309 Template: v1.PodTemplateSpec{
310 Spec: v1.PodSpec{
311 SecurityContext: new(v1.PodSecurityContext),
312 },
313 },
314 },
315 },
316 },
317 }
318
319 for k, tc := range testcases {
320
321 internal1 := &appsv1.Deployment{}
322 if err := legacyscheme.Scheme.Convert(tc.deployment1, internal1, nil); err != nil {
323 t.Errorf("%q - %q: unexpected error: %v", k, "from apps to v1beta2", err)
324 }
325 if !apiequality.Semantic.DeepEqual(internal1, tc.deployment2) {
326 t.Errorf("%q - %q: expected\n\t%#v, got \n\t%#v", k, "from apps to v1beta2", tc.deployment2, internal1)
327 }
328
329
330 internal2 := &apps.Deployment{}
331 if err := legacyscheme.Scheme.Convert(tc.deployment2, internal2, nil); err != nil {
332 t.Errorf("%q - %q: unexpected error: %v", k, "from v1beta2 to apps", err)
333 }
334 if !apiequality.Semantic.DeepEqual(internal2, tc.deployment1) {
335 t.Errorf("%q - %q: expected\n\t%#v, got \n\t%#v", k, "from v1beta2 to apps", tc.deployment1, internal2)
336 }
337 }
338 }
339
340 func TestV1DeploymentSpecConversion(t *testing.T) {
341 replica := utilpointer.Int32(2)
342 revisionHistoryLimit := utilpointer.Int32(2)
343 progressDeadlineSeconds := utilpointer.Int32(2)
344
345 testcases := map[string]struct {
346 deploymentSpec1 *apps.DeploymentSpec
347 deploymentSpec2 *appsv1.DeploymentSpec
348 }{
349 "DeploymentSpec Conversion 1": {
350 deploymentSpec1: &apps.DeploymentSpec{
351 Replicas: *replica,
352 Template: api.PodTemplateSpec{
353 Spec: api.PodSpec{
354 SecurityContext: new(api.PodSecurityContext),
355 },
356 },
357 },
358 deploymentSpec2: &appsv1.DeploymentSpec{
359 Replicas: replica,
360 Template: v1.PodTemplateSpec{
361 Spec: v1.PodSpec{
362 SecurityContext: new(v1.PodSecurityContext),
363 },
364 },
365 },
366 },
367 "DeploymentSpec Conversion 2": {
368 deploymentSpec1: &apps.DeploymentSpec{
369 Replicas: *replica,
370 RevisionHistoryLimit: revisionHistoryLimit,
371 MinReadySeconds: 2,
372 Paused: true,
373 Template: api.PodTemplateSpec{
374 Spec: api.PodSpec{
375 SecurityContext: new(api.PodSecurityContext),
376 },
377 },
378 },
379 deploymentSpec2: &appsv1.DeploymentSpec{
380 Replicas: replica,
381 RevisionHistoryLimit: revisionHistoryLimit,
382 MinReadySeconds: 2,
383 Paused: true,
384 Template: v1.PodTemplateSpec{
385 Spec: v1.PodSpec{
386 SecurityContext: new(v1.PodSecurityContext),
387 },
388 },
389 },
390 },
391 "DeploymentSpec Conversion 3": {
392 deploymentSpec1: &apps.DeploymentSpec{
393 Replicas: *replica,
394 ProgressDeadlineSeconds: progressDeadlineSeconds,
395 Template: api.PodTemplateSpec{
396 Spec: api.PodSpec{
397 SecurityContext: new(api.PodSecurityContext),
398 },
399 },
400 },
401 deploymentSpec2: &appsv1.DeploymentSpec{
402 Replicas: replica,
403 ProgressDeadlineSeconds: progressDeadlineSeconds,
404 Template: v1.PodTemplateSpec{
405 Spec: v1.PodSpec{
406 SecurityContext: new(v1.PodSecurityContext),
407 },
408 },
409 },
410 },
411 }
412
413
414 for k, tc := range testcases {
415 internal := &appsv1.DeploymentSpec{}
416 if err := legacyscheme.Scheme.Convert(tc.deploymentSpec1, internal, nil); err != nil {
417 t.Errorf("%q - %q: unexpected error: %v", "apps -> appsv1", k, err)
418 }
419
420 if !apiequality.Semantic.DeepEqual(internal, tc.deploymentSpec2) {
421 t.Errorf("%q - %q: expected\n\t%+v, got \n\t%+v", "apps -> appsv1", k, tc.deploymentSpec2, internal)
422 }
423 }
424
425
426 for k, tc := range testcases {
427 internal := &apps.DeploymentSpec{}
428 if err := legacyscheme.Scheme.Convert(tc.deploymentSpec2, internal, nil); err != nil {
429 t.Errorf("%q - %q: unexpected error: %v", "appsv1 -> apps", k, err)
430 }
431 if !apiequality.Semantic.DeepEqual(internal, tc.deploymentSpec1) {
432 t.Errorf("%q - %q: expected\n\t%+v, got \n\t%+v", "appsv1 -> apps", k, tc.deploymentSpec1, internal)
433 }
434 }
435
436 }
437
438 func TestV1DeploymentStrategyConversion(t *testing.T) {
439 maxUnavailable := intstr.FromInt32(2)
440 maxSurge := intstr.FromInt32(2)
441 appsRollingUpdate := apps.RollingUpdateDeployment{MaxUnavailable: maxUnavailable, MaxSurge: maxSurge}
442 appsv1RollingUpdate := appsv1.RollingUpdateDeployment{MaxUnavailable: &maxUnavailable, MaxSurge: &maxSurge}
443 testcases := map[string]struct {
444 deploymentStrategy1 *apps.DeploymentStrategy
445 deploymentStrategy2 *appsv1.DeploymentStrategy
446 }{
447 "DeploymentStrategy Conversion 1": {
448 deploymentStrategy1: &apps.DeploymentStrategy{Type: apps.DeploymentStrategyType("foo")},
449 deploymentStrategy2: &appsv1.DeploymentStrategy{Type: appsv1.DeploymentStrategyType("foo")},
450 },
451 "DeploymentStrategy Conversion 2": {
452 deploymentStrategy1: &apps.DeploymentStrategy{Type: apps.DeploymentStrategyType("foo"), RollingUpdate: &appsRollingUpdate},
453 deploymentStrategy2: &appsv1.DeploymentStrategy{Type: appsv1.DeploymentStrategyType("foo"), RollingUpdate: &appsv1RollingUpdate},
454 },
455 }
456
457 for k, tc := range testcases {
458
459 internal1 := &appsv1.DeploymentStrategy{}
460 if err := legacyscheme.Scheme.Convert(tc.deploymentStrategy1, internal1, nil); err != nil {
461 t.Errorf("%q - %q: unexpected error: %v", k, "apps -> appsv1", err)
462 }
463 if !apiequality.Semantic.DeepEqual(internal1, tc.deploymentStrategy2) {
464 t.Errorf("%q - %q: expected\n\t%#v, got \n\t%#v", k, "apps -> appsv1", tc.deploymentStrategy2, internal1)
465 }
466
467
468 internal2 := &apps.DeploymentStrategy{}
469 if err := legacyscheme.Scheme.Convert(tc.deploymentStrategy2, internal2, nil); err != nil {
470 t.Errorf("%q - %q: unexpected error: %v", k, "appsv1 -> apps", err)
471 }
472 if !apiequality.Semantic.DeepEqual(internal2, tc.deploymentStrategy1) {
473 t.Errorf("%q - %q: expected\n\t%#v, got \n\t%#v", k, "appsv1 -> apps", tc.deploymentStrategy1, internal2)
474 }
475 }
476 }
477
478 func TestV1RollingUpdateDeploymentConversion(t *testing.T) {
479 nilIntStr := intstr.IntOrString{}
480 maxUnavailable := intstr.FromInt32(2)
481 maxSurge := intstr.FromInt32(2)
482 testcases := map[string]struct {
483 rollingUpdateDeployment1 *apps.RollingUpdateDeployment
484 rollingUpdateDeployment2 *appsv1.RollingUpdateDeployment
485 }{
486 "RollingUpdateDeployment Conversion 1": {
487 rollingUpdateDeployment1: &apps.RollingUpdateDeployment{},
488 rollingUpdateDeployment2: &appsv1.RollingUpdateDeployment{MaxUnavailable: &nilIntStr, MaxSurge: &nilIntStr},
489 },
490 "RollingUpdateDeployment Conversion 2": {
491 rollingUpdateDeployment1: &apps.RollingUpdateDeployment{MaxUnavailable: maxUnavailable},
492 rollingUpdateDeployment2: &appsv1.RollingUpdateDeployment{MaxUnavailable: &maxUnavailable, MaxSurge: &nilIntStr},
493 },
494 "RollingUpdateDeployment Conversion 3": {
495 rollingUpdateDeployment1: &apps.RollingUpdateDeployment{MaxSurge: maxSurge},
496 rollingUpdateDeployment2: &appsv1.RollingUpdateDeployment{MaxSurge: &maxSurge, MaxUnavailable: &nilIntStr},
497 },
498 "RollingUpdateDeployment Conversion 4": {
499 rollingUpdateDeployment1: &apps.RollingUpdateDeployment{MaxUnavailable: maxUnavailable, MaxSurge: maxSurge},
500 rollingUpdateDeployment2: &appsv1.RollingUpdateDeployment{MaxUnavailable: &maxUnavailable, MaxSurge: &maxSurge},
501 },
502 }
503
504 for k, tc := range testcases {
505
506 internal1 := &appsv1.RollingUpdateDeployment{}
507 if err := legacyscheme.Scheme.Convert(tc.rollingUpdateDeployment1, internal1, nil); err != nil {
508 t.Errorf("%q - %q: unexpected error: %v", k, "apps -> appsv1", err)
509 }
510 if !apiequality.Semantic.DeepEqual(internal1, tc.rollingUpdateDeployment2) {
511 t.Errorf("%q - %q: expected\n\t%#v, got \n\t%#v", k, "apps -> appsv1", tc.rollingUpdateDeployment2, internal1)
512 }
513
514
515 internal2 := &apps.RollingUpdateDeployment{}
516 if err := legacyscheme.Scheme.Convert(tc.rollingUpdateDeployment2, internal2, nil); err != nil {
517 t.Errorf("%q - %q: unexpected error: %v", k, "appsv1 -> apps", err)
518 }
519 if !apiequality.Semantic.DeepEqual(internal2, tc.rollingUpdateDeployment1) {
520 t.Errorf("%q - %q: expected\n\t%#v, got \n\t%#v", k, "appsv1 -> apps", tc.rollingUpdateDeployment1, internal2)
521 }
522 }
523 }
524
525 func TestV1ReplicaSetSpecConversion(t *testing.T) {
526 replicas := new(int32)
527 *replicas = 2
528 matchExpressions := []metav1.LabelSelectorRequirement{
529 {Key: "foo", Operator: metav1.LabelSelectorOpIn, Values: []string{"foo"}},
530 }
531 matchLabels := map[string]string{"foo": "bar"}
532 selector := &metav1.LabelSelector{MatchLabels: matchLabels, MatchExpressions: matchExpressions}
533
534 testcases := map[string]struct {
535 replicaset1 *apps.ReplicaSetSpec
536 replicaset2 *appsv1.ReplicaSetSpec
537 }{
538 "ReplicaSetSpec Conversion 1": {
539 replicaset1: &apps.ReplicaSetSpec{
540 Replicas: *replicas,
541 MinReadySeconds: 2,
542 Template: api.PodTemplateSpec{
543 Spec: api.PodSpec{
544 SecurityContext: new(api.PodSecurityContext),
545 },
546 },
547 },
548 replicaset2: &appsv1.ReplicaSetSpec{
549 Replicas: replicas,
550 MinReadySeconds: 2,
551 Template: v1.PodTemplateSpec{
552 Spec: v1.PodSpec{
553 SecurityContext: new(v1.PodSecurityContext),
554 },
555 },
556 },
557 },
558 "ReplicaSetSpec Conversion 2": {
559 replicaset1: &apps.ReplicaSetSpec{
560 Replicas: *replicas,
561 Selector: selector,
562 Template: api.PodTemplateSpec{
563 Spec: api.PodSpec{
564 SecurityContext: new(api.PodSecurityContext),
565 },
566 },
567 },
568 replicaset2: &appsv1.ReplicaSetSpec{
569 Replicas: replicas,
570 Selector: selector,
571 Template: v1.PodTemplateSpec{
572 Spec: v1.PodSpec{
573 SecurityContext: new(v1.PodSecurityContext),
574 },
575 },
576 },
577 },
578 }
579
580 for k, tc := range testcases {
581
582 internal1 := &appsv1.ReplicaSetSpec{}
583 if err := legacyscheme.Scheme.Convert(tc.replicaset1, internal1, nil); err != nil {
584 t.Errorf("%q - %q: unexpected error: %v", k, "apps -> appsv1", err)
585 }
586
587 if !apiequality.Semantic.DeepEqual(internal1, tc.replicaset2) {
588 t.Errorf("%q - %q: expected\n\t%+v, got \n\t%+v", k, "apps -> appsv1", tc.replicaset2, internal1)
589 }
590
591
592 internal2 := &apps.ReplicaSetSpec{}
593 if err := legacyscheme.Scheme.Convert(tc.replicaset2, internal2, nil); err != nil {
594 t.Errorf("%q - %q: unexpected error: %v", k, "appsv1 -> apps", err)
595 }
596 if !apiequality.Semantic.DeepEqual(internal2, tc.replicaset1) {
597 t.Errorf("%q - %q: expected\n\t%+v, got \n\t%+v", k, "appsv1 -> apps", tc.replicaset1, internal2)
598 }
599 }
600 }
601
View as plain text