Skip to content

Commit

Permalink
Implement AffinityBlock list for all nodes, on KDD
Browse files Browse the repository at this point in the history
Neil Jerram committed Sep 7, 2018
1 parent 6452ece commit 4dd0e61
Showing 2 changed files with 41 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/backend/k8s/k8s_test.go
Original file line number Diff line number Diff line change
@@ -1422,12 +1422,6 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
})
})

It("should error on unsupported List() calls", func() {
objs, err := c.List(ctx, model.BlockAffinityListOptions{}, "")
Expect(err).To(HaveOccurred())
Expect(objs).To(BeNil())
})

It("should not error on unsupported List() calls", func() {
var nodename string
By("Listing all Nodes to find a suitable Node name", func() {
@@ -1441,6 +1435,11 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
Expect(err).NotTo(HaveOccurred())
Expect(len(objs.KVPairs)).To(Equal(1))
})
By("Listing all BlockAffinity for all Nodes", func() {
objs, err := c.List(ctx, model.BlockAffinityListOptions{}, "")
Expect(err).NotTo(HaveOccurred())
Expect(len(objs.KVPairs)).To(Equal(1))
})
})

It("should support setting and getting FelixConfig", func() {
36 changes: 36 additions & 0 deletions lib/backend/k8s/resources/affinityblock.go
Original file line number Diff line number Diff line change
@@ -116,6 +116,42 @@ func (c *AffinityBlockClient) List(ctx context.Context, list model.ListInterface
return kvpl, nil
}

// When host is not specified...
if bl.IPVersion == 0 {
// Get the node settings, we use the nodes PodCIDR as the only node affinity block.
nodeList, err := c.clientSet.CoreV1().Nodes().List(metav1.ListOptions{ResourceVersion: revision})
if err != nil {
err = K8sErrorToCalico(err, list)
if _, ok := err.(cerrors.ErrorResourceDoesNotExist); !ok {
return nil, err
}
return kvpl, nil
}

kvpl.Revision = nodeList.ResourceVersion
for _, node := range nodeList.Items {
// Return no results if the pod CIDR is not assigned.
podcidr := node.Spec.PodCIDR
if len(podcidr) == 0 {
continue
}

_, cidr, err := cnet.ParseCIDR(podcidr)
if err != nil {
return nil, err
}
kvpl.KVPairs = append(kvpl.KVPairs, &model.KVPair{
Key: model.BlockAffinityKey{
CIDR: *cidr,
Host: node.Name,
},
Value: &model.BlockAffinity{State: model.StateConfirmed},
Revision: node.ResourceVersion,
})
}
return kvpl, nil
}

// Currently querying the affinity block is only used by the BGP syncer *and* we always
// query for a specific Node, so for now fail List requests for all nodes.
log.Warn("Operation List (all nodes or all IP versions) is not supported on AffinityBlock type")

0 comments on commit 4dd0e61

Please sign in to comment.