Skip to content

Commit

Permalink
remove the support for checking add-on hub lease (#275)
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Liu <[email protected]>

Signed-off-by: Wei Liu <[email protected]>
  • Loading branch information
skeeey authored Oct 19, 2022
1 parent fd7eb39 commit b391219
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 170 deletions.
5 changes: 2 additions & 3 deletions pkg/hub/addon/healthcheck_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

operatorhelpers "github.com/openshift/library-go/pkg/operator/v1helpers"
addonv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
addonclient "open-cluster-management.io/api/client/addon/clientset/versioned"
addoninformerv1alpha1 "open-cluster-management.io/api/client/addon/informers/externalversions/addon/v1alpha1"
addonlisterv1alpha1 "open-cluster-management.io/api/client/addon/listers/addon/v1alpha1"
Expand All @@ -22,8 +23,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)

const addOnAvailableConditionType = "Available" //TODO add this to ManagedClusterAddOn api

// managedClusterAddonHealthCheckController udpates managed cluster addons status through watching the managed cluster status on
// the hub cluster.
type managedClusterAddOnHealthCheckController struct {
Expand Down Expand Up @@ -95,7 +94,7 @@ func (c *managedClusterAddOnHealthCheckController) sync(ctx context.Context, syn
addOn.Namespace,
addOn.Name,
helpers.UpdateManagedClusterAddOnStatusFn(metav1.Condition{
Type: addOnAvailableConditionType,
Type: addonv1alpha1.ManagedClusterAddOnConditionAvailable,
Status: managedClusterAvailableCondition.Status,
Reason: managedClusterAvailableCondition.Reason,
Message: managedClusterAvailableCondition.Message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ rules:
# Allow spoke registration agent to get/update coordination.k8s.io/lease
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
#TODO: for backward compatible, we do not limit the resource name in release 2.3.
#After release 2.3, we will limit the resource name.
#resourceNames: ["managed-cluster-lease"]
resourceNames: ["managed-cluster-lease"]
verbs: ["get", "update"]
# Allow agent to get/list/watch managed cluster addons
- apiGroups: ["addon.open-cluster-management.io"]
Expand Down
5 changes: 2 additions & 3 deletions pkg/hub/managedcluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ func (c *managedClusterController) sync(ctx context.Context, syncCtx factory.Syn
return err
}

// TODO: we will add the managedcluster-namespace.yaml back to staticFiles
// in next release, currently, we need keep the namespace after the managed
// cluster is deleted.
// TODO consider to add the managedcluster-namespace.yaml back to staticFiles,
// currently, we keep the namespace after the managed cluster is deleted.
applyFiles := []string{"manifests/managedcluster-namespace.yaml"}
applyFiles = append(applyFiles, staticFiles...)

Expand Down
32 changes: 2 additions & 30 deletions pkg/spoke/addon/lease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/clock"
coordv1client "k8s.io/client-go/kubernetes/typed/coordination/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/utils/clock"
)

const leaseDurationTimes = 5

// AddOnLeaseControllerLeaseDurationSeconds is exposed so that integration tests can crank up the lease update speed.
// TODO: we may add this to ManagedClusterAddOn API to allow addon to adjust its own lease duration seconds
// TODO we may add this to ManagedClusterAddOn API to allow addon to adjust its own lease duration seconds
var AddOnLeaseControllerLeaseDurationSeconds = 60

// managedClusterAddOnLeaseController updates the managed cluster addons status on the hub cluster through checking the add-on
Expand All @@ -37,7 +37,6 @@ type managedClusterAddOnLeaseController struct {
clock clock.Clock
addOnClient addonclient.Interface
addOnLister addonlisterv1alpha1.ManagedClusterAddOnLister
hubLeaseClient coordv1client.CoordinationV1Interface
managementLeaseClient coordv1client.CoordinationV1Interface
spokeLeaseClient coordv1client.CoordinationV1Interface
}
Expand All @@ -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,
Expand All @@ -56,7 +54,6 @@ func NewManagedClusterAddOnLeaseController(clusterName string,
clock: clock.RealClock{},
addOnClient: addOnClient,
addOnLister: addOnInformer.Lister(),
hubLeaseClient: hubLeaseClient,
managementLeaseClient: managementLeaseClient,
spokeLeaseClient: spokeLeaseClient,
}
Expand Down Expand Up @@ -129,31 +126,6 @@ func (c *managedClusterAddOnLeaseController) syncSingle(ctx context.Context,
var condition metav1.Condition
switch {
case errors.IsNotFound(err):
// for backward compatible, before release-2.3, 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: after release-2.3, we will remove these code
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,
Expand Down
45 changes: 2 additions & 43 deletions pkg/spoke/addon/lease_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/clock"
kubefake "k8s.io/client-go/kubernetes/fake"
clienttesting "k8s.io/client-go/testing"
clocktesting "k8s.io/utils/clock/testing"
)

var now = time.Now()
Expand Down Expand Up @@ -100,7 +100,6 @@ func TestSync(t *testing.T) {
name string
queueKey string
addOns []runtime.Object
hubLeases []runtime.Object
managementLeases []runtime.Object
spokeLeases []runtime.Object
validateActions func(t *testing.T, ctx *testinghelpers.FakeSyncContext, actions []clienttesting.Action)
Expand All @@ -109,7 +108,6 @@ func TestSync(t *testing.T) {
name: "bad queue key",
queueKey: "test/test/test",
addOns: []runtime.Object{},
hubLeases: []runtime.Object{},
spokeLeases: []runtime.Object{},
validateActions: func(t *testing.T, ctx *testinghelpers.FakeSyncContext, actions []clienttesting.Action) {
testinghelpers.AssertNoActions(t, actions)
Expand All @@ -119,7 +117,6 @@ func TestSync(t *testing.T) {
name: "no addons",
queueKey: "test/test",
addOns: []runtime.Object{},
hubLeases: []runtime.Object{},
spokeLeases: []runtime.Object{},
validateActions: func(t *testing.T, ctx *testinghelpers.FakeSyncContext, actions []clienttesting.Action) {
testinghelpers.AssertNoActions(t, actions)
Expand All @@ -137,7 +134,6 @@ func TestSync(t *testing.T) {
InstallNamespace: "test",
},
}},
hubLeases: []runtime.Object{},
spokeLeases: []runtime.Object{},
validateActions: func(t *testing.T, ctx *testinghelpers.FakeSyncContext, actions []clienttesting.Action) {
testinghelpers.AssertActions(t, actions, "get", "patch")
Expand Down Expand Up @@ -169,7 +165,6 @@ func TestSync(t *testing.T) {
InstallNamespace: "test",
},
}},
hubLeases: []runtime.Object{},
spokeLeases: []runtime.Object{
testinghelpers.NewAddOnLease("test", "test", now.Add(-5*time.Minute)),
},
Expand Down Expand Up @@ -203,7 +198,6 @@ func TestSync(t *testing.T) {
InstallNamespace: "test",
},
}},
hubLeases: []runtime.Object{},
spokeLeases: []runtime.Object{
testinghelpers.NewAddOnLease("test", "test", now),
},
Expand Down Expand Up @@ -247,7 +241,6 @@ func TestSync(t *testing.T) {
},
},
}},
hubLeases: []runtime.Object{},
spokeLeases: []runtime.Object{
testinghelpers.NewAddOnLease("test", "test", now),
},
Expand Down Expand Up @@ -275,7 +268,6 @@ func TestSync(t *testing.T) {
},
},
},
hubLeases: []runtime.Object{},
spokeLeases: []runtime.Object{
testinghelpers.NewAddOnLease("test1", "test1", now.Add(-5*time.Minute)),
},
Expand All @@ -300,7 +292,6 @@ func TestSync(t *testing.T) {
InstallNamespace: "test",
},
}},
hubLeases: []runtime.Object{},
managementLeases: []runtime.Object{
testinghelpers.NewAddOnLease("test", "test", now),
},
Expand All @@ -322,35 +313,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 *testinghelpers.FakeSyncContext, actions []clienttesting.Action) {
testinghelpers.AssertActions(t, actions, "get", "patch")
patch := actions[1].(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",
Expand All @@ -365,7 +327,6 @@ func TestSync(t *testing.T) {
},
},
}},
hubLeases: []runtime.Object{},
spokeLeases: []runtime.Object{},
validateActions: func(t *testing.T, ctx *testinghelpers.FakeSyncContext, actions []clienttesting.Action) {
testinghelpers.AssertNoActions(t, actions)
Expand All @@ -384,14 +345,12 @@ func TestSync(t *testing.T) {
}
}

