Skip to content

Commit cf53853

Browse files
committed
Addressed review comments
1 parent 7ea90d8 commit cf53853

File tree

4 files changed

+36
-39
lines changed

4 files changed

+36
-39
lines changed

controllers/endpoint/endpointpredicate.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ import (
1818
func ReadyEndpoints(logger logr.Logger) predicate.Predicate {
1919
log := logger.WithValues("predicate", "ReadyEndpointsPredicate")
2020
isEndpointReady := func(obj runtime.Object) bool {
21-
ep, ok := obj.(*discoveryv1.EndpointSlice)
22-
if !ok || ep == nil {
21+
epSlice, ok := obj.(*discoveryv1.EndpointSlice)
22+
if !ok || epSlice == nil {
2323
return false
2424
}
25-
for _, subset := range ep.Endpoints {
26-
if len(subset.Addresses) > 0 {
25+
for _, endpoints := range epSlice.Endpoints {
26+
if len(endpoints.Addresses) > 0 {
2727
return true
2828
}
2929
}
30-
log.Info("Endpoint does not have any IP address. Skipping processing this endpoint", "namespace", ep.Namespace, "endpoint", ep.Name)
30+
log.Info("Endpoint does not have any IP address. Skipping processing this endpoint", "namespace", epSlice.Namespace, "endpoint", epSlice.Name)
3131
return false
3232
}
3333

@@ -60,11 +60,11 @@ func ReadyEndpoints(logger logr.Logger) predicate.Predicate {
6060
// MatchingEndpoints is a predicate to allow events for only configured endpoints
6161
func MatchingEndpoints(epMap map[string]wapi.DependantSelectors) predicate.Predicate {
6262
isMatchingEndpoints := func(obj runtime.Object, epMap map[string]wapi.DependantSelectors) bool {
63-
ep, ok := obj.(*discoveryv1.EndpointSlice)
64-
if !ok || ep == nil {
63+
epSlice, ok := obj.(*discoveryv1.EndpointSlice)
64+
if !ok || epSlice == nil {
6565
return false
6666
}
67-
_, exists := epMap[ep.Name]
67+
_, exists := epMap[epSlice.Name]
6868
return exists
6969
}
7070

controllers/endpoint/endpointpredicate_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ import (
1919
"sigs.k8s.io/controller-runtime/pkg/event"
2020
)
2121

22-
func turnReady(ep *discoveryv1.EndpointSlice) {
23-
ep.Endpoints = []discoveryv1.Endpoint{
22+
func turnReady(epSlice *discoveryv1.EndpointSlice) {
23+
epSlice.Endpoints = []discoveryv1.Endpoint{
2424
{
2525
Addresses: []string{"10.1.0.52"},
2626
NodeName: ptr.To("node-0"),
2727
},
2828
}
29-
ep.Ports = []discoveryv1.EndpointPort{}
29+
epSlice.Ports = []discoveryv1.EndpointPort{}
3030
}
3131

3232
func TestReadyEndpoints(t *testing.T) {
3333
g := NewWithT(t)
3434
predicate := ReadyEndpoints(logr.Discard())
3535

36-
readyEp := &discoveryv1.EndpointSlice{}
37-
turnReady(readyEp)
36+
readyEpSlice := &discoveryv1.EndpointSlice{}
37+
turnReady(readyEpSlice)
3838

39-
notReadyEp := &discoveryv1.EndpointSlice{}
39+
notReadyEpSlice := &discoveryv1.EndpointSlice{}
4040

4141
testcases := []struct {
4242
name string
@@ -49,49 +49,49 @@ func TestReadyEndpoints(t *testing.T) {
4949
}{
5050
{
5151
name: "no ep -> Ready ep",
52-
ep: readyEp,
52+
ep: readyEpSlice,
5353
expectedCreateEventFilterOutput: true,
5454
expectedUpdateEventFilterOutput: true,
5555
expectedDeleteEventFilterOutput: false,
5656
expectedGenericEventFilterOutput: true,
5757
},
5858
{
5959
name: "no ep -> NotReady ep",
60-
ep: notReadyEp,
60+
ep: notReadyEpSlice,
6161
expectedCreateEventFilterOutput: false,
6262
expectedUpdateEventFilterOutput: false,
6363
expectedDeleteEventFilterOutput: false,
6464
expectedGenericEventFilterOutput: false,
6565
},
6666
{
6767
name: "NotReady ep -> Ready ep",
68-
ep: readyEp,
69-
oldEp: notReadyEp,
68+
ep: readyEpSlice,
69+
oldEp: notReadyEpSlice,
7070
expectedCreateEventFilterOutput: true,
7171
expectedUpdateEventFilterOutput: true,
7272
expectedDeleteEventFilterOutput: false,
7373
expectedGenericEventFilterOutput: true,
7474
},
7575
{
7676
name: "Ready ep -> Ready ep",
77-
ep: readyEp,
78-
oldEp: readyEp,
77+
ep: readyEpSlice,
78+
oldEp: readyEpSlice,
7979
expectedCreateEventFilterOutput: true,
8080
expectedUpdateEventFilterOutput: false,
8181
expectedDeleteEventFilterOutput: false,
8282
expectedGenericEventFilterOutput: true,
8383
},
8484
{
8585
name: "Ready ep -> no ep",
86-
oldEp: readyEp,
86+
oldEp: readyEpSlice,
8787
expectedCreateEventFilterOutput: false,
8888
expectedUpdateEventFilterOutput: false,
8989
expectedDeleteEventFilterOutput: false,
9090
expectedGenericEventFilterOutput: false,
9191
},
9292
{
9393
name: "NotReady ep -> no ep",
94-
oldEp: notReadyEp,
94+
oldEp: notReadyEpSlice,
9595
expectedCreateEventFilterOutput: false,
9696
expectedUpdateEventFilterOutput: false,
9797
expectedDeleteEventFilterOutput: false,

controllers/endpoint/endpoints_controller.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package endpoint
66

77
import (
88
"context"
9-
"time"
109

1110
wapi "github.com/gardener/dependency-watchdog/api/weeder"
1211
"github.com/gardener/dependency-watchdog/internal/weeder"
@@ -39,20 +38,19 @@ type Reconciler struct {
3938
// Reconcile listens to create/update events for `Endpoints` resources and manages weeder which shoot the dependent pods of the configured services, if necessary
4039
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
4140
log := logf.FromContext(ctx)
42-
//Get the endpoint object
43-
var ep discoveryv1.EndpointSlice
44-
err := r.Client.Get(ctx, req.NamespacedName, &ep)
45-
if err != nil {
46-
return ctrl.Result{RequeueAfter: 10 * time.Second}, err
41+
//Get the endpoint slice object
42+
var epSlice discoveryv1.EndpointSlice
43+
if err := r.Client.Get(ctx, req.NamespacedName, &epSlice); err != nil {
44+
return ctrl.Result{}, err
4745
}
48-
log.Info("Starting a new weeder for endpoint, replacing old weeder, if any exists", "namespace", req.Namespace, "endpoint", ep.Name)
49-
r.startWeeder(ctx, log, req.Namespace, &ep)
46+
log.Info("Starting a new weeder for endpoint, replacing old weeder, if any exists", "namespace", req.Namespace, "endpoint", epSlice.Name)
47+
r.startWeeder(ctx, log, req.Namespace, &epSlice)
5048
return ctrl.Result{}, nil
5149
}
5250

5351
// startWeeder starts a new weeder for the endpoint
54-
func (r *Reconciler) startWeeder(ctx context.Context, logger logr.Logger, namespace string, ep *discoveryv1.EndpointSlice) {
55-
w := weeder.NewWeeder(ctx, namespace, r.WeederConfig, r.Client, r.SeedClient, ep, logger)
52+
func (r *Reconciler) startWeeder(ctx context.Context, logger logr.Logger, namespace string, epSlice *discoveryv1.EndpointSlice) {
53+
w := weeder.NewWeeder(ctx, namespace, r.WeederConfig, r.Client, r.SeedClient, epSlice, logger)
5654
// Register the weeder
5755
r.WeederMgr.Register(*w)
5856
go w.Run()

controllers/endpoint/endpoints_controller_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ func testPodTurningCLBFAfterWatchDuration(ctx context.Context, _ context.CancelF
263263

264264
func testNoCLBFPodDeletionWhenEndpointNotReady(ctx context.Context, _ context.CancelFunc, g *WithT, reconciler *Reconciler, namespace string) {
265265
createEp(ctx, g, reconciler, namespace, false)
266-
ep := &discoveryv1.EndpointSlice{}
267-
g.Expect(reconciler.Client.Get(ctx, types.NamespacedName{Name: epName, Namespace: namespace}, ep)).To(Succeed())
268-
turnEndpointToNotReady(ctx, g, reconciler.Client, ep)
266+
epSlice := &discoveryv1.EndpointSlice{}
267+
g.Expect(reconciler.Client.Get(ctx, types.NamespacedName{Name: epName, Namespace: namespace}, epSlice)).To(Succeed())
268+
turnEndpointToNotReady(ctx, g, reconciler.Client, epSlice)
269269

270270
el := discoveryv1.EndpointSliceList{}
271271
g.Expect(reconciler.Client.List(ctx, &el)).To(Succeed())
@@ -335,14 +335,14 @@ func deleteAllPods(ctx context.Context, g *WithT, crClient client.Client) {
335335
}
336336

337337
func deleteAllEp(ctx context.Context, g *WithT, cli client.Client) {
338-
el := &v1.EndpointsList{}
338+
el := &discoveryv1.EndpointSliceList{}
339339
select {
340340
case <-ctx.Done():
341341
return
342342
default:
343343
g.Expect(cli.List(ctx, el)).To(Succeed())
344-
for _, ep := range el.Items {
345-
g.Expect(client.IgnoreNotFound(cli.Delete(ctx, &ep))).To(Succeed())
344+
for _, epSlice := range el.Items {
345+
g.Expect(client.IgnoreNotFound(cli.Delete(ctx, &epSlice))).To(Succeed())
346346
}
347347
}
348348
}
@@ -409,7 +409,6 @@ func turnPodToHealthy(ctx context.Context, g *WithT, crClient client.Client, p *
409409

410410
func newEndpoint(name, namespace string) *discoveryv1.EndpointSlice {
411411
es := discoveryv1.EndpointSlice{
412-
TypeMeta: metav1.TypeMeta{APIVersion: "discovery.k8s.io/v1", Kind: "EndpointSlice"},
413412
ObjectMeta: metav1.ObjectMeta{
414413
UID: uuid.NewUUID(),
415414
Name: name,

0 commit comments

Comments
 (0)