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:
Serge Logvinov
2023-03-11 20:33:07 +02:00
parent 9e1b15e7c6
commit c80d5520ae
3 changed files with 12 additions and 3 deletions

View File

@@ -25,6 +25,7 @@ Well-Known [labels](https://kubernetes.io/docs/reference/labels-annotations-tain
Talos specific labels: Talos specific labels:
* node.cloudprovider.kubernetes.io/clustername - talos cluster name * node.cloudprovider.kubernetes.io/clustername - talos cluster name
* node.cloudprovider.kubernetes.io/platform - name of platform * node.cloudprovider.kubernetes.io/platform - name of platform
* node.cloudprovider.kubernetes.io/lifecycle - spot instance type
Node specs: Node specs:
* providerID magic string * providerID magic string

View File

@@ -10,7 +10,7 @@ import (
) )
const ( const (
// ProviderName is the name of the Talo provider. // ProviderName is the name of the Talos provider.
ProviderName = "talos" ProviderName = "talos"
// ServiceAccountName is the service account name used in kube-system namespace. // ServiceAccountName is the service account name used in kube-system namespace.
ServiceAccountName = "talos-cloud-controller-manager" ServiceAccountName = "talos-cloud-controller-manager"
@@ -19,6 +19,8 @@ const (
ClusterNameNodeLabel = "node.cloudprovider.kubernetes.io/clustername" ClusterNameNodeLabel = "node.cloudprovider.kubernetes.io/clustername"
// ClusterNodePlatformLabel is the node label of platform name. // ClusterNodePlatformLabel is the node label of platform name.
ClusterNodePlatformLabel = "node.cloudprovider.kubernetes.io/platform" ClusterNodePlatformLabel = "node.cloudprovider.kubernetes.io/platform"
// ClusterNodeLifeCycleLabel is a life cycle type of compute node.
ClusterNodeLifeCycleLabel = "node.cloudprovider.kubernetes.io/lifecycle"
) )
type cloud struct { type cloud struct {

View File

@@ -75,8 +75,10 @@ func (i *instances) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloud
addresses := getNodeAddresses(i.c.config, meta.Platform, providedIP, ifaces) addresses := getNodeAddresses(i.c.config, meta.Platform, providedIP, ifaces)
if meta.Hostname != "" && len(addresses) > 0 { addresses = append(addresses, v1.NodeAddress{Type: v1.NodeHostName, Address: node.Name})
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeHostName, Address: meta.Hostname})
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 { 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 labelsToUpdate[ClusterNodePlatformLabel] = meta.Platform
} }
if meta.Spot && nodeLabels[ClusterNodeLifeCycleLabel] != "spot" {
labelsToUpdate[ClusterNodeLifeCycleLabel] = "spot"
}
if clusterName := c.talos.GetClusterName(); clusterName != "" && nodeLabels[ClusterNameNodeLabel] != clusterName { if clusterName := c.talos.GetClusterName(); clusterName != "" && nodeLabels[ClusterNameNodeLabel] != clusterName {
labelsToUpdate[ClusterNameNodeLabel] = clusterName labelsToUpdate[ClusterNameNodeLabel] = clusterName
} }