-
Notifications
You must be signed in to change notification settings - Fork 273
/
preflightvalidations.go
71 lines (65 loc) 路 2.93 KB
/
preflightvalidations.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
package upgradevalidations
import (
"context"
"fmt"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/config"
"github.com/aws/eks-anywhere/pkg/types"
"github.com/aws/eks-anywhere/pkg/validations"
)
func (u *UpgradeValidations) PreflightValidations(ctx context.Context) (err error) {
k := u.Opts.Kubectl
targetCluster := &types.Cluster{
Name: u.Opts.WorkloadCluster.Name,
KubeconfigFile: u.Opts.ManagementCluster.KubeconfigFile,
}
upgradeValidations := []validations.ValidationResult{
{
Name: "validate certificate for registry mirror",
Remediation: fmt.Sprintf("provide a valid certificate for you registry endpoint using %s env var", anywherev1.RegistryMirrorCAKey),
Err: validations.ValidateCertForRegistryMirror(u.Opts.Spec, u.Opts.TlsValidator),
},
{
Name: "control plane ready",
Remediation: fmt.Sprintf("ensure control plane nodes and pods for cluster %s are Ready", u.Opts.WorkloadCluster.Name),
Err: k.ValidateControlPlaneNodes(ctx, targetCluster, targetCluster.Name),
},
{
Name: "worker nodes ready",
Remediation: fmt.Sprintf("ensure machine deployments for cluster %s are Ready", u.Opts.WorkloadCluster.Name),
Err: k.ValidateWorkerNodes(ctx, u.Opts.Spec.Cluster.Name, targetCluster.KubeconfigFile),
},
{
Name: "nodes ready",
Remediation: fmt.Sprintf("check the Status of the control plane and worker nodes in cluster %s and verify they are Ready", u.Opts.WorkloadCluster.Name),
Err: k.ValidateNodes(ctx, u.Opts.WorkloadCluster.KubeconfigFile),
},
{
Name: "cluster CRDs ready",
Remediation: "",
Err: k.ValidateClustersCRD(ctx, u.Opts.ManagementCluster),
},
{
Name: "cluster object present on workload cluster",
Remediation: fmt.Sprintf("ensure that the CAPI cluster object %s representing cluster %s is present", clusterv1.GroupVersion, u.Opts.WorkloadCluster.Name),
Err: ValidateClusterObjectExists(ctx, k, u.Opts.ManagementCluster),
},
{
Name: "upgrade cluster kubernetes version increment",
Remediation: "ensure that the cluster kubernetes version is incremented by one minor version exactly (e.g. 1.18 -> 1.19)",
Err: ValidateServerVersionSkew(ctx, u.Opts.Spec.Cluster.Spec.KubernetesVersion, u.Opts.WorkloadCluster, k),
},
{
Name: "validate authentication for git provider",
Remediation: fmt.Sprintf("ensure %s, %s env variable are set and valid", config.EksaGitPrivateKeyTokenEnv, config.EksaGitKnownHostsFileEnv),
Err: validations.ValidateAuthenticationForGitProvider(u.Opts.Spec, u.Opts.CliConfig),
},
{
Name: "validate immutable fields",
Remediation: "",
Err: ValidateImmutableFields(ctx, k, targetCluster, u.Opts.Spec, u.Opts.Provider),
},
}
return validations.RunPreflightValidations(upgradeValidations)
}