diff --git a/v2/config/rbac/coil-controller_role.yaml b/v2/config/rbac/coil-controller_role.yaml index 99da96c7..10e366f7 100644 --- a/v2/config/rbac/coil-controller_role.yaml +++ b/v2/config/rbac/coil-controller_role.yaml @@ -61,6 +61,8 @@ rules: verbs: - get - list + - patch + - update - watch - apiGroups: - coil.cybozu.com diff --git a/v2/controllers/addresspool_controller.go b/v2/controllers/addresspool_controller.go index 13637c1b..baf82738 100644 --- a/v2/controllers/addresspool_controller.go +++ b/v2/controllers/addresspool_controller.go @@ -29,7 +29,7 @@ type AddressPoolReconciler struct { var _ reconcile.Reconciler = &AddressPoolReconciler{} -// +kubebuilder:rbac:groups=coil.cybozu.com,resources=addresspools,verbs=get;list;watch +// +kubebuilder:rbac:groups=coil.cybozu.com,resources=addresspools,verbs=get;list;watch;update;patch // +kubebuilder:rbac:groups=coil.cybozu.com,resources=addressblocks,verbs=get;list;watch // Reconcile implements Reconciler interface. diff --git a/v2/e2e/coil_test.go b/v2/e2e/coil_test.go index f8600623..b4631dc3 100644 --- a/v2/e2e/coil_test.go +++ b/v2/e2e/coil_test.go @@ -503,4 +503,42 @@ var _ = Describe("Coil", func() { Expect(resp).To(HaveLen(1 << 20)) } }) + + It("should delete address pool", func() { + By("creating a dummy address pool") + _, err := kubectl(nil, "apply", "-f", "manifests/dummy_pool.yaml") + Expect(err).NotTo(HaveOccurred()) + + Eventually(func() error { + ap := coilv2.AddressPool{} + out, err := kubectl(nil, "get", "addresspool", "dummy", "-o", "json") + if err != nil { + return err + } + if err := json.Unmarshal(out, &ap); err != nil { + return err + } + return nil + }).Should(Succeed()) + + By("deleting the dummy address pool") + _, err = kubectl(nil, "delete", "-f", "manifests/dummy_pool.yaml") + Expect(err).NotTo(HaveOccurred()) + + Consistently(func() error { + apList := coilv2.AddressPoolList{} + out, err := kubectl(nil, "get", "addresspool", "-o", "json") + if err != nil { + return err + } + if err := json.Unmarshal(out, &apList); err != nil { + return err + } + if len(apList.Items) == 1 { + return nil + } + return fmt.Errorf("the number of AddressPool must be 1") + }).Should(Succeed()) + + }) }) diff --git a/v2/e2e/manifests/dummy_pool.yaml b/v2/e2e/manifests/dummy_pool.yaml new file mode 100644 index 00000000..e1d16f42 --- /dev/null +++ b/v2/e2e/manifests/dummy_pool.yaml @@ -0,0 +1,8 @@ +apiVersion: coil.cybozu.com/v2 +kind: AddressPool +metadata: + name: dummy +spec: + blockSizeBits: 0 + subnets: + - ipv4: 10.225.0.0/30