Skip to content

Commit

Permalink
Gateway API: remove gateway controller name config option (#6145)
Browse files Browse the repository at this point in the history
Closes #5923.

Signed-off-by: Steve Kriss <stephen.kriss@gmail.com>
  • Loading branch information
skriss authored Feb 13, 2024
1 parent 5763f7f commit 1cc89d0
Show file tree
Hide file tree
Showing 47 changed files with 234 additions and 2,689 deletions.
37 changes: 0 additions & 37 deletions .github/workflows/build_daily.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,43 +88,6 @@ jobs:
steps: ${{ toJson(steps) }}
channel: '#contour-ci-notifications'
if: ${{ failure() && github.ref == 'refs/heads/main' }}
e2e-gateway-reconcile-controller:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
persist-credentials: false
- uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
with:
# * Module download cache
# * Build cache (Linux)
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-${{ github.job }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-${{ github.job }}-go-
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ${{ env.GO_VERSION }}
cache: false
- name: add deps to path
run: |
./hack/actions/install-kubernetes-toolchain.sh $GITHUB_WORKSPACE/bin
echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH
- name: e2e tests
env:
CONTOUR_E2E_IMAGE: ghcr.io/projectcontour/contour:main
CONTOUR_E2E_PACKAGE_FOCUS: ./test/e2e/gateway
CONTOUR_E2E_GATEWAY_RECONCILE_MODE: controller
run: |
make setup-kind-cluster run-e2e cleanup-kind
- uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f # v2.0.0
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: '#contour-ci-notifications'
if: ${{ failure() && github.ref == 'refs/heads/main' }}
e2e-ipv6:
runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 0 additions & 5 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ outpkg: "mocks"
dir: '{{trimPrefix .PackagePath "github.com/projectcontour/contour/" }}/mocks'
disable-version-string: True
packages:
sigs.k8s.io/controller-runtime/pkg/manager:
config:
dir: "internal/controller/mocks"
interfaces:
Manager:
github.com/projectcontour/contour/internal/debug:
interfaces:
DagBuilder:
Expand Down
20 changes: 3 additions & 17 deletions apis/projectcontour/v1alpha1/contourconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,9 @@ type XDSServerConfig struct {

// GatewayConfig holds the config for Gateway API controllers.
type GatewayConfig struct {
// ControllerName is used to determine whether Contour should reconcile a
// GatewayClass. The string takes the form of "projectcontour.io/<namespace>/contour".
// If unset, the gatewayclass controller will not be started.
// Exactly one of ControllerName or GatewayRef must be set.
//
// Deprecated: users should use GatewayRef, or the Gateway provisioner,
// in place of this field. This field will be removed in a future release.
// +optional
ControllerName string `json:"controllerName,omitempty"`

// GatewayRef defines a specific Gateway that this Contour
// instance corresponds to. If set, Contour will reconcile
// only this gateway, and will not reconcile any gateway
// classes.
// Exactly one of ControllerName or GatewayRef must be set.
// +optional
GatewayRef *NamespacedName `json:"gatewayRef,omitempty"`
// GatewayRef defines the specific Gateway that this Contour
// instance corresponds to.
GatewayRef NamespacedName `json:"gatewayRef"`
}

// TLS holds TLS file config details.
Expand Down
14 changes: 3 additions & 11 deletions apis/projectcontour/v1alpha1/contourconfig_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,10 @@ func (f FeatureFlags) IsEndpointSliceEnabled() bool {
return slices.Contains(f, featureFlagUseEndpointSlices)
}

// Validate ensures that exactly one of ControllerName or GatewayRef are specified.
// Validate ensures that GatewayRef namespace/name is specified.
func (g *GatewayConfig) Validate() error {
if g == nil {
return nil
}

if len(g.ControllerName) > 0 && g.GatewayRef != nil {
return fmt.Errorf("invalid gateway configuration: exactly one of controller name or gateway ref must be specified")
}

if len(g.ControllerName) == 0 && g.GatewayRef == nil {
return fmt.Errorf("invalid gateway configuration: exactly one of controller name or gateway ref must be specified")
if g != nil && (g.GatewayRef.Namespace == "" || g.GatewayRef.Name == "") {
return fmt.Errorf("invalid gateway configuration: gateway ref namespace and name must be specified")
}

return nil
Expand Down
12 changes: 6 additions & 6 deletions apis/projectcontour/v1alpha1/contourconfig_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ func TestContourConfigurationSpecValidate(t *testing.T) {
Gateway: &contour_v1alpha1.GatewayConfig{},
}

c.Gateway.ControllerName = "foo"
c.Gateway.GatewayRef = contour_v1alpha1.NamespacedName{Namespace: "ns", Name: "name"}
require.NoError(t, c.Validate())

c.Gateway.ControllerName = ""
c.Gateway.GatewayRef = &contour_v1alpha1.NamespacedName{Namespace: "ns", Name: "name"}
require.NoError(t, c.Validate())
// empty namespace is not allowed
c.Gateway.GatewayRef = contour_v1alpha1.NamespacedName{Name: "name"}
require.Error(t, c.Validate())

c.Gateway.ControllerName = "foo"
c.Gateway.GatewayRef = &contour_v1alpha1.NamespacedName{Namespace: "ns", Name: "name"}
// empty name is not allowed
c.Gateway.GatewayRef = contour_v1alpha1.NamespacedName{Namespace: "ns"}
require.Error(t, c.Validate())
})

Expand Down
6 changes: 1 addition & 5 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: 4 additions & 0 deletions changelogs/unreleased/6145-skriss-deprecation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Configuring Contour with a GatewayClass controller name is no longer supported

Contour can no longer be configured with a GatewayClass controller name (gateway.controllerName in the config file or ContourConfiguration CRD), as the config field has been removed.
Instead, either use a specific Gateway reference (gateway.gatewayRef), or use the Gateway provisioner.
30 changes: 14 additions & 16 deletions cmd/contour/ingressstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ import (
// 5. If the worker is stopped, the informer continues but no further
// status updates are made.
type loadBalancerStatusWriter struct {
log logrus.FieldLogger
cache cache.Cache
lbStatus chan core_v1.LoadBalancerStatus
statusUpdater k8s.StatusUpdater
ingressClassNames []string
gatewayControllerName string
gatewayRef *types.NamespacedName
log logrus.FieldLogger
cache cache.Cache
lbStatus chan core_v1.LoadBalancerStatus
statusUpdater k8s.StatusUpdater
ingressClassNames []string
gatewayRef *types.NamespacedName
}

func (isw *loadBalancerStatusWriter) NeedLeaderElection() bool {
Expand All @@ -73,11 +72,10 @@ func (isw *loadBalancerStatusWriter) Start(ctx context.Context) error {

return log
}(),
Cache: isw.cache,
IngressClassNames: isw.ingressClassNames,
GatewayControllerName: isw.gatewayControllerName,
GatewayRef: isw.gatewayRef,
StatusUpdater: isw.statusUpdater,
Cache: isw.cache,
IngressClassNames: isw.ingressClassNames,
GatewayRef: isw.gatewayRef,
StatusUpdater: isw.statusUpdater,
}

// Create informers for the types that need load balancer
Expand All @@ -88,9 +86,9 @@ func (isw *loadBalancerStatusWriter) Start(ctx context.Context) error {
&networking_v1.Ingress{},
}

// Only create Gateway informer if a controller or specific gateway was provided,
// Only create Gateway informer if a gateway was provided,
// otherwise the API may not exist in the cluster.
if len(isw.gatewayControllerName) > 0 || isw.gatewayRef != nil {
if isw.gatewayRef != nil {
resources = append(resources, &gatewayapi_v1.Gateway{})
}

Expand Down Expand Up @@ -139,9 +137,9 @@ func (isw *loadBalancerStatusWriter) Start(ctx context.Context) error {
}
}

// Only list Gateways if a controller or specific gateway was configured,
// Only list Gateways if a gateway was configured,
// otherwise the API may not exist in the cluster.
if len(isw.gatewayControllerName) > 0 || isw.gatewayRef != nil {
if isw.gatewayRef != nil {
var gatewayList gatewayapi_v1.GatewayList
if err := isw.cache.List(context.Background(), &gatewayList); err != nil {
isw.log.WithError(err).WithField("kind", "Gateway").Error("failed to list objects")
Expand Down
Loading

0 comments on commit 1cc89d0

Please sign in to comment.