Skip to content

Commit

Permalink
Add support for disabled-features in provitioner
Browse files Browse the repository at this point in the history
Signed-off-by: Lubron Zhan <lubronzhan@gmail.com>
  • Loading branch information
lubronzhan committed Feb 1, 2024
1 parent 62f81db commit 463ac78
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apis/projectcontour/v1/httpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1514,3 +1514,7 @@ type SlowStartPolicy struct {
// +kubebuilder:validation:Maximum=100
MinimumWeightPercent uint32 `json:"minWeightPercent"`
}


Check failure on line 1518 in apis/projectcontour/v1/httpproxy.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
// +kubebuilder:validation:Enum=grpcroutes;tlsroutes;extensionservices
type Feature string
11 changes: 11 additions & 0 deletions apis/projectcontour/v1alpha1/contourdeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,18 @@ type ContourSettings struct {
// +kubebuilder:validation:Type=array
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=42
// +kubebuilder:validation:UniqueItems=true
WatchNamespaces []contour_api_v1.Namespace `json:"watchNamespaces,omitempty"`


Check failure on line 136 in apis/projectcontour/v1alpha1/contourdeployment.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
// DisabledFeatures defines an array of Gateway API CRDs that will be ignored by
// contour reconciler.
// +optional
// +kubebuilder:validation:Type=array
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=42
// +kubebuilder:validation:UniqueItems=true
DisabledFeatures []contour_api_v1.Feature `json:"disabledFeatures,omitempty"`
}

// DeploymentSettings contains settings for Deployment resources.
Expand Down
16 changes: 16 additions & 0 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,21 @@ spec:
type: string
type: object
type: object
disabledFeatures:
description: |-
DisabledFeatures defines an array of Gateway API CRDs that will be ignored by
contour reconciler.
Allowed values are
items:
enum:
- grpcroutes
- tlsroutes
- extensionservices
type: string
maxItems: 42
minItems: 1
type: array
uniqueItems: true
kubernetesLogLevel:
description: |-
KubernetesLogLevel Enable Kubernetes client debug logging with log level. If unset,
Expand Down Expand Up @@ -1644,6 +1659,7 @@ spec:
maxItems: 42
minItems: 1
type: array
uniqueItems: true
type: object
envoy:
description: |-
Expand Down
16 changes: 16 additions & 0 deletions examples/render/contour-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,21 @@ spec:
type: string
type: object
type: object
disabledFeatures:
description: |-
DisabledFeatures defines an array of Gateway API CRDs that will be ignored by
contour reconciler.
Allowed values are
items:
enum:
- grpcroutes
- tlsroutes
- extensionservices
type: string
maxItems: 42
minItems: 1
type: array
uniqueItems: true
kubernetesLogLevel:
description: |-
KubernetesLogLevel Enable Kubernetes client debug logging with log level. If unset,
Expand Down Expand Up @@ -1863,6 +1878,7 @@ spec:
maxItems: 42
minItems: 1
type: array
uniqueItems: true
type: object
envoy:
description: |-
Expand Down
16 changes: 16 additions & 0 deletions examples/render/contour-gateway-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,21 @@ spec:
type: string
type: object
type: object
disabledFeatures:
description: |-
DisabledFeatures defines an array of Gateway API CRDs that will be ignored by
contour reconciler.
Allowed values are
items:
enum:
- grpcroutes
- tlsroutes
- extensionservices
type: string
maxItems: 42
minItems: 1
type: array
uniqueItems: true
kubernetesLogLevel:
description: |-
KubernetesLogLevel Enable Kubernetes client debug logging with log level. If unset,
Expand Down Expand Up @@ -1655,6 +1670,7 @@ spec:
maxItems: 42
minItems: 1
type: array
uniqueItems: true
type: object
envoy:
description: |-
Expand Down
16 changes: 16 additions & 0 deletions examples/render/contour-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,21 @@ spec:
type: string
type: object
type: object
disabledFeatures:
description: |-
DisabledFeatures defines an array of Gateway API CRDs that will be ignored by
contour reconciler.
Allowed values are
items:
enum:
- grpcroutes
- tlsroutes
- extensionservices
type: string
maxItems: 42
minItems: 1
type: array
uniqueItems: true
kubernetesLogLevel:
description: |-
KubernetesLogLevel Enable Kubernetes client debug logging with log level. If unset,
Expand Down Expand Up @@ -1866,6 +1881,7 @@ spec:
maxItems: 42
minItems: 1
type: array
uniqueItems: true
type: object
envoy:
description: |-
Expand Down
16 changes: 16 additions & 0 deletions examples/render/contour.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,21 @@ spec:
type: string
type: object
type: object
disabledFeatures:
description: |-
DisabledFeatures defines an array of Gateway API CRDs that will be ignored by
contour reconciler.
Allowed values are
items:
enum:
- grpcroutes
- tlsroutes
- extensionservices
type: string
maxItems: 42
minItems: 1
type: array
uniqueItems: true
kubernetesLogLevel:
description: |-
KubernetesLogLevel Enable Kubernetes client debug logging with log level. If unset,
Expand Down Expand Up @@ -1863,6 +1878,7 @@ spec:
maxItems: 42
minItems: 1
type: array
uniqueItems: true
type: object
envoy:
description: |-
Expand Down
13 changes: 13 additions & 0 deletions internal/provisioner/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package model

