diff --git a/pkg/registration/spoke/addon/lease_controller.go b/pkg/registration/spoke/addon/lease_controller.go index fff621308..bd69d36fd 100644 --- a/pkg/registration/spoke/addon/lease_controller.go +++ b/pkg/registration/spoke/addon/lease_controller.go @@ -37,7 +37,6 @@ type managedClusterAddOnLeaseController struct { patcher patcher.Patcher[ *addonv1alpha1.ManagedClusterAddOn, addonv1alpha1.ManagedClusterAddOnSpec, addonv1alpha1.ManagedClusterAddOnStatus] addOnLister addonlisterv1alpha1.ManagedClusterAddOnLister - hubLeaseClient coordv1client.CoordinationV1Interface managementLeaseClient coordv1client.CoordinationV1Interface spokeLeaseClient coordv1client.CoordinationV1Interface } @@ -46,7 +45,6 @@ type managedClusterAddOnLeaseController struct { func NewManagedClusterAddOnLeaseController(clusterName string, addOnClient addonclient.Interface, addOnInformer addoninformerv1alpha1.ManagedClusterAddOnInformer, - hubLeaseClient coordv1client.CoordinationV1Interface, managementLeaseClient coordv1client.CoordinationV1Interface, spokeLeaseClient coordv1client.CoordinationV1Interface, resyncInterval time.Duration, @@ -58,7 +56,6 @@ func NewManagedClusterAddOnLeaseController(clusterName string, *addonv1alpha1.ManagedClusterAddOn, addonv1alpha1.ManagedClusterAddOnSpec, addonv1alpha1.ManagedClusterAddOnStatus]( addOnClient.AddonV1alpha1().ManagedClusterAddOns(clusterName)), addOnLister: addOnInformer.Lister(), - hubLeaseClient: hubLeaseClient, managementLeaseClient: managementLeaseClient, spokeLeaseClient: spokeLeaseClient, } @@ -131,31 +128,6 @@ func (c *managedClusterAddOnLeaseController) syncSingle(ctx context.Context, var condition metav1.Condition switch { case errors.IsNotFound(err): - // for backward compatible, for lower versions kubernetes (less than 1.14), addons update their leases on hub - // cluster, so if we cannot find addon lease on managed/management cluster, we will try to use addon hub lease. - // TODO remove this after we no longer support lower versions kubernetes (less than 1.14) - observedLease, err = c.hubLeaseClient.Leases(addOn.Namespace).Get(ctx, addOn.Name, metav1.GetOptions{}) - if err == nil { - if now.Before(observedLease.Spec.RenewTime.Add(gracePeriod)) { - // the lease is constantly updated, update its addon status to available - condition = metav1.Condition{ - Type: addonv1alpha1.ManagedClusterAddOnConditionAvailable, - Status: metav1.ConditionTrue, - Reason: "ManagedClusterAddOnLeaseUpdated", - Message: fmt.Sprintf("%s add-on is available.", addOn.Name), - } - break - } - - // the lease is not constantly updated, update its addon status to unavailable - condition = metav1.Condition{ - Type: addonv1alpha1.ManagedClusterAddOnConditionAvailable, - Status: metav1.ConditionFalse, - Reason: "ManagedClusterAddOnLeaseUpdateStopped", - Message: fmt.Sprintf("%s add-on is not available.", addOn.Name), - } - break - } condition = metav1.Condition{ Type: addonv1alpha1.ManagedClusterAddOnConditionAvailable, Status: metav1.ConditionUnknown, diff --git a/pkg/registration/spoke/addon/lease_controller_test.go b/pkg/registration/spoke/addon/lease_controller_test.go index 227425dc7..dfb7b36d0 100644 --- a/pkg/registration/spoke/addon/lease_controller_test.go +++ b/pkg/registration/spoke/addon/lease_controller_test.go @@ -325,35 +325,6 @@ func TestSync(t *testing.T) { } }, }, - { - name: "addon update its lease constantly (compatibility)", - queueKey: "test/test", - addOns: []runtime.Object{&addonv1alpha1.ManagedClusterAddOn{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: testinghelpers.TestManagedClusterName, - Name: "test", - }, - }}, - hubLeases: []runtime.Object{testinghelpers.NewAddOnLease(testinghelpers.TestManagedClusterName, "test", now)}, - spokeLeases: []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 := &addonv1alpha1.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.ConditionTrue { - t.Errorf("expected addon available condition is available, but failed") - } - }, - }, { name: "addon has customized health check", queueKey: "test/test", @@ -387,14 +358,12 @@ func TestSync(t *testing.T) { } } - hubClient := kubefake.NewSimpleClientset(c.hubLeases...) - managementLeaseClient := kubefake.NewSimpleClientset(c.managementLeases...) - spokeLeaseClient := kubefake.NewSimpleClientset(c.spokeLeases...) + managementLeaseClient := kubefake.NewClientset(c.managementLeases...) + spokeLeaseClient := kubefake.NewClientset(c.spokeLeases...) ctrl := &managedClusterAddOnLeaseController{ - clusterName: testinghelpers.TestManagedClusterName, - clock: clocktesting.NewFakeClock(time.Now()), - hubLeaseClient: hubClient.CoordinationV1(), + clusterName: testinghelpers.TestManagedClusterName, + clock: clocktesting.NewFakeClock(time.Now()), patcher: patcher.NewPatcher[ *addonv1alpha1.ManagedClusterAddOn, addonv1alpha1.ManagedClusterAddOnSpec, addonv1alpha1.ManagedClusterAddOnStatus]( addOnClient.AddonV1alpha1().ManagedClusterAddOns(testinghelpers.TestManagedClusterName)), diff --git a/pkg/registration/spoke/spokeagent.go b/pkg/registration/spoke/spokeagent.go index 5a46df550..9d79aed49 100644 --- a/pkg/registration/spoke/spokeagent.go +++ b/pkg/registration/spoke/spokeagent.go @@ -454,7 +454,6 @@ func (o *SpokeAgentConfig) RunSpokeAgentWithSpokeInformers(ctx context.Context, o.agentOptions.SpokeClusterName, addOnClient, addOnInformerFactory.Addon().V1alpha1().ManagedClusterAddOns(), - hubKubeClient.CoordinationV1(), managementKubeClient.CoordinationV1(), spokeKubeClient.CoordinationV1(), AddOnLeaseControllerSyncInterval, //TODO: this interval time should be allowed to change from outside