Improve diagnostic message when hosted addon lease is not found (#1651)

Signed-off-by: Mike Ng <ming@redhat.com>
This commit is contained in:
Mike Ng
2026-08-11 07:50:53 +00:00
committed by GitHub
parent 729fd972be
commit b864cf0c52
2 changed files with 48 additions and 1 deletions
@@ -125,11 +125,18 @@ func (c *managedClusterAddOnLeaseController) syncSingle(ctx context.Context,
var condition metav1.Condition
switch {
case errors.IsNotFound(err):
message := fmt.Sprintf("The status of %s add-on is unknown.", addOn.Name)
if isAddonRunningOutsideManagedCluster(addOn) {
// No lease on the declared hosting cluster usually means it doesn't match the klusterlet's actual hosting cluster.
hostingCluster := addOn.Annotations[addonv1beta1.HostingClusterNameAnnotationKey]
message = fmt.Sprintf("%s No lease found on hosting cluster %q; verify it matches the cluster "+
"where this managed cluster's klusterlet actually runs.", message, hostingCluster)
}
condition = metav1.Condition{
Type: addonv1beta1.ManagedClusterAddOnConditionAvailable,
Status: metav1.ConditionUnknown,
Reason: "ManagedClusterAddOnLeaseNotFound",
Message: fmt.Sprintf("The status of %s add-on is unknown.", addOn.Name),
Message: message,
}
case err != nil:
return err
@@ -3,6 +3,7 @@ package addon
import (
"context"
"encoding/json"
"strings"
"testing"
"time"
@@ -332,6 +333,45 @@ func TestSync(t *testing.T) {
}
},
},
{
name: "no addon lease on management cluster names the hosting cluster in the message",
queueKey: "test/test",
addOns: []runtime.Object{&addonv1beta1.ManagedClusterAddOn{
ObjectMeta: metav1.ObjectMeta{
Namespace: testinghelpers.TestManagedClusterName,
Name: "test",
Annotations: map[string]string{
addonv1beta1.HostingClusterNameAnnotationKey: "cluster1",
},
},
Spec: addonv1beta1.ManagedClusterAddOnSpec{},
Status: addonv1beta1.ManagedClusterAddOnStatus{
Namespace: "test",
},
}},
hubLeases: []runtime.Object{},
managementLeases: []runtime.Object{},
validateActions: func(t *testing.T, ctx *testingcommon.FakeSyncContext, actions []clienttesting.Action) {
testingcommon.AssertActions(t, actions, "patch")
patch := actions[0].(clienttesting.PatchAction).GetPatch()
addOn := &addonv1beta1.ManagedClusterAddOn{}
err := json.Unmarshal(patch, addOn)
if err != nil {
t.Fatal(err)
}
addOnCond := meta.FindStatusCondition(addOn.Status.Conditions, "Available")
if addOnCond == nil {
t.Errorf("expected addon available condition, but failed")
return
}
if addOnCond.Status != metav1.ConditionUnknown {
t.Errorf("expected addon available condition is unknown, but failed")
}
if !strings.Contains(addOnCond.Message, "cluster1") {
t.Errorf("expected message to name the declared hosting cluster, got: %s", addOnCond.Message)
}
},
},
{
name: "addon has customized health check",
queueKey: "test/test",