import (
contourv1 "github.com/projectcontour/contour/apis/projectcontour/v1"
contourv1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
"github.com/projectcontour/contour/internal/ref"

Expand Down Expand Up @@ -254,6 +255,18 @@ type ContourSpec struct {
// to only watch these set of namespaces
// default is nil, contour will watch resource of all namespaces
WatchNamespaces []string

// DisabledFeatures defines an array of Gateway API CRDs that will be ignored by
// contour reconciler.
DisabledFeatures []contourv1.Feature
}

func FeaturesToStrings(fs []contourv1.Feature) []string {
res := make([]string, len(fs))
for i := range fs {
res[i] = string(fs[i])
}
return res
}

// WorkloadType is the type of Kubernetes workload to use for a component.
Expand Down
4 changes: 4 additions & 0 deletions internal/provisioner/objects/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func DesiredDeployment(contour *model.Contour, image string) *appsv1.Deployment
args = append(args, fmt.Sprintf("--watch-namespaces=%s", strings.Join(ns, ",")))
}

if contour.Spec.DisabledFeatures != nil && len(contour.Spec.DisabledFeatures) > 0 {
args = append(args, fmt.Sprintf("--disable-feature=%s", strings.Join(model.FeaturesToStrings(contour.Spec.DisabledFeatures), ",")))
}

// Pass the insecure/secure flags to Contour if using non-default ports.
for _, port := range contour.Spec.NetworkPublishing.Envoy.Ports {
switch {
Expand Down
32 changes: 32 additions & 0 deletions internal/provisioner/objects/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"strings"
"testing"

contour_v1 "github.com/projectcontour/contour/apis/projectcontour/v1"
"github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
"github.com/projectcontour/contour/internal/provisioner/model"

Expand Down Expand Up @@ -270,3 +271,34 @@ func TestNodePlacementDeployment(t *testing.T) {
checkDeploymentHasNodeSelector(t, deploy, selectors)
checkDeploymentHasTolerations(t, deploy, tolerations)
}

func TestDesiredDeploymentWhenSettingDisabledFeature(t *testing.T) {
testCases := []struct {
description string
disabledFeatures []contour_v1.Feature
}{
{
description: "several disabled features",
disabledFeatures: []contour_v1.Feature{"ns1", "ns2"},
},
{
description: "single disabled features",
disabledFeatures: []contour_v1.Feature{"ns1"},
},
}

for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
name := "deploy-test"
cntr := model.Default(fmt.Sprintf("%s-ns", name), name)
icName := "test-ic"
cntr.Spec.IngressClassName = &icName
cntr.Spec.DisabledFeatures = tc.disabledFeatures
// Change the Contour watch namespaces flag
deploy := DesiredDeployment(cntr, "ghcr.io/projectcontour/contour:test")
container := checkDeploymentHasContainer(t, deploy, contourContainerName, true)
arg := fmt.Sprintf("--disable-feature=%s", strings.Join(model.FeaturesToStrings(tc.disabledFeatures), ","))
checkContainerHasArg(t, container, arg)
})
}
}
25 changes: 25 additions & 0 deletions site/content/docs/main/config/api-reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,14 @@ <h3 id="projectcontour.io/v1.ExtensionServiceReference">ExtensionServiceReferenc
</tr>
</tbody>
</table>
<h3 id="projectcontour.io/v1.Feature">Feature
(<code>string</code> alias)</p></h3>
<p>
(<em>Appears on:</em>
<a href="#projectcontour.io/v1alpha1.ContourSettings">ContourSettings</a>)
</p>
<p>
</p>
<h3 id="projectcontour.io/v1.GenericKeyDescriptor">GenericKeyDescriptor
</h3>
<p>
Expand Down Expand Up @@ -6284,6 +6292,23 @@ <h3 id="projectcontour.io/v1alpha1.ContourSettings">ContourSettings
to only watch this subset of namespaces.</p>
</td>
</tr>
<tr>
<td style="white-space:nowrap">
<code>disabledFeatures</code>
<br>
<em>
<a href="#projectcontour.io/v1.Feature">
[]Feature
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>DisabledFeatures defines an array of Gateway API CRDs that will be ignored by
contour reconciler.
Allowed values are</p>
</td>
</tr>
</tbody>
</table>
<h3 id="projectcontour.io/v1alpha1.CustomTag">CustomTag
Expand Down
Loading

0 comments on commit 463ac78

Please sign in to comment.