Skip to content
This repository was archived by the owner on Nov 17, 2021. It is now read-only.

Commit 6a687a1

Browse files
committed
integration: update against new k8s api
1 parent 92ce2b2 commit 6a687a1

File tree

4 files changed

+50
-42
lines changed

4 files changed

+50
-42
lines changed

integration/delete_test.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
package integration
44

55
import (
6-
"k8s.io/api/core/v1"
6+
"context"
7+
8+
v1 "k8s.io/api/core/v1"
79
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
810
"k8s.io/apimachinery/pkg/runtime"
911
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
@@ -50,7 +52,7 @@ var _ = Describe("delete", func() {
5052

5153
Context("With no existing state", func() {
5254
It("should succeed", func() {
53-
Expect(c.ConfigMaps(ns).List(metav1.ListOptions{})).
55+
Expect(c.ConfigMaps(ns).List(context.Background(), metav1.ListOptions{})).
5456
To(WithTransform(objNames, BeEmpty()))
5557
})
5658
})
@@ -68,14 +70,14 @@ var _ = Describe("delete", func() {
6870
toCreate = append(toCreate, baz)
6971

7072
for _, cm := range toCreate {
71-
_, err := c.ConfigMaps(ns).Create(cm)
73+
_, err := c.ConfigMaps(ns).Create(context.Background(), cm, metav1.CreateOptions{})
7274
Expect(err).To(Not(HaveOccurred()))
7375
}
7476
})
7577

7678
It("should delete mentioned objects", func() {
7779
Eventually(func() (*v1.ConfigMapList, error) {
78-
return c.ConfigMaps(ns).List(metav1.ListOptions{})
80+
return c.ConfigMaps(ns).List(context.Background(), metav1.ListOptions{})
7981
}).Should(WithTransform(objNames, ConsistOf("baz")))
8082
})
8183
})

integration/integration_suite_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package integration
44

55
import (
6+
"context"
67
"flag"
78
"fmt"
89
"io"
@@ -12,7 +13,7 @@ import (
1213
"path/filepath"
1314
"testing"
1415

15-
"k8s.io/api/core/v1"
16+
v1 "k8s.io/api/core/v1"
1617
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1718
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1819
"k8s.io/apimachinery/pkg/runtime"
@@ -49,11 +50,13 @@ func clusterConfigOrDie() *rest.Config {
4950

5051
func createNsOrDie(c corev1.CoreV1Interface, ns string) string {
5152
result, err := c.Namespaces().Create(
53+
context.Background(),
5254
&v1.Namespace{
5355
ObjectMeta: metav1.ObjectMeta{
5456
GenerateName: ns,
5557
},
56-
})
58+
},
59+
metav1.CreateOptions{})
5760
if err != nil {
5861
panic(err.Error())
5962
}
@@ -63,7 +66,7 @@ func createNsOrDie(c corev1.CoreV1Interface, ns string) string {
6366
}
6467

6568
func deleteNsOrDie(c corev1.CoreV1Interface, ns string) {
66-
err := c.Namespaces().Delete(ns, &metav1.DeleteOptions{})
69+
err := c.Namespaces().Delete(context.Background(), ns, metav1.DeleteOptions{})
6770
if err != nil {
6871
panic(err.Error())
6972
}

integration/kubeflags_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
package integration
44

55
import (
6+
"context"
67
"io/ioutil"
78
"os"
89
"os/exec"
910

10-
"k8s.io/api/core/v1"
11+
v1 "k8s.io/api/core/v1"
1112
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1213
"k8s.io/apimachinery/pkg/runtime"
1314
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
@@ -93,7 +94,7 @@ var _ = Describe("flags", func() {
9394

9495
It("should update correct namespace", func() {
9596
Expect(kubecfgExit).NotTo(HaveOccurred())
96-
Expect(c.ConfigMaps(ns).Get(testName, metav1.GetOptions{})).
97+
Expect(c.ConfigMaps(ns).Get(context.Background(), testName, metav1.GetOptions{})).
9798
NotTo(BeNil())
9899
})
99100
})
@@ -108,7 +109,7 @@ var _ = Describe("flags", func() {
108109

109110
It("should update correct namespace", func() {
110111
Expect(kubecfgExit).NotTo(HaveOccurred())
111-
Expect(c.ConfigMaps(ns).Get(testName, metav1.GetOptions{})).
112+
Expect(c.ConfigMaps(ns).Get(context.Background(), testName, metav1.GetOptions{})).
112113
NotTo(BeNil())
113114
})
114115
})

integration/update_test.go

+34-32
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ package integration
44

55
import (
66
"bytes"
7+
"context"
78
"fmt"
89

910
appsv1 "k8s.io/api/apps/v1"
10-
"k8s.io/api/core/v1"
11+
v1 "k8s.io/api/core/v1"
1112
"k8s.io/apimachinery/pkg/api/errors"
1213
"k8s.io/apimachinery/pkg/api/resource"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -116,7 +117,7 @@ var _ = Describe("update", func() {
116117

117118
Context("With no existing state", func() {
118119
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{})).
120121
To(WithTransform(cmData, HaveKeyWithValue("foo", "bar")))
121122
Expect(kubecfgOut.String()).
122123
To(ContainSubstring("Creating configmaps %s", cmName))
@@ -127,12 +128,12 @@ var _ = Describe("update", func() {
127128

128129
Context("With existing non-kubecfg object", func() {
129130
BeforeEach(func() {
130-
_, err := c.ConfigMaps(ns).Create(cm)
131+
_, err := c.ConfigMaps(ns).Create(context.Background(), cm, metav1.CreateOptions{})
131132
Expect(err).NotTo(HaveOccurred())
132133
})
133134

134135
It("should succeed", func() {
135-
Expect(c.ConfigMaps(ns).Get(cmName, metav1.GetOptions{})).
136+
Expect(c.ConfigMaps(ns).Get(context.Background(), cmName, metav1.GetOptions{})).
136137
To(WithTransform(cmData, HaveKeyWithValue("foo", "bar")))
137138
// NB: may report "Updating" - that's ok.
138139
Expect(kubecfgOut.String()).
@@ -145,12 +146,12 @@ var _ = Describe("update", func() {
145146
err := runKubecfgWith([]string{"update", "-vv", "-n", ns}, []runtime.Object{cm})
146147
Expect(err).NotTo(HaveOccurred())
147148

148-
Expect(c.ConfigMaps(ns).Get(cmName, metav1.GetOptions{})).
149+
Expect(c.ConfigMaps(ns).Get(context.Background(), cmName, metav1.GetOptions{})).
149150
To(WithTransform(metav1.Object.GetAnnotations, HaveKey(kubecfg.AnnotationOrigObject)))
150151
})
151152

152153
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{})).
154155
To(WithTransform(cmData, HaveKeyWithValue("foo", "bar")))
155156
// no change -> should report neither Updating nor Creating
156157
Expect(kubecfgOut.String()).
@@ -172,7 +173,7 @@ var _ = Describe("update", func() {
172173
})
173174

174175
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{})).
176177
To(WithTransform(cmData, HaveKeyWithValue("foo", "bar")))
177178
Expect(kubecfgOut.String()).
178179
To(ContainSubstring("Updating configmaps %s", cmName))
@@ -193,14 +194,14 @@ var _ = Describe("update", func() {
193194
Expect(err).NotTo(HaveOccurred())
194195

195196
// ... 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{})
198199
Expect(err).NotTo(HaveOccurred())
199200
fmt.Fprintf(GinkgoWriter, "patch result is %v\n", o)
200201
})
201202

202203
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{})
204205
Expect(err).NotTo(HaveOccurred())
205206
Expect(cm).To(WithTransform(cmData, HaveKeyWithValue("foo", "bar")))
206207
Expect(cm).To(WithTransform(metav1.Object.GetAnnotations, And(
@@ -282,11 +283,11 @@ var _ = Describe("update", func() {
282283
Version: "v1beta1",
283284
Resource: "customresourcedefinitions",
284285
})
285-
_ = rc.Delete("things.random.example.com", &metav1.DeleteOptions{})
286+
_ = rc.Delete(context.Background(), "things.random.example.com", metav1.DeleteOptions{})
286287
})
287288

288289
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{})).
290291
To(WithTransform(metav1.Object.GetAnnotations,
291292
HaveKeyWithValue("gen", "one")))
292293

@@ -297,7 +298,7 @@ var _ = Describe("update", func() {
297298
Expect(err).NotTo(HaveOccurred())
298299

299300
// Verify result
300-
Expect(rc.Namespace(ns).Get("thing1", metav1.GetOptions{})).
301+
Expect(rc.Namespace(ns).Get(context.Background(), "thing1", metav1.GetOptions{})).
301302
To(WithTransform(metav1.Object.GetAnnotations, And(
302303
HaveKeyWithValue("gen", "two"),
303304
HaveKeyWithValue("unrelated", "baz"),
@@ -328,7 +329,7 @@ var _ = Describe("update", func() {
328329
})
329330

330331
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{})
332333
Expect(err).NotTo(HaveOccurred())
333334
Expect(svc).To(WithTransform(metav1.Object.GetAnnotations,
334335
HaveKeyWithValue("generation", "one")))
@@ -341,7 +342,7 @@ var _ = Describe("update", func() {
341342
Expect(err).NotTo(HaveOccurred())
342343

343344
// 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{})
345346
Expect(err).NotTo(HaveOccurred())
346347
Expect(svc).To(WithTransform(metav1.Object.GetAnnotations,
347348
HaveKeyWithValue("generation", "two")))
@@ -384,9 +385,10 @@ var _ = Describe("update", func() {
384385
It("should merge correctly into containers[]", func() {
385386
// Simulate change by 3rd-party
386387
appsc := appsv1client.NewForConfigOrDie(clusterConfigOrDie())
387-
_, err := appsc.Deployments(ns).Patch(deployName,
388+
_, err := appsc.Deployments(ns).Patch(context.Background(), deployName,
388389
types.StrategicMergePatchType,
389390
[]byte(`{"spec": {"template": {"spec": {"containers": [{"name": "c", "resources": {"limits": {"cpu": "1"}}}]}}}}`),
391+
metav1.PatchOptions{},
390392
)
391393
Expect(err).NotTo(HaveOccurred())
392394

@@ -396,7 +398,7 @@ var _ = Describe("update", func() {
396398
Expect(err).NotTo(HaveOccurred())
397399

398400
// 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{})
400402
Expect(err).NotTo(HaveOccurred())
401403
Expect(d).To(WithTransform(metav1.Object.GetAnnotations,
402404
HaveKeyWithValue("gen", "two")))
@@ -437,13 +439,13 @@ var _ = Describe("update", func() {
437439
})
438440

439441
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{})).
441443
NotTo(BeNil())
442444

443-
Expect(c.ConfigMaps(ns).Get("ns1", metav1.GetOptions{})).
445+
Expect(c.ConfigMaps(ns).Get(context.Background(), "ns1", metav1.GetOptions{})).
444446
NotTo(BeNil())
445447

446-
Expect(c.ConfigMaps(ns2).Get("ns2", metav1.GetOptions{})).
448+
Expect(c.ConfigMaps(ns2).Get(context.Background(), "ns2", metav1.GetOptions{})).
447449
NotTo(BeNil())
448450
})
449451
})
@@ -465,7 +467,7 @@ var _ = Describe("update", func() {
465467

466468
JustBeforeEach(func() {
467469
for _, obj := range preExist {
468-
_, err := c.ConfigMaps(ns).Create(obj)
470+
_, err := c.ConfigMaps(ns).Create(context.Background(), obj, metav1.CreateOptions{})
469471
Expect(err).NotTo(HaveOccurred())
470472
}
471473

@@ -578,7 +580,7 @@ var _ = Describe("update", func() {
578580
})
579581

580582
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{})
582584
Expect(err).NotTo(HaveOccurred())
583585
// [gctag-migration]: Remove annotation in phase2
584586
Expect(o.ObjectMeta.Annotations).
@@ -588,7 +590,7 @@ var _ = Describe("update", func() {
588590
})
589591

590592
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{})
592594
Expect(err).NotTo(HaveOccurred())
593595
// [gctag-migration]: Remove annotation in phase2
594596
Expect(o.ObjectMeta.Annotations).
@@ -599,29 +601,29 @@ var _ = Describe("update", func() {
599601

600602
// [gctag-migration]: Pre-migration test. Remove in phase2
601603
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{})
603605
Expect(err).NotTo(HaveOccurred())
604606
Expect(o.ObjectMeta.Labels).
605607
To(HaveKeyWithValue(kubecfg.LabelGcTag, gcTag))
606608
})
607609

608610
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{})
610612
Expect(errors.IsNotFound(err)).To(BeTrue())
611613
})
612614

613615
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{})).
615617
NotTo(BeNil())
616618
})
617619

618620
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{})).
620622
NotTo(BeNil())
621623
})
622624

623625
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{})).
625627
NotTo(BeNil())
626628
})
627629
})
@@ -653,12 +655,12 @@ var _ = Describe("update", func() {
653655
})
654656

655657
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{})).
657659
NotTo(BeNil())
658660
})
659661

660662
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{})
662664
Expect(errors.IsNotFound(err)).To(BeTrue())
663665
})
664666
})
@@ -690,12 +692,12 @@ var _ = Describe("update", func() {
690692
})
691693

692694
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{})).
694696
NotTo(BeNil())
695697
})
696698

697699
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{})
699701
Expect(err).NotTo(HaveOccurred())
700702
// [gctag-migration]: Remove annotation in phase2
701703
Expect(o.ObjectMeta.Annotations).

0 commit comments

Comments
 (0)