diff --git a/pkg/dataplane/baremetal.go b/pkg/dataplane/baremetal.go index 564e59a59..1c6bd94f2 100644 --- a/pkg/dataplane/baremetal.go +++ b/pkg/dataplane/baremetal.go @@ -28,6 +28,8 @@ import ( infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1" condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" "github.com/openstack-k8s-operators/lib-common/modules/common/helper" + "github.com/openstack-k8s-operators/lib-common/modules/common/labels" + "github.com/openstack-k8s-operators/lib-common/modules/common/util" utils "github.com/openstack-k8s-operators/lib-common/modules/common/util" baremetalv1 "github.com/openstack-k8s-operators/openstack-baremetal-operator/api/v1beta1" openstackv1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1" @@ -53,6 +55,9 @@ func DeployBaremetalSet( } utils.LogForObject(helper, "Reconciling BaremetalSet", instance) _, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), baremetalSet, func() error { + ownerLabels := labels.GetLabels(instance, labels.GetGroupLabel(NodeSetLabel), map[string]string{}) + baremetalSet.Labels = util.MergeStringMaps(baremetalSet.GetLabels(), ownerLabels) + instance.Spec.BaremetalSetTemplate.DeepCopyInto(&baremetalSet.Spec) // Set Images if containerImages.OsContainerImage != nil && instance.Spec.BaremetalSetTemplate.OSContainerImageURL == "" { diff --git a/pkg/dataplane/const.go b/pkg/dataplane/const.go index 26a51f431..85973445d 100644 --- a/pkg/dataplane/const.go +++ b/pkg/dataplane/const.go @@ -67,7 +67,4 @@ const ( //HostnameLabel label for marking secrets to be watched for changes HostnameLabel = "hostname" - - // IPSetOwnershipLabelKey label key to find all IPSets for OpenStackDataPlaneNodeSet - IPSetOwnershipLabelKey = "nodeset/name" ) diff --git a/pkg/dataplane/ipam.go b/pkg/dataplane/ipam.go index b3f434e69..471cf65e0 100644 --- a/pkg/dataplane/ipam.go +++ b/pkg/dataplane/ipam.go @@ -30,6 +30,7 @@ import ( infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1" condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" "github.com/openstack-k8s-operators/lib-common/modules/common/helper" + "github.com/openstack-k8s-operators/lib-common/modules/common/labels" "github.com/openstack-k8s-operators/lib-common/modules/common/util" dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1" ) @@ -296,10 +297,11 @@ func EnsureIPSets(ctx context.Context, helper *helper.Helper, func cleanupStaleReservations(ctx context.Context, helper *helper.Helper, instance *dataplanev1.OpenStackDataPlaneNodeSet) error { ipSetList := &infranetworkv1.IPSetList{} - labelSelectorMap := map[string]string{IPSetOwnershipLabelKey: instance.Name} + labelSelector := labels.GetLabels(instance, + labels.GetGroupLabel(NodeSetLabel), map[string]string{}) listOpts := []client.ListOption{ client.InNamespace(instance.Namespace), - client.MatchingLabels(labelSelectorMap), + client.MatchingLabels(labelSelector), } err := helper.GetClient().List(ctx, ipSetList, listOpts...) @@ -367,8 +369,8 @@ func reserveIPs(ctx context.Context, helper *helper.Helper, }, } _, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), ipSet, func() error { - ipSet.Labels = util.MergeStringMaps(ipSet.Labels, - map[string]string{IPSetOwnershipLabelKey: instance.Name}) + ownerLabels := labels.GetLabels(instance, labels.GetGroupLabel(NodeSetLabel), map[string]string{}) + ipSet.Labels = util.MergeStringMaps(ipSet.GetLabels(), ownerLabels) ipSet.Spec.Networks = nets // Set controller reference to the DataPlaneNode object err := controllerutil.SetControllerReference(