Skip to content

Commit

Permalink
Add label selector for member check
Browse files Browse the repository at this point in the history
  • Loading branch information
timuthy committed Nov 24, 2021
1 parent 870dd8c commit a524121
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
5 changes: 4 additions & 1 deletion pkg/component/etcd/lease/lease_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/health/etcdmember/check_ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}

Expand Down
15 changes: 10 additions & 5 deletions pkg/health/etcdmember/check_ready_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit a524121

Please sign in to comment.