Skip to content

Commit e7d7014

Browse files
Move nil EndpointSlice conditions in isReady (#4136)
Move nil EndpointSlice conditions handling into `EndpointSliceEndpoints.isReady()`. EndpointSlice endpoints with missing conditions is already treated as ready. So instead of having this check outside isReady moved it within. This makes the `isReady` function handle all cases and avoids requiring future callers to duplicate the nil-condition check. ## Tests ```bash go test ./dataclients/kubernetes -run TestEndpointSliceEndpointIsReady go test ./dataclients/kubernetes ``` Suggested label: refactor or bugfix (actually not a bug) Fixes #4137 Signed-off-by: shrikant23codes <jiturishrikant@gmail.com>
1 parent ff2ee71 commit e7d7014

3 files changed

Lines changed: 45 additions & 7 deletions

File tree

dataclients/kubernetes/clusterclient.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,6 @@ func collectReadyEndpoints(endpointSlices *endpointSliceList) map[definitions.Re
571571
// we should delete it, because of eventual consistency
572572
// it is actually terminating
573573
delete(resEps, address)
574-
} else if ep.Conditions == nil {
575-
// if conditions are nil then we need to treat is as ready
576-
resEps[address] = &skipperEndpoint{
577-
Address: address,
578-
Zone: ep.Zone,
579-
}
580574
} else if ep.isReady() {
581575
resEps[address] = &skipperEndpoint{
582576
Address: address,

dataclients/kubernetes/endpointslices.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,5 @@ func (ep *EndpointSliceEndpoints) isReady() bool {
157157
}
158158
// defaults to ready, see also https://github.com/kubernetes/kubernetes/blob/91aca10d5984313c1c5858979d4946ff9446615f/pkg/proxy/endpointslicecache.go#L137C39-L139
159159
// we ignore serving because of https://github.com/zalando/skipper/issues/2684
160-
return ep.Conditions.Ready == nil || *ep.Conditions.Ready
160+
return ep.Conditions == nil || ep.Conditions.Ready == nil || *ep.Conditions.Ready
161161
}

dataclients/kubernetes/endpointslices_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,47 @@ func TestAddresses(t *testing.T) {
8989
},
9090
}).addresses())
9191
}
92+
93+
func TestEndpointSliceEndpointIsReady(t *testing.T) {
94+
ready := true
95+
notReady := false
96+
terminating := true
97+
98+
for _, tt := range []struct {
99+
name string
100+
conditions *endpointsliceCondition
101+
want bool
102+
}{
103+
{
104+
name: "nil conditions default to ready",
105+
want: true,
106+
},
107+
{
108+
name: "nil ready condition defaults to ready",
109+
conditions: &endpointsliceCondition{},
110+
want: true,
111+
},
112+
{
113+
name: "ready true",
114+
conditions: &endpointsliceCondition{Ready: &ready},
115+
want: true,
116+
},
117+
{
118+
name: "ready false",
119+
conditions: &endpointsliceCondition{Ready: &notReady},
120+
want: false,
121+
},
122+
{
123+
name: "terminating overrides ready",
124+
conditions: &endpointsliceCondition{Terminating: &terminating},
125+
want: false,
126+
},
127+
} {
128+
t.Run(tt.name, func(t *testing.T) {
129+
ep := &EndpointSliceEndpoints{Conditions: tt.conditions}
130+
if got := ep.isReady(); got != tt.want {
131+
t.Fatalf("isReady() = %v, want = %v", got, tt.want)
132+
}
133+
})
134+
}
135+
}

0 commit comments

Comments
 (0)