-
Notifications
You must be signed in to change notification settings - Fork 283
/
nodename.go
40 lines (33 loc) · 1.36 KB
/
nodename.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package framework
import (
"fmt"
corev1 "k8s.io/api/core/v1"
"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/logger"
)
// ValidateControlPlaneNodeNameMatchCAPIMachineName validate if node name is same as CAPI machine name.
func ValidateControlPlaneNodeNameMatchCAPIMachineName(controlPlane v1alpha1.ControlPlaneConfiguration, node corev1.Node) error {
if controlPlane.MachineGroupRef.Kind == "CloudStackMachineConfig" {
logger.V(4).Info("Validating control plane node matches CAPI machine name")
return validateNodeNameMatchCAPIMachineName(node)
}
return nil
}
// ValidateWorkerNodeNameMatchCAPIMachineName validate if node name is same as CAPI machine name.
func ValidateWorkerNodeNameMatchCAPIMachineName(w v1alpha1.WorkerNodeGroupConfiguration, node corev1.Node) error {
if w.MachineGroupRef.Kind == "CloudStackMachineConfig" {
logger.V(4).Info("Validating worker node matches CAPI machine name")
return validateNodeNameMatchCAPIMachineName(node)
}
return nil
}
func validateNodeNameMatchCAPIMachineName(node corev1.Node) error {
capiMachineName, ok := node.Annotations["cluster.x-k8s.io/machine"]
if !ok {
return fmt.Errorf("CAPI machine name not found for node %s", node.Name)
}
if node.Name != capiMachineName {
return fmt.Errorf("node name %s not match CAPI machine name %s", node.Name, capiMachineName)
}
return nil
}