Skip to content

Commit

Permalink
Merge pull request #1085 from rabi/owner_label
Browse files Browse the repository at this point in the history
Use lib-common api for owner labels
  • Loading branch information
openshift-merge-bot[bot] authored Sep 20, 2024
2 parents 8025058 + bd19552 commit 26a4939
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 5 additions & 0 deletions pkg/dataplane/baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 == "" {
Expand Down
3 changes: 0 additions & 3 deletions pkg/dataplane/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
10 changes: 6 additions & 4 deletions pkg/dataplane/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 26a4939

Please sign in to comment.