Skip to content

Commit

Permalink
addressing comments
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Davis <[email protected]>
  • Loading branch information
Doug Davis committed Jan 15, 2017
1 parent 56b5ea7 commit a9584f6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
61 changes: 40 additions & 21 deletions calico_cni_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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"))
})
})
})
Expand Down
9 changes: 4 additions & 5 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit a9584f6

Please sign in to comment.