Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation: use EndpointSlices by default #6149

Merged
merged 10 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apis/projectcontour/v1alpha1/contourconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ type ContourConfigurationSpec struct {
// FeatureFlags defines toggle to enable new contour features.
// Available toggles are:
// useEndpointSlices - configures contour to fetch endpoint data
sunjayBhatia marked this conversation as resolved.
Show resolved Hide resolved
// from k8s endpoint slices. defaults to false and reading endpoint
// data from the k8s endpoints.
// from k8s endpoint slices. defaults to true.
izturn marked this conversation as resolved.
Show resolved Hide resolved
// if false then reading endpoint data from the k8s endpoints.
izturn marked this conversation as resolved.
Show resolved Hide resolved
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
sunjayBhatia marked this conversation as resolved.
Show resolved Hide resolved
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 exactly one of ControllerName or GatewayRef are 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 @@ -302,10 +302,26 @@ func TestFeatureFlagsValidate(t *testing.T) {
expected error
}{
{
name: "valid flag",
name: "valid flag: no value",
flags: v1alpha1.FeatureFlags{"useEndpointSlices"},
expected: nil,
},
{
name: "valid flag2: empty",
flags: v1alpha1.FeatureFlags{"useEndpointSlices="},
expected: nil,
},
{
name: "valid flag: true",
flags: v1alpha1.FeatureFlags{"useEndpointSlices=true"},
expected: nil,
},
{
name: "valid flag: false",
flags: v1alpha1.FeatureFlags{"useEndpointSlices=false"},
expected: nil,
},

{
name: "invalid flag",
flags: v1alpha1.FeatureFlags{"invalidFlag"},
Expand All @@ -330,3 +346,68 @@ func TestFeatureFlagsValidate(t *testing.T) {
})
}
}

func TestFeatureFlagsIsEndpointSliceEnabled(t *testing.T) {
tests := []struct {
name string
flags v1alpha1.FeatureFlags
expected bool
}{
{
name: "valid flag: no value",
flags: v1alpha1.FeatureFlags{"useEndpointSlices"},
expected: true,
},
{
name: "valid flag2: empty",
flags: v1alpha1.FeatureFlags{"useEndpointSlices="},
expected: true,
},
{
name: "valid flag: true",
flags: v1alpha1.FeatureFlags{"useEndpointSlices=true"},
expected: true,
},
{
name: "valid flag: ANY",
flags: v1alpha1.FeatureFlags{"useEndpointSlices=ANY"},
expected: true,
},

{
name: "empty flags",
flags: v1alpha1.FeatureFlags{},
expected: true,
},
{
name: "empty string",
flags: v1alpha1.FeatureFlags{""},
expected: true,
},

{
name: "multi-flags",
flags: v1alpha1.FeatureFlags{"useEndpointSlices", "otherFlag"},
expected: true,
},

{
name: "valid flag: false",
flags: v1alpha1.FeatureFlags{"useEndpointSlices=false"},
expected: false,
},

{
name: "valid flag: FALSE",
flags: 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)
})
}
}
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
izturn marked this conversation as resolved.
Show resolved Hide resolved

Enables contour to consume the kubernetes endpointslice API to determine the endpoints to configure Envoy with by default.
sunjayBhatia marked this conversation as resolved.
Show resolved Hide resolved
Note: if you need to continue using the old configuration, please set the flag: `useEndpointSlices=false` explicitly.
izturn marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 4 additions & 4 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,8 @@ spec:
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.
items:
type: string
type: array
Expand Down Expand Up @@ -4282,8 +4282,8 @@ spec:
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.
items:
type: string
type: array
Expand Down
8 changes: 4 additions & 4 deletions examples/render/contour-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,8 @@ spec:
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.
items:
type: string
type: array
Expand Down Expand Up @@ -4501,8 +4501,8 @@ spec:
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.
items:
type: string
type: array
Expand Down
8 changes: 4 additions & 4 deletions examples/render/contour-gateway-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ spec:
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.
items:
type: string
type: array
Expand Down Expand Up @@ -4293,8 +4293,8 @@ spec:
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.
items:
type: string
type: array
Expand Down
8 changes: 4 additions & 4 deletions examples/render/contour-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,8 @@ spec:
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.
items:
type: string
type: array
Expand Down Expand Up @@ -4504,8 +4504,8 @@ spec:
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.
items:
type: string
type: array
Expand Down
8 changes: 4 additions & 4 deletions examples/render/contour.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,8 @@ spec:
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.
items:
type: string
type: array
Expand Down Expand Up @@ -4501,8 +4501,8 @@ spec:
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.
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 @@ -728,8 +728,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.
izturn marked this conversation as resolved.
Show resolved Hide resolved
FeatureFlags []string `yaml:"featureFlags,omitempty"`
}

Expand Down
8 changes: 4 additions & 4 deletions site/content/docs/main/config/api-reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -5184,8 +5184,8 @@ <h3 id="projectcontour.io/v1alpha1.ContourConfiguration">ContourConfiguration
<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>
from k8s endpoint slices. defaults to true.
if false then reading endpoint data from the k8s endpoints.</p>
</td>
</tr>
</table>
Expand Down Expand Up @@ -5977,8 +5977,8 @@ <h3 id="projectcontour.io/v1alpha1.ContourConfigurationSpec">ContourConfiguratio
<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>
from k8s endpoint slices. defaults to true.
if false then reading endpoint data from the k8s endpoints.</p>
</td>
</tr>
</tbody>
Expand Down
Loading