Skip to content

Commit b835ef9

Browse files
committed
Migration to EndpointSlices
Signed-off-by: Jirka Kremser <jiri.kremser@gmail.com>
1 parent d2bed33 commit b835ef9

19 files changed

+256
-176
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This changelog keeps track of work items that have been completed and are ready
2121

2222
### Breaking Changes
2323

24+
- **General**: `v1.Endpoints` -> `EndpointSlices` ([#1297](https://github.com/kedacore/http-add-on/issues/1297)) Potentially breaking for old versions of k8s.
2425
- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))
2526

2627
### New

config/interceptor/kustomization.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,31 @@ labels:
1616
includeTemplates: true
1717
pairs:
1818
app.kubernetes.io/instance: interceptor
19+
images:
20+
- name: ghcr.io/kedacore/http-add-on-interceptor
21+
newName: ghcr.io/kedacore/http-add-on-interceptor
22+
newTag: main
23+
patches:
24+
- path: e2e-test/otel/deployment.yaml
25+
target:
26+
group: apps
27+
kind: Deployment
28+
name: interceptor
29+
version: v1
30+
- path: e2e-test/otel/scaledobject.yaml
31+
target:
32+
group: keda.sh
33+
kind: ScaledObject
34+
name: interceptor
35+
version: v1alpha1
36+
- path: e2e-test/tls/deployment.yaml
37+
target:
38+
group: apps
39+
kind: Deployment
40+
name: interceptor
41+
version: v1
42+
- path: e2e-test/tls/proxy.service.yaml
43+
target:
44+
kind: Service
45+
name: interceptor-proxy
46+
version: v1

config/interceptor/role.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ rules:
77
- apiGroups:
88
- ""
99
resources:
10-
- endpoints
10+
- services
1111
verbs:
1212
- get
1313
- list
1414
- watch
1515
- apiGroups:
16-
- ""
16+
- discovery.k8s.io
1717
resources:
18-
- services
18+
- endpointslices
1919
verbs:
20+
- deletecollection
2021
- get
2122
- list
2223
- watch

config/scaler/kustomization.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ labels:
1111
includeTemplates: true
1212
pairs:
1313
app.kubernetes.io/instance: external-scaler
14+
images:
15+
- name: ghcr.io/kedacore/http-add-on-scaler
16+
newName: ghcr.io/kedacore/http-add-on-scaler
17+
newTag: main
18+
patches:
19+
- path: e2e-test/otel/deployment.yaml
20+
target:
21+
group: apps
22+
kind: Deployment
23+
name: scaler
24+
version: v1

config/scaler/role.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ metadata:
55
name: scaler
66
rules:
77
- apiGroups:
8-
- ""
8+
- discovery.k8s.io
99
resources:
10-
- endpoints
10+
- endpointslices
1111
verbs:
12+
- deletecollection
1213
- get
1314
- list
1415
- watch

interceptor/forward_wait_func.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66

77
"github.com/go-logr/logr"
8-
v1 "k8s.io/api/core/v1"
8+
discov1 "k8s.io/api/discovery/v1"
99

