Skip to content

Commit 35e410d

Browse files
committed
Modify the spec
Signed-off-by: Lubron Zhan <[email protected]>
1 parent a52c282 commit 35e410d

File tree

11 files changed

+58
-33
lines changed

11 files changed

+58
-33
lines changed

apis/projectcontour/v1alpha1/contourdeployment.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ type ContourSettings struct {
123123
// +optional
124124
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
125125

126-
// WatchNamespaces when set restricts a subset of namespaces that the contour instance
127-
// will be watching.
126+
// WatchNamespaces is an array of namespaces. Setting it will instruct the contour instance
127+
// to only watch these set of namespaces
128128
// +optional
129-
WatchNamespaces *string `json:"watchNamespaces,omitempty"`
129+
WatchNamespaces []string `json:"watchNamespaces,omitempty"`
130130
}
131131

132132
// DeploymentSettings contains settings for Deployment resources.

apis/projectcontour/v1alpha1/zz_generated.deepcopy.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/contour/01-crds.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,9 +1561,12 @@ spec:
15611561
type: object
15621562
type: object
15631563
watchNamespaces:
1564-
description: WatchNamespaces when set restricts a subset of namespaces
1565-
that the contour instance will be watching.
1566-
type: string
1564+
description: WatchNamespaces is an array of namespaces. Setting
1565+
it will instruct the contour instance to only watch these set
1566+
of namespaces
1567+
items:
1568+
type: string
1569+
type: array
15671570
type: object
15681571
envoy:
15691572
description: Envoy specifies deployment-time settings for the Envoy

examples/render/contour-deployment.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,9 +1780,12 @@ spec:
17801780
type: object
17811781
type: object
17821782
watchNamespaces:
1783-
description: WatchNamespaces when set restricts a subset of namespaces
1784-
that the contour instance will be watching.
1785-
type: string
1783+
description: WatchNamespaces is an array of namespaces. Setting
1784+
it will instruct the contour instance to only watch these set
1785+
of namespaces
1786+
items:
1787+
type: string
1788+
type: array
17861789
type: object
17871790
envoy:
17881791
description: Envoy specifies deployment-time settings for the Envoy

examples/render/contour-gateway-provisioner.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,9 +1572,12 @@ spec:
15721572
type: object
15731573
type: object
15741574
watchNamespaces:
1575-
description: WatchNamespaces when set restricts a subset of namespaces
1576-
that the contour instance will be watching.
1577-
type: string
1575+
description: WatchNamespaces is an array of namespaces. Setting
1576+
it will instruct the contour instance to only watch these set
1577+
of namespaces
1578+
items:
1579+
type: string
1580+
type: array
15781581
type: object
15791582
envoy:
15801583
description: Envoy specifies deployment-time settings for the Envoy

examples/render/contour-gateway.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,9 +1783,12 @@ spec:
17831783
type: object
17841784
type: object
17851785
watchNamespaces:
1786-
description: WatchNamespaces when set restricts a subset of namespaces
1787-
that the contour instance will be watching.
1788-
type: string
1786+
description: WatchNamespaces is an array of namespaces. Setting
1787+
it will instruct the contour instance to only watch these set
1788+
of namespaces
1789+
items:
1790+
type: string
1791+
type: array
17891792
type: object
17901793
envoy:
17911794
description: Envoy specifies deployment-time settings for the Envoy

examples/render/contour.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,9 +1780,12 @@ spec:
17801780
type: object
17811781
type: object
17821782
watchNamespaces:
1783-
description: WatchNamespaces when set restricts a subset of namespaces
1784-
that the contour instance will be watching.
1785-
type: string
1783+
description: WatchNamespaces is an array of namespaces. Setting
1784+
it will instruct the contour instance to only watch these set
1785+
of namespaces
1786+
items:
1787+
type: string
1788+
type: array
17861789
type: object
17871790
envoy:
17881791
description: Envoy specifies deployment-time settings for the Envoy

