-
Notifications
You must be signed in to change notification settings - Fork 279
/
defaults.go
90 lines (73 loc) · 3.42 KB
/
defaults.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package cluster
import (
"context"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/constants"
)
func SetConfigDefaults(c *Config) error {
return manager().SetDefaults(c)
}
// ControlPlaneIPCheckAnnotationDefaulter is the defaulter created to set the skip ip value.
type ControlPlaneIPCheckAnnotationDefaulter struct {
skipCPIPCheck bool
}
// NewControlPlaneIPCheckAnnotationDefaulter allows to create a new ControlPlaneIPCheckAnnotationDefaulter.
func NewControlPlaneIPCheckAnnotationDefaulter(skipIPCheck bool) ControlPlaneIPCheckAnnotationDefaulter {
return ControlPlaneIPCheckAnnotationDefaulter{
skipCPIPCheck: skipIPCheck,
}
}
// ControlPlaneIPCheckDefault sets the annotation for control plane skip ip check if the flag is set to true.
func (d ControlPlaneIPCheckAnnotationDefaulter) ControlPlaneIPCheckDefault(ctx context.Context, spec *Spec) (*Spec, error) {
if d.skipCPIPCheck {
spec.Cluster.DisableControlPlaneIPCheck()
}
return spec, nil
}
// MachineHealthCheckDefaulter is the defaulter created to configure the machine health check timeouts.
type MachineHealthCheckDefaulter struct {
NodeStartupTimeout time.Duration
UnhealthyMachineTimeout time.Duration
}
// NewMachineHealthCheckDefaulter allows to create a new MachineHealthCheckDefaulter.
func NewMachineHealthCheckDefaulter(nodeStartupTimeout, unhealthyMachineTimeout time.Duration) MachineHealthCheckDefaulter {
return MachineHealthCheckDefaulter{
NodeStartupTimeout: nodeStartupTimeout,
UnhealthyMachineTimeout: unhealthyMachineTimeout,
}
}
// MachineHealthCheckDefault sets the defaults for machine health check timeouts.
func (d MachineHealthCheckDefaulter) MachineHealthCheckDefault(ctx context.Context, spec *Spec) (*Spec, error) {
SetMachineHealthCheckTimeoutDefaults(spec.Cluster, d.NodeStartupTimeout, d.UnhealthyMachineTimeout)
return spec, nil
}
// SetMachineHealthCheckTimeoutDefaults sests defaults for mhcs in the EKSA cluster object based on the input.
func SetMachineHealthCheckTimeoutDefaults(cluster *anywherev1.Cluster, nodeStartupTimeout, unhealthyMachineTimeout time.Duration) {
if cluster.Spec.MachineHealthCheck != nil && cluster.Spec.MachineHealthCheck.NodeStartupTimeout != nil && cluster.Spec.MachineHealthCheck.UnhealthyMachineTimeout != nil {
return
}
if cluster.Spec.MachineHealthCheck == nil {
cluster.Spec.MachineHealthCheck = &anywherev1.MachineHealthCheck{}
}
if cluster.Spec.MachineHealthCheck.NodeStartupTimeout == nil {
if cluster.Spec.DatacenterRef.Kind == anywherev1.TinkerbellDatacenterKind && nodeStartupTimeout == constants.DefaultNodeStartupTimeout {
nodeStartupTimeout = constants.DefaultTinkerbellNodeStartupTimeout
}
}
setMachineHealthCheckTimeoutDefaults(cluster, nodeStartupTimeout, unhealthyMachineTimeout)
}
// setMachineHealthCheckTimeoutDefaults sets default timeout values for cluster's machine health checks.
func setMachineHealthCheckTimeoutDefaults(cluster *anywherev1.Cluster, nodeStartupTimeout, unhealthyMachineTimeout time.Duration) {
if cluster.Spec.MachineHealthCheck.NodeStartupTimeout == nil {
cluster.Spec.MachineHealthCheck.NodeStartupTimeout = &metav1.Duration{
Duration: nodeStartupTimeout,
}
}
if cluster.Spec.MachineHealthCheck.UnhealthyMachineTimeout == nil {
cluster.Spec.MachineHealthCheck.UnhealthyMachineTimeout = &metav1.Duration{
Duration: unhealthyMachineTimeout,
}
}
}