@@ -58,13 +58,15 @@ var _ = Describe("Client", func() {
58
58
var pod * corev1.Pod
59
59
var node * corev1.Node
60
60
var count uint64 = 0
61
+ var replicaCount int32 = 2
61
62
var ns = "default"
62
63
63
64
BeforeEach (func (done Done ) {
64
65
atomic .AddUint64 (& count , 1 )
65
66
dep = & appsv1.Deployment {
66
67
ObjectMeta : metav1.ObjectMeta {Name : fmt .Sprintf ("deployment-name-%v" , count ), Namespace : ns },
67
68
Spec : appsv1.DeploymentSpec {
69
+ Replicas : & replicaCount ,
68
70
Selector : & metav1.LabelSelector {
69
71
MatchLabels : map [string ]string {"foo" : "bar" },
70
72
},
@@ -391,6 +393,127 @@ var _ = Describe("Client", func() {
391
393
})
392
394
})
393
395
396
+ Describe ("UpdateStatus" , func () {
397
+ It ("should update status of an existing object" , func (done Done ) {
398
+ cl , err := client .New (cfg , client.Options {})
399
+ Expect (err ).NotTo (HaveOccurred ())
400
+ Expect (cl ).NotTo (BeNil ())
401
+
402
+ By ("initially creating a Deployment" )
403
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
404
+ Expect (err ).NotTo (HaveOccurred ())
405
+
406
+ By ("updating the status of Deployment" )
407
+ dep .Status .Replicas = 1
408
+ err = cl .UpdateStatus (context .TODO (), dep )
409
+ Expect (err ).NotTo (HaveOccurred ())
410
+
411
+ By ("validating updated Deployment has new status" )
412
+ actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
413
+ Expect (err ).NotTo (HaveOccurred ())
414
+ Expect (actual ).NotTo (BeNil ())
415
+ Expect (actual .Status .Replicas ).To (BeEquivalentTo (1 ))
416
+
417
+ close (done )
418
+ })
419
+
420
+ It ("should not update spec of an existing object" , func (done Done ) {
421
+ cl , err := client .New (cfg , client.Options {})
422
+ Expect (err ).NotTo (HaveOccurred ())
423
+ Expect (cl ).NotTo (BeNil ())
424
+
425
+ By ("initially creating a Deployment" )
426
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
427
+ Expect (err ).NotTo (HaveOccurred ())
428
+
429
+ By ("updating the spec and status of Deployment" )
430
+ var rc int32 = 1
431
+ dep .Status .Replicas = 1
432
+ dep .Spec .Replicas = & rc
433
+ err = cl .UpdateStatus (context .TODO (), dep )
434
+ Expect (err ).NotTo (HaveOccurred ())
435
+
436
+ By ("validating updated Deployment has new status and unchanged spec" )
437
+ actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
438
+ Expect (err ).NotTo (HaveOccurred ())
439
+ Expect (actual ).NotTo (BeNil ())
440
+ Expect (actual .Status .Replicas ).To (BeEquivalentTo (1 ))
441
+ Expect (* actual .Spec .Replicas ).To (BeEquivalentTo (replicaCount ))
442
+
443
+ close (done )
444
+ })
445
+
446
+ It ("should update an existing object non-namespace object" , func (done Done ) {
447
+ cl , err := client .New (cfg , client.Options {})
448
+ Expect (err ).NotTo (HaveOccurred ())
449
+ Expect (cl ).NotTo (BeNil ())
450
+
451
+ node , err := clientset .CoreV1 ().Nodes ().Create (node )
452
+ Expect (err ).NotTo (HaveOccurred ())
453
+
454
+ By ("updating status of the object" )
455
+ node .Status .Phase = corev1 .NodeRunning
456
+ err = cl .UpdateStatus (context .TODO (), node )
457
+ Expect (err ).NotTo (HaveOccurred ())
458
+
459
+ By ("validate updated Node had new annotation" )
460
+ actual , err := clientset .CoreV1 ().Nodes ().Get (node .Name , metav1.GetOptions {})
461
+ Expect (err ).NotTo (HaveOccurred ())
462
+ Expect (actual ).NotTo (BeNil ())
463
+ Expect (actual .Status .Phase ).To (Equal (corev1 .NodeRunning ))
464
+
465
+ close (done )
466
+ })
467
+
468
+ It ("should fail if the object does not exists" , func (done Done ) {
469
+ cl , err := client .New (cfg , client.Options {})
470
+ Expect (err ).NotTo (HaveOccurred ())
471
+ Expect (cl ).NotTo (BeNil ())
472
+
473
+ By ("updating status of a non-existent object" )
474
+ err = cl .UpdateStatus (context .TODO (), dep )
475
+ Expect (err ).To (HaveOccurred ())
476
+
477
+ close (done )
478
+ })
479
+
480
+ It ("should fail if the object does not pass server-side validation" , func () {
481
+
482
+ })
483
+
484
+ It ("should fail if the object doesn't have meta" , func () {
485
+
486
+ })
487
+
488
+ It ("should fail if the object cannot be mapped to a GVK" , func (done Done ) {
489
+ By ("creating client with empty Scheme" )
490
+ emptyScheme := runtime .NewScheme ()
491
+ cl , err := client .New (cfg , client.Options {Scheme : emptyScheme })
492
+ Expect (err ).NotTo (HaveOccurred ())
493
+ Expect (cl ).NotTo (BeNil ())
494
+
495
+ By ("initially creating a Deployment" )
496
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
497
+ Expect (err ).NotTo (HaveOccurred ())
498
+
499
+ By ("updating status of the Deployment" )
500
+ dep .Status .Replicas = 1
501
+ err = cl .UpdateStatus (context .TODO (), dep )
502
+ Expect (err ).To (HaveOccurred ())
503
+ Expect (err .Error ()).To (ContainSubstring ("no kind is registered for the type" ))
504
+
505
+ close (done )
506
+ })
507
+
508
+ It ("should fail if the GVK cannot be mapped to a Resource" , func () {
509
+
510
+ })
511
+
512
+ It ("should fail if an API does not implement Status subresource" , func () {
513
+
514
+ })
515
+ })
516
+
394
517
Describe ("Delete" , func () {
395
518
It ("should delete an existing object from a go struct" , func (done Done ) {
396
519
cl , err := client .New (cfg , client.Options {})
0 commit comments