Skip to content

⚠️ Generic claim reconciler #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
v1alpha2 "sigs.k8s.io/cluster-api-ipam-provider-in-cluster/api/v1alpha2"
)

func Convert_v1alpha1_InClusterIPPoolSpec_To_v1alpha2_InClusterIPPoolSpec(in *InClusterIPPoolSpec, out *v1alpha2.InClusterIPPoolSpec, scope conversion.Scope) error {
func Convert_v1alpha1_InClusterIPPoolSpec_To_v1alpha2_InClusterIPPoolSpec(in *InClusterIPPoolSpec, out *v1alpha2.InClusterIPPoolSpec, _ conversion.Scope) error {
out.Gateway = in.Gateway
out.Prefix = in.Prefix
out.Addresses = in.Addresses
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module sigs.k8s.io/cluster-api-ipam-provider-in-cluster

go 1.20
go 1.21

require (
github.com/onsi/ginkgo/v2 v2.13.2
Expand Down
348 changes: 103 additions & 245 deletions internal/controllers/ipaddressclaim.go

Large diffs are not rendered by default.

31 changes: 16 additions & 15 deletions internal/controllers/ipaddressclaim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
. "sigs.k8s.io/controller-runtime/pkg/envtest/komega"

"sigs.k8s.io/cluster-api-ipam-provider-in-cluster/api/v1alpha2"
"sigs.k8s.io/cluster-api-ipam-provider-in-cluster/pkg/ipamutil"
)

var IgnoreUIDsOnIPAddress = IgnorePaths{
Expand Down Expand Up @@ -119,7 +120,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespace,
Finalizers: []string{ProtectAddressFinalizer},
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "ipam.cluster.x-k8s.io/v1beta1",
Expand Down Expand Up @@ -234,7 +235,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespace,
Finalizers: []string{ProtectAddressFinalizer},
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "ipam.cluster.x-k8s.io/v1beta1",
Expand Down Expand Up @@ -416,7 +417,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespace,
Finalizers: []string{ProtectAddressFinalizer},
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "ipam.cluster.x-k8s.io/v1beta1",
Expand Down Expand Up @@ -491,7 +492,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespace,
Finalizers: []string{ProtectAddressFinalizer},
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "ipam.cluster.x-k8s.io/v1beta1",
Expand Down Expand Up @@ -528,7 +529,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test-second-namespace",
Namespace: secondNamespace,
Finalizers: []string{ProtectAddressFinalizer},
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "ipam.cluster.x-k8s.io/v1beta1",
Expand Down Expand Up @@ -708,7 +709,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test-1",
Namespace: namespace,
Finalizers: []string{ProtectAddressFinalizer},
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "ipam.cluster.x-k8s.io/v1beta1",
Expand Down Expand Up @@ -745,7 +746,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test-2",
Namespace: secondNamespace,
Finalizers: []string{ProtectAddressFinalizer},
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "ipam.cluster.x-k8s.io/v1beta1",
Expand Down Expand Up @@ -837,7 +838,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test-1",
Namespace: namespace,
Finalizers: []string{ProtectAddressFinalizer},
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "ipam.cluster.x-k8s.io/v1beta1",
Expand Down Expand Up @@ -874,7 +875,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test-2",
Namespace: namespace,
Finalizers: []string{ProtectAddressFinalizer},
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "ipam.cluster.x-k8s.io/v1beta1",
Expand Down Expand Up @@ -971,7 +972,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
})

When("a claim is deleted", func() {
const poolName = "paused-delete-claim-pool"
const poolName = "paused-delete-claim-pool" // #nosec G101
var pool v1alpha2.InClusterIPPool

BeforeEach(func() {
Expand Down Expand Up @@ -1088,7 +1089,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespace,
Finalizers: []string{ProtectAddressFinalizer},
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "ipam.cluster.x-k8s.io/v1beta1",
Expand Down Expand Up @@ -1178,7 +1179,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespace,
Finalizers: []string{ProtectAddressFinalizer},
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "alpha-dummy",
Expand Down Expand Up @@ -1245,7 +1246,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespace,
Finalizers: []string{ProtectAddressFinalizer},
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "ipam.cluster.x-k8s.io/v1beta1",
Expand Down Expand Up @@ -1282,7 +1283,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespace2,
Finalizers: []string{ProtectAddressFinalizer},
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "ipam.cluster.x-k8s.io/v1beta1",
Expand Down Expand Up @@ -1675,7 +1676,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: namespace,
Finalizers: []string{ProtectAddressFinalizer},
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "ipam.cluster.x-k8s.io/v1beta1",
Expand Down
8 changes: 5 additions & 3 deletions internal/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
//+kubebuilder:scaffold:imports
v1alpha2 "sigs.k8s.io/cluster-api-ipam-provider-in-cluster/api/v1alpha2"
"sigs.k8s.io/cluster-api-ipam-provider-in-cluster/internal/index"
"sigs.k8s.io/cluster-api-ipam-provider-in-cluster/pkg/ipamutil"
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
Expand Down Expand Up @@ -97,9 +98,10 @@ var _ = BeforeSuite(func() {
Expect(index.SetupIndexes(ctx, mgr)).To(Succeed())

Expect(
(&IPAddressClaimReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
(&ipamutil.ClaimReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Adapter: &InClusterProviderAdapter{Client: mgr.GetClient()},
}).SetupWithManager(ctx, mgr),
).To(Succeed())

Expand Down
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"sigs.k8s.io/cluster-api-ipam-provider-in-cluster/internal/controllers"
"sigs.k8s.io/cluster-api-ipam-provider-in-cluster/internal/index"
"sigs.k8s.io/cluster-api-ipam-provider-in-cluster/internal/webhooks"
"sigs.k8s.io/cluster-api-ipam-provider-in-cluster/pkg/ipamutil"
)

var (
Expand Down Expand Up @@ -109,9 +110,14 @@ func main() {
os.Exit(1)
}

if err = (&controllers.IPAddressClaimReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
if err = (&ipamutil.ClaimReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
WatchFilterValue: watchFilter,
Adapter: &controllers.InClusterProviderAdapter{
Client: mgr.GetClient(),
WatchFilterValue: watchFilter,
},
}).SetupWithManager(ctx, mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IPAddressClaim")
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions pkg/ipamutil/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func NewIPAddress(claim *ipamv1.IPAddressClaim, pool client.Object) ipamv1.IPAdd
}
}

// EnsureIPAddressOwnerReferences ensures that an IPAddress has the
// ensureIPAddressOwnerReferences ensures that an IPAddress has the
// IPAddressClaim and IPPool as an OwnerReference.
func EnsureIPAddressOwnerReferences(scheme *runtime.Scheme, address *ipamv1.IPAddress, claim *ipamv1.IPAddressClaim, pool client.Object) error {
func ensureIPAddressOwnerReferences(scheme *runtime.Scheme, address *ipamv1.IPAddress, claim *ipamv1.IPAddressClaim, pool client.Object) error {
if err := controllerutil.SetControllerReference(claim, address, scheme); err != nil {
if _, ok := err.(*controllerutil.AlreadyOwnedError); !ok {
return errors.Wrap(err, "Failed to update address's claim owner reference")
Expand Down
Loading