internal/provisioner/model/model.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,10 @@ type ContourSpec struct {
246246
// defaults to 0.
247247
EnvoyMaxHeapSizeBytes uint64
248248

249-
// WatchNamespaces specifies a subset of namespaces that the contour instance
250-
// will be watching.
251-
// Expect value should be comma separate namespaces
252-
// For example, ns1,ns2,ns3
253-
WatchNamespaces *string
249+
// WatchNamespaces is an array of namespaces. Setting it will instruct the contour instance
250+
// to only watch these set of namespaces
251+
// default is nil, contour will watch resource of all namespaces
252+
WatchNamespaces []string
254253
}
255254

256255
// WorkloadType is the type of Kubernetes workload to use for a component.

internal/provisioner/objects/deployment/deployment.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"context"
1818
"fmt"
1919
"path/filepath"
20+
"strings"
2021

2122
"github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
2223
"github.com/projectcontour/contour/internal/provisioner/equality"
@@ -100,8 +101,8 @@ func DesiredDeployment(contour *model.Contour, image string) *appsv1.Deployment
100101
args = append(args, "--debug")
101102
}
102103

103-
if contour.Spec.WatchNamespaces != nil && *contour.Spec.WatchNamespaces != corev1.NamespaceAll {
104-
args = append(args, fmt.Sprintf("--watch-namespaces=%s", *contour.Spec.WatchNamespaces))
104+
if contour.Spec.WatchNamespaces != nil && len(contour.Spec.WatchNamespaces) > 0 && !contains(contour.Spec.WatchNamespaces, corev1.NamespaceAll) {
105+
args = append(args, fmt.Sprintf("--watch-namespaces=%s", strings.Join(contour.Spec.WatchNamespaces, ",")))
105106
}
106107

107108
// Pass the insecure/secure flags to Contour if using non-default ports.
@@ -329,3 +330,12 @@ func contourPodAnnotations(contour *model.Contour) map[string]string {
329330

330331
return annotations
331332
}
333+
334+
func contains(s []string, e string) bool {
335+
for _, a := range s {
336+
if a == e {
337+
return true
338+
}
339+
}
340+
return false
341+
}

internal/provisioner/objects/deployment/deployment_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package deployment
1515

1616
import (
1717
"fmt"
18+
"strings"
1819
"testing"
1920

2021
"github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
@@ -140,7 +141,7 @@ func TestDesiredDeployment(t *testing.T) {
140141
cntr := model.Default(fmt.Sprintf("%s-ns", name), name)
141142
icName := "test-ic"
142143
cntr.Spec.IngressClassName = &icName
143-
testNamespaces := "ns1,ns2,ns3"
144+
testNamespaces := []string{"ns1", "ns2", "ns3"}
144145
resQutoa := corev1.ResourceRequirements{
145146
Limits: corev1.ResourceList{
146147
corev1.ResourceCPU: resource.MustParse("400m"),
@@ -165,7 +166,7 @@ func TestDesiredDeployment(t *testing.T) {
165166
cntr.Spec.ContourLogLevel = v1alpha1.DebugLog
166167

167168
// Change the Contour watch namespaces flag
168-
cntr.Spec.WatchNamespaces = &testNamespaces
169+
cntr.Spec.WatchNamespaces = testNamespaces
169170

170171
cntr.Spec.ResourceLabels = map[string]string{
171172
"key": "value",
@@ -210,7 +211,7 @@ func TestDesiredDeployment(t *testing.T) {
210211
arg = fmt.Sprintf("--kubernetes-debug=%d", cntr.Spec.KubernetesLogLevel)
211212
checkContainerHasArg(t, container, arg)
212213

213-
arg = fmt.Sprintf("--watch-namespaces=%s", *cntr.Spec.WatchNamespaces)
214+
arg = fmt.Sprintf("--watch-namespaces=%s", strings.Join(testNamespaces, ","))
214215
checkContainerHasArg(t, container, arg)
215216

216217
checkDeploymentHasNodeSelector(t, deploy, nil)

0 commit comments

Comments
 (0)