@@ -59,6 +59,7 @@ func deleteNamespace(ns *corev1.Namespace) {
59
59
var _ = Describe ("Client" , func () {
60
60
61
61
var scheme * runtime.Scheme
62
+ var depGvk schema.GroupVersionKind
62
63
var dep * appsv1.Deployment
63
64
var pod * corev1.Pod
64
65
var node * corev1.Node
@@ -82,6 +83,11 @@ var _ = Describe("Client", func() {
82
83
},
83
84
},
84
85
}
86
+ depGvk = schema.GroupVersionKind {
87
+ Group : "apps" ,
88
+ Kind : "Deployment" ,
89
+ Version : "v1" ,
90
+ }
85
91
// Pod is invalid without a container field in the PodSpec
86
92
pod = & corev1.Pod {
87
93
ObjectMeta : metav1.ObjectMeta {Name : fmt .Sprintf ("pod-%v" , count ), Namespace : ns },
@@ -453,6 +459,26 @@ var _ = Describe("Client", func() {
453
459
close (done )
454
460
})
455
461
462
+ It ("should update and preserve type information" , func (done Done ) {
463
+ cl , err := client .New (cfg , client.Options {})
464
+ Expect (err ).NotTo (HaveOccurred ())
465
+ Expect (cl ).NotTo (BeNil ())
466
+
467
+ By ("initially creating a Deployment" )
468
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
469
+ Expect (err ).NotTo (HaveOccurred ())
470
+
471
+ By ("updating the Deployment" )
472
+ dep .SetGroupVersionKind (depGvk )
473
+ err = cl .Update (context .TODO (), dep )
474
+ Expect (err ).NotTo (HaveOccurred ())
475
+
476
+ By ("validating updated Deployment has type information" )
477
+ Expect (dep .GroupVersionKind ()).To (Equal (depGvk ))
478
+
479
+ close (done )
480
+ })
481
+
456
482
It ("should update an existing object non-namespace object from a go struct" , func (done Done ) {
457
483
cl , err := client .New (cfg , client.Options {})
458
484
Expect (err ).NotTo (HaveOccurred ())
@@ -550,6 +576,29 @@ var _ = Describe("Client", func() {
550
576
close (done )
551
577
})
552
578
579
+ It ("should update and preserve type information" , func (done Done ) {
580
+ cl , err := client .New (cfg , client.Options {})
581
+ Expect (err ).NotTo (HaveOccurred ())
582
+ Expect (cl ).NotTo (BeNil ())
583
+
584
+ By ("initially creating a Deployment" )
585
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
586
+ Expect (err ).NotTo (HaveOccurred ())
587
+
588
+ By ("updating the Deployment" )
589
+ u := & unstructured.Unstructured {}
590
+ Expect (scheme .Convert (dep , u , nil )).To (Succeed ())
591
+ u .SetGroupVersionKind (depGvk )
592
+ u .SetAnnotations (map [string ]string {"foo" : "bar" })
593
+ err = cl .Update (context .TODO (), u )
594
+ Expect (err ).NotTo (HaveOccurred ())
595
+
596
+ By ("validating updated Deployment has type information" )
597
+ Expect (u .GroupVersionKind ()).To (Equal (depGvk ))
598
+
599
+ close (done )
600
+ })
601
+
553
602
It ("should update an existing object non-namespace object from a go struct" , func (done Done ) {
554
603
cl , err := client .New (cfg , client.Options {})
555
604
Expect (err ).NotTo (HaveOccurred ())
@@ -586,11 +635,7 @@ var _ = Describe("Client", func() {
586
635
By ("updating non-existent object" )
587
636
u := & unstructured.Unstructured {}
588
637
Expect (scheme .Convert (dep , u , nil )).To (Succeed ())
589
- u .SetGroupVersionKind (schema.GroupVersionKind {
590
- Group : "apps" ,
591
- Kind : "Deployment" ,
592
- Version : "v1" ,
593
- })
638
+ u .SetGroupVersionKind (depGvk )
594
639
err = cl .Update (context .TODO (), dep )
595
640
Expect (err ).To (HaveOccurred ())
596
641
@@ -624,6 +669,49 @@ var _ = Describe("Client", func() {
624
669
close (done )
625
670
})
626
671
672
+ It ("should update status and preserve type information" , func (done Done ) {
673
+ cl , err := client .New (cfg , client.Options {})
674
+ Expect (err ).NotTo (HaveOccurred ())
675
+ Expect (cl ).NotTo (BeNil ())
676
+
677
+ By ("initially creating a Deployment" )
678
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
679
+ Expect (err ).NotTo (HaveOccurred ())
680
+
681
+ By ("updating the status of Deployment" )
682
+ dep .SetGroupVersionKind (depGvk )
683
+ dep .Status .Replicas = 1
684
+ err = cl .Status ().Update (context .TODO (), dep )
685
+ Expect (err ).NotTo (HaveOccurred ())
686
+
687
+ By ("validating updated Deployment has type information" )
688
+ Expect (dep .GroupVersionKind ()).To (Equal (depGvk ))
689
+
690
+ close (done )
691
+ })
692
+
693
+ It ("should patch status and preserve type information" , func (done Done ) {
694
+ cl , err := client .New (cfg , client.Options {})
695
+ Expect (err ).NotTo (HaveOccurred ())
696
+ Expect (cl ).NotTo (BeNil ())
697
+
698
+ By ("initially creating a Deployment" )
699
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
700
+ Expect (err ).NotTo (HaveOccurred ())
701
+
702
+ By ("patching the status of Deployment" )
703
+ dep .SetGroupVersionKind (depGvk )
704
+ depPatch := client .MergeFrom (dep .DeepCopy ())
705
+ dep .Status .Replicas = 1
706
+ err = cl .Status ().Patch (context .TODO (), dep , depPatch )
707
+ Expect (err ).NotTo (HaveOccurred ())
708
+
709
+ By ("validating updated Deployment has type information" )
710
+ Expect (dep .GroupVersionKind ()).To (Equal (depGvk ))
711
+
712
+ close (done )
713
+ })
714
+
627
715
It ("should not update spec of an existing object" , func (done Done ) {
628
716
cl , err := client .New (cfg , client.Options {})
629
717
Expect (err ).NotTo (HaveOccurred ())
@@ -1001,6 +1089,26 @@ var _ = Describe("Client", func() {
1001
1089
close (done )
1002
1090
})
1003
1091
1092
+ It ("should patch and preserve type information" , func (done Done ) {
1093
+ cl , err := client .New (cfg , client.Options {})
1094
+ Expect (err ).NotTo (HaveOccurred ())
1095
+ Expect (cl ).NotTo (BeNil ())
1096
+
1097
+ By ("initially creating a Deployment" )
1098
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
1099
+ Expect (err ).NotTo (HaveOccurred ())
1100
+
1101
+ By ("patching the Deployment" )
1102
+ dep .SetGroupVersionKind (depGvk )
1103
+ err = cl .Patch (context .TODO (), dep , client .ConstantPatch (types .MergePatchType , mergePatch ))
1104
+ Expect (err ).NotTo (HaveOccurred ())
1105
+
1106
+ By ("validating updated Deployment has type information" )
1107
+ Expect (dep .GroupVersionKind ()).To (Equal (depGvk ))
1108
+
1109
+ close (done )
1110
+ })
1111
+
1004
1112
It ("should patch an existing object non-namespace object from a go struct" , func (done Done ) {
1005
1113
cl , err := client .New (cfg , client.Options {})
1006
1114
Expect (err ).NotTo (HaveOccurred ())
@@ -1115,6 +1223,28 @@ var _ = Describe("Client", func() {
1115
1223
close (done )
1116
1224
})
1117
1225
1226
+ It ("should patch and preserve type information" , func (done Done ) {
1227
+ cl , err := client .New (cfg , client.Options {})
1228
+ Expect (err ).NotTo (HaveOccurred ())
1229
+ Expect (cl ).NotTo (BeNil ())
1230
+
1231
+ By ("initially creating a Deployment" )
1232
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
1233
+ Expect (err ).NotTo (HaveOccurred ())
1234
+
1235
+ By ("patching the Deployment" )
1236
+ u := & unstructured.Unstructured {}
1237
+ Expect (scheme .Convert (dep , u , nil )).To (Succeed ())
1238
+ u .SetGroupVersionKind (depGvk )
1239
+ err = cl .Patch (context .TODO (), u , client .ConstantPatch (types .MergePatchType , mergePatch ))
1240
+ Expect (err ).NotTo (HaveOccurred ())
1241
+
1242
+ By ("validating updated Deployment has type information" )
1243
+ Expect (u .GroupVersionKind ()).To (Equal (depGvk ))
1244
+
1245
+ close (done )
1246
+ })
1247
+
1118
1248
It ("should patch an existing object non-namespace object from a go struct" , func (done Done ) {
1119
1249
cl , err := client .New (cfg , client.Options {})
1120
1250
Expect (err ).NotTo (HaveOccurred ())
0 commit comments