Skip to content

Commit

Permalink
Fix to be able to remove AddressPool finalizer by controller
Browse files Browse the repository at this point in the history
Signed-off-by: terasihma <[email protected]>
  • Loading branch information
terassyi committed Apr 22, 2024
1 parent 17888a9 commit 99c5e06
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions v2/config/rbac/coil-controller_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ rules:
verbs:
- get
- list
- patch
- update
- watch
- apiGroups:
- coil.cybozu.com
Expand Down
2 changes: 1 addition & 1 deletion v2/controllers/addresspool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 38 additions & 0 deletions v2/e2e/coil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

})
})
8 changes: 8 additions & 0 deletions v2/e2e/manifests/dummy_pool.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: coil.cybozu.com/v2
kind: AddressPool
metadata:
name: dummy
spec:
blockSizeBits: 0
subnets:
- ipv4: 10.225.0.0/30

0 comments on commit 99c5e06

Please sign in to comment.