From 544d2da50a138757a5bc45304717d51a6e7daa0a Mon Sep 17 00:00:00 2001 From: Chris Doherty Date: Tue, 27 Feb 2024 18:49:07 -0600 Subject: [PATCH] Improve validation error messages (#7729) --- pkg/executables/kubectl.go | 10 ++++------ .../upgradevalidations/preflightvalidations.go | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pkg/executables/kubectl.go b/pkg/executables/kubectl.go index 6c508828909a..a62adfde2986 100644 --- a/pkg/executables/kubectl.go +++ b/pkg/executables/kubectl.go @@ -888,20 +888,18 @@ func (k *Kubectl) ValidateControlPlaneNodes(ctx context.Context, cluster *types. observedGeneration := cp.Status.ObservedGeneration generation := cp.Generation if observedGeneration != generation { - return fmt.Errorf("kubeadm control plane %s status needs to be refreshed: observed generation is %d, want %d", cp.Name, observedGeneration, generation) + return fmt.Errorf("kubeadm control plane %s status needs to be refreshed: generation=%v, observedGeneration=%d", cp.Name, generation, observedGeneration) } if !cp.Status.Ready { - return errors.New("control plane is not ready") + return errors.New("api server is not ready") } if cp.Status.UnavailableReplicas != 0 { - return fmt.Errorf("%v control plane replicas are unavailable", cp.Status.UnavailableReplicas) + return fmt.Errorf("%v/%v control plane replicas are unavailable", + cp.Status.UnavailableReplicas, cp.Status.Replicas) } - if cp.Status.ReadyReplicas != cp.Status.Replicas { - return fmt.Errorf("%v control plane replicas are not ready", cp.Status.Replicas-cp.Status.ReadyReplicas) - } return nil } diff --git a/pkg/validations/upgradevalidations/preflightvalidations.go b/pkg/validations/upgradevalidations/preflightvalidations.go index bf3a3978f2e1..650bd9f941e2 100644 --- a/pkg/validations/upgradevalidations/preflightvalidations.go +++ b/pkg/validations/upgradevalidations/preflightvalidations.go @@ -48,14 +48,14 @@ func (u *UpgradeValidations) PreflightValidations(ctx context.Context) []validat func() *validations.ValidationResult { return &validations.ValidationResult{ Name: "control plane ready", - Remediation: fmt.Sprintf("ensure control plane nodes and pods for cluster %s are Ready", u.Opts.WorkloadCluster.Name), + 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), } }, func() *validations.ValidationResult { return &validations.ValidationResult{ Name: "worker nodes ready", - Remediation: fmt.Sprintf("ensure machine deployments for cluster %s are Ready", u.Opts.WorkloadCluster.Name), + 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), } },