Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/node-termination-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func main() {

interruptionEventStore := interruptioneventstore.New(nthConfig)
nodeMetadata := imds.GetNodeMetadata()
nodeMetadata.NodeLabels, err = (*node).GetNodeLabels(nthConfig.NodeName)
if err != nil {
log.Warn().Err(err).Msg("Unable to fetch node labels")
}
// Populate the aws region if available from node metadata and not already explicitly configured
if nthConfig.AWSRegion == "" && nodeMetadata.Region != "" {
nthConfig.AWSRegion = nodeMetadata.Region
Expand Down
19 changes: 10 additions & 9 deletions pkg/ec2metadata/ec2metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,16 @@ type RebalanceRecommendation struct {

// NodeMetadata contains information that applies to every drain event
type NodeMetadata struct {
AccountId string `json:"accountId"`
InstanceID string `json:"instanceId"`
InstanceType string `json:"instanceType"`
PublicHostname string `json:"publicHostname"`
PublicIP string `json:"publicIp"`
LocalHostname string `json:"localHostname"`
LocalIP string `json:"privateIp"`
AvailabilityZone string `json:"availabilityZone"`
Region string `json:"region"`
AccountId string `json:"accountId"`
InstanceID string `json:"instanceId"`
InstanceType string `json:"instanceType"`
PublicHostname string `json:"publicHostname"`
PublicIP string `json:"publicIp"`
LocalHostname string `json:"localHostname"`
LocalIP string `json:"privateIp"`
AvailabilityZone string `json:"availabilityZone"`
Region string `json:"region"`
NodeLabels map[string]string `json:"nodeLabels"`
}

// New constructs an instance of the Service client
Expand Down
13 changes: 13 additions & 0 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,19 @@ func (n Node) removeLabel(nodeName string, key string) error {
return nil
}

// GetNodeLabels will fetch node labels for a given nodeName
func (n Node) GetNodeLabels(nodeName string) (map[string]string, error) {
if n.nthConfig.DryRun {
log.Log().Str("node_name", nodeName).Msg("Node labels would have been fetched, but dry-run flag was set")
return nil, nil
}
node, err := n.fetchKubernetesNode(nodeName)
if err != nil {
return nil, err
}
return node.Labels, nil
}

// TaintSpotItn adds the spot termination notice taint onto a node
func (n Node) TaintSpotItn(nodeName string, eventID string) error {
if !n.nthConfig.TaintNode {
Expand Down