Skip to content

Commit da68952

Browse files
committed
Complete support for Calico policy using KDD client
1 parent 7eb7610 commit da68952

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

lib/backend/k8s/k8s.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ func (c *KubeClient) Syncer(callbacks api.SyncerCallbacks) api.Syncer {
257257
func (c *KubeClient) Create(d *model.KVPair) (*model.KVPair, error) {
258258
log.Debugf("Performing 'Create' for %+v", d)
259259
switch d.Key.(type) {
260+
case model.PolicyKey:
261+
return c.gnpClient.Create(d)
260262
case model.GlobalConfigKey:
261263
return c.globalFelixConfigClient.Create(d)
262264
case model.IPPoolKey:
@@ -285,6 +287,8 @@ func (c *KubeClient) Create(d *model.KVPair) (*model.KVPair, error) {
285287
func (c *KubeClient) Update(d *model.KVPair) (*model.KVPair, error) {
286288
log.Debugf("Performing 'Update' for %+v", d)
287289
switch d.Key.(type) {
290+
case model.PolicyKey:
291+
return c.gnpClient.Update(d)
288292
case model.GlobalConfigKey:
289293
return c.globalFelixConfigClient.Update(d)
290294
case model.IPPoolKey:
@@ -315,6 +319,8 @@ func (c *KubeClient) Apply(d *model.KVPair) (*model.KVPair, error) {
315319
switch d.Key.(type) {
316320
case model.WorkloadEndpointKey:
317321
return c.applyWorkloadEndpoint(d)
322+
case model.PolicyKey:
323+
return c.gnpClient.Apply(d)
318324
case model.GlobalConfigKey:
319325
return c.globalFelixConfigClient.Apply(d)
320326
case model.IPPoolKey:
@@ -344,10 +350,12 @@ func (c *KubeClient) Apply(d *model.KVPair) (*model.KVPair, error) {
344350
}
345351
}
346352

347-
// Delete an entry in the datastore. This is a no-op when using the k8s backend.
353+
// Delete an entry in the datastore. Returns an error if the entry does not exist.
348354
func (c *KubeClient) Delete(d *model.KVPair) error {
349355
log.Debugf("Performing 'Delete' for %+v", d)
350356
switch d.Key.(type) {
357+
case model.PolicyKey:
358+
return c.gnpClient.Delete(d)
351359
case model.GlobalConfigKey:
352360
return c.globalFelixConfigClient.Delete(d)
353361
case model.IPPoolKey:

lib/backend/k8s/k8s_fv_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,8 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
518518
// Make sure we clean up after ourselves. We allow this to fail because
519519
// part of our explicit testing below is to delete the resource.
520520
defer func() {
521-
c.gnpClient.Delete(kvp1a)
522-
c.gnpClient.Delete(kvp2a)
521+
c.Delete(kvp1a)
522+
c.Delete(kvp2a)
523523
}()
524524

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

533533
By("Creating a Global Network Policy", func() {
534-
_, err := c.gnpClient.Create(kvp1a)
534+
_, err := c.Create(kvp1a)
535535
Expect(err).NotTo(HaveOccurred())
536536
})
537537

@@ -547,12 +547,12 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
547547
})
548548

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

554554
By("Updating an existing Global Network Policy", func() {
555-
_, err := c.gnpClient.Update(kvp1b)
555+
_, err := c.Update(kvp1b)
556556
Expect(err).NotTo(HaveOccurred())
557557
})
558558

@@ -568,7 +568,7 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
568568
})
569569

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

@@ -578,7 +578,7 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
578578
})
579579

580580
By("Updating the Global Network Policy created by Apply", func() {
581-
_, err := c.gnpClient.Apply(kvp2b)
581+
_, err := c.Apply(kvp2b)
582582
Expect(err).NotTo(HaveOccurred())
583583
})
584584

@@ -588,7 +588,7 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
588588
})
589589

590590
By("Deleted the Global Network Policy created by Apply", func() {
591-
err := c.gnpClient.Delete(kvp2a)
591+
err := c.Delete(kvp2a)
592592
Expect(err).NotTo(HaveOccurred())
593593
})
594594

@@ -600,7 +600,7 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
600600
// Perform Get operations directly on the main client - this
601601
// will fan out requests to the appropriate Policy client
602602
// (including the Global Network Policy client).
603-
By("Getting a Global Network Policy that does noe exist", func() {
603+
By("Getting a Global Network Policy that does not exist", func() {
604604
_, err := c.Get(model.PolicyKey{Name: "my-non-existent-test-gnp"})
605605
Expect(err).To(HaveOccurred())
606606
})
@@ -629,7 +629,7 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
629629
})
630630

631631
By("Deleting an existing Global Network Policy", func() {
632-
err := c.gnpClient.Delete(kvp1a)
632+
err := c.Delete(kvp1a)
633633
Expect(err).NotTo(HaveOccurred())
634634
})
635635

0 commit comments

Comments
 (0)