Skip to content

Commit

Permalink
Use root cluster name
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbenjemaa committed Dec 14, 2023
1 parent a147cf2 commit b592d73
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/service/vmservice/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func handleIPAddressForDevice(ctx context.Context, machineScope *scope.MachineSc
}
machineScope.Logger.V(4).Info("IPAddress not found, creating it.", "device", device)
// IpAddress not yet created.
err = machineScope.IPAMHelper.CreateIPAddressClaim(ctx, machineScope.ProxmoxMachine, device, format, ipamRef)
err = machineScope.IPAMHelper.CreateIPAddressClaim(ctx, machineScope.ProxmoxMachine, device, format, machineScope.InfraCluster.Cluster.GetName(), ipamRef)
if err != nil {
return "", errors.Wrapf(err, "unable to create Ip address claim for machine %s", machineScope.Name())
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubernetes/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (h *Helper) GetGlobalInClusterIPPool(ctx context.Context, ref *corev1.Typed
}

// CreateIPAddressClaim creates an IPAddressClaim for a given object.
func (h *Helper) CreateIPAddressClaim(ctx context.Context, owner client.Object, device, format string, ref *corev1.TypedLocalObjectReference) error {
func (h *Helper) CreateIPAddressClaim(ctx context.Context, owner client.Object, device, format, clusterNameLabel string, ref *corev1.TypedLocalObjectReference) error {
var gvk schema.GroupVersionKind
key := client.ObjectKey{
Namespace: owner.GetNamespace(),
Expand Down Expand Up @@ -201,7 +201,7 @@ 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.
labels := map[string]string{
clusterv1.ClusterNameLabel: h.cluster.GetName(),
clusterv1.ClusterNameLabel: clusterNameLabel,
}

desired := &ipamv1.IPAddressClaim{
Expand Down
13 changes: 7 additions & 6 deletions pkg/kubernetes/ipam/ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ func (s *IPAMTestSuite) Test_CreateIPAddressClaim() {

device := "net0"

err := s.helper.CreateIPAddressClaim(s.ctx, getCluster(), device, infrav1.IPV4Format, nil)
rootClusterName := "test"
err := s.helper.CreateIPAddressClaim(s.ctx, getCluster(), device, infrav1.IPV4Format, rootClusterName, nil)
s.NoError(err)

// Ensure cluster label is set.
Expand All @@ -245,7 +246,7 @@ func (s *IPAMTestSuite) Test_CreateIPAddressClaim() {
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])
s.Equal(rootClusterName, claim.ObjectMeta.Labels[clusterv1.ClusterNameLabel])

// additional device with InClusterIPPool
s.NoError(s.helper.ctrlClient.Create(s.ctx, &ipamicv1.InClusterIPPool{
Expand All @@ -268,7 +269,7 @@ func (s *IPAMTestSuite) Test_CreateIPAddressClaim() {

additionalDevice := "net1"

err = s.helper.CreateIPAddressClaim(s.ctx, getCluster(), additionalDevice, infrav1.IPV4Format, &corev1.TypedLocalObjectReference{
err = s.helper.CreateIPAddressClaim(s.ctx, getCluster(), additionalDevice, infrav1.IPV4Format, "test-cluster", &corev1.TypedLocalObjectReference{
Name: "test-additional-cluster-icip",
Kind: "InClusterIPPool",
APIGroup: ptr.To("ipam.cluster.x-k8s.io"),
Expand All @@ -294,7 +295,7 @@ func (s *IPAMTestSuite) Test_CreateIPAddressClaim() {

globalDevice := "net2"

err = s.helper.CreateIPAddressClaim(s.ctx, getCluster(), globalDevice, infrav1.IPV4Format, &corev1.TypedLocalObjectReference{
err = s.helper.CreateIPAddressClaim(s.ctx, getCluster(), globalDevice, infrav1.IPV4Format, "test-cluster", &corev1.TypedLocalObjectReference{
Name: "test-global-cluster-icip",
Kind: "GlobalInClusterIPPool",
APIGroup: ptr.To("ipam.cluster.x-k8s.io"),
Expand All @@ -315,7 +316,7 @@ func (s *IPAMTestSuite) Test_CreateIPAddressClaim() {
Name: "test-cluster-v6-icip",
}, &poolV6))

err = s.helper.CreateIPAddressClaim(s.ctx, getCluster(), device, infrav1.IPV6Format, nil)
err = s.helper.CreateIPAddressClaim(s.ctx, getCluster(), device, infrav1.IPV6Format, "test-cluster", nil)
s.NoError(err)
}

Expand All @@ -328,7 +329,7 @@ func (s *IPAMTestSuite) Test_GetIPAddress() {
Name: "test-cluster-v4-icip",
}, &pool))

err := s.helper.CreateIPAddressClaim(s.ctx, getCluster(), "net0", infrav1.IPV4Format, &corev1.TypedLocalObjectReference{
err := s.helper.CreateIPAddressClaim(s.ctx, getCluster(), "net0", infrav1.IPV4Format, "test-cluster", &corev1.TypedLocalObjectReference{
Name: "test-cluster-icip",
})
s.NoError(err)
Expand Down

0 comments on commit b592d73

Please sign in to comment.