Skip to content

Commit

Permalink
Merge pull request #523 from doublek/kdd-calico-policy
Browse files Browse the repository at this point in the history
Completes support for Calico policy when using KDD client
  • Loading branch information
caseydavenport authored Sep 21, 2017
2 parents aeceb9b + da68952 commit fb0f930
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
10 changes: 9 additions & 1 deletion lib/backend/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ func (c *KubeClient) Syncer(callbacks api.SyncerCallbacks) api.Syncer {
func (c *KubeClient) Create(d *model.KVPair) (*model.KVPair, error) {
log.Debugf("Performing 'Create' for %+v", d)
switch d.Key.(type) {
case model.PolicyKey:
return c.gnpClient.Create(d)
case model.GlobalConfigKey:
return c.globalFelixConfigClient.Create(d)
case model.IPPoolKey:
Expand Down Expand Up @@ -335,6 +337,8 @@ func (c *KubeClient) Create(d *model.KVPair) (*model.KVPair, error) {
func (c *KubeClient) Update(d *model.KVPair) (*model.KVPair, error) {
log.Debugf("Performing 'Update' for %+v", d)
switch d.Key.(type) {
case model.PolicyKey:
return c.gnpClient.Update(d)
case model.GlobalConfigKey:
return c.globalFelixConfigClient.Update(d)
case model.IPPoolKey:
Expand Down Expand Up @@ -365,6 +369,8 @@ func (c *KubeClient) Apply(d *model.KVPair) (*model.KVPair, error) {
switch d.Key.(type) {
case model.WorkloadEndpointKey:
return c.applyWorkloadEndpoint(d)
case model.PolicyKey:
return c.gnpClient.Apply(d)
case model.GlobalConfigKey:
return c.globalFelixConfigClient.Apply(d)
case model.IPPoolKey:
Expand Down Expand Up @@ -394,10 +400,12 @@ func (c *KubeClient) Apply(d *model.KVPair) (*model.KVPair, error) {
}
}

// Delete an entry in the datastore. This is a no-op when using the k8s backend.
// Delete an entry in the datastore. Returns an error if the entry does not exist.
func (c *KubeClient) Delete(d *model.KVPair) error {
log.Debugf("Performing 'Delete' for %+v", d)
switch d.Key.(type) {
case model.PolicyKey:
return c.gnpClient.Delete(d)
case model.GlobalConfigKey:
return c.globalFelixConfigClient.Delete(d)
case model.IPPoolKey:
Expand Down
20 changes: 10 additions & 10 deletions lib/backend/k8s/k8s_fv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
// Make sure we clean up after ourselves. We allow this to fail because
// part of our explicit testing below is to delete the resource.
defer func() {
c.gnpClient.Delete(kvp1a)
c.gnpClient.Delete(kvp2a)
c.Delete(kvp1a)
c.Delete(kvp2a)
}()

// Check our syncer has the correct GNP entries for the two
Expand All @@ -607,7 +607,7 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
})

By("Creating a Global Network Policy", func() {
_, err := c.gnpClient.Create(kvp1a)
_, err := c.Create(kvp1a)
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -623,12 +623,12 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
})

By("Attempting to recreate an existing Global Network Policy", func() {
_, err := c.gnpClient.Create(kvp1a)
_, err := c.Create(kvp1a)
Expect(err).To(HaveOccurred())
})

By("Updating an existing Global Network Policy", func() {
_, err := c.gnpClient.Update(kvp1b)
_, err := c.Update(kvp1b)
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -644,7 +644,7 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
})

By("Applying a non-existent Global Network Policy", func() {
_, err := c.gnpClient.Apply(kvp2a)
_, err := c.Apply(kvp2a)
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -654,7 +654,7 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
})

By("Updating the Global Network Policy created by Apply", func() {
_, err := c.gnpClient.Apply(kvp2b)
_, err := c.Apply(kvp2b)
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -664,7 +664,7 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
})

By("Deleted the Global Network Policy created by Apply", func() {
err := c.gnpClient.Delete(kvp2a)
err := c.Delete(kvp2a)
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -676,7 +676,7 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
// Perform Get operations directly on the main client - this
// will fan out requests to the appropriate Policy client
// (including the Global Network Policy client).
By("Getting a Global Network Policy that does noe exist", func() {
By("Getting a Global Network Policy that does not exist", func() {
_, err := c.Get(model.PolicyKey{Name: "my-non-existent-test-gnp"})
Expect(err).To(HaveOccurred())
})
Expand Down Expand Up @@ -705,7 +705,7 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
})

By("Deleting an existing Global Network Policy", func() {
err := c.gnpClient.Delete(kvp1a)
err := c.Delete(kvp1a)
Expect(err).NotTo(HaveOccurred())
})

Expand Down

0 comments on commit fb0f930

Please sign in to comment.