From a5241217afec321f72c18a04f2d460b63043105c Mon Sep 17 00:00:00 2001 From: Tim Usner Date: Wed, 24 Nov 2021 18:14:22 +0100 Subject: [PATCH] Add label selector for member check --- pkg/component/etcd/lease/lease_member.go | 5 ++++- pkg/health/etcdmember/check_ready.go | 7 ++++++- pkg/health/etcdmember/check_ready_test.go | 15 ++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/pkg/component/etcd/lease/lease_member.go b/pkg/component/etcd/lease/lease_member.go index abfb83ca6..6c1b27bde 100644 --- a/pkg/component/etcd/lease/lease_member.go +++ b/pkg/component/etcd/lease/lease_member.go @@ -87,10 +87,13 @@ func (l *leases) syncMemberLeases(ctx context.Context) error { return flow.Parallel(fns...)(ctx) } +// PurposeMemberLease is a constant used as a purpose for etcd member lease objects. +const PurposeMemberLease = "etcd-member-lease" + func getMemberLeaseLabels(val Values) map[string]string { return map[string]string{ common.GardenerOwnedBy: val.EtcdName, - v1beta1constants.GardenerPurpose: "etcd-member-lease", + v1beta1constants.GardenerPurpose: PurposeMemberLease, } } diff --git a/pkg/health/etcdmember/check_ready.go b/pkg/health/etcdmember/check_ready.go index 9b9d63d8c..b273d7549 100644 --- a/pkg/health/etcdmember/check_ready.go +++ b/pkg/health/etcdmember/check_ready.go @@ -20,6 +20,10 @@ import ( "strings" "time" + componentlease "github.com/gardener/etcd-druid/pkg/component/etcd/lease" + + v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants" + kutil "github.com/gardener/gardener/pkg/utils/kubernetes" "github.com/go-logr/logr" coordinationv1 "k8s.io/api/coordination/v1" @@ -49,7 +53,8 @@ func (r *readyCheck) Check(ctx context.Context, etcd druidv1alpha1.Etcd) []Resul ) leases := &coordinationv1.LeaseList{} - if err := r.cl.List(ctx, leases, client.InNamespace(etcd.Namespace), client.MatchingLabels{common.GardenerOwnedBy: etcd.Name}); err != nil { + if err := r.cl.List(ctx, leases, client.InNamespace(etcd.Namespace), client.MatchingLabels{ + common.GardenerOwnedBy: etcd.Name, v1beta1constants.GardenerPurpose: componentlease.PurposeMemberLease}); err != nil { r.logger.Error(err, "failed to get leases for etcd member readiness check") } diff --git a/pkg/health/etcdmember/check_ready_test.go b/pkg/health/etcdmember/check_ready_test.go index 2d63f5004..7353622a1 100644 --- a/pkg/health/etcdmember/check_ready_test.go +++ b/pkg/health/etcdmember/check_ready_test.go @@ -20,6 +20,8 @@ import ( "fmt" "time" + v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants" + kutil "github.com/gardener/gardener/pkg/utils/kubernetes" "github.com/gardener/gardener/pkg/utils/test" "github.com/golang/mock/gomock" @@ -37,6 +39,7 @@ import ( druidv1alpha1 "github.com/gardener/etcd-druid/api/v1alpha1" controllersconfig "github.com/gardener/etcd-druid/controllers/config" "github.com/gardener/etcd-druid/pkg/common" + componentlease "github.com/gardener/etcd-druid/pkg/component/etcd/lease" . "github.com/gardener/etcd-druid/pkg/health/etcdmember" mockclient "github.com/gardener/etcd-druid/pkg/mock/controller-runtime/client" ) @@ -88,11 +91,13 @@ var _ = Describe("ReadyCheck", func() { }) JustBeforeEach(func() { - cl.EXPECT().List(ctx, gomock.AssignableToTypeOf(&coordinationv1.LeaseList{}), client.InNamespace(etcd.Namespace), client.MatchingLabels{common.GardenerOwnedBy: etcd.Name}).DoAndReturn( - func(_ context.Context, leases *coordinationv1.LeaseList, _ ...client.ListOption) error { - *leases = *leasesList - return nil - }) + cl.EXPECT().List(ctx, gomock.AssignableToTypeOf(&coordinationv1.LeaseList{}), client.InNamespace(etcd.Namespace), + client.MatchingLabels{common.GardenerOwnedBy: etcd.Name, v1beta1constants.GardenerPurpose: componentlease.PurposeMemberLease}). + DoAndReturn( + func(_ context.Context, leases *coordinationv1.LeaseList, _ ...client.ListOption) error { + *leases = *leasesList + return nil + }) }) Context("when just expired", func() {