Skip to content

Commit 7fc8fed

Browse files
committed
Resolve comments
Signed-off-by: Lubron Zhan <[email protected]>
1 parent c8666ad commit 7fc8fed

File tree

10 files changed

+42
-77
lines changed

10 files changed

+42
-77
lines changed

apis/projectcontour/v1/httpproxy.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,27 @@ type HTTPProxySpec struct {
4242
IngressClassName string `json:"ingressClassName,omitempty"`
4343
}
4444

45+
// Namespace refers to a Kubernetes namespace. It must be a RFC 1123 label.
46+
//
47+
// This validation is based off of the corresponding Kubernetes validation:
48+
// https://github.com/kubernetes/apimachinery/blob/02cfb53916346d085a6c6c7c66f882e3c6b0eca6/pkg/util/validation/validation.go#L187
49+
//
50+
// This is used for Namespace name validation here:
51+
// https://github.com/kubernetes/apimachinery/blob/02cfb53916346d085a6c6c7c66f882e3c6b0eca6/pkg/api/validation/generic.go#L63
52+
//
53+
// Valid values include:
54+
//
55+
// * "example"
56+
//
57+
// Invalid values include:
58+
//
59+
// * "example.com" - "." is an invalid character
60+
//
61+
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
62+
// +kubebuilder:validation:MinLength=1
63+
// +kubebuilder:validation:MaxLength=63
64+
type Namespace string
65+
4566
// Include describes a set of policies that can be applied to an HTTPProxy in a namespace.
4667
type Include struct {
4768
// Name of the HTTPProxy

apis/projectcontour/v1alpha1/contourdeployment_helpers.go renamed to apis/projectcontour/v1/httpproxy_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
package v1alpha1
14+
package v1
1515

1616
func NamespacesToStrings(ns []Namespace) []string {
1717
res := make([]string, len(ns))

apis/projectcontour/v1alpha1/contourdeployment_helpers_test.go renamed to apis/projectcontour/v1/httpproxy_helpers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
package v1alpha1
14+
package v1
1515

1616
import (
1717
"reflect"
1818
"testing"
1919
)
2020

21-
func TestDesiredRoleBindingInNamespace(t *testing.T) {
21+
func TestNamespacesToStrings(t *testing.T) {
2222
testCases := []struct {
2323
description string
2424
namespaces []Namespace

apis/projectcontour/v1alpha1/contourdeployment.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package v1alpha1
1515

1616
import (
17+
contour_api_v1 "github.com/projectcontour/contour/apis/projectcontour/v1"
1718
appsv1 "k8s.io/api/apps/v1"
1819
corev1 "k8s.io/api/core/v1"
1920
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -75,27 +76,6 @@ type ContourDeploymentSpec struct {
7576
ResourceLabels map[string]string `json:"resourceLabels,omitempty"`
7677
}
7778

78-
// Namespace refers to a Kubernetes namespace. It must be a RFC 1123 label.
79-
//
80-
// This validation is based off of the corresponding Kubernetes validation:
81-
// https://github.com/kubernetes/apimachinery/blob/02cfb53916346d085a6c6c7c66f882e3c6b0eca6/pkg/util/validation/validation.go#L187
82-
//
83-
// This is used for Namespace name validation here:
84-
// https://github.com/kubernetes/apimachinery/blob/02cfb53916346d085a6c6c7c66f882e3c6b0eca6/pkg/api/validation/generic.go#L63
85-
//
86-
// Valid values include:
87-
//
88-
// * "example"
89-
//
90-
// Invalid values include:
91-
//
92-
// * "example.com" - "." is an invalid character
93-
//
94-
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
95-
// +kubebuilder:validation:MinLength=1
96-
// +kubebuilder:validation:MaxLength=63
97-
type Namespace string
98-
9979
// ContourSettings contains settings for the Contour part of the installation,
10080
// i.e. the xDS server/control plane and associated resources.
10181
type ContourSettings struct {
@@ -150,7 +130,7 @@ type ContourSettings struct {
150130
// +kubebuilder:validation:Type=array
151131
// +kubebuilder:validation:MinItems=1
152132
// +kubebuilder:validation:MaxItems=42
153-
WatchNamespaces []Namespace `json:"watchNamespaces,omitempty"`
133+
WatchNamespaces []contour_api_v1.Namespace `json:"watchNamespaces,omitempty"`
154134
}
155135

156136
// DeploymentSettings contains settings for Deployment resources.

apis/projectcontour/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0X
114114
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
115115
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
116116
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
117-
github.com/go-asn1-ber/asn1-ber v1.5.4 h1:vXT6d/FNDiELJnLb6hGNa309LMsrCoYFvpwHDF0+Y1A=
118-
github.com/go-asn1-ber/asn1-ber v1.5.4/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
119117
github.com/go-asn1-ber/asn1-ber v1.5.5 h1:MNHlNMBDgEKD4TcKr36vQN68BA00aDfjIt3/bD50WnA=
120118
github.com/go-asn1-ber/asn1-ber v1.5.5/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
121119
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
@@ -381,8 +379,6 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
381379
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
382380
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
383381
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
384-
github.com/tsaarni/certyaml v0.9.2 h1:LoRTuajwjJ1CHAJiMv5cpOtwQ05207Oqe6cT9D7WDaQ=
385-
github.com/tsaarni/certyaml v0.9.2/go.mod h1:s+ErAC1wZ32r1ihSULvR7HXedKKN5HZasdb8Cj8gT9E=
386382
github.com/tsaarni/certyaml v0.9.3 h1:m8HHbuUzWVUOmv8IQU9HgVZZ8r5ICExKm++54DJKCs0=
387383
github.com/tsaarni/certyaml v0.9.3/go.mod h1:hhuU1qYr5re488geArUP4gZWqMUMqGlj4HA2qUyGYLk=
388384
github.com/tsaarni/x500dn v1.0.0 h1:LvaWTkqRpse4VHBhB5uwf3wytokK4vF9IOyNAEyiA+U=

internal/provisioner/controller/gateway.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"context"
1818
"fmt"
1919

20+
contour_api_v1 "github.com/projectcontour/contour/apis/projectcontour/v1"
2021
contour_api_v1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
2122
"github.com/projectcontour/contour/internal/gatewayapi"
2223
"github.com/projectcontour/contour/internal/provisioner/model"
@@ -261,7 +262,7 @@ func (r *gatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
261262

262263
contourModel.Spec.KubernetesLogLevel = contourParams.KubernetesLogLevel
263264

264-
contourModel.Spec.WatchNamespaces = contour_api_v1alpha1.NamespacesToStrings(contourParams.WatchNamespaces)
265+
contourModel.Spec.WatchNamespaces = contour_api_v1.NamespacesToStrings(contourParams.WatchNamespaces)
265266

266267
if contourParams.Deployment != nil &&
267268
contourParams.Deployment.Strategy != nil {

internal/provisioner/objects/deployment/deployment_test.go

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,6 @@ func checkDeploymentHasStrategy(t *testing.T, ds *appsv1.Deployment, expected ap
135135
t.Errorf("deployment has unexpected strategy %q", expected)
136136
}
137137

138-
func ensureContainerDoesntHaveArg(t *testing.T, container *corev1.Container, arg string) {
139-
t.Helper()
140-
141-
for _, a := range container.Args {
142-
if a == arg {
143-
t.Errorf("container has arg %q", arg)
144-
}
145-
}
146-
}
147-
148138
func TestDesiredDeployment(t *testing.T) {
149139
name := "deploy-test"
150140
cntr := model.Default(fmt.Sprintf("%s-ns", name), name)
@@ -225,19 +215,16 @@ func TestDesiredDeployment(t *testing.T) {
225215

226216
func TestDesiredDeploymentWhenSettingWatchNamespaces(t *testing.T) {
227217
testCases := []struct {
228-
description string
229-
namespaces []string
230-
expectArgExist bool
218+
description string
219+
namespaces []string
231220
}{
232221
{
233-
description: "several valid namespaces",
234-
namespaces: []string{"ns1", "ns2"},
235-
expectArgExist: true,
222+
description: "several valid namespaces",
223+
namespaces: []string{"ns1", "ns2"},
236224
},
237225
{
238-
description: "single valid namespace",
239-
namespaces: []string{"ns1"},
240-
expectArgExist: true,
226+
description: "single valid namespace",
227+
namespaces: []string{"ns1"},
241228
},
242229
}
243230

@@ -252,11 +239,7 @@ func TestDesiredDeploymentWhenSettingWatchNamespaces(t *testing.T) {
252239
deploy := DesiredDeployment(cntr, "ghcr.io/projectcontour/contour:test")
253240
container := checkDeploymentHasContainer(t, deploy, contourContainerName, true)
254241
arg := fmt.Sprintf("--watch-namespaces=%s", strings.Join(append(tc.namespaces, cntr.Namespace), ","))
255-
if tc.expectArgExist {
256-
checkContainerHasArg(t, container, arg)
257-
} else {
258-
ensureContainerDoesntHaveArg(t, container, arg)
259-
}
242+
checkContainerHasArg(t, container, arg)
260243
})
261244
}
262245
}

test/e2e/framework.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -472,21 +472,6 @@ func (f *Framework) DeleteGatewayClass(gwc *gatewayapi_v1beta1.GatewayClass, wai
472472
return nil
473473
}
474474

475-
// DeleteHTTPRoute deletes the provided HTTPROUTE in the
476-
// Kubernetes API or fails the test if it encounters an error.
477-
func (f *Framework) DeleteHTTPRoute(r *gatewayapi_v1beta1.HTTPRoute, waitForDeletion bool) error {
478-
require.NoError(f.t, f.Client.Delete(context.TODO(), r))
479-
480-
if waitForDeletion {
481-
require.Eventually(f.t, func() bool {
482-
err := f.Client.Get(context.TODO(), client.ObjectKeyFromObject(r), r)
483-
return api_errors.IsNotFound(err)
484-
}, time.Minute*3, time.Millisecond*50)
485-
}
486-
487-
return nil
488-
}
489-
490475
// GetEchoResponseBody decodes an HTTP response body that is
491476
// expected to have come from ingress-conformance-echo into an
492477
// EchoResponseBody, or fails the test if it encounters an error.

test/e2e/provisioner/provisioner_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
. "github.com/onsi/ginkgo/v2"
2727
. "github.com/onsi/gomega"
28+
contour_api_v1 "github.com/projectcontour/contour/apis/projectcontour/v1"
2829
contour_api_v1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
2930
"github.com/projectcontour/contour/internal/gatewayapi"
3031
"github.com/projectcontour/contour/internal/k8s"
@@ -519,7 +520,7 @@ var _ = Describe("Gateway provisioner", func() {
519520
Spec: contour_api_v1alpha1.ContourDeploymentSpec{
520521
RuntimeSettings: contourDeploymentRuntimeSettings(),
521522
Contour: &contour_api_v1alpha1.ContourSettings{
522-
WatchNamespaces: []contour_api_v1alpha1.Namespace{"testns-1", "testns-2"},
523+
WatchNamespaces: []contour_api_v1.Namespace{"testns-1", "testns-2"},
523524
},
524525
},
525526
}
@@ -643,17 +644,15 @@ var _ = Describe("Gateway provisioner", func() {
643644
// Root proxy in non-watched namespace should fail
644645
By(fmt.Sprintf("Expect namespace %s not to be watched by contour", t.namespace))
645646
hr, ok := f.CreateHTTPRouteAndWaitFor(route, e2e.HTTPRouteIngnoredByContour)
646-
By(fmt.Sprintf("Expect httproute under namespace %s is not accepted", t.namespace))
647-
require.True(f.T(), ok, fmt.Sprintf("httproute's is %v", hr))
648647

649648
By(fmt.Sprintf("Expect httproute under namespace %s is not accepted for a period of time", t.namespace))
650649
require.Never(f.T(), func() bool {
651-
r := &gatewayapi_v1beta1.HTTPRoute{}
652-
if err := f.Client.Get(context.Background(), k8s.NamespacedNameOf(hr), r); err != nil {
650+
hr = &gatewayapi_v1beta1.HTTPRoute{}
651+
if err := f.Client.Get(context.Background(), k8s.NamespacedNameOf(hr), hr); err != nil {
653652
return false
654653
}
655-
return e2e.HTTPRouteAccepted(r)
656-
}, 10*time.Second, time.Second)
654+
return e2e.HTTPRouteAccepted(hr)
655+
}, 10*time.Second, time.Second, hr)
657656
require.True(f.T(), ok, fmt.Sprintf("httproute's is %v", hr))
658657
}
659658
}

0 commit comments

Comments
 (0)