Skip to content

Commit ddb24fb

Browse files
committed
KCP: make EtcdMemberHealthy less verbose on client creation failures
1 parent f948999 commit ddb24fb

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

controlplane/kubeadm/internal/etcd_client_generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func NewEtcdClientGenerator(restConfig *rest.Config, tlsConfig *tls.Config, etcd
6969
func (c *EtcdClientGenerator) forFirstAvailableNode(ctx context.Context, nodeNames []string) (*etcd.Client, error) {
7070
// This is an additional safeguard for avoiding this func to return nil, nil.
7171
if len(nodeNames) == 0 {
72-
return nil, errors.New("invalid argument: forLeader can't be called with an empty list of nodes")
72+
return nil, errors.New("invalid argument: forFirstAvailableNode can't be called with an empty list of nodes")
7373
}
7474

7575
// Loop through the existing control plane nodes.

controlplane/kubeadm/internal/etcd_client_generator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestFirstAvailableNode(t *testing.T) {
6363
name: "Fails when called with an empty node list",
6464
nodes: nil,
6565
cc: nil,
66-
expectedErr: "invalid argument: forLeader can't be called with an empty list of nodes",
66+
expectedErr: "invalid argument: forFirstAvailableNode can't be called with an empty list of nodes",
6767
},
6868
{
6969
name: "Returns error from client",
@@ -97,7 +97,7 @@ func TestFirstAvailableNode(t *testing.T) {
9797

9898
if tt.expectedErr != "" {
9999
g.Expect(err).To(HaveOccurred())
100-
g.Expect(err.Error()).Should(Equal(tt.expectedErr))
100+
g.Expect(err.Error()).Should(BeComparableTo(tt.expectedErr))
101101
} else {
102102
g.Expect(*client).Should(BeComparableTo(tt.expectedClient))
103103
}

controlplane/kubeadm/internal/workload_cluster_conditions.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,17 @@ func (w *Workload) updateManagedEtcdConditions(ctx context.Context, controlPlane
316316
return retryableError
317317
}
318318

319+
func unwrapAll(err error) error {
320+
for {
321+
newErr := errors.Unwrap(err)
322+
if newErr == nil {
323+
break
324+
}
325+
err = newErr
326+
}
327+
return err
328+
}
329+
319330
func (w *Workload) getCurrentEtcdMembers(ctx context.Context, machine *clusterv1.Machine, nodeName string) ([]*etcd.Member, error) {
320331
// Create the etcd Client for the etcd Pod scheduled on the Node
321332
etcdClient, err := w.etcdClientGenerator.forFirstAvailableNode(ctx, []string{nodeName})
@@ -326,7 +337,7 @@ func (w *Workload) getCurrentEtcdMembers(ctx context.Context, machine *clusterv1
326337
Type: controlplanev1.KubeadmControlPlaneMachineEtcdMemberHealthyV1Beta2Condition,
327338
Status: metav1.ConditionUnknown,
328339
Reason: controlplanev1.KubeadmControlPlaneMachineEtcdMemberInspectionFailedV1Beta2Reason,
329-
Message: fmt.Sprintf("Failed to connect to the etcd Pod on the %s Node: %s", nodeName, err),
340+
Message: fmt.Sprintf("Failed to connect to the etcd Pod on the %s Node: %s", nodeName, unwrapAll(err)),
330341
})
331342
return nil, errors.Wrapf(err, "failed to get current etcd members: failed to connect to the etcd Pod on the %s Node", nodeName)
332343
}

0 commit comments

Comments
 (0)