@@ -541,114 +541,218 @@ var _ = Describe("Client", func() {
541
541
})
542
542
543
543
Describe ("StatusClient" , func () {
544
- It ("should update status of an existing object" , func (done Done ) {
545
- cl , err := client .New (cfg , client.Options {})
546
- Expect (err ).NotTo (HaveOccurred ())
547
- Expect (cl ).NotTo (BeNil ())
544
+ Context ("with structured objects" , func () {
545
+ It ("should update status of an existing object" , func (done Done ) {
546
+ cl , err := client .New (cfg , client.Options {})
547
+ Expect (err ).NotTo (HaveOccurred ())
548
+ Expect (cl ).NotTo (BeNil ())
548
549
549
- By ("initially creating a Deployment" )
550
- dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
551
- Expect (err ).NotTo (HaveOccurred ())
550
+ By ("initially creating a Deployment" )
551
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
552
+ Expect (err ).NotTo (HaveOccurred ())
552
553
553
- By ("updating the status of Deployment" )
554
- dep .Status .Replicas = 1
555
- err = cl .Status ().Update (context .TODO (), dep )
556
- Expect (err ).NotTo (HaveOccurred ())
554
+ By ("updating the status of Deployment" )
555
+ dep .Status .Replicas = 1
556
+ err = cl .Status ().Update (context .TODO (), dep )
557
+ Expect (err ).NotTo (HaveOccurred ())
557
558
558
- By ("validating updated Deployment has new status" )
559
- actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
560
- Expect (err ).NotTo (HaveOccurred ())
561
- Expect (actual ).NotTo (BeNil ())
562
- Expect (actual .Status .Replicas ).To (BeEquivalentTo (1 ))
559
+ By ("validating updated Deployment has new status" )
560
+ actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
561
+ Expect (err ).NotTo (HaveOccurred ())
562
+ Expect (actual ).NotTo (BeNil ())
563
+ Expect (actual .Status .Replicas ).To (BeEquivalentTo (1 ))
563
564
564
- close (done )
565
- })
565
+ close (done )
566
+ })
566
567
567
- It ("should not update spec of an existing object" , func (done Done ) {
568
- cl , err := client .New (cfg , client.Options {})
569
- Expect (err ).NotTo (HaveOccurred ())
570
- Expect (cl ).NotTo (BeNil ())
568
+ It ("should not update spec of an existing object" , func (done Done ) {
569
+ cl , err := client .New (cfg , client.Options {})
570
+ Expect (err ).NotTo (HaveOccurred ())
571
+ Expect (cl ).NotTo (BeNil ())
571
572
572
- By ("initially creating a Deployment" )
573
- dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
574
- Expect (err ).NotTo (HaveOccurred ())
573
+ By ("initially creating a Deployment" )
574
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
575
+ Expect (err ).NotTo (HaveOccurred ())
575
576
576
- By ("updating the spec and status of Deployment" )
577
- var rc int32 = 1
578
- dep .Status .Replicas = 1
579
- dep .Spec .Replicas = & rc
580
- err = cl .Status ().Update (context .TODO (), dep )
581
- Expect (err ).NotTo (HaveOccurred ())
577
+ By ("updating the spec and status of Deployment" )
578
+ var rc int32 = 1
579
+ dep .Status .Replicas = 1
580
+ dep .Spec .Replicas = & rc
581
+ err = cl .Status ().Update (context .TODO (), dep )
582
+ Expect (err ).NotTo (HaveOccurred ())
582
583
583
- By ("validating updated Deployment has new status and unchanged spec" )
584
- actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
585
- Expect (err ).NotTo (HaveOccurred ())
586
- Expect (actual ).NotTo (BeNil ())
587
- Expect (actual .Status .Replicas ).To (BeEquivalentTo (1 ))
588
- Expect (* actual .Spec .Replicas ).To (BeEquivalentTo (replicaCount ))
584
+ By ("validating updated Deployment has new status and unchanged spec" )
585
+ actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
586
+ Expect (err ).NotTo (HaveOccurred ())
587
+ Expect (actual ).NotTo (BeNil ())
588
+ Expect (actual .Status .Replicas ).To (BeEquivalentTo (1 ))
589
+ Expect (* actual .Spec .Replicas ).To (BeEquivalentTo (replicaCount ))
589
590
590
- close (done )
591
- })
591
+ close (done )
592
+ })
592
593
593
- It ("should update an existing object non-namespace object" , func (done Done ) {
594
- cl , err := client .New (cfg , client.Options {})
595
- Expect (err ).NotTo (HaveOccurred ())
596
- Expect (cl ).NotTo (BeNil ())
594
+ It ("should update an existing object non-namespace object" , func (done Done ) {
595
+ cl , err := client .New (cfg , client.Options {})
596
+ Expect (err ).NotTo (HaveOccurred ())
597
+ Expect (cl ).NotTo (BeNil ())
597
598
598
- node , err := clientset .CoreV1 ().Nodes ().Create (node )
599
- Expect (err ).NotTo (HaveOccurred ())
599
+ node , err := clientset .CoreV1 ().Nodes ().Create (node )
600
+ Expect (err ).NotTo (HaveOccurred ())
600
601
601
- By ("updating status of the object" )
602
- node .Status .Phase = corev1 .NodeRunning
603
- err = cl .Status ().Update (context .TODO (), node )
604
- Expect (err ).NotTo (HaveOccurred ())
602
+ By ("updating status of the object" )
603
+ node .Status .Phase = corev1 .NodeRunning
604
+ err = cl .Status ().Update (context .TODO (), node )
605
+ Expect (err ).NotTo (HaveOccurred ())
605
606
606
- By ("validate updated Node had new annotation" )
607
- actual , err := clientset .CoreV1 ().Nodes ().Get (node .Name , metav1.GetOptions {})
608
- Expect (err ).NotTo (HaveOccurred ())
609
- Expect (actual ).NotTo (BeNil ())
610
- Expect (actual .Status .Phase ).To (Equal (corev1 .NodeRunning ))
607
+ By ("validate updated Node had new annotation" )
608
+ actual , err := clientset .CoreV1 ().Nodes ().Get (node .Name , metav1.GetOptions {})
609
+ Expect (err ).NotTo (HaveOccurred ())
610
+ Expect (actual ).NotTo (BeNil ())
611
+ Expect (actual .Status .Phase ).To (Equal (corev1 .NodeRunning ))
611
612
612
- close (done )
613
- })
613
+ close (done )
614
+ })
614
615
615
- It ("should fail if the object does not exists" , func (done Done ) {
616
- cl , err := client .New (cfg , client.Options {})
617
- Expect (err ).NotTo (HaveOccurred ())
618
- Expect (cl ).NotTo (BeNil ())
616
+ It ("should fail if the object does not exists" , func (done Done ) {
617
+ cl , err := client .New (cfg , client.Options {})
618
+ Expect (err ).NotTo (HaveOccurred ())
619
+ Expect (cl ).NotTo (BeNil ())
619
620
620
- By ("updating status of a non-existent object" )
621
- err = cl .Status ().Update (context .TODO (), dep )
622
- Expect (err ).To (HaveOccurred ())
621
+ By ("updating status of a non-existent object" )
622
+ err = cl .Status ().Update (context .TODO (), dep )
623
+ Expect (err ).To (HaveOccurred ())
623
624
624
- close (done )
625
- })
625
+ close (done )
626
+ })
626
627
627
- It ("should fail if the object cannot be mapped to a GVK" , func (done Done ) {
628
- By ("creating client with empty Scheme" )
629
- emptyScheme := runtime .NewScheme ()
630
- cl , err := client .New (cfg , client.Options {Scheme : emptyScheme })
631
- Expect (err ).NotTo (HaveOccurred ())
632
- Expect (cl ).NotTo (BeNil ())
628
+ It ("should fail if the object cannot be mapped to a GVK" , func (done Done ) {
629
+ By ("creating client with empty Scheme" )
630
+ emptyScheme := runtime .NewScheme ()
631
+ cl , err := client .New (cfg , client.Options {Scheme : emptyScheme })
632
+ Expect (err ).NotTo (HaveOccurred ())
633
+ Expect (cl ).NotTo (BeNil ())
633
634
634
- By ("initially creating a Deployment" )
635
- dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
636
- Expect (err ).NotTo (HaveOccurred ())
635
+ By ("initially creating a Deployment" )
636
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
637
+ Expect (err ).NotTo (HaveOccurred ())
637
638
638
- By ("updating status of the Deployment" )
639
- dep .Status .Replicas = 1
640
- err = cl .Status ().Update (context .TODO (), dep )
641
- Expect (err ).To (HaveOccurred ())
642
- Expect (err .Error ()).To (ContainSubstring ("no kind is registered for the type" ))
639
+ By ("updating status of the Deployment" )
640
+ dep .Status .Replicas = 1
641
+ err = cl .Status ().Update (context .TODO (), dep )
642
+ Expect (err ).To (HaveOccurred ())
643
+ Expect (err .Error ()).To (ContainSubstring ("no kind is registered for the type" ))
643
644
644
- close (done )
645
- })
645
+ close (done )
646
+ })
646
647
647
- PIt ("should fail if the GVK cannot be mapped to a Resource" , func () {
648
+ PIt ("should fail if the GVK cannot be mapped to a Resource" , func () {
649
+
650
+ })
648
651
652
+ PIt ("should fail if an API does not implement Status subresource" , func () {
653
+
654
+ })
649
655
})
650
656
651
- PIt ("should fail if an API does not implement Status subresource" , func () {
657
+ Context ("with unstructured objects" , func () {
658
+ It ("should update status of an existing object" , func (done Done ) {
659
+ cl , err := client .New (cfg , client.Options {})
660
+ Expect (err ).NotTo (HaveOccurred ())
661
+ Expect (cl ).NotTo (BeNil ())
662
+
663
+ By ("initially creating a Deployment" )
664
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
665
+ Expect (err ).NotTo (HaveOccurred ())
666
+
667
+ By ("updating the status of Deployment" )
668
+ u := & unstructured.Unstructured {}
669
+ dep .Status .Replicas = 1
670
+ scheme .Convert (dep , u , nil )
671
+ err = cl .Status ().Update (context .TODO (), u )
672
+ Expect (err ).NotTo (HaveOccurred ())
673
+
674
+ By ("validating updated Deployment has new status" )
675
+ actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
676
+ Expect (err ).NotTo (HaveOccurred ())
677
+ Expect (actual ).NotTo (BeNil ())
678
+ Expect (actual .Status .Replicas ).To (BeEquivalentTo (1 ))
679
+
680
+ close (done )
681
+ })
682
+
683
+ It ("should not update spec of an existing object" , func (done Done ) {
684
+ cl , err := client .New (cfg , client.Options {})
685
+ Expect (err ).NotTo (HaveOccurred ())
686
+ Expect (cl ).NotTo (BeNil ())
687
+
688
+ By ("initially creating a Deployment" )
689
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
690
+ Expect (err ).NotTo (HaveOccurred ())
691
+
692
+ By ("updating the spec and status of Deployment" )
693
+ u := & unstructured.Unstructured {}
694
+ var rc int32 = 1
695
+ dep .Status .Replicas = 1
696
+ dep .Spec .Replicas = & rc
697
+ scheme .Convert (dep , u , nil )
698
+ err = cl .Status ().Update (context .TODO (), u )
699
+ Expect (err ).NotTo (HaveOccurred ())
700
+
701
+ By ("validating updated Deployment has new status and unchanged spec" )
702
+ actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
703
+ Expect (err ).NotTo (HaveOccurred ())
704
+ Expect (actual ).NotTo (BeNil ())
705
+ Expect (actual .Status .Replicas ).To (BeEquivalentTo (1 ))
706
+ Expect (* actual .Spec .Replicas ).To (BeEquivalentTo (replicaCount ))
707
+
708
+ close (done )
709
+ })
710
+
711
+ It ("should update an existing object non-namespace object" , func (done Done ) {
712
+ cl , err := client .New (cfg , client.Options {})
713
+ Expect (err ).NotTo (HaveOccurred ())
714
+ Expect (cl ).NotTo (BeNil ())
715
+
716
+ node , err := clientset .CoreV1 ().Nodes ().Create (node )
717
+ Expect (err ).NotTo (HaveOccurred ())
718
+
719
+ By ("updating status of the object" )
720
+ u := & unstructured.Unstructured {}
721
+ node .Status .Phase = corev1 .NodeRunning
722
+ scheme .Convert (node , u , nil )
723
+ err = cl .Status ().Update (context .TODO (), u )
724
+ Expect (err ).NotTo (HaveOccurred ())
725
+
726
+ By ("validate updated Node had new annotation" )
727
+ actual , err := clientset .CoreV1 ().Nodes ().Get (node .Name , metav1.GetOptions {})
728
+ Expect (err ).NotTo (HaveOccurred ())
729
+ Expect (actual ).NotTo (BeNil ())
730
+ Expect (actual .Status .Phase ).To (Equal (corev1 .NodeRunning ))
731
+
732
+ close (done )
733
+ })
734
+
735
+ It ("should fail if the object does not exists" , func (done Done ) {
736
+ cl , err := client .New (cfg , client.Options {})
737
+ Expect (err ).NotTo (HaveOccurred ())
738
+ Expect (cl ).NotTo (BeNil ())
739
+
740
+ By ("updating status of a non-existent object" )
741
+ u := & unstructured.Unstructured {}
742
+ scheme .Convert (dep , u , nil )
743
+ err = cl .Status ().Update (context .TODO (), u )
744
+ Expect (err ).To (HaveOccurred ())
745
+
746
+ close (done )
747
+ })
748
+
749
+ PIt ("should fail if the GVK cannot be mapped to a Resource" , func () {
750
+
751
+ })
752
+
753
+ PIt ("should fail if an API does not implement Status subresource" , func () {
754
+
755
+ })
652
756
653
757
})
654
758
})
0 commit comments