Skip to content

Commit

Permalink
Merge pull request #1922 from vmware-tanzu/clarify_err_msg
Browse files Browse the repository at this point in the history
clarify error message for when there is no healthy controller manager
  • Loading branch information
cfryanr authored Apr 22, 2024
2 parents c79f8c8 + 1d8310e commit 5fe94c4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
11 changes: 9 additions & 2 deletions internal/controller/kubecertagent/kubecertagent.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2023 the Pinniped contributors. All Rights Reserved.
// Copyright 2021-2024 the Pinniped contributors. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// Package kubecertagent provides controllers that ensure a pod (the kube-cert-agent), is
Expand All @@ -9,6 +9,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -278,7 +279,13 @@ func (c *agentController) Sync(ctx controllerlib.Context) error {
// If there are no healthy controller manager pods, we alert the user that we can't find the keypair via
// the CredentialIssuer.
if newestControllerManager == nil {
err := fmt.Errorf("could not find a healthy kube-controller-manager pod (%s)", pluralize(controllerManagerPods))
msg := fmt.Sprintf("could not find a healthy kube-controller-manager pod (%s)", pluralize(controllerManagerPods))
if len(controllerManagerPods) == 0 {
err = fmt.Errorf("%s: note that this error is the expected behavior for some cluster types, "+
"including most cloud provider clusters (e.g. GKE, AKS, EKS)", msg)
} else {
err = errors.New(msg)
}
return c.failStrategyAndErr(ctx.Context, credIssuer, err, configv1alpha1.CouldNotFetchKeyStrategyReason)
}

Expand Down
12 changes: 7 additions & 5 deletions internal/controller/kubecertagent/kubecertagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,15 @@ func TestAgentController(t *testing.T) {
},
},
wantDistinctErrors: []string{
"could not find a healthy kube-controller-manager pod (0 candidates)",
"could not find a healthy kube-controller-manager pod (0 candidates): " +
"note that this error is the expected behavior for some cluster types, including most cloud provider clusters (e.g. GKE, AKS, EKS)",
},
wantStrategy: &configv1alpha1.CredentialIssuerStrategy{
Type: configv1alpha1.KubeClusterSigningCertificateStrategyType,
Status: configv1alpha1.ErrorStrategyStatus,
Reason: configv1alpha1.CouldNotFetchKeyStrategyReason,
Message: "could not find a healthy kube-controller-manager pod (0 candidates)",
Type: configv1alpha1.KubeClusterSigningCertificateStrategyType,
Status: configv1alpha1.ErrorStrategyStatus,
Reason: configv1alpha1.CouldNotFetchKeyStrategyReason,
Message: "could not find a healthy kube-controller-manager pod (0 candidates): " +
"note that this error is the expected behavior for some cluster types, including most cloud provider clusters (e.g. GKE, AKS, EKS)",
LastUpdateTime: metav1.NewTime(now),
},
},
Expand Down
5 changes: 3 additions & 2 deletions test/integration/concierge_credentialissuer_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2021 the Pinniped contributors. All Rights Reserved.
// Copyright 2020-2024 the Pinniped contributors. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package integration
Expand Down Expand Up @@ -90,7 +90,8 @@ func TestCredentialIssuer(t *testing.T) {
} else {
require.Equal(t, configv1alpha1.ErrorStrategyStatus, actualStatusStrategy.Status)
require.Equal(t, configv1alpha1.CouldNotFetchKeyStrategyReason, actualStatusStrategy.Reason)
require.Contains(t, actualStatusStrategy.Message, "could not find a healthy kube-controller-manager pod (0 candidates)")
require.Contains(t, actualStatusStrategy.Message, "could not find a healthy kube-controller-manager pod (0 candidates): "+
"note that this error is the expected behavior for some cluster types, including most cloud provider clusters (e.g. GKE, AKS, EKS)")
require.Nil(t, actualStatusKubeConfigInfo)
}
})
Expand Down

0 comments on commit 5fe94c4

Please sign in to comment.