Skip to content

Commit 26a4939

Browse files
Merge pull request #1085 from rabi/owner_label
Use lib-common api for owner labels
2 parents 8025058 + bd19552 commit 26a4939

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

pkg/dataplane/baremetal.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1"
2929
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
3030
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
31+
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
32+
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
3133
utils "github.com/openstack-k8s-operators/lib-common/modules/common/util"
3234
baremetalv1 "github.com/openstack-k8s-operators/openstack-baremetal-operator/api/v1beta1"
3335
openstackv1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
@@ -53,6 +55,9 @@ func DeployBaremetalSet(
5355
}
5456
utils.LogForObject(helper, "Reconciling BaremetalSet", instance)
5557
_, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), baremetalSet, func() error {
58+
ownerLabels := labels.GetLabels(instance, labels.GetGroupLabel(NodeSetLabel), map[string]string{})
59+
baremetalSet.Labels = util.MergeStringMaps(baremetalSet.GetLabels(), ownerLabels)
60+
5661
instance.Spec.BaremetalSetTemplate.DeepCopyInto(&baremetalSet.Spec)
5762
// Set Images
5863
if containerImages.OsContainerImage != nil && instance.Spec.BaremetalSetTemplate.OSContainerImageURL == "" {

pkg/dataplane/const.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,4 @@ const (
6767

6868
//HostnameLabel label for marking secrets to be watched for changes
6969
HostnameLabel = "hostname"
70-
71-
// IPSetOwnershipLabelKey label key to find all IPSets for OpenStackDataPlaneNodeSet
72-
IPSetOwnershipLabelKey = "nodeset/name"
7370
)

pkg/dataplane/ipam.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1"
3131
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
3232
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
33+
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
3334
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
3435
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1"
3536
)
@@ -296,10 +297,11 @@ func EnsureIPSets(ctx context.Context, helper *helper.Helper,
296297
func cleanupStaleReservations(ctx context.Context, helper *helper.Helper,
297298
instance *dataplanev1.OpenStackDataPlaneNodeSet) error {
298299
ipSetList := &infranetworkv1.IPSetList{}
299-
labelSelectorMap := map[string]string{IPSetOwnershipLabelKey: instance.Name}
300+
labelSelector := labels.GetLabels(instance,
301+
labels.GetGroupLabel(NodeSetLabel), map[string]string{})
300302
listOpts := []client.ListOption{
301303
client.InNamespace(instance.Namespace),
302-
client.MatchingLabels(labelSelectorMap),
304+
client.MatchingLabels(labelSelector),
303305
}
304306

305307
err := helper.GetClient().List(ctx, ipSetList, listOpts...)
@@ -367,8 +369,8 @@ func reserveIPs(ctx context.Context, helper *helper.Helper,
367369
},
368370
}
369371
_, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), ipSet, func() error {
370-
ipSet.Labels = util.MergeStringMaps(ipSet.Labels,
371-
map[string]string{IPSetOwnershipLabelKey: instance.Name})
372+
ownerLabels := labels.GetLabels(instance, labels.GetGroupLabel(NodeSetLabel), map[string]string{})
373+
ipSet.Labels = util.MergeStringMaps(ipSet.GetLabels(), ownerLabels)
372374
ipSet.Spec.Networks = nets
373375
// Set controller reference to the DataPlaneNode object
374376
err := controllerutil.SetControllerReference(

0 commit comments

Comments
 (0)