@@ -4,10 +4,11 @@ package integration
4
4
5
5
import (
6
6
"bytes"
7
+ "context"
7
8
"fmt"
8
9
9
10
appsv1 "k8s.io/api/apps/v1"
10
- "k8s.io/api/core/v1"
11
+ v1 "k8s.io/api/core/v1"
11
12
"k8s.io/apimachinery/pkg/api/errors"
12
13
"k8s.io/apimachinery/pkg/api/resource"
13
14
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -116,7 +117,7 @@ var _ = Describe("update", func() {
116
117
117
118
Context ("With no existing state" , func () {
118
119
It ("should produce expected object" , func () {
119
- Expect (c .ConfigMaps (ns ).Get (cmName , metav1.GetOptions {})).
120
+ Expect (c .ConfigMaps (ns ).Get (context . Background (), cmName , metav1.GetOptions {})).
120
121
To (WithTransform (cmData , HaveKeyWithValue ("foo" , "bar" )))
121
122
Expect (kubecfgOut .String ()).
122
123
To (ContainSubstring ("Creating configmaps %s" , cmName ))
@@ -127,12 +128,12 @@ var _ = Describe("update", func() {
127
128
128
129
Context ("With existing non-kubecfg object" , func () {
129
130
BeforeEach (func () {
130
- _ , err := c .ConfigMaps (ns ).Create (cm )
131
+ _ , err := c .ConfigMaps (ns ).Create (context . Background (), cm , metav1. CreateOptions {} )
131
132
Expect (err ).NotTo (HaveOccurred ())
132
133
})
133
134
134
135
It ("should succeed" , func () {
135
- Expect (c .ConfigMaps (ns ).Get (cmName , metav1.GetOptions {})).
136
+ Expect (c .ConfigMaps (ns ).Get (context . Background (), cmName , metav1.GetOptions {})).
136
137
To (WithTransform (cmData , HaveKeyWithValue ("foo" , "bar" )))
137
138
// NB: may report "Updating" - that's ok.
138
139
Expect (kubecfgOut .String ()).
@@ -145,12 +146,12 @@ var _ = Describe("update", func() {
145
146
err := runKubecfgWith ([]string {"update" , "-vv" , "-n" , ns }, []runtime.Object {cm })
146
147
Expect (err ).NotTo (HaveOccurred ())
147
148
148
- Expect (c .ConfigMaps (ns ).Get (cmName , metav1.GetOptions {})).
149
+ Expect (c .ConfigMaps (ns ).Get (context . Background (), cmName , metav1.GetOptions {})).
149
150
To (WithTransform (metav1 .Object .GetAnnotations , HaveKey (kubecfg .AnnotationOrigObject )))
150
151
})
151
152
152
153
It ("should not report a change" , func () {
153
- Expect (c .ConfigMaps (ns ).Get (cmName , metav1.GetOptions {})).
154
+ Expect (c .ConfigMaps (ns ).Get (context . Background (), cmName , metav1.GetOptions {})).
154
155
To (WithTransform (cmData , HaveKeyWithValue ("foo" , "bar" )))
155
156
// no change -> should report neither Updating nor Creating
156
157
Expect (kubecfgOut .String ()).
@@ -172,7 +173,7 @@ var _ = Describe("update", func() {
172
173
})
173
174
174
175
It ("should update the object" , func () {
175
- Expect (c .ConfigMaps (ns ).Get (cmName , metav1.GetOptions {})).
176
+ Expect (c .ConfigMaps (ns ).Get (context . Background (), cmName , metav1.GetOptions {})).
176
177
To (WithTransform (cmData , HaveKeyWithValue ("foo" , "bar" )))
177
178
Expect (kubecfgOut .String ()).
178
179
To (ContainSubstring ("Updating configmaps %s" , cmName ))
@@ -193,14 +194,14 @@ var _ = Describe("update", func() {
193
194
Expect (err ).NotTo (HaveOccurred ())
194
195
195
196
// ... and then modified by another controller/whatever.
196
- o , err := c .ConfigMaps (ns ).Patch (cmName , types .MergePatchType ,
197
- []byte (`{"metadata": {"annotations": {"addedby": "3rd-party"}}}` ))
197
+ o , err := c .ConfigMaps (ns ).Patch (context . Background (), cmName , types .MergePatchType ,
198
+ []byte (`{"metadata": {"annotations": {"addedby": "3rd-party"}}}` ), metav1. PatchOptions {} )
198
199
Expect (err ).NotTo (HaveOccurred ())
199
200
fmt .Fprintf (GinkgoWriter , "patch result is %v\n " , o )
200
201
})
201
202
202
203
It ("should update the object" , func () {
203
- cm , err := c .ConfigMaps (ns ).Get (cmName , metav1.GetOptions {})
204
+ cm , err := c .ConfigMaps (ns ).Get (context . Background (), cmName , metav1.GetOptions {})
204
205
Expect (err ).NotTo (HaveOccurred ())
205
206
Expect (cm ).To (WithTransform (cmData , HaveKeyWithValue ("foo" , "bar" )))
206
207
Expect (cm ).To (WithTransform (metav1 .Object .GetAnnotations , And (
@@ -282,11 +283,11 @@ var _ = Describe("update", func() {
282
283
Version : "v1beta1" ,
283
284
Resource : "customresourcedefinitions" ,
284
285
})
285
- _ = rc .Delete ("things.random.example.com" , & metav1.DeleteOptions {})
286
+ _ = rc .Delete (context . Background (), "things.random.example.com" , metav1.DeleteOptions {})
286
287
})
287
288
288
289
It ("should update correctly" , func () {
289
- Expect (rc .Namespace (ns ).Get ("thing1" , metav1.GetOptions {})).
290
+ Expect (rc .Namespace (ns ).Get (context . Background (), "thing1" , metav1.GetOptions {})).
290
291
To (WithTransform (metav1 .Object .GetAnnotations ,
291
292
HaveKeyWithValue ("gen" , "one" )))
292
293
@@ -297,7 +298,7 @@ var _ = Describe("update", func() {
297
298
Expect (err ).NotTo (HaveOccurred ())
298
299
299
300
// Verify result
300
- Expect (rc .Namespace (ns ).Get ("thing1" , metav1.GetOptions {})).
301
+ Expect (rc .Namespace (ns ).Get (context . Background (), "thing1" , metav1.GetOptions {})).
301
302
To (WithTransform (metav1 .Object .GetAnnotations , And (
302
303
HaveKeyWithValue ("gen" , "two" ),
303
304
HaveKeyWithValue ("unrelated" , "baz" ),
@@ -328,7 +329,7 @@ var _ = Describe("update", func() {
328
329
})
329
330
330
331
It ("should not change ports on subsequent updates" , func () {
331
- svc , err := c .Services (ns ).Get (svcName , metav1.GetOptions {})
332
+ svc , err := c .Services (ns ).Get (context . Background (), svcName , metav1.GetOptions {})
332
333
Expect (err ).NotTo (HaveOccurred ())
333
334
Expect (svc ).To (WithTransform (metav1 .Object .GetAnnotations ,
334
335
HaveKeyWithValue ("generation" , "one" )))
@@ -341,7 +342,7 @@ var _ = Describe("update", func() {
341
342
Expect (err ).NotTo (HaveOccurred ())
342
343
343
344
// Check NodePort hasn't changed
344
- svc , err = c .Services (ns ).Get (svcName , metav1.GetOptions {})
345
+ svc , err = c .Services (ns ).Get (context . Background (), svcName , metav1.GetOptions {})
345
346
Expect (err ).NotTo (HaveOccurred ())
346
347
Expect (svc ).To (WithTransform (metav1 .Object .GetAnnotations ,
347
348
HaveKeyWithValue ("generation" , "two" )))
@@ -384,9 +385,10 @@ var _ = Describe("update", func() {
384
385
It ("should merge correctly into containers[]" , func () {
385
386
// Simulate change by 3rd-party
386
387
appsc := appsv1client .NewForConfigOrDie (clusterConfigOrDie ())
387
- _ , err := appsc .Deployments (ns ).Patch (deployName ,
388
+ _ , err := appsc .Deployments (ns ).Patch (context . Background (), deployName ,
388
389
types .StrategicMergePatchType ,
389
390
[]byte (`{"spec": {"template": {"spec": {"containers": [{"name": "c", "resources": {"limits": {"cpu": "1"}}}]}}}}` ),
391
+ metav1.PatchOptions {},
390
392
)
391
393
Expect (err ).NotTo (HaveOccurred ())
392
394
@@ -396,7 +398,7 @@ var _ = Describe("update", func() {
396
398
Expect (err ).NotTo (HaveOccurred ())
397
399
398
400
// Check container.resources was preserved
399
- d , err := appsc .Deployments (ns ).Get (deployName , metav1.GetOptions {})
401
+ d , err := appsc .Deployments (ns ).Get (context . Background (), deployName , metav1.GetOptions {})
400
402
Expect (err ).NotTo (HaveOccurred ())
401
403
Expect (d ).To (WithTransform (metav1 .Object .GetAnnotations ,
402
404
HaveKeyWithValue ("gen" , "two" )))
@@ -437,13 +439,13 @@ var _ = Describe("update", func() {
437
439
})
438
440
439
441
It ("should create objects in the correct namespaces" , func () {
440
- Expect (c .ConfigMaps (ns ).Get ("nons" , metav1.GetOptions {})).
442
+ Expect (c .ConfigMaps (ns ).Get (context . Background (), "nons" , metav1.GetOptions {})).
441
443
NotTo (BeNil ())
442
444
443
- Expect (c .ConfigMaps (ns ).Get ("ns1" , metav1.GetOptions {})).
445
+ Expect (c .ConfigMaps (ns ).Get (context . Background (), "ns1" , metav1.GetOptions {})).
444
446
NotTo (BeNil ())
445
447
446
- Expect (c .ConfigMaps (ns2 ).Get ("ns2" , metav1.GetOptions {})).
448
+ Expect (c .ConfigMaps (ns2 ).Get (context . Background (), "ns2" , metav1.GetOptions {})).
447
449
NotTo (BeNil ())
448
450
})
449
451
})
@@ -465,7 +467,7 @@ var _ = Describe("update", func() {
465
467
466
468
JustBeforeEach (func () {
467
469
for _ , obj := range preExist {
468
- _ , err := c .ConfigMaps (ns ).Create (obj )
470
+ _ , err := c .ConfigMaps (ns ).Create (context . Background (), obj , metav1. CreateOptions {} )
469
471
Expect (err ).NotTo (HaveOccurred ())
470
472
}
471
473
@@ -578,7 +580,7 @@ var _ = Describe("update", func() {
578
580
})
579
581
580
582
It ("should add gctag to new object" , func () {
581
- o , err := c .ConfigMaps (ns ).Get ("new" , metav1.GetOptions {})
583
+ o , err := c .ConfigMaps (ns ).Get (context . Background (), "new" , metav1.GetOptions {})
582
584
Expect (err ).NotTo (HaveOccurred ())
583
585
// [gctag-migration]: Remove annotation in phase2
584
586
Expect (o .ObjectMeta .Annotations ).
@@ -588,7 +590,7 @@ var _ = Describe("update", func() {
588
590
})
589
591
590
592
It ("should keep gctag on existing object" , func () {
591
- o , err := c .ConfigMaps (ns ).Get ("existing" , metav1.GetOptions {})
593
+ o , err := c .ConfigMaps (ns ).Get (context . Background (), "existing" , metav1.GetOptions {})
592
594
Expect (err ).NotTo (HaveOccurred ())
593
595
// [gctag-migration]: Remove annotation in phase2
594
596
Expect (o .ObjectMeta .Annotations ).
@@ -599,29 +601,29 @@ var _ = Describe("update", func() {
599
601
600
602
// [gctag-migration]: Pre-migration test. Remove in phase2
601
603
It ("should add gctag label to pre-migration object" , func () {
602
- o , err := c .ConfigMaps (ns ).Get ("existing-premigration" , metav1.GetOptions {})
604
+ o , err := c .ConfigMaps (ns ).Get (context . Background (), "existing-premigration" , metav1.GetOptions {})
603
605
Expect (err ).NotTo (HaveOccurred ())
604
606
Expect (o .ObjectMeta .Labels ).
605
607
To (HaveKeyWithValue (kubecfg .LabelGcTag , gcTag ))
606
608
})
607
609
608
610
It ("should delete stale object" , func () {
609
- _ , err := c .ConfigMaps (ns ).Get ("existing-stale" , metav1.GetOptions {})
611
+ _ , err := c .ConfigMaps (ns ).Get (context . Background (), "existing-stale" , metav1.GetOptions {})
610
612
Expect (errors .IsNotFound (err )).To (BeTrue ())
611
613
})
612
614
613
615
It ("should not delete tagless object" , func () {
614
- Expect (c .ConfigMaps (ns ).Get ("existing-stale-notag" , metav1.GetOptions {})).
616
+ Expect (c .ConfigMaps (ns ).Get (context . Background (), "existing-stale-notag" , metav1.GetOptions {})).
615
617
NotTo (BeNil ())
616
618
})
617
619
618
620
It ("should not delete object with different gc tag" , func () {
619
- Expect (c .ConfigMaps (ns ).Get ("existing-othertag" , metav1.GetOptions {})).
621
+ Expect (c .ConfigMaps (ns ).Get (context . Background (), "existing-othertag" , metav1.GetOptions {})).
620
622
NotTo (BeNil ())
621
623
})
622
624
623
625
It ("should not delete strategy=ignore object" , func () {
624
- Expect (c .ConfigMaps (ns ).Get ("existing-precious" , metav1.GetOptions {})).
626
+ Expect (c .ConfigMaps (ns ).Get (context . Background (), "existing-precious" , metav1.GetOptions {})).
625
627
NotTo (BeNil ())
626
628
})
627
629
})
@@ -653,12 +655,12 @@ var _ = Describe("update", func() {
653
655
})
654
656
655
657
It ("should not delete existing object" , func () {
656
- Expect (c .ConfigMaps (ns ).Get ("existing" , metav1.GetOptions {})).
658
+ Expect (c .ConfigMaps (ns ).Get (context . Background (), "existing" , metav1.GetOptions {})).
657
659
NotTo (BeNil ())
658
660
})
659
661
660
662
It ("should not create new object" , func () {
661
- _ , err := c .ConfigMaps (ns ).Get ("new" , metav1.GetOptions {})
663
+ _ , err := c .ConfigMaps (ns ).Get (context . Background (), "new" , metav1.GetOptions {})
662
664
Expect (errors .IsNotFound (err )).To (BeTrue ())
663
665
})
664
666
})
@@ -690,12 +692,12 @@ var _ = Describe("update", func() {
690
692
})
691
693
692
694
It ("should not delete existing object" , func () {
693
- Expect (c .ConfigMaps (ns ).Get ("existing" , metav1.GetOptions {})).
695
+ Expect (c .ConfigMaps (ns ).Get (context . Background (), "existing" , metav1.GetOptions {})).
694
696
NotTo (BeNil ())
695
697
})
696
698
697
699
It ("should add gctag to new object" , func () {
698
- o , err := c .ConfigMaps (ns ).Get ("new" , metav1.GetOptions {})
700
+ o , err := c .ConfigMaps (ns ).Get (context . Background (), "new" , metav1.GetOptions {})
699
701
Expect (err ).NotTo (HaveOccurred ())
700
702
// [gctag-migration]: Remove annotation in phase2
701
703
Expect (o .ObjectMeta .Annotations ).
0 commit comments