[node operator] helpers: find node vpc IP and check if node is control-plane node

Signed-off-by: Malte Poll <mp@edgeless.systems>
This commit is contained in:
Malte Poll 2022-07-18 16:37:59 +02:00 committed by Malte Poll
parent de9fa37f63
commit bef2bcc4a9
2 changed files with 87 additions and 5 deletions

View file

@ -1,12 +1,15 @@
package node
import (
"errors"
"regexp"
updatev1alpha1 "github.com/edgelesssys/constellation/operators/constellation-node-operator/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
)
const controlPlaneRoleLabel = "node-role.kubernetes.io/control-plane"
var reservedHostRegex = regexp.MustCompile(`^(.+\.|)(kubernetes|k8s)\.io(/.*)?$`)
// Ready checks if a kubernetes node has the `NodeReady` condition set to true.
@ -19,6 +22,22 @@ func Ready(node *corev1.Node) bool {
return false
}
// VPCIP returns the VPC IP of a node.
func VPCIP(node *corev1.Node) (string, error) {
for _, addr := range node.Status.Addresses {
if addr.Type == corev1.NodeInternalIP {
return addr.Address, nil
}
}
return "", errors.New("no VPC IP found")
}
// IsControlPlaneNode returns true if the node is a control plane node.
func IsControlPlaneNode(node *corev1.Node) bool {
_, ok := node.Labels[controlPlaneRoleLabel]
return ok
}
// FindPending searches for a pending node that matches a node.
// The pending node has to have the goal to join the cluster and be reported as ready be the CSP.
// if the node is not found, nil is returned.