From a9584f6b7d7883c17cc56ab2041f49cac5b5da91 Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Sun, 15 Jan 2017 05:10:47 -0800 Subject: [PATCH] addressing comments Signed-off-by: Doug Davis --- calico_cni_k8s_test.go | 61 +++++++++++++++++++++++++++--------------- glide.lock | 9 +++---- k8s/k8s.go | 4 +-- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/calico_cni_k8s_test.go b/calico_cni_k8s_test.go index 7e1124eae..d868f5251 100644 --- a/calico_cni_k8s_test.go +++ b/calico_cni_k8s_test.go @@ -53,7 +53,7 @@ var _ = Describe("CalicoCni", func() { "subnet": "10.0.0.0/8" }, "kubernetes": { - "k8s_api_root": "http://127.0.0.1:8080" + "k8s_api_root": "http://127.0.0.1:8080" }, "policy": {"type": "k8s"}, "log_level":"info" @@ -84,27 +84,8 @@ var _ = Describe("CalicoCni", func() { if err != nil { panic(err) } - - // Now create a K8s pod passing in an IP pool - name2 := name + "-pool" - pod, err := clientset.Pods(K8S_TEST_NS).Create(&v1.Pod{ - ObjectMeta: v1.ObjectMeta{ - Name: name2, - Annotations: map[string]string{ - "cni.calico/ipv4pools": "192.169.1.0/24", - }, - }, - Spec: v1.PodSpec{Containers: []v1.Container{{ - Name: fmt.Sprintf("container-%s", name2), - Image: "ignore", - }}}, - }) - if err != nil { - panic(err) - } - fmt.Printf("POD: %#v\n", pod) - containerID, netnspath, session, contVeth, contAddresses, contRoutes, err := CreateContainer(netconf, name) + Expect(err).ShouldNot(HaveOccurred()) Eventually(session).Should(gexec.Exit()) @@ -190,6 +171,44 @@ var _ = Describe("CalicoCni", func() { Expect(err).Should(HaveOccurred()) Expect(err.Error()).Should(Equal("Link not found")) + // Now create a K8s pod passing in an IP pool + name2 := name + "-pool" + pod, err := clientset.Pods(K8S_TEST_NS).Create(&v1.Pod{ + ObjectMeta: v1.ObjectMeta{ + Name: name2, + Annotations: map[string]string{ + "ipam.cni.projectcalico.org/ipv4pools": "192.169.1.0/24", + }, + }, + Spec: v1.PodSpec{Containers: []v1.Container{{ + Name: fmt.Sprintf("container-%s", name2), + Image: "ignore", + }}}, + }) + if err != nil { + panic(err) + } + + fmt.Printf("POD: %#v\n", pod) + + /* + // Wait for the pod to be created + for { + pod, err = clientset.Pods(K8S_TEST_NS).Get(name2) + fmt.Printf("POD2: %#v\n", pod) + if pod.Status.Phase != "Pending" { + break + } + time.Sleep(5 * time.Second) + } + fmt.Printf("POD2: %#v\n", pod) + */ + + containerID, netnspath, session, contVeth, contAddresses, contRoutes, err = CreateContainer(netconf, name2) + + // This will fail until I figure out how to call the CNI plugin + ip = contAddresses[0].IP.String() + Expect(ip).Should(Equal("192.169.1.0")) }) }) }) diff --git a/glide.lock b/glide.lock index 7d84c0a54..3a0a2d06d 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ hash: 1efa10f7d9f9793128d78496760c641fb6ee82b2686a4fd476ba83a624f1506c -updated: 2017-01-02T13:52:34.929573726Z +updated: 2016-12-13T15:51:57.719804486-08:00 imports: - name: cloud.google.com/go version: 3b1ae45394a234c385be014e9a488f2bb6eef821 @@ -20,7 +20,7 @@ imports: - pkg/utils/hwaddr - pkg/version - name: github.com/coreos/etcd - version: 24601ca24b46f5d700746c5902ee62aca6b1b805 + version: 454f1da2f2bc48f9d2aede84fece95d292c8e3fc subpackages: - client - pkg/fileutil @@ -165,7 +165,6 @@ imports: - lib/net - lib/numorstring - lib/scope - - lib/testutils - name: github.com/PuerkitoBio/purell version: 8a290539e2e8629dbc4e6bad948158f790ec31f4 - name: github.com/PuerkitoBio/urlesc @@ -173,7 +172,7 @@ imports: - name: github.com/satori/go.uuid version: b061729afc07e77a8aa4fad0a2fd840958f1942a - name: github.com/Sirupsen/logrus - version: 881bee4e20a5d11a6a88a5667c6f292072ac1963 + version: d26492970760ca5d33129d2d799e34be5c4782eb - name: github.com/spf13/pflag version: c7e63cf4530bcd3ba943729cee0efeff2ebea63f - name: github.com/ugorji/go @@ -207,7 +206,7 @@ imports: - jws - jwt - name: golang.org/x/sys - version: d75a52659825e75fff6158388dddc6a5b04f9ba5 + version: 478fcf54317e52ab69f40bb4c7a1520288d7f7ea subpackages: - unix - name: golang.org/x/text diff --git a/k8s/k8s.go b/k8s/k8s.go index 00b84c53e..df40b2d2f 100644 --- a/k8s/k8s.go +++ b/k8s/k8s.go @@ -123,8 +123,8 @@ func CmdAddK8s(args *skel.CmdArgs, conf utils.NetConf, hostname string, calicoCl logger.WithField("labels", labels).Debug("Fetched K8s labels") logger.WithField("annotations", annot).Debug("Fetched K8s annotations") - v4pools := annot["cni.calico/ipv4pools"] - v6pools := annot["cni.calico/ipv6pools"] + v4pools := annot["ipam.cni.projectcalico.org/ipv4pools"] + v6pools := annot["ipam.cni.projectcalico.org/ipv6pools"] if len(v4pools) != 0 || len(v6pools) != 0 { var stdinData map[string]interface{}