diff --git a/apis/projectcontour/v1alpha1/contourconfig.go b/apis/projectcontour/v1alpha1/contourconfig.go index e967051d7dc..08fd76a23fc 100644 --- a/apis/projectcontour/v1alpha1/contourconfig.go +++ b/apis/projectcontour/v1alpha1/contourconfig.go @@ -87,9 +87,9 @@ type ContourConfigurationSpec struct { // FeatureFlags defines toggle to enable new contour features. // Available toggles are: - // useEndpointSlices - configures contour to fetch endpoint data - // from k8s endpoint slices. defaults to false and reading endpoint - // data from the k8s endpoints. + // useEndpointSlices - Configures contour to fetch endpoint data + // from k8s endpoint slices. defaults to true, + // If false then reads endpoint data from the k8s endpoints. FeatureFlags FeatureFlags `json:"featureFlags,omitempty"` } diff --git a/apis/projectcontour/v1alpha1/contourconfig_helpers.go b/apis/projectcontour/v1alpha1/contourconfig_helpers.go index babadc5bc09..ffe4978267c 100644 --- a/apis/projectcontour/v1alpha1/contourconfig_helpers.go +++ b/apis/projectcontour/v1alpha1/contourconfig_helpers.go @@ -15,18 +15,16 @@ package v1alpha1 import ( "fmt" - "slices" "strconv" + "strings" "k8s.io/apimachinery/pkg/util/sets" ) -const ( - featureFlagUseEndpointSlices string = "useEndpointSlices" -) +const featureFlagUseEndpointSlices string = "useEndpointSlices" -var featureFlagsMap = map[string]bool{ - featureFlagUseEndpointSlices: true, +var featureFlagsMap = map[string]struct{}{ + featureFlagUseEndpointSlices: {}, } // Validate configuration that is not already covered by CRD validation. @@ -226,16 +224,26 @@ func (e *EnvoyTLS) SanitizedCipherSuites() []string { func (f FeatureFlags) Validate() error { for _, featureFlag := range f { - if _, found := featureFlagsMap[featureFlag]; !found { + fields := strings.Split(featureFlag, "=") + if _, found := featureFlagsMap[fields[0]]; !found { return fmt.Errorf("invalid contour configuration, unknown feature flag:%s", featureFlag) } } - return nil } func (f FeatureFlags) IsEndpointSliceEnabled() bool { - return slices.Contains(f, featureFlagUseEndpointSlices) + // only when the flag: 'useEndpointSlices=false' is exists, return false + for _, flag := range f { + if !strings.HasPrefix(flag, featureFlagUseEndpointSlices) { + continue + } + fields := strings.Split(flag, "=") + if len(fields) == 2 && strings.ToLower(fields[1]) == "false" { + return false + } + } + return true } // Validate ensures that GatewayRef namespace/name is specified. diff --git a/apis/projectcontour/v1alpha1/contourconfig_helpers_test.go b/apis/projectcontour/v1alpha1/contourconfig_helpers_test.go index 1b6fdbcb116..0db2b44c161 100644 --- a/apis/projectcontour/v1alpha1/contourconfig_helpers_test.go +++ b/apis/projectcontour/v1alpha1/contourconfig_helpers_test.go @@ -303,10 +303,26 @@ func TestFeatureFlagsValidate(t *testing.T) { expected error }{ { - name: "valid flag", + name: "valid flag: no value", flags: contour_v1alpha1.FeatureFlags{"useEndpointSlices"}, expected: nil, }, + { + name: "valid flag2: empty", + flags: contour_v1alpha1.FeatureFlags{"useEndpointSlices="}, + expected: nil, + }, + { + name: "valid flag: true", + flags: contour_v1alpha1.FeatureFlags{"useEndpointSlices=true"}, + expected: nil, + }, + { + name: "valid flag: false", + flags: contour_v1alpha1.FeatureFlags{"useEndpointSlices=false"}, + expected: nil, + }, + { name: "invalid flag", flags: contour_v1alpha1.FeatureFlags{"invalidFlag"}, @@ -331,3 +347,68 @@ func TestFeatureFlagsValidate(t *testing.T) { }) } } + +func TestFeatureFlagsIsEndpointSliceEnabled(t *testing.T) { + tests := []struct { + name string + flags contour_v1alpha1.FeatureFlags + expected bool + }{ + { + name: "valid flag: no value", + flags: contour_v1alpha1.FeatureFlags{"useEndpointSlices"}, + expected: true, + }, + { + name: "valid flag2: empty", + flags: contour_v1alpha1.FeatureFlags{"useEndpointSlices="}, + expected: true, + }, + { + name: "valid flag: true", + flags: contour_v1alpha1.FeatureFlags{"useEndpointSlices=true"}, + expected: true, + }, + { + name: "valid flag: ANY", + flags: contour_v1alpha1.FeatureFlags{"useEndpointSlices=ANY"}, + expected: true, + }, + + { + name: "empty flags", + flags: contour_v1alpha1.FeatureFlags{}, + expected: true, + }, + { + name: "empty string", + flags: contour_v1alpha1.FeatureFlags{""}, + expected: true, + }, + + { + name: "multi-flags", + flags: contour_v1alpha1.FeatureFlags{"useEndpointSlices", "otherFlag"}, + expected: true, + }, + + { + name: "valid flag: false", + flags: contour_v1alpha1.FeatureFlags{"useEndpointSlices=false"}, + expected: false, + }, + + { + name: "valid flag: FALSE", + flags: contour_v1alpha1.FeatureFlags{"useEndpointSlices=FALSE"}, + expected: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.flags.IsEndpointSliceEnabled() + assert.Equal(t, tt.expected, err) + }) + } +} diff --git a/changelogs/unreleased/6149-izturn-deprecation.md b/changelogs/unreleased/6149-izturn-deprecation.md new file mode 100644 index 00000000000..2566d916f15 --- /dev/null +++ b/changelogs/unreleased/6149-izturn-deprecation.md @@ -0,0 +1,3 @@ +## Use of Endpoints API is deprecated + +Contour now uses the EndpointSlices API by default, and its usage of the Endpoints API is deprecated as of this release. Support for Endpoints, and the associated `useEndpointSlices` feature flag, will be removed in a future release. \ No newline at end of file diff --git a/changelogs/unreleased/6149-izturn-minor.md b/changelogs/unreleased/6149-izturn-minor.md new file mode 100644 index 00000000000..9fa8122d473 --- /dev/null +++ b/changelogs/unreleased/6149-izturn-minor.md @@ -0,0 +1,5 @@ + +## Use EndpointSlices by default + +Contour now uses the Kubernetes EndpointSlices API by default to determine the endpoints to configure Envoy, instead of the Endpoints API. +Note: if you need to continue using the Endpoints API, you can disable the feature flag via `featureFlags: ["useEndpointSlices=false"]` in the Contour config file or ContourConfiguration CRD. diff --git a/examples/contour/01-crds.yaml b/examples/contour/01-crds.yaml index 0666bd83e57..a8f75e123d9 100644 --- a/examples/contour/01-crds.yaml +++ b/examples/contour/01-crds.yaml @@ -600,9 +600,9 @@ spec: description: |- FeatureFlags defines toggle to enable new contour features. Available toggles are: - useEndpointSlices - configures contour to fetch endpoint data - from k8s endpoint slices. defaults to false and reading endpoint - data from the k8s endpoints. + useEndpointSlices - Configures contour to fetch endpoint data + from k8s endpoint slices. defaults to true, + If false then reads endpoint data from the k8s endpoints. items: type: string type: array @@ -4285,9 +4285,9 @@ spec: description: |- FeatureFlags defines toggle to enable new contour features. Available toggles are: - useEndpointSlices - configures contour to fetch endpoint data - from k8s endpoint slices. defaults to false and reading endpoint - data from the k8s endpoints. + useEndpointSlices - Configures contour to fetch endpoint data + from k8s endpoint slices. defaults to true, + If false then reads endpoint data from the k8s endpoints. items: type: string type: array diff --git a/examples/render/contour-deployment.yaml b/examples/render/contour-deployment.yaml index 128e3899940..5378f4a64f9 100644 --- a/examples/render/contour-deployment.yaml +++ b/examples/render/contour-deployment.yaml @@ -820,9 +820,9 @@ spec: description: |- FeatureFlags defines toggle to enable new contour features. Available toggles are: - useEndpointSlices - configures contour to fetch endpoint data - from k8s endpoint slices. defaults to false and reading endpoint - data from the k8s endpoints. + useEndpointSlices - Configures contour to fetch endpoint data + from k8s endpoint slices. defaults to true, + If false then reads endpoint data from the k8s endpoints. items: type: string type: array @@ -4505,9 +4505,9 @@ spec: description: |- FeatureFlags defines toggle to enable new contour features. Available toggles are: - useEndpointSlices - configures contour to fetch endpoint data - from k8s endpoint slices. defaults to false and reading endpoint - data from the k8s endpoints. + useEndpointSlices - Configures contour to fetch endpoint data + from k8s endpoint slices. defaults to true, + If false then reads endpoint data from the k8s endpoints. items: type: string type: array diff --git a/examples/render/contour-gateway-provisioner.yaml b/examples/render/contour-gateway-provisioner.yaml index 396d8c87dc7..baa032deb70 100644 --- a/examples/render/contour-gateway-provisioner.yaml +++ b/examples/render/contour-gateway-provisioner.yaml @@ -611,9 +611,9 @@ spec: description: |- FeatureFlags defines toggle to enable new contour features. Available toggles are: - useEndpointSlices - configures contour to fetch endpoint data - from k8s endpoint slices. defaults to false and reading endpoint - data from the k8s endpoints. + useEndpointSlices - Configures contour to fetch endpoint data + from k8s endpoint slices. defaults to true, + If false then reads endpoint data from the k8s endpoints. items: type: string type: array @@ -4296,9 +4296,9 @@ spec: description: |- FeatureFlags defines toggle to enable new contour features. Available toggles are: - useEndpointSlices - configures contour to fetch endpoint data - from k8s endpoint slices. defaults to false and reading endpoint - data from the k8s endpoints. + useEndpointSlices - Configures contour to fetch endpoint data + from k8s endpoint slices. defaults to true, + If false then reads endpoint data from the k8s endpoints. items: type: string type: array diff --git a/examples/render/contour-gateway.yaml b/examples/render/contour-gateway.yaml index 62dd4220b5f..160f08a51a0 100644 --- a/examples/render/contour-gateway.yaml +++ b/examples/render/contour-gateway.yaml @@ -636,9 +636,9 @@ spec: description: |- FeatureFlags defines toggle to enable new contour features. Available toggles are: - useEndpointSlices - configures contour to fetch endpoint data - from k8s endpoint slices. defaults to false and reading endpoint - data from the k8s endpoints. + useEndpointSlices - Configures contour to fetch endpoint data + from k8s endpoint slices. defaults to true, + If false then reads endpoint data from the k8s endpoints. items: type: string type: array @@ -4321,9 +4321,9 @@ spec: description: |- FeatureFlags defines toggle to enable new contour features. Available toggles are: - useEndpointSlices - configures contour to fetch endpoint data - from k8s endpoint slices. defaults to false and reading endpoint - data from the k8s endpoints. + useEndpointSlices - Configures contour to fetch endpoint data + from k8s endpoint slices. defaults to true, + If false then reads endpoint data from the k8s endpoints. items: type: string type: array diff --git a/examples/render/contour.yaml b/examples/render/contour.yaml index 3c4479ae071..522757b3f1e 100644 --- a/examples/render/contour.yaml +++ b/examples/render/contour.yaml @@ -820,9 +820,9 @@ spec: description: |- FeatureFlags defines toggle to enable new contour features. Available toggles are: - useEndpointSlices - configures contour to fetch endpoint data - from k8s endpoint slices. defaults to false and reading endpoint - data from the k8s endpoints. + useEndpointSlices - Configures contour to fetch endpoint data + from k8s endpoint slices. defaults to true, + If false then reads endpoint data from the k8s endpoints. items: type: string type: array @@ -4505,9 +4505,9 @@ spec: description: |- FeatureFlags defines toggle to enable new contour features. Available toggles are: - useEndpointSlices - configures contour to fetch endpoint data - from k8s endpoint slices. defaults to false and reading endpoint - data from the k8s endpoints. + useEndpointSlices - Configures contour to fetch endpoint data + from k8s endpoint slices. defaults to true, + If false then reads endpoint data from the k8s endpoints. items: type: string type: array diff --git a/pkg/config/parameters.go b/pkg/config/parameters.go index e1bafe249f9..b4c7aaa3869 100644 --- a/pkg/config/parameters.go +++ b/pkg/config/parameters.go @@ -709,8 +709,8 @@ type Parameters struct { // FeatureFlags defines toggle to enable new contour features. // available toggles are // useEndpointSlices - configures contour to fetch endpoint data - // from k8s endpoint slices. defaults to false and reading endpoint - // data from the k8s endpoints. + // from k8s endpoint slices. defaults to true, + // if false then reading endpoint data from the k8s endpoints. FeatureFlags []string `yaml:"featureFlags,omitempty"` } diff --git a/site/content/docs/main/config/api-reference.html b/site/content/docs/main/config/api-reference.html index e2f957d50b4..b9ba8f7400d 100644 --- a/site/content/docs/main/config/api-reference.html +++ b/site/content/docs/main/config/api-reference.html @@ -5191,9 +5191,9 @@

ContourConfiguration

FeatureFlags defines toggle to enable new contour features. Available toggles are: -useEndpointSlices - configures contour to fetch endpoint data -from k8s endpoint slices. defaults to false and reading endpoint -data from the k8s endpoints.

+useEndpointSlices - Configures contour to fetch endpoint data +from k8s endpoint slices. defaults to true, +If false then reads endpoint data from the k8s endpoints.

@@ -5984,9 +5984,9 @@

ContourConfiguratio

FeatureFlags defines toggle to enable new contour features. Available toggles are: -useEndpointSlices - configures contour to fetch endpoint data -from k8s endpoint slices. defaults to false and reading endpoint -data from the k8s endpoints.

+useEndpointSlices - Configures contour to fetch endpoint data +from k8s endpoint slices. defaults to true, +If false then reads endpoint data from the k8s endpoints.