Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Clayton Gonsalves <clayton.gonsalves@reddit.com>
  • Loading branch information
clayton-gonsalves committed Sep 26, 2023
1 parent 3f537d0 commit 1fd6eea
Show file tree
Hide file tree
Showing 19 changed files with 237 additions and 78 deletions.
13 changes: 9 additions & 4 deletions apis/projectcontour/v1alpha1/contourconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ type ContourConfigurationSpec struct {
// Tracing defines properties for exporting trace data to OpenTelemetry.
Tracing *TracingConfig `json:"tracing,omitempty"`

// useEndpointSlice configures contour to fetch endpoint data
// from k8s endpoint slices. defaults to false and reading endpoint
// data from the k8s endpoints.
UseEndpointSlice bool `json:"useEndpointSlice,omitempty"`
// FeatureFlags defines toggle for new contour features.
FeatureFlags FeatureFlags `json:"featureFlags,omitempty"`
}

// XDSServerType is the type of xDS server implementation.
Expand Down Expand Up @@ -864,3 +862,10 @@ type ContourConfigurationList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []ContourConfiguration `json:"items"`
}

type FeatureFlags struct {
// useEndpointSlice configures contour to fetch endpoint data
// from k8s endpoint slices. defaults to false and reading endpoint
// data from the k8s endpoints.
UseEndpointSlice bool `json:"useEndpointSlice,omitempty"`
}
16 changes: 16 additions & 0 deletions apis/projectcontour/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions changelogs/unreleased/5745-clayton-gonsalves-minor.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Add Kubernetes Endpoint Slice support.

