diff --git a/lib/backend/k8s/k8s.go b/lib/backend/k8s/k8s.go index 0a4deabce..9ca897d1f 100644 --- a/lib/backend/k8s/k8s.go +++ b/lib/backend/k8s/k8s.go @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/lib/backend/k8s/k8s_fv_test.go b/lib/backend/k8s/k8s_fv_test.go index 18046edc3..153abb410 100644 --- a/lib/backend/k8s/k8s_fv_test.go +++ b/lib/backend/k8s/k8s_fv_test.go @@ -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 @@ -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()) }) @@ -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()) }) @@ -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()) }) @@ -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()) }) @@ -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()) }) @@ -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()) }) @@ -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()) })