Skip to content

Commit

Permalink
Add Openstack server hostId as k8s node label
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Hros <[email protected]>
  • Loading branch information
chess-knight committed Jul 19, 2024
1 parent e39dffb commit a00ee1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 10 additions & 0 deletions pkg/openstack/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (
instanceShutoff = "SHUTOFF"
RegionalProviderIDEnv = "OS_CCM_REGIONAL"
noSortPriority = 0
LabelHostID = "topology.openstack.org/host-id"
)

var _ cloudprovider.Instances = &Instances{}
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions pkg/openstack/instancesv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit a00ee1d

Please sign in to comment.