MCPcopy Index your code
hub / github.com/aws/aws-node-termination-handler / fetchKubernetesNode

Method fetchKubernetesNode

pkg/node/node.go:647–673  ·  view source on GitHub ↗

fetchKubernetesNode will send an http request to the k8s api server and return the corev1 model node

(nodeName string)

Source from the content-addressed store, hash-verified

645
646// fetchKubernetesNode will send an http request to the k8s api server and return the corev1 model node
647func (n Node) fetchKubernetesNode(nodeName string) (*corev1.Node, error) {
648 node := &corev1.Node{
649 ObjectMeta: metav1.ObjectMeta{Name: nodeName},
650 Spec: corev1.NodeSpec{},
651 }
652 if n.nthConfig.DryRun {
653 return node, nil
654 }
655 shortNodeName := strings.Split(nodeName, ".")[0]
656 labelSelector := metav1.LabelSelector{
657 MatchExpressions: []metav1.LabelSelectorRequirement{
658 {
659 Key: "kubernetes.io/hostname",
660 Operator: metav1.LabelSelectorOpIn,
661 Values: []string{nodeName, shortNodeName},
662 },
663 },
664 }
665
666 listOptions := metav1.ListOptions{LabelSelector: metav1.FormatLabelSelector(&labelSelector)}
667 matchingNodes, err := n.drainHelper.Client.CoreV1().Nodes().List(context.TODO(), listOptions)
668 if err != nil || len(matchingNodes.Items) == 0 {
669 log.Warn().Msgf("Unable to list Nodes w/ label, falling back to direct Get lookup of node")
670 return n.drainHelper.Client.CoreV1().Nodes().Get(context.TODO(), nodeName, metav1.GetOptions{})
671 }
672 return &matchingNodes.Items[0], nil
673}
674
675// fetchKubernetesNode will send an http request to the k8s api server and return list of AWS EC2 instance id
676func (n Node) FetchKubernetesNodeInstanceIds() ([]string, error) {

Callers 15

CordonAndDrainMethod · 0.95
CordonMethod · 0.95
UncordonMethod · 0.95
IsUnschedulableMethod · 0.95
GetEventIDMethod · 0.95
addLabelMethod · 0.95
removeLabelMethod · 0.95
GetNodeLabelsMethod · 0.95
TaintSpotItnMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected