Skip to content

Commit

Permalink
fix: unset ports in endpointslices (#3156)
Browse files Browse the repository at this point in the history
fix #3151 unset ports in endpointslices should not be considered in our lb members list

Signed-off-by: Sandor Szücs <[email protected]>
  • Loading branch information
szuecs authored Jul 15, 2024
1 parent 3bc6a86 commit 243e431
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 2 deletions.
8 changes: 6 additions & 2 deletions dataclients/kubernetes/clusterclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,12 @@ func (c *clusterClient) loadEndpointSlices() (map[definitions.ResourceID]*skippe
func collectReadyEndpoints(endpointSlices *endpointSliceList) map[definitions.ResourceID]*skipperEndpointSlice {
mapSlices := make(map[definitions.ResourceID][]*endpointSlice)
for _, endpointSlice := range endpointSlices.Items {
resID := endpointSlice.ToResourceID() // service resource ID
mapSlices[resID] = append(mapSlices[resID], endpointSlice)
// https://github.com/zalando/skipper/issues/3151
// endpointslices can have nil ports
if endpointSlice.Ports != nil {
resID := endpointSlice.ToResourceID() // service resource ID
mapSlices[resID] = append(mapSlices[resID], endpointSlice)
}
}

result := make(map[definitions.ResourceID]*skipperEndpointSlice)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kube_default__myapp_ingress__example_org____myapp_service:
Host("^(example[.]org[.]?(:[0-9]+)?)$")
-> "http://10.3.0.5:8080";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable-kubernetes-endpointslices: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
labels:
app: myapp
spec:
replicas: 2
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myapp:v1
ports:
- containerPort: 80
name: my-port
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
labels:
app: myapp-deployment
name: myapp-service
spec:
clusterIP: 10.3.190.1
ports:
- name: this-is-my-service-port-name
port: 8080
protocol: TCP
targetPort: my-port
selector:
app: myapp
type: ClusterIP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
labels:
app: myapp
name: myapp-ingress
namespace: default
spec:
rules:
- host: example.org
http:
paths:
- backend:
service:
name: myapp-service
port:
number: 8080
pathType: ImplementationSpecific
---
apiVersion: v1
kind: EndpointSlice
metadata:
labels:
app: myapp-deployment
kubernetes.io/service-name: myapp-service
name: myapp-service-foo
namespace: default
endpoints:
- addresses:
- 10.3.0.3
zone: my-zone
ports: null
---
apiVersion: v1
kind: EndpointSlice
metadata:
labels:
app: myapp-deployment
kubernetes.io/service-name: myapp-service
name: myapp-service-bar
namespace: default
endpoints:
- addresses:
- 10.3.0.5
zone: my-zone
ports:
- port: 8080
protocol: TCP
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kube_default__myapp_ingress__example_org____myapp_service:
Host("^(example[.]org[.]?(:[0-9]+)?)$")
-> status(502)
-> inlineContent("no endpoints")
-> <shunt>;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable-kubernetes-endpointslices: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
labels:
app: myapp
spec:
replicas: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myapp:v1
ports:
- containerPort: 80
name: my-port
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
labels:
app: myapp-deployment
name: myapp-service
spec:
clusterIP: 10.3.190.1
ports:
- name: this-is-my-service-port-name
port: 8080
protocol: TCP
targetPort: my-port
selector:
app: myapp
type: ClusterIP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
labels:
app: myapp
name: myapp-ingress
namespace: default
spec:
rules:
- host: example.org
http:
paths:
- backend:
service:
name: myapp-service
port:
number: 8080
pathType: ImplementationSpecific
---
apiVersion: v1
kind: EndpointSlice
metadata:
labels:
app: myapp-deployment
kubernetes.io/service-name: myapp-service
name: myapp-service-foo
namespace: default
endpoints:
- addresses:
- 10.3.0.3
zone: my-zone
ports: null

0 comments on commit 243e431

Please sign in to comment.