Skip to content

Commit

Permalink
Improve validation error messages (#7729)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdoherty4 authored Feb 28, 2024
1 parent 3311d96 commit 544d2da
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions pkg/executables/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/validations/upgradevalidations/preflightvalidations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
},
Expand Down

0 comments on commit 544d2da

Please sign in to comment.