@@ -70,7 +70,7 @@ var _ = Describe("Client", func() {
70
70
BeforeEach (func (done Done ) {
71
71
atomic .AddUint64 (& count , 1 )
72
72
dep = & appsv1.Deployment {
73
- ObjectMeta : metav1.ObjectMeta {Name : fmt .Sprintf ("deployment-name-%v" , count ), Namespace : ns },
73
+ ObjectMeta : metav1.ObjectMeta {Name : fmt .Sprintf ("deployment-name-%v" , count ), Namespace : ns , Labels : map [ string ] string { "app" : fmt . Sprintf ( "bar-%v" , count )} },
74
74
Spec : appsv1.DeploymentSpec {
75
75
Replicas : & replicaCount ,
76
76
Selector : & metav1.LabelSelector {
@@ -898,6 +898,37 @@ var _ = Describe("Client", func() {
898
898
PIt ("should fail if the GVK cannot be mapped to a Resource" , func () {
899
899
900
900
})
901
+
902
+ It ("should delete a collection of objects" , func (done Done ) {
903
+ cl , err := client .New (cfg , client.Options {})
904
+ Expect (err ).NotTo (HaveOccurred ())
905
+ Expect (cl ).NotTo (BeNil ())
906
+
907
+ By ("initially creating two Deployments" )
908
+
909
+ dep2 := dep .DeepCopy ()
910
+ dep2 .Name = dep2 .Name + "-2"
911
+
912
+ dep , err = clientset .AppsV1 ().Deployments (ns ).Create (dep )
913
+ Expect (err ).NotTo (HaveOccurred ())
914
+ dep2 , err = clientset .AppsV1 ().Deployments (ns ).Create (dep2 )
915
+ Expect (err ).NotTo (HaveOccurred ())
916
+
917
+ depName := dep .Name
918
+ dep2Name := dep2 .Name
919
+
920
+ By ("deleting Deployments" )
921
+ err = cl .DeleteAllOf (context .TODO (), dep , client .InNamespace (ns ), client .MatchingLabels (dep .ObjectMeta .Labels ))
922
+ Expect (err ).NotTo (HaveOccurred ())
923
+
924
+ By ("validating the Deployment no longer exists" )
925
+ _ , err = clientset .AppsV1 ().Deployments (ns ).Get (depName , metav1.GetOptions {})
926
+ Expect (err ).To (HaveOccurred ())
927
+ _ , err = clientset .AppsV1 ().Deployments (ns ).Get (dep2Name , metav1.GetOptions {})
928
+ Expect (err ).To (HaveOccurred ())
929
+
930
+ close (done )
931
+ })
901
932
})
902
933
Context ("with unstructured objects" , func () {
903
934
It ("should delete an existing object from a go struct" , func (done Done ) {
@@ -974,6 +1005,44 @@ var _ = Describe("Client", func() {
974
1005
975
1006
close (done )
976
1007
})
1008
+
1009
+ It ("should delete a collection of object" , func (done Done ) {
1010
+ cl , err := client .New (cfg , client.Options {})
1011
+ Expect (err ).NotTo (HaveOccurred ())
1012
+ Expect (cl ).NotTo (BeNil ())
1013
+
1014
+ By ("initially creating two Deployments" )
1015
+
1016
+ dep2 := dep .DeepCopy ()
1017
+ dep2 .Name = dep2 .Name + "-2"
1018
+
1019
+ dep , err = clientset .AppsV1 ().Deployments (ns ).Create (dep )
1020
+ Expect (err ).NotTo (HaveOccurred ())
1021
+ dep2 , err = clientset .AppsV1 ().Deployments (ns ).Create (dep2 )
1022
+ Expect (err ).NotTo (HaveOccurred ())
1023
+
1024
+ depName := dep .Name
1025
+ dep2Name := dep2 .Name
1026
+
1027
+ By ("deleting Deployments" )
1028
+ u := & unstructured.Unstructured {}
1029
+ Expect (scheme .Convert (dep , u , nil )).To (Succeed ())
1030
+ u .SetGroupVersionKind (schema.GroupVersionKind {
1031
+ Group : "apps" ,
1032
+ Kind : "Deployment" ,
1033
+ Version : "v1" ,
1034
+ })
1035
+ err = cl .DeleteAllOf (context .TODO (), u , client .InNamespace (ns ), client .MatchingLabels (dep .ObjectMeta .Labels ))
1036
+ Expect (err ).NotTo (HaveOccurred ())
1037
+
1038
+ By ("validating the Deployment no longer exists" )
1039
+ _ , err = clientset .AppsV1 ().Deployments (ns ).Get (depName , metav1.GetOptions {})
1040
+ Expect (err ).To (HaveOccurred ())
1041
+ _ , err = clientset .AppsV1 ().Deployments (ns ).Get (dep2Name , metav1.GetOptions {})
1042
+ Expect (err ).To (HaveOccurred ())
1043
+
1044
+ close (done )
1045
+ })
977
1046
})
978
1047
})
979
1048
@@ -1994,6 +2063,10 @@ var _ = Describe("Client", func() {
1994
2063
PIt ("should fail if the object doesn't have meta" , func () {
1995
2064
1996
2065
})
2066
+
2067
+ PIt ("should filter results by namespace selector" , func () {
2068
+
2069
+ })
1997
2070
})
1998
2071
})
1999
2072
@@ -2072,6 +2145,34 @@ var _ = Describe("Client", func() {
2072
2145
})
2073
2146
})
2074
2147
2148
+ Describe ("DeleteCollectionOptions" , func () {
2149
+ It ("should be convertable to list options" , func () {
2150
+ gp := int64 (1 )
2151
+ do := & client.DeleteAllOfOptions {}
2152
+ do .ApplyOptions ([]client.DeleteAllOfOption {
2153
+ client .GracePeriodSeconds (gp ),
2154
+ client.MatchingLabels {"foo" : "bar" },
2155
+ })
2156
+
2157
+ listOpts := do .AsListOptions ()
2158
+ Expect (listOpts ).NotTo (BeNil ())
2159
+ Expect (listOpts .LabelSelector ).To (Equal ("foo=bar" ))
2160
+ })
2161
+
2162
+ It ("should be convertable to delete options" , func () {
2163
+ gp := int64 (1 )
2164
+ do := & client.DeleteAllOfOptions {}
2165
+ do .ApplyOptions ([]client.DeleteAllOfOption {
2166
+ client .GracePeriodSeconds (gp ),
2167
+ client.MatchingLabels {"foo" : "bar" },
2168
+ })
2169
+
2170
+ deleteOpts := do .AsDeleteOptions ()
2171
+ Expect (deleteOpts ).NotTo (BeNil ())
2172
+ Expect (deleteOpts .GracePeriodSeconds ).To (Equal (& gp ))
2173
+ })
2174
+ })
2175
+
2075
2176
Describe ("ListOptions" , func () {
2076
2177
It ("should be convertable to metav1.ListOptions" , func () {
2077
2178
lo := (& client.ListOptions {}).ApplyOptions ([]client.ListOption {
@@ -2105,6 +2206,13 @@ var _ = Describe("Client", func() {
2105
2206
Expect (lo ).NotTo (BeNil ())
2106
2207
Expect (lo .Namespace ).To (Equal ("test" ))
2107
2208
})
2209
+
2210
+ It ("should produce empty metav1.ListOptions if nil" , func () {
2211
+ var do * client.ListOptions
2212
+ Expect (do .AsListOptions ()).To (Equal (& metav1.ListOptions {}))
2213
+ do = & client.ListOptions {}
2214
+ Expect (do .AsListOptions ()).To (Equal (& metav1.ListOptions {}))
2215
+ })
2108
2216
})
2109
2217
2110
2218
Describe ("UpdateOptions" , func () {
0 commit comments