1010
"github.com/kedacore/http-add-on/pkg/k8s"
1111
)
@@ -14,10 +14,10 @@ import (
1414
// before proceeding to serve the request.
1515
type forwardWaitFunc func(context.Context, string, string) (bool, error)
1616

17-
func workloadActiveEndpoints(endpoints v1.Endpoints) int {
17+
func workloadActiveEndpoints(endpoints discov1.EndpointSlice) int {
1818
total := 0
19-
for _, subset := range endpoints.Subsets {
20-
total += len(subset.Addresses)
19+
for _, e := range endpoints.Endpoints {
20+
total += len(e.Addresses)
2121
}
2222
return total
2323
}
@@ -55,7 +55,7 @@ func newWorkloadReplicasForwardWaitFunc(
5555
for {
5656
select {
5757
case event := <-eventCh:
58-
endpoints, ok := event.Object.(*v1.Endpoints)
58+
endpoints, ok := event.Object.(*discov1.EndpointSlice)
5959
if !ok {
6060
lggr.Info(
6161
"Didn't get a endpoints back in event",

interceptor/forward_wait_func_test.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/go-logr/logr"
99
"github.com/stretchr/testify/require"
1010
"golang.org/x/sync/errgroup"
11-
v1 "k8s.io/api/core/v1"
11+
discov1 "k8s.io/api/discovery/v1"
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1313
"k8s.io/apimachinery/pkg/watch"
1414

@@ -27,7 +27,7 @@ func TestForwardWaitFuncOneReplica(t *testing.T) {
2727
endpoints := *newEndpoint(ns, endpointsName)
2828
cache := k8s.NewFakeEndpointsCache()
2929
cache.Set(endpoints)
30-
r.NoError(cache.SetSubsets(ns, endpointsName, 1))
30+
r.NoError(cache.SetEndpoints(ns, endpointsName, 1))
3131

3232
ctx, done := context.WithTimeout(ctx, waitFuncWait)
3333
defer done()
@@ -97,10 +97,10 @@ func TestWaitFuncWaitsUntilReplicas(t *testing.T) {
9797
watcher := cache.GetWatcher(ns, endpointsName)
9898
r.NotNil(watcher, "watcher was not found")
9999
modifiedEndpoints := endpoints.DeepCopy()
100-
modifiedEndpoints.Subsets = []v1.EndpointSubset{
100+
modifiedEndpoints.Endpoints = []discov1.Endpoint{
101101
{
102-
Addresses: []v1.EndpointAddress{
103-
{IP: "1.2.3.4"},
102+
Addresses: []string{
103+
"1.2.3.4",
104104
},
105105
},
106106
}
@@ -119,11 +119,14 @@ func TestWaitFuncWaitsUntilReplicas(t *testing.T) {
119119
func newEndpoint(
120120
namespace,
121121
name string,
122-
) *v1.Endpoints {
123-
endpoints := &v1.Endpoints{
122+
) *discov1.EndpointSlice {
123+
endpoints := &discov1.EndpointSlice{
124124
ObjectMeta: metav1.ObjectMeta{
125-
Name: name,
126-
Namespace: namespace,
125+
GenerateName: name,
126+
Namespace: namespace,
127+
Labels: map[string]string{
128+
discov1.LabelServiceName: name,
129+
},
127130
},
128131
}
129132

interceptor/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var (
4545
)
4646

4747
// +kubebuilder:rbac:groups=http.keda.sh,resources=httpscaledobjects,verbs=get;list;watch
48-
// +kubebuilder:rbac:groups="",resources=endpoints,verbs=get;list;watch
48+
// +kubebuilder:rbac:groups=discovery.k8s.io,resources=endpointslices,verbs=get;list;watch;deletecollection
4949
// +kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch
5050

5151
func main() {

interceptor/proxy_handlers_integration_test.go

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/stretchr/testify/assert"
1818
"github.com/stretchr/testify/require"
1919
"golang.org/x/sync/errgroup"
20-
v1 "k8s.io/api/core/v1"
20+
discov1 "k8s.io/api/discovery/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
"k8s.io/apimachinery/pkg/util/wait"
2323

@@ -55,13 +55,16 @@ func TestIntegrationHappyPath(t *testing.T) {
5555
)
5656
h.routingTable.Memory[hostForTest(t)] = target
5757

58-
h.endpCache.Set(v1.Endpoints{
58+
h.endpCache.Set(discov1.EndpointSlice{
5959
ObjectMeta: metav1.ObjectMeta{
60-
Name: serviceName,
61-
Namespace: target.GetNamespace(),
60+
GenerateName: serviceName,
61+
Namespace: target.GetNamespace(),
62+
Labels: map[string]string{
63+
discov1.LabelServiceName: serviceName,
64+
},
6265
},
6366
})
64-
r.NoError(h.endpCache.SetSubsets(target.GetNamespace(), serviceName, 1))
67+
r.NoError(h.endpCache.SetEndpoints(target.GetNamespace(), serviceName, 1))
6568

6669
// happy path
6770
res, err := doRequest(
@@ -122,10 +125,13 @@ func TestIntegrationNoReplicas(t *testing.T) {
122125
h.routingTable.Memory[hostForTest(t)] = target
123126

124127
// 0 replicas
125-
h.endpCache.Set(v1.Endpoints{
128+
h.endpCache.Set(discov1.EndpointSlice{
126129
ObjectMeta: metav1.ObjectMeta{
127-
Name: serviceName,
128-
Namespace: target.GetNamespace(),
130+
GenerateName: serviceName,
131+
Namespace: target.GetNamespace(),
132+
Labels: map[string]string{
133+
discov1.LabelServiceName: serviceName,
134+
},
129135
},
130136
})
131137

@@ -173,10 +179,13 @@ func TestIntegrationWaitReplicas(t *testing.T) {
173179
// set up a endpoint with zero replicas and create
174180
// a watcher we can use later to fake-send a endpoint
175181
// event
176-
h.endpCache.Set(v1.Endpoints{
182+
h.endpCache.Set(discov1.EndpointSlice{
177183
ObjectMeta: metav1.ObjectMeta{
178-
Name: serviceName,
179-
Namespace: target.GetNamespace(),
184+
GenerateName: serviceName,
185+
Namespace: target.GetNamespace(),
186+
Labels: map[string]string{
187+
discov1.LabelServiceName: serviceName,
188+
},
180189
},
181190
})
182191
endpoints, _ := h.endpCache.Get(target.GetNamespace(), serviceName)
@@ -207,10 +216,10 @@ func TestIntegrationWaitReplicas(t *testing.T) {
207216
t.Logf("Woke up, setting replicas to 10")
208217

209218
modifiedEndpoints := endpoints.DeepCopy()
210-
modifiedEndpoints.Subsets = []v1.EndpointSubset{
219+
modifiedEndpoints.Endpoints = []discov1.Endpoint{
211220
{
212-
Addresses: []v1.EndpointAddress{
213-
{IP: "1.2.3.4"},
221+
Addresses: []string{
222+
"1.2.3.4",
214223
},
215224
},
216225
}

operator/controllers/http/ping_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,9 @@ func TestPingInterceptors(t *testing.T) {
4242
url.Port(),
4343
))
4444
reqs := hdl.IncomingRequests()
45-
r.Equal(len(endpoints.Subsets[0].Addresses), len(reqs))
45+
var endpointsAddrs []string
46+
for _, e := range endpoints.Endpoints {
47+
endpointsAddrs = append(endpointsAddrs, e.Addresses...)
48+
}
49+
r.Equal(len(endpointsAddrs), len(reqs))
4650
}

0 commit comments

Comments
 (0)