From 887a47b2b24409fdd154e1e200baeb0b5c79f46f 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 f8a9b5e74e..734b83c2c8 100644 --- a/pkg/openstack/instancesv2.go +++ b/pkg/openstack/instancesv2.go @@ -137,11 +137,12 @@ func (i *InstancesV2) InstanceMetadata(ctx context.Context, node *v1.Node) (*clo availabilityZone := util.SanitizeLabel(server.AvailabilityZone) return &cloudprovider.InstanceMetadata{ - ProviderID: i.makeInstanceID(&server), - InstanceType: instanceType, - NodeAddresses: addresses, - Zone: availabilityZone, - Region: i.region, + ProviderID: i.makeInstanceID(&server), + InstanceType: instanceType, + NodeAddresses: addresses, + Zone: availabilityZone, + Region: i.region, + AdditionalLabels: getAdditionalLabels(&server), }, nil }