This change optionally enables Contour to consume the kuberentes endpointslice API to determine the endpoints to configure Envoy with.
Note: This change is off by default and is gated by the config flag `useEndpointSlice`.
This change optionally enables Contour to consume the kubernetes endpointslice API to determine the endpoints to configure Envoy with.
Note: This change is off by default and is gated by the feature flag `useEndpointSlice`.
8 changes: 4 additions & 4 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func (s *Server) doServe() error {

// Endpoints updates are handled directly by the EndpointsTranslator/EndpointSliceTranslator due to the high update volume.
var endpointHandler EndpointsTranslator
if contourConfiguration.UseEndpointSlice {
if contourConfiguration.FeatureFlags.UseEndpointSlice {
endpointHandler = xdscache_v3.NewEndpointSliceTranslator(s.log.WithField("context", "endpointstranslator"))
} else {
endpointHandler = xdscache_v3.NewEndpointsTranslator(s.log.WithField("context", "endpointstranslator"))
Expand Down Expand Up @@ -600,19 +600,19 @@ func (s *Server) doServe() error {
}

// Inform on endpoints/endpointSlices.
if contourConfiguration.UseEndpointSlice {
if contourConfiguration.FeatureFlags.UseEndpointSlice {
if err := informOnResource(&discoveryv1.EndpointSlice{}, &contour.EventRecorder{
Next: endpointHandler,
Counter: contourMetrics.EventHandlerOperations,
}, s.mgr.GetCache()); err != nil {
s.log.WithError(err).WithField("resource", "endpoints").Fatal("failed to create informer")
s.log.WithError(err).WithField("resource", "endpointslices").Fatal("failed to create informer")
}
} else {
if err := informOnResource(&corev1.Endpoints{}, &contour.EventRecorder{
Next: endpointHandler,
Counter: contourMetrics.EventHandlerOperations,
}, s.mgr.GetCache()); err != nil {
s.log.WithError(err).WithField("resource", "endpoints").Fatal("failed to create informer")
s.log.WithError(err).WithField("resource", "endpointslices").Fatal("failed to create informer")
}

Check warning on line 616 in cmd/contour/serve.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/serve.go#L603-L616

Added lines #L603 - L616 were not covered by tests
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/contour/servecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,9 @@ func (ctx *serveContext) convertToContourConfigurationSpec() contour_api_v1alpha
Policy: policy,
Metrics: &contourMetrics,
Tracing: tracingConfig,
UseEndpointSlice: ctx.Config.UseEndpointSlice,
FeatureFlags: contour_api_v1alpha1.FeatureFlags{
UseEndpointSlice: ctx.Config.FeatureFlags.UseEndpointSlice,
},
}

xdsServerType := contour_api_v1alpha1.ContourServerType
Expand Down
28 changes: 18 additions & 10 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,15 @@ spec:
type: string
type: object
type: object
featureFlags:
description: FeatureFlags defines toggle for new contour features.
properties:
useEndpointSlice:
description: useEndpointSlice configures contour to fetch endpoint
data from k8s endpoint slices. defaults to false and reading
endpoint data from the k8s endpoints.
type: boolean
type: object
gateway:
description: Gateway contains parameters for the gateway-api Gateway
that Contour is configured to serve traffic.
Expand Down Expand Up @@ -947,11 +956,6 @@ spec:
required:
- extensionService
type: object
useEndpointSlice:
description: useEndpointSlice configures contour to fetch endpoint
data from k8s endpoint slices. defaults to false and reading endpoint
data from the k8s endpoints.
type: boolean
xdsServer:
description: XDSServer contains parameters for the xDS server.
properties:
Expand Down Expand Up @@ -3894,6 +3898,15 @@ spec:
type: string
type: object
type: object
featureFlags:
description: FeatureFlags defines toggle for new contour features.
properties:
useEndpointSlice:
description: useEndpointSlice configures contour to fetch
endpoint data from k8s endpoint slices. defaults to false
and reading endpoint data from the k8s endpoints.
type: boolean
type: object
gateway:
description: Gateway contains parameters for the gateway-api Gateway
that Contour is configured to serve traffic.
Expand Down Expand Up @@ -4405,11 +4418,6 @@ spec:
required:
- extensionService
type: object
useEndpointSlice:
description: useEndpointSlice configures contour to fetch endpoint
data from k8s endpoint slices. defaults to false and reading
endpoint data from the k8s endpoints.
type: boolean
xdsServer:
description: XDSServer contains parameters for the xDS server.
properties:
Expand Down
8 changes: 8 additions & 0 deletions examples/contour/02-role-contour.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ rules:
- get
- list
- watch
- apiGroups:
- discovery.k8s.io
resources:
- endpointslices
verbs:
- get
- list
- watch
- apiGroups:
- gateway.networking.k8s.io
resources:
Expand Down
8 changes: 8 additions & 0 deletions examples/gateway-provisioner/01-roles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ rules:
- create
- get
- update
- apiGroups:
- discovery.k8s.io
resources:
- endpointslices
verbs:
- get
- list
- watch
- apiGroups:
- gateway.networking.k8s.io
resources:
Expand Down
36 changes: 26 additions & 10 deletions examples/render/contour-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,15 @@ spec:
type: string
type: object
type: object
featureFlags:
description: FeatureFlags defines toggle for new contour features.
properties:
useEndpointSlice:
description: useEndpointSlice configures contour to fetch endpoint
data from k8s endpoint slices. defaults to false and reading
endpoint data from the k8s endpoints.
type: boolean
type: object
gateway:
description: Gateway contains parameters for the gateway-api Gateway
that Contour is configured to serve traffic.
Expand Down Expand Up @@ -1166,11 +1175,6 @@ spec:
required:
- extensionService
type: object
useEndpointSlice:
description: useEndpointSlice configures contour to fetch endpoint
data from k8s endpoint slices. defaults to false and reading endpoint
data from the k8s endpoints.
type: boolean
xdsServer:
description: XDSServer contains parameters for the xDS server.
properties:
Expand Down Expand Up @@ -4113,6 +4117,15 @@ spec:
type: string
type: object
type: object
featureFlags:
description: FeatureFlags defines toggle for new contour features.
properties:
useEndpointSlice:
description: useEndpointSlice configures contour to fetch
endpoint data from k8s endpoint slices. defaults to false
and reading endpoint data from the k8s endpoints.
type: boolean
type: object
gateway:
description: Gateway contains parameters for the gateway-api Gateway
that Contour is configured to serve traffic.
Expand Down Expand Up @@ -4624,11 +4637,6 @@ spec:
required:
- extensionService
type: object
useEndpointSlice:
description: useEndpointSlice configures contour to fetch endpoint
data from k8s endpoint slices. defaults to false and reading
endpoint data from the k8s endpoints.
type: boolean
xdsServer:
description: XDSServer contains parameters for the xDS server.
properties:
Expand Down Expand Up @@ -8382,6 +8390,14 @@ rules:
- get
- list
- watch
- apiGroups:
- discovery.k8s.io
resources:
- endpointslices
verbs:
- get
- list
- watch
- apiGroups:
- gateway.networking.k8s.io
resources:
Expand Down
36 changes: 26 additions & 10 deletions examples/render/contour-gateway-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,15 @@ spec:
type: string
type: object
type: object
featureFlags:
description: FeatureFlags defines toggle for new contour features.
properties:
useEndpointSlice:
description: useEndpointSlice configures contour to fetch endpoint
data from k8s endpoint slices. defaults to false and reading
endpoint data from the k8s endpoints.
type: boolean
type: object
gateway:
description: Gateway contains parameters for the gateway-api Gateway
that Contour is configured to serve traffic.
Expand Down Expand Up @@ -961,11 +970,6 @@ spec:
required:
- extensionService
type: object
useEndpointSlice:
description: useEndpointSlice configures contour to fetch endpoint
data from k8s endpoint slices. defaults to false and reading endpoint
data from the k8s endpoints.
type: boolean
xdsServer:
description: XDSServer contains parameters for the xDS server.
properties:
Expand Down Expand Up @@ -3908,6 +3912,15 @@ spec:
type: string
type: object
type: object
featureFlags:
description: FeatureFlags defines toggle for new contour features.
properties:
useEndpointSlice:
description: useEndpointSlice configures contour to fetch
endpoint data from k8s endpoint slices. defaults to false
and reading endpoint data from the k8s endpoints.
type: boolean
type: object
gateway:
description: Gateway contains parameters for the gateway-api Gateway
that Contour is configured to serve traffic.
Expand Down Expand Up @@ -4419,11 +4432,6 @@ spec:
required:
- extensionService
type: object
useEndpointSlice:
description: useEndpointSlice configures contour to fetch endpoint
data from k8s endpoint slices. defaults to false and reading
endpoint data from the k8s endpoints.
type: boolean
xdsServer:
description: XDSServer contains parameters for the xDS server.
properties:
Expand Down Expand Up @@ -19140,6 +19148,14 @@ rules:
- create
- get
- update
- apiGroups:
- discovery.k8s.io
resources:
- endpointslices
verbs:
- get
- list
- watch
- apiGroups:
- gateway.networking.k8s.io
resources:
Expand Down
Loading

0 comments on commit 1fd6eea

Please sign in to comment.