Skip to content

Commit

Permalink
use EndpointSlices by default (#6149)
Browse files Browse the repository at this point in the history
Closes #5891.

Signed-off-by: gang.liu <gang.liu@daocloud.io>
  • Loading branch information
izturn authored Apr 10, 2024
1 parent e79d56a commit 6f7010a
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 51 deletions.
6 changes: 3 additions & 3 deletions apis/projectcontour/v1alpha1/contourconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
26 changes: 17 additions & 9 deletions apis/projectcontour/v1alpha1/contourconfig_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
83 changes: 82 additions & 1 deletion apis/projectcontour/v1alpha1/contourconfig_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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)
})
}
}
3 changes: 3 additions & 0 deletions changelogs/unreleased/6149-izturn-deprecation.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions changelogs/unreleased/6149-izturn-minor.md
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 6 additions & 6 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions examples/render/contour-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions examples/render/contour-gateway-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions examples/render/contour-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions examples/render/contour.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
12 changes: 6 additions & 6 deletions site/content/docs/main/config/api-reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -5191,9 +5191,9 @@ <h3 id="projectcontour.io/v1alpha1.ContourConfiguration">ContourConfiguration
<td>
<p>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.</p>
useEndpointSlices - Configures contour to fetch endpoint data
from k8s endpoint slices. defaults to true,
If false then reads endpoint data from the k8s endpoints.</p>
</td>
</tr>
</table>
Expand Down Expand Up @@ -5984,9 +5984,9 @@ <h3 id="projectcontour.io/v1alpha1.ContourConfigurationSpec">ContourConfiguratio
<td>
<p>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.</p>
useEndpointSlices - Configures contour to fetch endpoint data
from k8s endpoint slices. defaults to true,
If false then reads endpoint data from the k8s endpoints.</p>
</td>
</tr>
</tbody>
Expand Down

0 comments on commit 6f7010a

Please sign in to comment.