Skip to content

Commit

Permalink
Fixes pause of IPAddressClaim
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbenjemaa committed Dec 14, 2023
1 parent 0b40010 commit a147cf2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/kubernetes/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ func (h *Helper) CreateIPAddressClaim(ctx context.Context, owner client.Object,

// Ensures that the claim has a reference to the cluster of the VM to
// support pausing reconciliation.
annotations := map[string]string{
clusterv1.ClusterNameAnnotation: h.cluster.GetName(),
labels := map[string]string{
clusterv1.ClusterNameLabel: h.cluster.GetName(),
}

desired := &ipamv1.IPAddressClaim{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-%s-%s", owner.GetName(), device, suffix),
Namespace: owner.GetNamespace(),
Annotations: annotations,
Name: fmt.Sprintf("%s-%s-%s", owner.GetName(), device, suffix),
Namespace: owner.GetNamespace(),
Labels: labels,
},
Spec: ipamv1.IPAddressClaimSpec{
PoolRef: corev1.TypedLocalObjectReference{
Expand Down
10 changes: 10 additions & 0 deletions pkg/kubernetes/ipam/ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package ipam

import (
"context"
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -237,6 +238,15 @@ func (s *IPAMTestSuite) Test_CreateIPAddressClaim() {
err := s.helper.CreateIPAddressClaim(s.ctx, getCluster(), device, infrav1.IPV4Format, nil)
s.NoError(err)

// Ensure cluster label is set.
var claim ipamv1.IPAddressClaim
name := fmt.Sprintf("%s-%s-%s", getCluster().GetName(), device, infrav1.DefaultSuffix)
nn := types.NamespacedName{Name: name, Namespace: getCluster().GetNamespace()}
err = s.cl.Get(s.ctx, nn, &claim)
s.NoError(err)
s.Contains(claim.ObjectMeta.Labels, clusterv1.ClusterNameLabel)
s.Equal(getCluster().GetName(), claim.ObjectMeta.Labels[clusterv1.ClusterNameLabel])

// additional device with InClusterIPPool
s.NoError(s.helper.ctrlClient.Create(s.ctx, &ipamicv1.InClusterIPPool{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit a147cf2

Please sign in to comment.