From a00ee1d8336be8e87535edc27387c6066aa2b574 Mon Sep 17 00:00:00 2001 From: Roman Hros Date: Fri, 19 Jul 2024 09:15:08 +0200 Subject: [PATCH] Add Openstack server hostId as k8s node label Signed-off-by: Roman Hros --- pkg/openstack/instances.go | 10 ++++++++++ pkg/openstack/instancesv2.go | 11 ++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pkg/openstack/instances.go b/pkg/openstack/instances.go index f799c6137c..fdc0a70aab 100644 --- a/pkg/openstack/instances.go +++ b/pkg/openstack/instances.go @@ -60,6 +60,7 @@ const ( instanceShutoff = "SHUTOFF" RegionalProviderIDEnv = "OS_CCM_REGIONAL" noSortPriority = 0 + LabelHostID = "topology.openstack.org/host-id" ) var _ cloudprovider.Instances = &Instances{} @@ -441,6 +442,15 @@ func srvInstanceType(client *gophercloud.ServiceClient, srv *servers.Server) (st return "", fmt.Errorf("flavor original_name/id not found") } +func getAdditionalLabels(srv *servers.Server) map[string]string { + additionalLabels := map[string]string{} + + // Add the host ID to the additional labels + additionalLabels[LabelHostID] = srv.HostID + + return additionalLabels +} + func isValidLabelValue(v string) bool { if errs := validation.IsValidLabelValue(v); len(errs) != 0 { return false diff --git a/pkg/openstack/instancesv2.go b/pkg/openstack/instancesv2.go index c27c7a6ce3..a29eb0cba2 100644 --- a/pkg/openstack/instancesv2.go +++ b/pkg/openstack/instancesv2.go @@ -134,11 +134,12 @@ func (i *InstancesV2) InstanceMetadata(ctx context.Context, node *v1.Node) (*clo } return &cloudprovider.InstanceMetadata{ - ProviderID: i.makeInstanceID(&server), - InstanceType: instanceType, - NodeAddresses: addresses, - Zone: server.AvailabilityZone, - Region: i.region, + ProviderID: i.makeInstanceID(&server), + InstanceType: instanceType, + NodeAddresses: addresses, + Zone: server.AvailabilityZone, + Region: i.region, + AdditionalLabels: getAdditionalLabels(&server), }, nil }