Skip to content

Commit

Permalink
Add clustername label to ipaddressclaims to make clusterctl move work
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattes83 committed Aug 9, 2024
1 parent e55ee99 commit d891113
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/service/k8s/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
ipamv1 "sigs.k8s.io/cluster-api/exp/ipam/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -219,7 +220,7 @@ func (h *Helper) handleIPAddressForNIC(ctx context.Context, machineScope *scope.
return "", err
}
log.V(4).Info("IPAddressClaim not found, creating it.", "nic", nic)
err = h.CreateIPAddressClaim(ctx, machineScope.IonosMachine, key.Name, poolRef)
err = h.CreateIPAddressClaim(ctx, machineScope.IonosMachine, key.Name, machineScope.ClusterScope.Cluster.Name, poolRef)
if err != nil {
return "", errors.Join(err, fmt.Errorf("unable to create IPAddressClaim for machine %s", machineScope.IonosMachine.Name))
}
Expand Down Expand Up @@ -251,12 +252,11 @@ func (h *Helper) handleIPAddressForNIC(ctx context.Context, machineScope *scope.
}

// CreateIPAddressClaim creates an IPAddressClaim for a given object.
func (h *Helper) CreateIPAddressClaim(ctx context.Context, owner client.Object, name string, poolRef *corev1.TypedLocalObjectReference) error {
func (h *Helper) CreateIPAddressClaim(ctx context.Context, owner client.Object, name string, cluster string, poolRef *corev1.TypedLocalObjectReference) error {
claimRef := types.NamespacedName{
Namespace: owner.GetNamespace(),
Name: name,
}

ipAddrClaim := &ipamv1.IPAddressClaim{}
var err error
if err = h.client.Get(ctx, claimRef, ipAddrClaim); err != nil && !apierrors.IsNotFound(err) {
Expand All @@ -272,6 +272,7 @@ func (h *Helper) CreateIPAddressClaim(ctx context.Context, owner client.Object,
ObjectMeta: metav1.ObjectMeta{
Name: claimRef.Name,
Namespace: claimRef.Namespace,
Labels: map[string]string{clusterv1.ClusterNameLabel: cluster},
},
Spec: ipamv1.IPAddressClaimSpec{
PoolRef: *poolRef,
Expand Down

0 comments on commit d891113

Please sign in to comment.