hubClient := kubefake.NewSimpleClientset(c.hubLeases...)
managementLeaseClient := kubefake.NewSimpleClientset(c.managementLeases...)
spokeLeaseClient := kubefake.NewSimpleClientset(c.spokeLeases...)

ctrl := &managedClusterAddOnLeaseController{
clusterName: testinghelpers.TestManagedClusterName,
clock: clock.NewFakeClock(time.Now()),
hubLeaseClient: hubClient.CoordinationV1(),
clock: clocktesting.NewFakeClock(time.Now()),
addOnClient: addOnClient,
addOnLister: addOnInformerFactory.Addon().V1alpha1().ManagedClusterAddOns().Lister(),
managementLeaseClient: managementLeaseClient.CoordinationV1(),
Expand Down
1 change: 0 additions & 1 deletion pkg/spoke/spokeagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ func (o *SpokeAgentOptions) RunSpokeAgent(ctx context.Context, controllerContext
o.ClusterName,
addOnClient,
addOnInformerFactory.Addon().V1alpha1().ManagedClusterAddOns(),
hubKubeClient.CoordinationV1(),
managementKubeClient.CoordinationV1(),
spokeKubeClient.CoordinationV1(),
AddOnLeaseControllerSyncInterval, //TODO: this interval time should be allowed to change from outside
Expand Down
86 changes: 0 additions & 86 deletions vendor/k8s.io/apimachinery/pkg/util/clock/clock.go

This file was deleted.

1 change: 0 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,6 @@ k8s.io/apimachinery/pkg/runtime/serializer/yaml
k8s.io/apimachinery/pkg/selection
k8s.io/apimachinery/pkg/types
k8s.io/apimachinery/pkg/util/cache
k8s.io/apimachinery/pkg/util/clock
k8s.io/apimachinery/pkg/util/diff
k8s.io/apimachinery/pkg/util/errors
k8s.io/apimachinery/pkg/util/framer
Expand Down

0 comments on commit b391219

Please sign in to comment.