mirror of
https://github.com/outbackdingo/talos-cloud-controller-manager.git
synced 2026-01-28 02:20:18 +00:00
feat: label spot instanses
Set label `node.cloudprovider.kubernetes.io/lifecycle=spot` to spot instance. Signed-off-by: Serge Logvinov <serge.logvinov@sinextra.dev>
This commit is contained in:
@@ -25,6 +25,7 @@ Well-Known [labels](https://kubernetes.io/docs/reference/labels-annotations-tain
|
||||
Talos specific labels:
|
||||
* node.cloudprovider.kubernetes.io/clustername - talos cluster name
|
||||
* node.cloudprovider.kubernetes.io/platform - name of platform
|
||||
* node.cloudprovider.kubernetes.io/lifecycle - spot instance type
|
||||
|
||||
Node specs:
|
||||
* providerID magic string
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// ProviderName is the name of the Talo provider.
|
||||
// ProviderName is the name of the Talos provider.
|
||||
ProviderName = "talos"
|
||||
// ServiceAccountName is the service account name used in kube-system namespace.
|
||||
ServiceAccountName = "talos-cloud-controller-manager"
|
||||
@@ -19,6 +19,8 @@ const (
|
||||
ClusterNameNodeLabel = "node.cloudprovider.kubernetes.io/clustername"
|
||||
// ClusterNodePlatformLabel is the node label of platform name.
|
||||
ClusterNodePlatformLabel = "node.cloudprovider.kubernetes.io/platform"
|
||||
// ClusterNodeLifeCycleLabel is a life cycle type of compute node.
|
||||
ClusterNodeLifeCycleLabel = "node.cloudprovider.kubernetes.io/lifecycle"
|
||||
)
|
||||
|
||||
type cloud struct {
|
||||
|
||||
@@ -75,8 +75,10 @@ func (i *instances) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloud
|
||||
|
||||
addresses := getNodeAddresses(i.c.config, meta.Platform, providedIP, ifaces)
|
||||
|
||||
if meta.Hostname != "" && len(addresses) > 0 {
|
||||
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeHostName, Address: meta.Hostname})
|
||||
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeHostName, Address: node.Name})
|
||||
|
||||
if meta.Hostname != "" && strings.IndexByte(meta.Hostname, '.') > 0 {
|
||||
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeInternalDNS, Address: meta.Hostname})
|
||||
}
|
||||
|
||||
if err := syncNodeLabels(i.c, node, meta); err != nil {
|
||||
@@ -157,6 +159,10 @@ func syncNodeLabels(c *client, node *v1.Node, meta *runtime.PlatformMetadataSpec
|
||||
labelsToUpdate[ClusterNodePlatformLabel] = meta.Platform
|
||||
}
|
||||
|
||||
if meta.Spot && nodeLabels[ClusterNodeLifeCycleLabel] != "spot" {
|
||||
labelsToUpdate[ClusterNodeLifeCycleLabel] = "spot"
|
||||
}
|
||||
|
||||
if clusterName := c.talos.GetClusterName(); clusterName != "" && nodeLabels[ClusterNameNodeLabel] != clusterName {
|
||||
labelsToUpdate[ClusterNameNodeLabel] = clusterName
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user