fetchKubernetesNode will send an http request to the k8s api server and return the corev1 model node
(nodeName string)
| 645 | |
| 646 | // fetchKubernetesNode will send an http request to the k8s api server and return the corev1 model node |
| 647 | func (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 |
| 676 | func (n Node) FetchKubernetesNodeInstanceIds() ([]string, error) { |
no outgoing calls
no test coverage detected