...

Source file src/edge-infra.dev/pkg/sds/ien/node/node.go

Documentation: edge-infra.dev/pkg/sds/ien/node

     1  package node
     2  
     3  import (
     4  	"fmt"
     5  
     6  	corev1 "k8s.io/api/core/v1"
     7  
     8  	v1ien "edge-infra.dev/pkg/sds/ien/k8s/apis/v1"
     9  )
    10  
    11  const (
    12  	// Hostname of the Edge node
    13  	HostnameLabel string = "node.ncr.com/hostname"
    14  	// Kubernetes node role (worker or controlplane)
    15  	RoleLabel string = "node.ncr.com/role"
    16  	// Lane number for the Edge node (touchpoints).
    17  	LaneLabel string = "node.ncr.com/lane"
    18  	// Depicts if an Edge node is front-of-house touchpoint (POS)
    19  	// or a back-of-house server (touchpoint or server).
    20  	ClassLabel string = "node.ncr.com/class"
    21  	// The worker class label is attached to k8s worker nodes
    22  	// and defines the nodes class (touchpoint or server).
    23  	WorkerClassLabel string = "node.ncr.com/worker-class"
    24  	// Label applied to kubernetes control plane nodes.
    25  	ControlPlaneLabel string = "node-role.kubernetes.io/control-plane"
    26  	// Terminal ID annotation
    27  	TerminalIDLabel string = "node.ncr.com/terminal-id"
    28  )
    29  
    30  func IsTouchPointNode(node *corev1.Node) (bool, string) {
    31  	class := node.ObjectMeta.Labels[ClassLabel]
    32  	lane := node.ObjectMeta.Labels[LaneLabel]
    33  	if class == string(v1ien.Touchpoint) && lane != "" {
    34  		return true, lane
    35  	}
    36  	return false, ""
    37  }
    38  
    39  func IsControlPlaneNode(node *corev1.Node) (bool, error) {
    40  	nodeRole, ok := node.ObjectMeta.Labels[RoleLabel]
    41  	if !ok {
    42  		return false, fmt.Errorf("could not find %s annotation for node %s", RoleLabel, node.ObjectMeta.Name)
    43  	}
    44  	return v1ien.Role(nodeRole) == v1ien.ControlPlane, nil
    45  }
    46  

View as plain text