diff --git a/.golangci.yml b/.golangci.yml index 1b750174c13..123dfa64617 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,7 +4,7 @@ run: linters: enable: - bodyclose - - gofmt + - gofumpt - goimports - revive - gosec @@ -23,8 +23,6 @@ linters-settings: - clas - cancelled locale: US - gofmt: - simplify: true unparam: check-exported: false goheader: @@ -62,8 +60,12 @@ linters-settings: enable-all: true ginkgolinter: forbid-focus-container: true + gofumpt: + extra-rules: true issues: + max-issues-per-linter: 0 + max-same-issues: 0 exclude-rules: - linters: ["unparam"] text: "always receives" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2a70deab318..46d75d0be64 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -311,6 +311,13 @@ At a maintainer's discretion, pull requests with multiple commits can be merged Merging pull requests with multiple commits can make sense in cases where a change involves code generation or mechanical changes that can be cleanly separated from semantic changes. The maintainer should review commit messages for each commit and make sure that each commit builds and passes tests. +### Code formatting + +Contour utilizes [`gofumpt`](https://github.com/mvdan/gofumpt) for strict Golang formatting of the contour codebase. +The `lint` CI job checks this to ensure all commits are formatted as expected. + +The `make format` target can be used to run `gofumpt` locally before making a PR. + ### Import Aliases Naming is one of the most difficult things in software engineering. diff --git a/Makefile b/Makefile index faee470df42..58f23dfcd5a 100644 --- a/Makefile +++ b/Makefile @@ -223,6 +223,11 @@ lint-flags: exit 2; \ fi +.PHONY: format +format: ## Run gofumpt to format the codebase. + @echo Running gofumpt... + @./hack/gofumpt -l -w -extra . + .PHONY: generate generate: ## Re-generate generated code and documentation generate: generate-rbac generate-crd-deepcopy generate-crd-yaml generate-gateway-yaml generate-deployment generate-api-docs generate-metrics-docs generate-uml generate-go diff --git a/apis/projectcontour/v1/helpers.go b/apis/projectcontour/v1/helpers.go index 409e6beda18..21b17f02936 100644 --- a/apis/projectcontour/v1/helpers.go +++ b/apis/projectcontour/v1/helpers.go @@ -179,7 +179,6 @@ func (dc *DetailedCondition) IsPositivePolarity() bool { // getIndex checks if a SubCondition of type condType exists in the // slice, and returns its index if so. If not, returns -1. func getIndex(condType string, subconds []SubCondition) int { - for i, cond := range subconds { if cond.Type == condType { return i @@ -191,7 +190,6 @@ func getIndex(condType string, subconds []SubCondition) int { // GetConditionFor returns the a pointer to the condition for a given type, // or nil if there are none currently present. func (status *HTTPProxyStatus) GetConditionFor(condType string) *DetailedCondition { - for i, cond := range status.Conditions { if cond.Type == condType { return &status.Conditions[i] diff --git a/apis/projectcontour/v1/helpers_test.go b/apis/projectcontour/v1/helpers_test.go index 5b5a2919951..18b267c4c10 100644 --- a/apis/projectcontour/v1/helpers_test.go +++ b/apis/projectcontour/v1/helpers_test.go @@ -30,7 +30,6 @@ type subConditionDetails struct { } func TestAddErrorConditions(t *testing.T) { - tests := map[string]struct { dc *DetailedCondition subconditions []subConditionDetails @@ -274,7 +273,6 @@ func TestAddErrorConditions(t *testing.T) { } func TestAddWarningConditions(t *testing.T) { - tests := map[string]struct { dc *DetailedCondition subconditions []subConditionDetails @@ -544,7 +542,6 @@ func TestGetConditionFor(t *testing.T) { } func TestGetError(t *testing.T) { - dcWithErrors := &DetailedCondition{ Errors: []SubCondition{ { @@ -571,11 +568,9 @@ func TestGetError(t *testing.T) { emptySubCond, ok := dcEmpty.GetError(ConditionTypeServiceError) assert.False(t, ok) assert.Equal(t, SubCondition{}, emptySubCond) - } func TestGetWarning(t *testing.T) { - dcWithErrors := &DetailedCondition{ Warnings: []SubCondition{ { @@ -612,10 +607,9 @@ func TestGetWarning(t *testing.T) { emptySubCond, ok := dcEmpty.GetWarning("SimpleTest1") assert.False(t, ok) assert.Equal(t, SubCondition{}, emptySubCond) - } -func TestTruncateLongMessage(t *testing.T) { +func TestTruncateLongMessage(t *testing.T) { shortmessage := "This is a message shorter than the max length" assert.Equal(t, shortmessage, truncateLongMessage(shortmessage)) @@ -623,7 +617,6 @@ func TestTruncateLongMessage(t *testing.T) { truncatedLongMessage := longMessage[:LongMessageLength] assert.Equal(t, truncatedLongMessage, truncateLongMessage(longMessage)) - } // nolint:misspell diff --git a/apis/projectcontour/v1/register.go b/apis/projectcontour/v1/register.go index 673a1a89082..3014e9357e7 100644 --- a/apis/projectcontour/v1/register.go +++ b/apis/projectcontour/v1/register.go @@ -28,8 +28,10 @@ const ( // New code should use GroupVersion. var SchemeGroupVersion = GroupVersion -var HTTPProxyGVR = GroupVersion.WithResource("httpproxies") -var TLSCertificateDelegationGVR = GroupVersion.WithResource("tlscertificatedelegations") +var ( + HTTPProxyGVR = GroupVersion.WithResource("httpproxies") + TLSCertificateDelegationGVR = GroupVersion.WithResource("tlscertificatedelegations") +) // Resource gets an Contour GroupResource for a specified resource func Resource(resource string) schema.GroupResource { diff --git a/apis/projectcontour/v1/tlscertificatedelegation.go b/apis/projectcontour/v1/tlscertificatedelegation.go index 31e49813ce0..3623defbf79 100644 --- a/apis/projectcontour/v1/tlscertificatedelegation.go +++ b/apis/projectcontour/v1/tlscertificatedelegation.go @@ -25,7 +25,6 @@ type TLSCertificateDelegationSpec struct { // CertificateDelegation maps the authority to reference a secret // in the current namespace to a set of namespaces. type CertificateDelegation struct { - // required, the name of a secret in the current namespace. SecretName string `json:"secretName"` diff --git a/apis/projectcontour/v1alpha1/accesslog.go b/apis/projectcontour/v1alpha1/accesslog.go index 4bab149b1b3..9d1ece7e164 100644 --- a/apis/projectcontour/v1alpha1/accesslog.go +++ b/apis/projectcontour/v1alpha1/accesslog.go @@ -191,7 +191,6 @@ const ( type AccessLogJSONFields []string func (a AccessLogJSONFields) Validate() error { - for key, val := range a.AsFieldMap() { if val == "" { return fmt.Errorf("invalid JSON log field name %s", key) diff --git a/apis/projectcontour/v1alpha1/contourconfig_helpers_test.go b/apis/projectcontour/v1alpha1/contourconfig_helpers_test.go index 290256e4d6c..4dda74cf897 100644 --- a/apis/projectcontour/v1alpha1/contourconfig_helpers_test.go +++ b/apis/projectcontour/v1alpha1/contourconfig_helpers_test.go @@ -230,7 +230,6 @@ func TestContourConfigurationSpecValidate(t *testing.T) { } c.Tracing.CustomTags = customTags require.Error(t, c.Validate()) - }) } diff --git a/cmd/contour/certgen.go b/cmd/contour/certgen.go index fe31763f819..ef55f004f2e 100644 --- a/cmd/contour/certgen.go +++ b/cmd/contour/certgen.go @@ -53,7 +53,6 @@ func registerCertGen(app *kingpin.Application) (*kingpin.CmdClause, *certgenConf // certgenConfig holds the configuration for the certificate generation process. type certgenConfig struct { - // KubeConfig is the path to the Kubeconfig file if we're not running in a cluster KubeConfig string @@ -154,5 +153,4 @@ func doCertgen(config *certgenConfig, log logrus.FieldLogger) { if oerr := OutputCerts(config, coreClient, generatedCerts); oerr != nil { log.WithError(oerr).Fatalf("failed output certificates") } - } diff --git a/cmd/contour/certgen_test.go b/cmd/contour/certgen_test.go index b8d335631ba..6dcea53c9d4 100644 --- a/cmd/contour/certgen_test.go +++ b/cmd/contour/certgen_test.go @@ -276,7 +276,7 @@ func TestOutputFileMode(t *testing.T) { err = filepath.Walk(outputDir, func(path string, info os.FileInfo, err error) error { if !info.IsDir() { - assert.Equal(t, os.FileMode(0600), info.Mode(), "incorrect mode for file "+path) + assert.Equal(t, os.FileMode(0o600), info.Mode(), "incorrect mode for file "+path) } return nil }) diff --git a/cmd/contour/contour.go b/cmd/contour/contour.go index 16f01005dea..a2b92fd1865 100644 --- a/cmd/contour/contour.go +++ b/cmd/contour/contour.go @@ -187,5 +187,4 @@ func main() { app.Usage(args) os.Exit(2) } - } diff --git a/cmd/contour/serve.go b/cmd/contour/serve.go index a59295a715d..f4fb77abe05 100644 --- a/cmd/contour/serve.go +++ b/cmd/contour/serve.go @@ -91,7 +91,6 @@ func registerServe(app *kingpin.Application) (*kingpin.CmdClause, *serveContext) ctx := newServeContext() parseConfig := func(_ *kingpin.ParseContext) error { - if ctx.contourConfigurationName != "" && configFile != "" { return fmt.Errorf("cannot specify both %s and %s", "--contour-config", "-c/--config-path") } @@ -200,7 +199,6 @@ type EndpointsTranslator interface { // NewServer returns a Server object which contains the initial configuration // objects required to start an instance of Contour. func NewServer(log logrus.FieldLogger, ctx *serveContext) (*Server, error) { - var restConfigOpts []func(*rest.Config) if qps := ctx.Config.KubeClientQPS; qps > 0 { @@ -260,7 +258,8 @@ func NewServer(log logrus.FieldLogger, ctx *serveContext) (*Server, error) { secret.SetAnnotations(nil) return secret, nil - }}, + }, + }, }, // DefaultTransform is called for objects that do not have a TransformByObject function. DefaultTransform: func(obj any) (any, error) { @@ -742,7 +741,7 @@ func (s *Server) doServe() error { return s.mgr.Start(signals.SetupSignalHandler()) } -func (s *Server) getExtensionSvcConfig(name string, namespace string) (xdscache_v3.ExtensionServiceConfig, error) { +func (s *Server) getExtensionSvcConfig(name, namespace string) (xdscache_v3.ExtensionServiceConfig, error) { extensionSvc := &contour_api_v1alpha1.ExtensionService{} key := client.ObjectKey{ Namespace: namespace, @@ -822,7 +821,6 @@ func (s *Server) setupTracingService(tracingConfig *contour_api_v1alpha1.Tracing MaxPathTagLength: ref.Val(tracingConfig.MaxPathTagLength, 256), CustomTags: customTags, }, nil - } func (s *Server) setupRateLimitService(contourConfiguration contour_api_v1alpha1.ContourConfigurationSpec) (*xdscache_v3.RateLimitConfig, error) { @@ -954,8 +952,8 @@ func (x *xdsServer) Start(ctx context.Context) error { // setupMetrics creates metrics service for Contour. func (s *Server) setupMetrics(metricsConfig contour_api_v1alpha1.MetricsConfig, healthConfig contour_api_v1alpha1.HealthConfig, - registry *prometheus.Registry) error { - + registry *prometheus.Registry, +) error { // Create metrics service and register with mgr. metricsvc := &httpsvc.Service{ Addr: metricsConfig.Address, @@ -982,8 +980,8 @@ func (s *Server) setupMetrics(metricsConfig contour_api_v1alpha1.MetricsConfig, } func (s *Server) setupHealth(healthConfig contour_api_v1alpha1.HealthConfig, - metricsConfig contour_api_v1alpha1.MetricsConfig) error { - + metricsConfig contour_api_v1alpha1.MetricsConfig, +) error { if healthConfig.Address != metricsConfig.Address || healthConfig.Port != metricsConfig.Port { healthsvc := &httpsvc.Service{ Addr: healthConfig.Address, @@ -1002,8 +1000,8 @@ func (s *Server) setupHealth(healthConfig contour_api_v1alpha1.HealthConfig, } func (s *Server) setupGatewayAPI(contourConfiguration contour_api_v1alpha1.ContourConfigurationSpec, - mgr manager.Manager, eventHandler *contour.EventRecorder, sh *k8s.StatusUpdateHandler) []leadership.NeedLeaderElectionNotification { - + mgr manager.Manager, eventHandler *contour.EventRecorder, sh *k8s.StatusUpdateHandler, +) []leadership.NeedLeaderElectionNotification { needLeadershipNotification := []leadership.NeedLeaderElectionNotification{} // Check if GatewayAPI is configured. @@ -1129,7 +1127,6 @@ type dagBuilderConfig struct { } func (s *Server) getDAGBuilder(dbc dagBuilderConfig) *dag.Builder { - var ( requestHeadersPolicy dag.HeadersPolicy responseHeadersPolicy dag.HeadersPolicy @@ -1273,7 +1270,6 @@ func (s *Server) informOnResource(obj client.Object, handler cache.ResourceEvent } registration, err := inf.AddEventHandler(handler) - if err != nil { return err } diff --git a/cmd/contour/servecontext_test.go b/cmd/contour/servecontext_test.go index f9a2dbcfef8..395b4966d1c 100644 --- a/cmd/contour/servecontext_test.go +++ b/cmd/contour/servecontext_test.go @@ -340,7 +340,8 @@ func TestParseHTTPVersions(t *testing.T) { "http/1.1+http/2 duplicated": { versions: []contour_api_v1alpha1.HTTPVersionType{ contour_api_v1alpha1.HTTPVersion1, contour_api_v1alpha1.HTTPVersion2, - contour_api_v1alpha1.HTTPVersion1, contour_api_v1alpha1.HTTPVersion2}, + contour_api_v1alpha1.HTTPVersion1, contour_api_v1alpha1.HTTPVersion2, + }, parseVersions: []envoy_v3.HTTPVersionType{envoy_v3.HTTPVersion1, envoy_v3.HTTPVersion2}, }, } diff --git a/cmd/contour/shutdownmanager.go b/cmd/contour/shutdownmanager.go index b41f748ac81..4677523bd67 100644 --- a/cmd/contour/shutdownmanager.go +++ b/cmd/contour/shutdownmanager.go @@ -198,7 +198,6 @@ func (s *shutdownContext) shutdownHandler() { // shutdownEnvoy sends a POST request to /healthcheck/fail to tell Envoy to start draining connections func shutdownEnvoy(adminAddress string) error { - httpClient := http.Client{ Transport: &http.Transport{ DialContext: func(_ context.Context, _, _ string) (net.Conn, error) { @@ -221,7 +220,6 @@ func shutdownEnvoy(adminAddress string) error { // getOpenConnections parses a http request to a prometheus endpoint returning the sum of values found func getOpenConnections(adminAddress string) (int, error) { - httpClient := http.Client{ Transport: &http.Transport{ DialContext: func(_ context.Context, _, _ string) (net.Conn, error) { @@ -280,7 +278,6 @@ func parseOpenConnections(stats io.Reader) (int, error) { } func doShutdownManager(config *shutdownmanagerContext) { - config.Info("started envoy shutdown manager") http.HandleFunc("/healthz", config.healthzHandler) diff --git a/hack/actions/check-changefile-exists.go b/hack/actions/check-changefile-exists.go index 0b815b16837..ce31353b4a0 100644 --- a/hack/actions/check-changefile-exists.go +++ b/hack/actions/check-changefile-exists.go @@ -52,7 +52,6 @@ Error: %s Please see the "Commit message and PR guidelines" section of CONTRIBUTING.md, or https://github.com/projectcontour/contour/blob/main/design/changelog.md for background.`, errorMessage)) - } // We need a GITHUB_TOKEN and PR_NUMBER in the environment. @@ -62,7 +61,6 @@ or https://github.com/projectcontour/contour/blob/main/design/changelog.md for b token, ok := os.LookupEnv("GITHUB_TOKEN") if !ok { log.Fatal("No GITHUB_TOKEN set, check the Action config.") - } prEnv, ok := os.LookupEnv("PR_NUMBER") if !ok { diff --git a/hack/generate-metrics-doc.go b/hack/generate-metrics-doc.go index 2d6a4145b7a..9f13c243fe6 100644 --- a/hack/generate-metrics-doc.go +++ b/hack/generate-metrics-doc.go @@ -79,7 +79,7 @@ func main() { log.Fatalf("%s", err) } - f, err := os.OpenFile("table.md", os.O_CREATE|os.O_RDWR, 0644) + f, err := os.OpenFile("table.md", os.O_CREATE|os.O_RDWR, 0o644) if err != nil { log.Fatalf("%s", err) } diff --git a/hack/gofumpt b/hack/gofumpt new file mode 100755 index 00000000000..49d8e719f02 --- /dev/null +++ b/hack/gofumpt @@ -0,0 +1,3 @@ +#! /usr/bin/env bash + +go run mvdan.cc/gofumpt@v0.5.0 "$@" diff --git a/hack/release/prepare-release.go b/hack/release/prepare-release.go index 73b9cdc0955..a9d903c9714 100644 --- a/hack/release/prepare-release.go +++ b/hack/release/prepare-release.go @@ -66,7 +66,7 @@ func capture(cmd []string) string { return out.String() } -func updateMappingForTOC(filePath string, vers string, toc string) error { +func updateMappingForTOC(filePath, vers, toc string) error { data, err := os.ReadFile(filePath) if err != nil { return err @@ -86,7 +86,7 @@ func updateMappingForTOC(filePath string, vers string, toc string) error { }, ) - return os.WriteFile(filePath, []byte(rn.MustString()), 0600) + return os.WriteFile(filePath, []byte(rn.MustString()), 0o600) } // InsertAfter is like yaml.ElementAppender except it inserts after the named node. @@ -114,7 +114,7 @@ func (a InsertAfter) Filter(rn *yaml.RNode) (*yaml.RNode, error) { return rn, nil } -func updateConfigForSite(filePath string, vers string) error { +func updateConfigForSite(filePath, vers string) error { data, err := os.ReadFile(filePath) if err != nil { return err @@ -148,7 +148,7 @@ func updateConfigForSite(filePath string, vers string) error { log.Fatalf("%s", err) } - return os.WriteFile(filePath, []byte(rn.MustString()), 0600) + return os.WriteFile(filePath, []byte(rn.MustString()), 0o600) } func updateIndexFile(filePath, newVers string) error { @@ -160,7 +160,7 @@ func updateIndexFile(filePath, newVers string) error { upd := strings.ReplaceAll(string(data), "version: main", fmt.Sprintf("version: \"%s\"", newVers)) upd = strings.ReplaceAll(upd, "branch: main", "branch: release-"+newVers) - return os.WriteFile(filePath, []byte(upd), 0600) + return os.WriteFile(filePath, []byte(upd), 0o600) } func main() { diff --git a/internal/annotation/annotations.go b/internal/annotation/annotations.go index 5c39058a461..1a292ccfa8b 100644 --- a/internal/annotation/annotations.go +++ b/internal/annotation/annotations.go @@ -80,7 +80,7 @@ var annotationsByKind = map[string]map[string]struct{}{ } // ValidForKind checks if a particular annotation is valid for a given Kind. -func ValidForKind(kind string, key string) bool { +func ValidForKind(kind, key string) bool { if a, ok := annotationsByKind[kind]; ok { _, ok := a[key] return ok @@ -175,7 +175,6 @@ func WebsocketRoutes(i *networking_v1.Ingress) map[string]bool { // NumRetries returns the number of retries specified by the // "projectcontour.io/num-retries" annotation. func NumRetries(i *networking_v1.Ingress) uint32 { - val := parseInt32(ContourAnnotation(i, "num-retries")) // If set to -1, then retries set to 0. If set to 0 or @@ -213,7 +212,7 @@ func IngressClass(o metav1.Object) string { // TLSVersion returns the TLS protocol version specified by an ingress annotation // or default if non present. -func TLSVersion(version string, defaultVal string) string { +func TLSVersion(version, defaultVal string) string { switch version { case "1.2", "1.3": return version diff --git a/internal/certgen/certgen.go b/internal/certgen/certgen.go index ff2464886ce..df7544d4daf 100644 --- a/internal/certgen/certgen.go +++ b/internal/certgen/certgen.go @@ -52,7 +52,7 @@ const ( Overwrite OverwritePolicy = 1 ) -func newSecret(secretType corev1.SecretType, name string, namespace string, data map[string][]byte) *corev1.Secret { +func newSecret(secretType corev1.SecretType, name, namespace string, data map[string][]byte) *corev1.Secret { return &corev1.Secret{ Type: secretType, TypeMeta: metav1.TypeMeta{ diff --git a/internal/certgen/output.go b/internal/certgen/output.go index f4e7fc33f6d..8525304e5ea 100644 --- a/internal/certgen/output.go +++ b/internal/certgen/output.go @@ -30,8 +30,7 @@ func writeSecret(f *os.File, secret *corev1.Secret) error { } func createFile(filepath string, force bool) (*os.File, error) { - - err := os.MkdirAll(path.Dir(filepath), 0755) + err := os.MkdirAll(path.Dir(filepath), 0o755) if err != nil { return nil, fmt.Errorf("unable to create %s: %s", path.Dir(filepath), err) } @@ -46,7 +45,7 @@ func createFile(filepath string, force bool) (*os.File, error) { flags |= os.O_EXCL } - f, err := os.OpenFile(filepath, flags, 0600) + f, err := os.OpenFile(filepath, flags, 0o600) if err != nil { // File exists, and we don't want to create it. return nil, fmt.Errorf("can't create file %s: %s", filepath, err) diff --git a/internal/contour/metrics.go b/internal/contour/metrics.go index a2fe0db2818..e0f6ab6cfa4 100644 --- a/internal/contour/metrics.go +++ b/internal/contour/metrics.go @@ -122,7 +122,7 @@ func calculateRouteMetric(updates []*status.ProxyUpdate) metrics.RouteMetric { } } -func calcMetrics(u *status.ProxyUpdate, metricValid map[metrics.Meta]int, metricInvalid map[metrics.Meta]int, metricOrphaned map[metrics.Meta]int, metricTotal map[metrics.Meta]int) { +func calcMetrics(u *status.ProxyUpdate, metricValid, metricInvalid, metricOrphaned, metricTotal map[metrics.Meta]int) { validCond := u.ConditionFor(status.ValidCondition) switch validCond.Status { case contour_api_v1.ConditionTrue: diff --git a/internal/controller/gateway.go b/internal/controller/gateway.go index 69b5f1485c8..decbd9a5568 100644 --- a/internal/controller/gateway.go +++ b/internal/controller/gateway.go @@ -215,7 +215,8 @@ func (r *gatewayReconciler) Reconcile(ctx context.Context, request reconcile.Req ObjectMeta: metav1.ObjectMeta{ Namespace: request.Namespace, Name: request.Name, - }}) + }, + }) return reconcile.Result{}, nil } @@ -238,7 +239,8 @@ func (r *gatewayReconciler) Reconcile(ctx context.Context, request reconcile.Req ObjectMeta: metav1.ObjectMeta{ Namespace: request.Namespace, Name: request.Name, - }}) + }, + }) return reconcile.Result{}, nil } diff --git a/internal/controller/gatewayclass.go b/internal/controller/gatewayclass.go index 429fc375481..bf2220f0485 100644 --- a/internal/controller/gatewayclass.go +++ b/internal/controller/gatewayclass.go @@ -162,7 +162,8 @@ func (r *gatewayClassReconciler) Reconcile(ctx context.Context, request reconcil ObjectMeta: metav1.ObjectMeta{ Namespace: request.Namespace, Name: request.Name, - }}) + }, + }) return reconcile.Result{}, nil } diff --git a/internal/controller/grpcroute.go b/internal/controller/grpcroute.go index 8d57689726d..044e0ca863b 100644 --- a/internal/controller/grpcroute.go +++ b/internal/controller/grpcroute.go @@ -56,7 +56,6 @@ func RegisterGRPCRouteController(log logrus.FieldLogger, mgr manager.Manager, ev } func (r *grpcRouteReconciler) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { - // Fetch the GRPCRoute from the cache. grpcRoute := &gatewayapi_v1alpha2.GRPCRoute{} err := r.client.Get(ctx, request.NamespacedName, grpcRoute) diff --git a/internal/controller/httproute.go b/internal/controller/httproute.go index 27cb193b710..b0e758de1ae 100644 --- a/internal/controller/httproute.go +++ b/internal/controller/httproute.go @@ -56,7 +56,6 @@ func RegisterHTTPRouteController(log logrus.FieldLogger, mgr manager.Manager, ev } func (r *httpRouteReconciler) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { - // Fetch the HTTPRoute from the cache. httpRoute := &gatewayapi_v1beta1.HTTPRoute{} err := r.client.Get(ctx, request.NamespacedName, httpRoute) diff --git a/internal/controller/tcproute.go b/internal/controller/tcproute.go index 2d30640b714..507e6c9d134 100644 --- a/internal/controller/tcproute.go +++ b/internal/controller/tcproute.go @@ -56,7 +56,6 @@ func RegisterTCPRouteController(log logrus.FieldLogger, mgr manager.Manager, eve } func (r *tcpRouteReconciler) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { - // Fetch the TCPRoute from the cache. tcpRoute := &gatewayapi_v1alpha2.TCPRoute{} err := r.client.Get(ctx, request.NamespacedName, tcpRoute) diff --git a/internal/controller/tlsroute.go b/internal/controller/tlsroute.go index 7eff1534ec8..558dcb60f2b 100644 --- a/internal/controller/tlsroute.go +++ b/internal/controller/tlsroute.go @@ -56,7 +56,6 @@ func RegisterTLSRouteController(log logrus.FieldLogger, mgr manager.Manager, eve } func (r *tlsRouteReconciler) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { - // Fetch the TLSRoute from the cache. tlsroute := &gatewayapi_v1alpha2.TLSRoute{} err := r.client.Get(ctx, request.NamespacedName, tlsroute) diff --git a/internal/dag/accessors.go b/internal/dag/accessors.go index 3aff82c8c7a..bea91f36a3c 100644 --- a/internal/dag/accessors.go +++ b/internal/dag/accessors.go @@ -28,7 +28,7 @@ import ( // EnsureService looks for a Kubernetes service in the cache matching the provided // namespace, name and port, and returns a DAG service for it. If a matching service // cannot be found in the cache, an error is returned. -func (d *DAG) EnsureService(meta types.NamespacedName, port int, healthPort int, cache *KubernetesCache, enableExternalNameSvc bool) (*Service, error) { +func (d *DAG) EnsureService(meta types.NamespacedName, port, healthPort int, cache *KubernetesCache, enableExternalNameSvc bool) (*Service, error) { svc, svcPort, err := cache.LookupService(meta, intstr.FromInt(port)) if err != nil { return nil, err @@ -73,7 +73,6 @@ func (d *DAG) EnsureService(meta types.NamespacedName, port int, healthPort int, } func validateExternalName(svc *v1.Service, enableExternalNameSvc bool) error { - // If this isn't an ExternalName Service, we're all good here. en := externalName(svc) if en == "" { @@ -118,6 +117,7 @@ func toContourProtocol(appProtocol string) (string, bool) { }[appProtocol] return proto, ok } + func upstreamProtocol(svc *v1.Service, port v1.ServicePort) string { // if appProtocol is not nil, check it only if port.AppProtocol != nil { diff --git a/internal/dag/accessors_test.go b/internal/dag/accessors_test.go index ca9be59d39d..1312a9191fb 100644 --- a/internal/dag/accessors_test.go +++ b/internal/dag/accessors_test.go @@ -44,8 +44,8 @@ func makeServicePort(name string, protocol v1.Protocol, port int32, extras ...an } return p - } + func TestBuilderLookupService(t *testing.T) { s1 := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ diff --git a/internal/dag/builder.go b/internal/dag/builder.go index e73223b3cb4..7c2afff54d0 100644 --- a/internal/dag/builder.go +++ b/internal/dag/builder.go @@ -56,7 +56,6 @@ type Builder struct { // Build builds and returns a new DAG by running the // configured DAG processors, in order. func (b *Builder) Build() *DAG { - gatewayNSName := types.NamespacedName{} if b.Source.gateway != nil { gatewayNSName = k8s.NamespacedNameOf(b.Source.gateway) diff --git a/internal/dag/builder_test.go b/internal/dag/builder_test.go index a0a15db5e27..5709a3d9450 100644 --- a/internal/dag/builder_test.go +++ b/internal/dag/builder_test.go @@ -1383,15 +1383,16 @@ func TestDAGInsertGatewayAPI(t *testing.T) { }, Rules: []gatewayapi_v1beta1.HTTPRouteRule{{ Matches: gatewayapi.HTTPRouteMatch(gatewayapi_v1.PathMatchPathPrefix, "/"), - BackendRefs: []gatewayapi_v1beta1.HTTPBackendRef{{ - BackendRef: gatewayapi_v1beta1.BackendRef{ - BackendObjectReference: gatewayapi_v1beta1.BackendObjectReference{ - Kind: ref.To(gatewayapi_v1beta1.Kind("Service")), - Name: "kuard", + BackendRefs: []gatewayapi_v1beta1.HTTPBackendRef{ + { + BackendRef: gatewayapi_v1beta1.BackendRef{ + BackendObjectReference: gatewayapi_v1beta1.BackendObjectReference{ + Kind: ref.To(gatewayapi_v1beta1.Kind("Service")), + Name: "kuard", + }, }, }, }, - }, }}, }, }, @@ -2443,7 +2444,6 @@ func TestDAGInsertGatewayAPI(t *testing.T) { Namespace: "projectcontour", }, Spec: gatewayapi_v1beta1.HTTPRouteSpec{ - CommonRouteSpec: gatewayapi_v1beta1.CommonRouteSpec{ ParentRefs: []gatewayapi_v1beta1.ParentReference{ gatewayapi.GatewayListenerParentRef("projectcontour", "contour", "https-listener", 0), @@ -2559,7 +2559,8 @@ func TestDAGInsertGatewayAPI(t *testing.T) { }, }, BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), - }}, + }, + }, }, }, }, @@ -3391,7 +3392,8 @@ func TestDAGInsertGatewayAPI(t *testing.T) { }, }, }}, - }}, + }, + }, }, }, }, @@ -3452,7 +3454,8 @@ func TestDAGInsertGatewayAPI(t *testing.T) { }}, }, }, - }}, + }, + }, }, }, }, @@ -3508,7 +3511,8 @@ func TestDAGInsertGatewayAPI(t *testing.T) { }}, }, }, - }}, + }, + }, }, }, }, @@ -4991,7 +4995,6 @@ func TestDAGInsertGatewayAPI(t *testing.T) { Name: "tcp.projectcontour.io", }, TCPProxy: &TCPProxy{ - Clusters: clustersWeight( weightedService(kuardService, 1), weightedService(kuardService2, 2), @@ -5039,7 +5042,6 @@ func TestDAGInsertGatewayAPI(t *testing.T) { Name: "tcp.projectcontour.io", }, TCPProxy: &TCPProxy{ - Clusters: clustersWeight( weightedService(kuardService, 1), weightedService(kuardService2, 0), @@ -5087,7 +5089,6 @@ func TestDAGInsertGatewayAPI(t *testing.T) { Name: "tcp.projectcontour.io", }, TCPProxy: &TCPProxy{ - Clusters: clustersWeight( weightedService(kuardService, 1), weightedService(kuardService2, 1), @@ -5509,7 +5510,6 @@ func TestDAGInsertGatewayAPI(t *testing.T) { }, }, { - // Second instance of filter should be ignored. Type: gatewayapi_v1alpha2.GRPCRouteFilterRequestHeaderModifier, RequestHeaderModifier: &gatewayapi_v1alpha2.HTTPHeaderFilter{ @@ -5662,7 +5662,8 @@ func TestDAGInsertGatewayAPI(t *testing.T) { }, }, }}, - }}, + }, + }, }, }, }, @@ -5725,7 +5726,8 @@ func TestDAGInsertGatewayAPI(t *testing.T) { }}, }, }, - }}, + }, + }, }, }, }, @@ -5891,7 +5893,6 @@ func TestDAGInsertGatewayAPI(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - builder := Builder{ Source: KubernetesCache{ gatewayclass: tc.gatewayclass, @@ -6432,11 +6433,16 @@ func TestDAGInsert(t *testing.T) { }, Spec: networking_v1.IngressSpec{ Rules: []networking_v1.IngressRule{{ - IngressRuleValue: networking_v1.IngressRuleValue{HTTP: &networking_v1.HTTPIngressRuleValue{ - Paths: []networking_v1.HTTPIngressPath{{Path: "/", - Backend: *backendv1("kuard", intstr.FromString("http")), - }}}, - }}}}, + IngressRuleValue: networking_v1.IngressRuleValue{ + HTTP: &networking_v1.HTTPIngressRuleValue{ + Paths: []networking_v1.HTTPIngressPath{{ + Path: "/", + Backend: *backendv1("kuard", intstr.FromString("http")), + }}, + }, + }, + }}, + }, } i12dV1 := &networking_v1.Ingress{ @@ -6493,11 +6499,16 @@ func TestDAGInsert(t *testing.T) { }, Spec: networking_v1.IngressSpec{ Rules: []networking_v1.IngressRule{{ - IngressRuleValue: networking_v1.IngressRuleValue{HTTP: &networking_v1.HTTPIngressRuleValue{ - Paths: []networking_v1.HTTPIngressPath{{Path: "/", - Backend: *backendv1("kuard", intstr.FromString("http")), - }}}, - }}}}, + IngressRuleValue: networking_v1.IngressRuleValue{ + HTTP: &networking_v1.HTTPIngressRuleValue{ + Paths: []networking_v1.HTTPIngressPath{{ + Path: "/", + Backend: *backendv1("kuard", intstr.FromString("http")), + }}, + }, + }, + }}, + }, } // i13_v1 a and b are a pair of ingressesv1 for the same vhost @@ -11912,18 +11923,19 @@ func TestDAGInsert(t *testing.T) { ), &Route{ PathMatchCondition: prefixString("/blog/infotech"), - Clusters: []*Cluster{{ - Upstream: &Service{ - Weighted: WeightedService{ - Weight: 1, - ServiceName: s4.Name, - ServiceNamespace: s4.Namespace, - ServicePort: s4.Spec.Ports[0], - HealthPort: s4.Spec.Ports[0], + Clusters: []*Cluster{ + { + Upstream: &Service{ + Weighted: WeightedService{ + Weight: 1, + ServiceName: s4.Name, + ServiceNamespace: s4.Namespace, + ServicePort: s4.Spec.Ports[0], + HealthPort: s4.Spec.Ports[0], + }, }, }, }, - }, }, ), ), @@ -12851,34 +12863,35 @@ func TestDAGInsert(t *testing.T) { VirtualHost: &contour_api_v1.VirtualHost{ Fqdn: "projectcontour.io", }, - Routes: []contour_api_v1.Route{{ - Conditions: []contour_api_v1.MatchCondition{{ - Prefix: "/", - }}, - Services: []contour_api_v1.Service{{ - Name: s1.Name, - Port: 8080, - }}, - }, { - Conditions: []contour_api_v1.MatchCondition{{ - Prefix: "/direct", - }}, - DirectResponsePolicy: &contour_api_v1.HTTPDirectResponsePolicy{ - StatusCode: 404, - Body: "page not found", - }, - }, { - Conditions: []contour_api_v1.MatchCondition{{ - Prefix: "/redirect", - }}, - RequestRedirectPolicy: &contour_api_v1.HTTPRequestRedirectPolicy{ - Scheme: ref.To("https"), - Hostname: ref.To("envoyproxy.io"), - Port: ref.To(int32(443)), - StatusCode: ref.To(301), + Routes: []contour_api_v1.Route{ + { + Conditions: []contour_api_v1.MatchCondition{{ + Prefix: "/", + }}, + Services: []contour_api_v1.Service{{ + Name: s1.Name, + Port: 8080, + }}, + }, { + Conditions: []contour_api_v1.MatchCondition{{ + Prefix: "/direct", + }}, + DirectResponsePolicy: &contour_api_v1.HTTPDirectResponsePolicy{ + StatusCode: 404, + Body: "page not found", + }, + }, { + Conditions: []contour_api_v1.MatchCondition{{ + Prefix: "/redirect", + }}, + RequestRedirectPolicy: &contour_api_v1.HTTPRequestRedirectPolicy{ + Scheme: ref.To("https"), + Hostname: ref.To("envoyproxy.io"), + Port: ref.To(int32(443)), + StatusCode: ref.To(301), + }, }, }, - }, }, }, }, @@ -15140,7 +15153,6 @@ func TestGatewayWithHTTPProxyAndIngress(t *testing.T) { } func backendv1(name string, port intstr.IntOrString) *networking_v1.IngressBackend { - var v1port networking_v1.ServiceBackendPort switch port.Type { @@ -15495,17 +15507,20 @@ func TestHTTPProxyConficts(t *testing.T) { VirtualHost: &contour_api_v1.VirtualHost{ Fqdn: "example.com", }, - Routes: []contour_api_v1.Route{{ - Conditions: []contour_api_v1.MatchCondition{{Prefix: "/"}}, - Services: []contour_api_v1.Service{{ - Name: "missing-service", - Port: 8080, - }}}, { - Conditions: []contour_api_v1.MatchCondition{{Prefix: "/valid"}}, - Services: []contour_api_v1.Service{{ - Name: "existing-service-1", - Port: 8080, - }}}, + Routes: []contour_api_v1.Route{ + { + Conditions: []contour_api_v1.MatchCondition{{Prefix: "/"}}, + Services: []contour_api_v1.Service{{ + Name: "missing-service", + Port: 8080, + }}, + }, { + Conditions: []contour_api_v1.MatchCondition{{Prefix: "/valid"}}, + Services: []contour_api_v1.Service{{ + Name: "existing-service-1", + Port: 8080, + }}, + }, }, }, }, @@ -15539,21 +15554,23 @@ func TestHTTPProxyConficts(t *testing.T) { VirtualHost: &contour_api_v1.VirtualHost{ Fqdn: "example.com", }, - Routes: []contour_api_v1.Route{{ - Conditions: []contour_api_v1.MatchCondition{{Prefix: "/"}}, - Services: []contour_api_v1.Service{{ - Name: "missing-service", - Port: 8080, - Weight: 50, - }, { - Name: "existing-service-1", - Port: 8080, - Weight: 30, - }, { - Name: "existing-service-2", - Port: 8080, - Weight: 20, - }}}, + Routes: []contour_api_v1.Route{ + { + Conditions: []contour_api_v1.MatchCondition{{Prefix: "/"}}, + Services: []contour_api_v1.Service{{ + Name: "missing-service", + Port: 8080, + Weight: 50, + }, { + Name: "existing-service-1", + Port: 8080, + Weight: 30, + }, { + Name: "existing-service-2", + Port: 8080, + Weight: 20, + }}, + }, }, }, }, @@ -15677,7 +15694,8 @@ func TestHTTPProxyConficts(t *testing.T) { }}, }}, }, - }}, + }, + }, wantListeners: listeners( &Listener{ Name: HTTP_LISTENER_NAME, @@ -15834,86 +15852,87 @@ func TestDefaultHeadersPolicies(t *testing.T) { httpProxyReqHp *HeadersPolicy httpProxyRespHp *HeadersPolicy wantErr error - }{{ - name: "empty is fine", - }, { - name: "ingressv1: insert ingress w/ single unnamed backend", - objs: []any{ - i2V1, - s1, - }, - want: listeners( - &Listener{ - Name: HTTP_LISTENER_NAME, - Port: 8080, - VirtualHosts: virtualhosts( - virtualhost("*", &Route{ - PathMatchCondition: prefixString("/"), - Clusters: clusterHeadersUnweighted(map[string]string{"Custom-Header-Set": "foo-bar"}, nil, []string{"K-Nada"}, "", service(s1)), - }, - ), - ), + }{ + { + name: "empty is fine", + }, { + name: "ingressv1: insert ingress w/ single unnamed backend", + objs: []any{ + i2V1, + s1, }, - ), - ingressReqHp: &HeadersPolicy{ - // Add not currently siupported - // Add: map[string]string{ - // "Custom-Header-Add": "foo-bar", - // }, - Set: map[string]string{ - "Custom-Header-Set": "foo-bar", - }, - Remove: []string{"K-Nada"}, - }, - ingressRespHp: &HeadersPolicy{ - // Add not currently siupported - // Add: map[string]string{ - // "Custom-Header-Add": "foo-bar", - // }, - Set: map[string]string{ - "Custom-Header-Set": "foo-bar", - }, - Remove: []string{"K-Nada"}, - }, - }, { - name: "insert httpproxy referencing two backends", - objs: []any{ - proxyMultipleBackends, s1, s2, - }, - want: listeners( - &Listener{ - Name: HTTP_LISTENER_NAME, - Port: 8080, - VirtualHosts: virtualhosts( - virtualhost("example.com", &Route{ - PathMatchCondition: prefixString("/"), - Clusters: clusterHeadersUnweighted(map[string]string{"Custom-Header-Set": "foo-bar"}, nil, []string{"K-Nada"}, "", service(s1), service(s2)), - }, + want: listeners( + &Listener{ + Name: HTTP_LISTENER_NAME, + Port: 8080, + VirtualHosts: virtualhosts( + virtualhost("*", &Route{ + PathMatchCondition: prefixString("/"), + Clusters: clusterHeadersUnweighted(map[string]string{"Custom-Header-Set": "foo-bar"}, nil, []string{"K-Nada"}, "", service(s1)), + }, + ), ), - ), + }, + ), + ingressReqHp: &HeadersPolicy{ + // Add not currently siupported + // Add: map[string]string{ + // "Custom-Header-Add": "foo-bar", + // }, + Set: map[string]string{ + "Custom-Header-Set": "foo-bar", + }, + Remove: []string{"K-Nada"}, }, - ), - httpProxyReqHp: &HeadersPolicy{ - // Add not currently siupported - // Add: map[string]string{ - // "Custom-Header-Add": "foo-bar", - // }, - Set: map[string]string{ - "Custom-Header-Set": "foo-bar", + ingressRespHp: &HeadersPolicy{ + // Add not currently siupported + // Add: map[string]string{ + // "Custom-Header-Add": "foo-bar", + // }, + Set: map[string]string{ + "Custom-Header-Set": "foo-bar", + }, + Remove: []string{"K-Nada"}, }, - Remove: []string{"K-Nada"}, - }, - httpProxyRespHp: &HeadersPolicy{ - // Add not currently siupported - // Add: map[string]string{ - // "Custom-Header-Add": "foo-bar", - // }, - Set: map[string]string{ - "Custom-Header-Set": "foo-bar", + }, { + name: "insert httpproxy referencing two backends", + objs: []any{ + proxyMultipleBackends, s1, s2, + }, + want: listeners( + &Listener{ + Name: HTTP_LISTENER_NAME, + Port: 8080, + VirtualHosts: virtualhosts( + virtualhost("example.com", &Route{ + PathMatchCondition: prefixString("/"), + Clusters: clusterHeadersUnweighted(map[string]string{"Custom-Header-Set": "foo-bar"}, nil, []string{"K-Nada"}, "", service(s1), service(s2)), + }, + ), + ), + }, + ), + httpProxyReqHp: &HeadersPolicy{ + // Add not currently siupported + // Add: map[string]string{ + // "Custom-Header-Add": "foo-bar", + // }, + Set: map[string]string{ + "Custom-Header-Set": "foo-bar", + }, + Remove: []string{"K-Nada"}, + }, + httpProxyRespHp: &HeadersPolicy{ + // Add not currently siupported + // Add: map[string]string{ + // "Custom-Header-Add": "foo-bar", + // }, + Set: map[string]string{ + "Custom-Header-Set": "foo-bar", + }, + Remove: []string{"K-Nada"}, }, - Remove: []string{"K-Nada"}, }, - }, } for _, tc := range tests { @@ -16026,7 +16045,7 @@ func exactrouteGRPCRoute(path string, first *Service, rest ...*Service) *Route { return exactrouteHTTPRoute(path, first, rest...) } -func routeProtocol(prefix string, protocol string, first *Service, rest ...*Service) *Route { +func routeProtocol(prefix, protocol string, first *Service, rest ...*Service) *Route { services := append([]*Service{first}, rest...) cs := clusters(services...) @@ -16085,7 +16104,7 @@ func routeHeaders(prefix string, requestSet map[string]string, requestRemove []s return r } -func clusterHeaders(requestSet map[string]string, requestAdd map[string]string, requestRemove []string, hostRewrite string, responseSet map[string]string, responseAdd map[string]string, responseRemove []string, services ...*Service) (c []*Cluster) { +func clusterHeaders(requestSet, requestAdd map[string]string, requestRemove []string, hostRewrite string, responseSet, responseAdd map[string]string, responseRemove []string, services ...*Service) (c []*Cluster) { var requestHeadersPolicy *HeadersPolicy if requestSet != nil || requestAdd != nil || requestRemove != nil || hostRewrite != "" { requestHeadersPolicy = &HeadersPolicy{ @@ -16115,7 +16134,7 @@ func clusterHeaders(requestSet map[string]string, requestAdd map[string]string, return c } -func clusterHeadersUnweighted(headersSet map[string]string, headersAdd map[string]string, headersRemove []string, hostRewrite string, services ...*Service) (c []*Cluster) { +func clusterHeadersUnweighted(headersSet, headersAdd map[string]string, headersRemove []string, hostRewrite string, services ...*Service) (c []*Cluster) { for _, s := range services { c = append(c, &Cluster{ Upstream: s, @@ -16310,6 +16329,7 @@ func listeners(ls ...*Listener) []*Listener { func prefixString(prefix string) MatchCondition { return &PrefixMatchCondition{Prefix: prefix, PrefixMatchType: PrefixMatchString} } + func prefixSegment(prefix string) MatchCondition { return &PrefixMatchCondition{Prefix: prefix, PrefixMatchType: PrefixMatchSegment} } diff --git a/internal/dag/cache_test.go b/internal/dag/cache_test.go index b29ac815756..61f6cf74741 100644 --- a/internal/dag/cache_test.go +++ b/internal/dag/cache_test.go @@ -720,7 +720,8 @@ func TestKubernetesCacheInsert(t *testing.T) { TypeMeta: metav1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{ Name: "tlsroute", - Namespace: "default"}, + Namespace: "default", + }, Spec: gatewayapi_v1alpha2.TLSRouteSpec{ CommonRouteSpec: gatewayapi_v1alpha2.CommonRouteSpec{ ParentRefs: []gatewayapi_v1alpha2.ParentReference{ @@ -748,7 +749,8 @@ func TestKubernetesCacheInsert(t *testing.T) { TypeMeta: metav1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{ Name: "tlsroute", - Namespace: "tlsroute"}, + Namespace: "tlsroute", + }, Spec: gatewayapi_v1alpha2.TLSRouteSpec{ CommonRouteSpec: gatewayapi_v1alpha2.CommonRouteSpec{ ParentRefs: []gatewayapi_v1alpha2.ParentReference{ @@ -776,7 +778,8 @@ func TestKubernetesCacheInsert(t *testing.T) { TypeMeta: metav1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{ Name: "tlsroute", - Namespace: "default"}, + Namespace: "default", + }, Spec: gatewayapi_v1alpha2.TLSRouteSpec{ CommonRouteSpec: gatewayapi_v1alpha2.CommonRouteSpec{ ParentRefs: []gatewayapi_v1alpha2.ParentReference{ @@ -1125,7 +1128,8 @@ func TestKubernetesCacheInsert(t *testing.T) { cache := KubernetesCache{ ConfiguredGatewayToCache: tc.cacheGateway, ConfiguredSecretRefs: []*types.NamespacedName{ - {Name: "secretReferredByConfigFile", Namespace: "default"}}, + {Name: "secretReferredByConfigFile", Namespace: "default"}, + }, FieldLogger: fixture.NewTestLogger(t), Client: new(fakeReader), } @@ -1218,7 +1222,8 @@ func TestKubernetesCacheRemove(t *testing.T) { TypeMeta: metav1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{ Name: "tlsroute", - Namespace: "default"}, + Namespace: "default", + }, Spec: gatewayapi_v1alpha2.TLSRouteSpec{ CommonRouteSpec: gatewayapi_v1alpha2.CommonRouteSpec{ ParentRefs: []gatewayapi_v1alpha2.ParentReference{ @@ -1252,7 +1257,8 @@ func TestKubernetesCacheRemove(t *testing.T) { TypeMeta: metav1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{ Name: "tlsroute", - Namespace: "default"}, + Namespace: "default", + }, Spec: gatewayapi_v1alpha2.TLSRouteSpec{ CommonRouteSpec: gatewayapi_v1alpha2.CommonRouteSpec{ ParentRefs: []gatewayapi_v1alpha2.ParentReference{ @@ -1410,7 +1416,8 @@ func TestKubernetesCacheRemove(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "Gateway", Namespace: "default", - }}, + }, + }, &gatewayapi_v1beta1.HTTPRoute{ ObjectMeta: metav1.ObjectMeta{ Name: "httproute", @@ -1431,7 +1438,8 @@ func TestKubernetesCacheRemove(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", - }}, + }, + }, &gatewayapi_v1beta1.HTTPRoute{ ObjectMeta: metav1.ObjectMeta{ Name: "httproute", @@ -1466,7 +1474,8 @@ func TestKubernetesCacheRemove(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "Gateway", Namespace: "default", - }}, + }, + }, &gatewayapi_v1alpha2.TLSRoute{ ObjectMeta: metav1.ObjectMeta{ Name: "tlsroute", @@ -1486,7 +1495,8 @@ func TestKubernetesCacheRemove(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", - }}, + }, + }, &gatewayapi_v1alpha2.TLSRoute{ ObjectMeta: metav1.ObjectMeta{ Name: "tlsroute", @@ -1521,7 +1531,8 @@ func TestKubernetesCacheRemove(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "Gateway", Namespace: "default", - }}, + }, + }, &gatewayapi_v1alpha2.GRPCRoute{ ObjectMeta: metav1.ObjectMeta{ Name: "grpcroute", @@ -1541,7 +1552,8 @@ func TestKubernetesCacheRemove(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", - }}, + }, + }, &gatewayapi_v1alpha2.GRPCRoute{ ObjectMeta: metav1.ObjectMeta{ Name: "grpcroute", @@ -1576,7 +1588,8 @@ func TestKubernetesCacheRemove(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "Gateway", Namespace: "default", - }}, + }, + }, &gatewayapi_v1alpha2.TCPRoute{ ObjectMeta: metav1.ObjectMeta{ Name: "tcproute", @@ -1596,7 +1609,8 @@ func TestKubernetesCacheRemove(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", - }}, + }, + }, &gatewayapi_v1alpha2.TCPRoute{ ObjectMeta: metav1.ObjectMeta{ Name: "tcproute", @@ -1846,7 +1860,6 @@ func TestLookupService(t *testing.T) { } func TestServiceTriggersRebuild(t *testing.T) { - cache := func(objs ...any) *KubernetesCache { cache := KubernetesCache{ FieldLogger: fixture.NewTestLogger(t), @@ -2184,7 +2197,6 @@ func TestServiceTriggersRebuild(t *testing.T) { } func TestSecretTriggersRebuild(t *testing.T) { - secret := func(namespace, name string) *v1.Secret { return &v1.Secret{ ObjectMeta: metav1.ObjectMeta{ @@ -2221,7 +2233,7 @@ func TestSecretTriggersRebuild(t *testing.T) { } } - ingress := func(namespace, name, secretName string, secretNamespace string) *networking_v1.Ingress { + ingress := func(namespace, name, secretName, secretNamespace string) *networking_v1.Ingress { i := &networking_v1.Ingress{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -2484,7 +2496,6 @@ func TestSecretTriggersRebuild(t *testing.T) { } func TestRouteTriggersRebuild(t *testing.T) { - cache := func(objs ...any) *KubernetesCache { cache := KubernetesCache{ FieldLogger: fixture.NewTestLogger(t), diff --git a/internal/dag/conditions_test.go b/internal/dag/conditions_test.go index cc4a586349b..d9c9231959f 100644 --- a/internal/dag/conditions_test.go +++ b/internal/dag/conditions_test.go @@ -105,12 +105,14 @@ func TestPathMatchCondition(t *testing.T) { want: &ExactMatchCondition{Path: "/a/"}, }, "trailing slash on second prefix condition": { - matchconditions: []contour_api_v1.MatchCondition{{ - Prefix: "/a", - }, + matchconditions: []contour_api_v1.MatchCondition{ + { + Prefix: "/a", + }, { Prefix: "/b/", - }}, + }, + }, want: &PrefixMatchCondition{Prefix: "/a/b/"}, }, "nothing but slashes prefix": { @@ -120,14 +122,16 @@ func TestPathMatchCondition(t *testing.T) { }, { Prefix: "/", - }}, + }, + }, want: &PrefixMatchCondition{Prefix: "/"}, }, "nothing but slashes one exact": { matchconditions: []contour_api_v1.MatchCondition{ { Exact: "///", - }}, + }, + }, want: &ExactMatchCondition{Path: "/"}, }, "nothing but slashes mixed": { @@ -137,7 +141,8 @@ func TestPathMatchCondition(t *testing.T) { }, { Exact: "/", - }}, + }, + }, want: &ExactMatchCondition{Path: "/"}, }, "regex": { diff --git a/internal/dag/dag_test.go b/internal/dag/dag_test.go index 55f00e01773..f57a931d846 100644 --- a/internal/dag/dag_test.go +++ b/internal/dag/dag_test.go @@ -23,7 +23,6 @@ import ( ) func TestVirtualHostValid(t *testing.T) { - vh := VirtualHost{} assert.False(t, vh.Valid()) @@ -36,7 +35,6 @@ func TestVirtualHostValid(t *testing.T) { } func TestSecureVirtualHostValid(t *testing.T) { - vh := SecureVirtualHost{} assert.False(t, vh.Valid()) @@ -232,5 +230,4 @@ func TestServiceClusterRebalance(t *testing.T) { assert.Equal(t, c.want, s) }) } - } diff --git a/internal/dag/gatewayapi_processor.go b/internal/dag/gatewayapi_processor.go index 3b685bdc438..eeeb4bfb579 100644 --- a/internal/dag/gatewayapi_processor.go +++ b/internal/dag/gatewayapi_processor.go @@ -309,7 +309,6 @@ func (p *GatewayAPIProcessor) getListenersForRouteParentRef( attachedRoutes map[string]int, routeParentStatusAccessor *status.RouteParentStatusUpdate, ) []*listenerInfo { - // Find the set of valid listeners that are relevant given this // parent ref (either all of them, if the ref is to the entire // gateway, or one of them, if the ref is to a specific listener, @@ -434,7 +433,6 @@ func (p *GatewayAPIProcessor) computeListener( gwAccessor *status.GatewayStatusUpdate, validateListenersResult gatewayapi.ValidateListenersResult, ) *listenerInfo { - info := &listenerInfo{ listener: listener, dagListenerName: validateListenersResult.ListenerNames[string(listener.Name)], @@ -613,7 +611,6 @@ func (p *GatewayAPIProcessor) computeListener( info.tlsSecret = listenerSecret info.ready = true return info - } // getListenerRouteKinds gets a list of the valid route kinds that @@ -926,7 +923,6 @@ func (p *GatewayAPIProcessor) namespaceMatches(namespaces *gatewayapi_v1beta1.Ro case gatewayapi_v1.NamespacesFromSelector: // Look up the route's namespace in the list of cached namespaces. if ns := p.source.namespaces[routeNamespace]; ns != nil { - // Check that the route's namespace is included in the Gateway's // namespace selector. return namespaceSelector.Matches(labels.Set(ns.Labels)) @@ -1142,12 +1138,13 @@ func parseHTTPRouteTimeouts(httpRouteTimeouts *gatewayapi_v1.HTTPRouteTimeouts) ResponseTimeout: requestTimeout, }, nil } + func (p *GatewayAPIProcessor) computeHTTPRouteForListener( route *gatewayapi_v1beta1.HTTPRoute, routeAccessor *status.RouteParentStatusUpdate, listener *listenerInfo, - hosts sets.Set[string]) { - + hosts sets.Set[string], +) { for ruleIndex, rule := range route.Spec.Rules { // Get match conditions for the rule. var matchconditions []*matchConditions @@ -1764,8 +1761,8 @@ func (p *GatewayAPIProcessor) validateBackendObjectRef( backendObjectRef gatewayapi_v1beta1.BackendObjectReference, field string, routeKind string, - routeNamespace string) (*Service, *metav1.Condition) { - + routeNamespace string, +) (*Service, *metav1.Condition) { if !(backendObjectRef.Group == nil || *backendObjectRef.Group == "") { return nil, ref.To(resolvedRefsFalse(gatewayapi_v1beta1.RouteReasonInvalidKind, fmt.Sprintf("%s.Group must be \"\"", field))) } @@ -2147,7 +2144,6 @@ func (p *GatewayAPIProcessor) clusterRoutes( pathRewritePolicy *PathRewritePolicy, timeoutPolicy *RouteTimeoutPolicy, ) []*Route { - var routes []*Route // Per Gateway API: "Each match is independent, diff --git a/internal/dag/gatewayapi_processor_test.go b/internal/dag/gatewayapi_processor_test.go index a1cd47da0cb..2fe5db99e11 100644 --- a/internal/dag/gatewayapi_processor_test.go +++ b/internal/dag/gatewayapi_processor_test.go @@ -232,7 +232,6 @@ func TestComputeHosts(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - processor := &GatewayAPIProcessor{ FieldLogger: fixture.NewTestLogger(t), } @@ -389,7 +388,6 @@ func TestNamespaceMatches(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - processor := &GatewayAPIProcessor{ FieldLogger: fixture.NewTestLogger(t), source: &KubernetesCache{ @@ -738,7 +736,6 @@ func TestGetListenersForRouteParentRef(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - processor := &GatewayAPIProcessor{ FieldLogger: fixture.NewTestLogger(t), source: &KubernetesCache{ diff --git a/internal/dag/httpproxy_processor.go b/internal/dag/httpproxy_processor.go index 29278ea5328..f6a43c57a93 100644 --- a/internal/dag/httpproxy_processor.go +++ b/internal/dag/httpproxy_processor.go @@ -42,7 +42,6 @@ const defaultMaxRequestBytes uint32 = 1024 func defaultExtensionRef(ref contour_api_v1.ExtensionServiceReference) contour_api_v1.ExtensionServiceReference { if ref.APIVersion == "" { ref.APIVersion = contour_api_v1alpha1.GroupVersion.String() - } return ref @@ -1365,7 +1364,7 @@ func (p *HTTPProxyProcessor) computeVirtualHostAuthorization(auth *contour_api_v } if auth.WithRequestBody != nil { - var maxRequestBytes = defaultMaxRequestBytes + maxRequestBytes := defaultMaxRequestBytes if auth.WithRequestBody.MaxRequestBytes != 0 { maxRequestBytes = auth.WithRequestBody.MaxRequestBytes } @@ -1602,8 +1601,7 @@ func getProtocol(service contour_api_v1.Service, s *Service) (string, error) { // determineSNI decides what the SNI should be on the request. It is configured via RequestHeadersPolicy.Host key. // Policies set on service are used before policies set on a route. Otherwise the value of the externalService // is used if the route is configured to proxy to an externalService type. -func determineSNI(routeRequestHeaders *HeadersPolicy, clusterRequestHeaders *HeadersPolicy, service *Service) string { - +func determineSNI(routeRequestHeaders, clusterRequestHeaders *HeadersPolicy, service *Service) string { // Service RequestHeadersPolicy take precedence if clusterRequestHeaders != nil { if clusterRequestHeaders.HostRewrite != "" { diff --git a/internal/dag/httpproxy_processor_test.go b/internal/dag/httpproxy_processor_test.go index af345290514..a9e7cf66783 100644 --- a/internal/dag/httpproxy_processor_test.go +++ b/internal/dag/httpproxy_processor_test.go @@ -294,7 +294,6 @@ func TestToCORSPolicy(t *testing.T) { require.Equal(t, tc.want, got) }) } - } func TestSlowStart(t *testing.T) { diff --git a/internal/dag/ingress_processor.go b/internal/dag/ingress_processor.go index c15a1d8ae4c..efee9e4ef83 100644 --- a/internal/dag/ingress_processor.go +++ b/internal/dag/ingress_processor.go @@ -267,7 +267,7 @@ func (p *IngressProcessor) computeIngressRule(ing *networking_v1.Ingress, rule n } // route builds a dag.Route for the supplied Ingress. -func (p *IngressProcessor) route(ingress *networking_v1.Ingress, host string, path string, pathType networking_v1.PathType, service *Service, clientCertSecret *Secret, serviceName string, servicePort int32, log logrus.FieldLogger) (*Route, error) { +func (p *IngressProcessor) route(ingress *networking_v1.Ingress, host, path string, pathType networking_v1.PathType, service *Service, clientCertSecret *Secret, serviceName string, servicePort int32, log logrus.FieldLogger) (*Route, error) { log = log.WithFields(logrus.Fields{ "name": ingress.Name, "namespace": ingress.Namespace, diff --git a/internal/dag/policy.go b/internal/dag/policy.go index 4c237b96a5f..a03d4f2fea9 100644 --- a/internal/dag/policy.go +++ b/internal/dag/policy.go @@ -340,7 +340,7 @@ func escapeHeaderValue(value string, dynamicHeaders map[string]string) string { escapedValue = strings.ReplaceAll(escapedValue, "%%"+envoyVar+"%%", "%"+envoyVar+"%") } // REQ(header-name) - var validReqEnvoyVar = regexp.MustCompile(`%(%REQ\(:?[\w-]+(\?:?[\w-]+)?\)(:\d+)?%)%`) + validReqEnvoyVar := regexp.MustCompile(`%(%REQ\(:?[\w-]+(\?:?[\w-]+)?\)(:\d+)?%)%`) escapedValue = validReqEnvoyVar.ReplaceAllString(escapedValue, "$1") return escapedValue } @@ -808,7 +808,6 @@ func loadBalancerRequestHashPolicies(lbp *contour_api_v1.LoadBalancerPolicy, val default: return nil, strategy } - } func serviceCircuitBreakerPolicy(s *Service, cb *contour_api_v1alpha1.GlobalCircuitBreakerDefaults) *Service { diff --git a/internal/dag/policy_test.go b/internal/dag/policy_test.go index f1c5992e097..667a716efb2 100644 --- a/internal/dag/policy_test.go +++ b/internal/dag/policy_test.go @@ -282,7 +282,6 @@ func TestTimeoutPolicy(t *testing.T) { assert.Equal(t, tc.wantClusterTimeoutPolicy, gotClusterTimeoutPolicy) require.NoError(t, gotErr) } - }) } } diff --git a/internal/dag/secret_test.go b/internal/dag/secret_test.go index f2b1c24a477..9b38c65ebe4 100644 --- a/internal/dag/secret_test.go +++ b/internal/dag/secret_test.go @@ -286,9 +286,11 @@ func pemBundle(cert ...string) string { return data } + func makeTLSSecret(data map[string][]byte) *v1.Secret { return &v1.Secret{Type: v1.SecretTypeTLS, Data: data} } + func makeOpaqueSecret(data map[string][]byte) *v1.Secret { return &v1.Secret{Type: v1.SecretTypeOpaque, Data: data} } diff --git a/internal/dag/status.go b/internal/dag/status.go index 7649ded33c8..5098dc9c0db 100644 --- a/internal/dag/status.go +++ b/internal/dag/status.go @@ -78,6 +78,7 @@ func (sw *StatusWriter) commit(osw *ObjectStatusWriter) { } } } + func (osw *ObjectStatusWriter) WithValue(key, val string) *ObjectStatusWriter { osw.values[key] = val return osw diff --git a/internal/dag/status_test.go b/internal/dag/status_test.go index 659da1a04cb..13d55b31540 100644 --- a/internal/dag/status_test.go +++ b/internal/dag/status_test.go @@ -38,7 +38,6 @@ import ( ) func TestDAGStatus(t *testing.T) { - type testcase struct { objs []any fallbackCertificate *types.NamespacedName @@ -1310,11 +1309,15 @@ func TestDAGStatus(t *testing.T) { run(t, "duplicate include condition headers", testcase{ objs: []any{proxyInvalidDuplicateIncludeCondtionHeaders, proxyValidDelegatedRoots, fixture.ServiceRootsHome}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: proxyInvalidDuplicateIncludeCondtionHeaders.Name, - Namespace: proxyInvalidDuplicateIncludeCondtionHeaders.Namespace}: fixture.NewValidCondition(). + { + Name: proxyInvalidDuplicateIncludeCondtionHeaders.Name, + Namespace: proxyInvalidDuplicateIncludeCondtionHeaders.Namespace, + }: fixture.NewValidCondition(). WithGeneration(proxyInvalidDuplicateIncludeCondtionHeaders.Generation).WithError(contour_api_v1.ConditionTypeRouteError, "HeaderMatchConditionsNotValid", "cannot specify duplicate header 'exact match' conditions in the same route"), - {Name: proxyValidDelegatedRoots.Name, - Namespace: proxyValidDelegatedRoots.Namespace}: fixture.NewValidCondition(). + { + Name: proxyValidDelegatedRoots.Name, + Namespace: proxyValidDelegatedRoots.Namespace, + }: fixture.NewValidCondition(). WithGeneration(proxyValidDelegatedRoots.Generation).Orphaned(), }, }) @@ -1733,8 +1736,10 @@ func TestDAGStatus(t *testing.T) { Valid(), // Valid since there is a valid include preceding an invalid one. {Name: proxyValidBlogTeamB.Name, Namespace: proxyValidBlogTeamB.Namespace}: fixture.NewValidCondition(). Orphaned(), // Orphaned because the include pointing to this condition is a duplicate so the route is not programmed. - {Name: proxyInvalidConflictingIncludeConditionsSimple.Name, - Namespace: proxyInvalidConflictingIncludeConditionsSimple.Namespace}: fixture.NewValidCondition(). + { + Name: proxyInvalidConflictingIncludeConditionsSimple.Name, + Namespace: proxyInvalidConflictingIncludeConditionsSimple.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeIncludeError, "DuplicateMatchConditions", "duplicate conditions defined on an include"), }, }) @@ -1765,8 +1770,10 @@ func TestDAGStatus(t *testing.T) { Valid(), {Name: proxyValidBlogTeamB.Name, Namespace: proxyValidBlogTeamB.Namespace}: fixture.NewValidCondition(). Valid(), - {Name: proxyIncludeConditionsEmpty.Name, - Namespace: proxyIncludeConditionsEmpty.Namespace}: fixture.NewValidCondition(). + { + Name: proxyIncludeConditionsEmpty.Name, + Namespace: proxyIncludeConditionsEmpty.Namespace, + }: fixture.NewValidCondition(). Valid(), }, }) @@ -1806,8 +1813,10 @@ func TestDAGStatus(t *testing.T) { Valid(), {Name: proxyValidBlogTeamB.Name, Namespace: proxyValidBlogTeamB.Namespace}: fixture.NewValidCondition(). Valid(), - {Name: proxyIncludeConditionsPrefixRoot.Name, - Namespace: proxyIncludeConditionsPrefixRoot.Namespace}: fixture.NewValidCondition(). + { + Name: proxyIncludeConditionsPrefixRoot.Name, + Namespace: proxyIncludeConditionsPrefixRoot.Namespace, + }: fixture.NewValidCondition(). Valid(), }, }) @@ -1859,8 +1868,10 @@ func TestDAGStatus(t *testing.T) { Valid(), // Valid since there is a valid include preceding an invalid one. {Name: proxyValidBlogTeamB.Name, Namespace: proxyValidBlogTeamB.Namespace}: fixture.NewValidCondition(). Valid(), // Valid since there is a valid include preceding an invalid one. - {Name: proxyInvalidConflictingIncludeConditions.Name, - Namespace: proxyInvalidConflictingIncludeConditions.Namespace}: fixture.NewValidCondition(). + { + Name: proxyInvalidConflictingIncludeConditions.Name, + Namespace: proxyInvalidConflictingIncludeConditions.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeIncludeError, "DuplicateMatchConditions", "duplicate conditions defined on an include"), }, }) @@ -1917,14 +1928,20 @@ func TestDAGStatus(t *testing.T) { run(t, "duplicate header conditions on an include", testcase{ objs: []any{proxyInvalidConflictHeaderConditions, proxyValidBlogTeamA, proxyValidBlogTeamB, fixture.ServiceRootsHome, fixture.ServiceTeamAKuard, fixture.ServiceTeamBKuard}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: proxyValidBlogTeamA.Name, - Namespace: proxyValidBlogTeamA.Namespace}: fixture.NewValidCondition(). - Valid(), // Valid since there is a valid include preceding an invalid one. - {Name: proxyValidBlogTeamB.Name, - Namespace: proxyValidBlogTeamB.Namespace}: fixture.NewValidCondition(). - Valid(), // Valid since there is a valid include preceding an invalid one. - {Name: proxyInvalidConflictHeaderConditions.Name, - Namespace: proxyInvalidConflictHeaderConditions.Namespace}: fixture.NewValidCondition(). + { + Name: proxyValidBlogTeamA.Name, + Namespace: proxyValidBlogTeamA.Namespace, + }: fixture.NewValidCondition(). + Valid(), // Valid since there is a valid include preceding an invalid one. + { + Name: proxyValidBlogTeamB.Name, + Namespace: proxyValidBlogTeamB.Namespace, + }: fixture.NewValidCondition(). + Valid(), // Valid since there is a valid include preceding an invalid one. + { + Name: proxyInvalidConflictHeaderConditions.Name, + Namespace: proxyInvalidConflictHeaderConditions.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeIncludeError, "DuplicateMatchConditions", "duplicate conditions defined on an include"), }, }) @@ -1988,14 +2005,20 @@ func TestDAGStatus(t *testing.T) { run(t, "duplicate header conditions on an include mismatched order", testcase{ objs: []any{proxyInvalidDuplicateMultiHeaderConditions, proxyValidBlogTeamA, proxyValidBlogTeamB, fixture.ServiceRootsHome, fixture.ServiceTeamAKuard, fixture.ServiceTeamBKuard}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: proxyValidBlogTeamA.Name, - Namespace: proxyValidBlogTeamA.Namespace}: fixture.NewValidCondition(). - Valid(), // Valid since there is a valid include preceding an invalid one. - {Name: proxyValidBlogTeamB.Name, - Namespace: proxyValidBlogTeamB.Namespace}: fixture.NewValidCondition(). + { + Name: proxyValidBlogTeamA.Name, + Namespace: proxyValidBlogTeamA.Namespace, + }: fixture.NewValidCondition(). + Valid(), // Valid since there is a valid include preceding an invalid one. + { + Name: proxyValidBlogTeamB.Name, + Namespace: proxyValidBlogTeamB.Namespace, + }: fixture.NewValidCondition(). Orphaned(), - {Name: proxyInvalidDuplicateMultiHeaderConditions.Name, - Namespace: proxyInvalidDuplicateMultiHeaderConditions.Namespace}: fixture.NewValidCondition(). + { + Name: proxyInvalidDuplicateMultiHeaderConditions.Name, + Namespace: proxyInvalidDuplicateMultiHeaderConditions.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeIncludeError, "DuplicateMatchConditions", "duplicate conditions defined on an include"), }, }) @@ -2066,14 +2089,20 @@ func TestDAGStatus(t *testing.T) { run(t, "duplicate header conditions on an include with same path", testcase{ objs: []any{proxyInvalidDuplicateIncludeSamePathDiffHeaders, proxyValidBlogTeamA, proxyValidBlogTeamB, fixture.ServiceRootsHome, fixture.ServiceTeamAKuard, fixture.ServiceTeamBKuard}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: proxyValidBlogTeamA.Name, - Namespace: proxyValidBlogTeamA.Namespace}: fixture.NewValidCondition(). - Valid(), // Valid since there is a valid include preceding an invalid one. - {Name: proxyValidBlogTeamB.Name, - Namespace: proxyValidBlogTeamB.Namespace}: fixture.NewValidCondition(). - Valid(), // Valid since there is a valid include preceding an invalid one. - {Name: proxyInvalidDuplicateMultiHeaderConditions.Name, - Namespace: proxyInvalidDuplicateMultiHeaderConditions.Namespace}: fixture.NewValidCondition(). + { + Name: proxyValidBlogTeamA.Name, + Namespace: proxyValidBlogTeamA.Namespace, + }: fixture.NewValidCondition(). + Valid(), // Valid since there is a valid include preceding an invalid one. + { + Name: proxyValidBlogTeamB.Name, + Namespace: proxyValidBlogTeamB.Namespace, + }: fixture.NewValidCondition(). + Valid(), // Valid since there is a valid include preceding an invalid one. + { + Name: proxyInvalidDuplicateMultiHeaderConditions.Name, + Namespace: proxyInvalidDuplicateMultiHeaderConditions.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeIncludeError, "DuplicateMatchConditions", "duplicate conditions defined on an include"), }, }) @@ -2123,14 +2152,20 @@ func TestDAGStatus(t *testing.T) { run(t, "duplicate header+path conditions on an include", testcase{ objs: []any{proxyInvalidDuplicateHeaderAndPathConditions, proxyValidBlogTeamA, proxyValidBlogTeamB, fixture.ServiceRootsHome, fixture.ServiceTeamAKuard, fixture.ServiceTeamBKuard}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: proxyValidBlogTeamA.Name, - Namespace: proxyValidBlogTeamA.Namespace}: fixture.NewValidCondition(). - Valid(), // Valid since there is a valid include preceding an invalid one. - {Name: proxyValidBlogTeamB.Name, - Namespace: proxyValidBlogTeamB.Namespace}: fixture.NewValidCondition(). + { + Name: proxyValidBlogTeamA.Name, + Namespace: proxyValidBlogTeamA.Namespace, + }: fixture.NewValidCondition(). + Valid(), // Valid since there is a valid include preceding an invalid one. + { + Name: proxyValidBlogTeamB.Name, + Namespace: proxyValidBlogTeamB.Namespace, + }: fixture.NewValidCondition(). Orphaned(), - {Name: proxyInvalidDuplicateHeaderAndPathConditions.Name, - Namespace: proxyInvalidDuplicateHeaderAndPathConditions.Namespace}: fixture.NewValidCondition(). + { + Name: proxyInvalidDuplicateHeaderAndPathConditions.Name, + Namespace: proxyInvalidDuplicateHeaderAndPathConditions.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeIncludeError, "DuplicateMatchConditions", "duplicate conditions defined on an include"), }, }) @@ -2215,15 +2250,21 @@ func TestDAGStatus(t *testing.T) { run(t, "duplicate query param conditions on an include", testcase{ objs: []any{proxyInvalidConflictQueryConditions, proxyValidBlogTeamA, proxyValidBlogTeamB, fixture.ServiceRootsHome, fixture.ServiceTeamAKuard, fixture.ServiceTeamBKuard}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: proxyInvalidConflictQueryConditions.Name, - Namespace: proxyInvalidConflictQueryConditions.Namespace}: fixture.NewValidCondition(). + { + Name: proxyInvalidConflictQueryConditions.Name, + Namespace: proxyInvalidConflictQueryConditions.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeIncludeError, "DuplicateMatchConditions", "duplicate conditions defined on an include"), - {Name: proxyValidBlogTeamA.Name, - Namespace: proxyValidBlogTeamA.Namespace}: fixture.NewValidCondition(). - Valid(), // Valid since there is a valid include preceding an invalid one. - {Name: proxyValidBlogTeamB.Name, - Namespace: proxyValidBlogTeamB.Namespace}: fixture.NewValidCondition(). - Valid(), // Valid since there is a valid include preceding an invalid one. + { + Name: proxyValidBlogTeamA.Name, + Namespace: proxyValidBlogTeamA.Namespace, + }: fixture.NewValidCondition(). + Valid(), // Valid since there is a valid include preceding an invalid one. + { + Name: proxyValidBlogTeamB.Name, + Namespace: proxyValidBlogTeamB.Namespace, + }: fixture.NewValidCondition(). + Valid(), // Valid since there is a valid include preceding an invalid one. }, }) @@ -2285,15 +2326,21 @@ func TestDAGStatus(t *testing.T) { run(t, "duplicate query param+header conditions on an include", testcase{ objs: []any{proxyInvalidConflictQueryHeaderConditions, proxyValidBlogTeamA, proxyValidBlogTeamB, fixture.ServiceRootsHome, fixture.ServiceTeamAKuard, fixture.ServiceTeamBKuard}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: proxyInvalidConflictQueryHeaderConditions.Name, - Namespace: proxyInvalidConflictQueryHeaderConditions.Namespace}: fixture.NewValidCondition(). + { + Name: proxyInvalidConflictQueryHeaderConditions.Name, + Namespace: proxyInvalidConflictQueryHeaderConditions.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeIncludeError, "DuplicateMatchConditions", "duplicate conditions defined on an include"), - {Name: proxyValidBlogTeamA.Name, - Namespace: proxyValidBlogTeamA.Namespace}: fixture.NewValidCondition(). - Valid(), // Valid since there is a valid include preceding an invalid one. - {Name: proxyValidBlogTeamB.Name, - Namespace: proxyValidBlogTeamB.Namespace}: fixture.NewValidCondition(). - Valid(), // Valid since there is a valid include. + { + Name: proxyValidBlogTeamA.Name, + Namespace: proxyValidBlogTeamA.Namespace, + }: fixture.NewValidCondition(). + Valid(), // Valid since there is a valid include preceding an invalid one. + { + Name: proxyValidBlogTeamB.Name, + Namespace: proxyValidBlogTeamB.Namespace, + }: fixture.NewValidCondition(). + Valid(), // Valid since there is a valid include. }, }) @@ -2345,14 +2392,20 @@ func TestDAGStatus(t *testing.T) { run(t, "query param+header conditions on an include should not be duplicate", testcase{ objs: []any{proxyValidQueryHeaderConditions, proxyValidBlogTeamA, proxyValidBlogTeamB, fixture.ServiceRootsHome, fixture.ServiceTeamAKuard, fixture.ServiceTeamBKuard}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: proxyValidBlogTeamA.Name, - Namespace: proxyValidBlogTeamA.Namespace}: fixture.NewValidCondition(). + { + Name: proxyValidBlogTeamA.Name, + Namespace: proxyValidBlogTeamA.Namespace, + }: fixture.NewValidCondition(). Valid(), - {Name: proxyValidBlogTeamB.Name, - Namespace: proxyValidBlogTeamB.Namespace}: fixture.NewValidCondition(). + { + Name: proxyValidBlogTeamB.Name, + Namespace: proxyValidBlogTeamB.Namespace, + }: fixture.NewValidCondition(). Valid(), - {Name: proxyValidQueryHeaderConditions.Name, - Namespace: proxyValidQueryHeaderConditions.Namespace}: fixture.NewValidCondition(). + { + Name: proxyValidQueryHeaderConditions.Name, + Namespace: proxyValidQueryHeaderConditions.Namespace, + }: fixture.NewValidCondition(). Valid(), }, }) @@ -2592,20 +2645,28 @@ func TestDAGStatus(t *testing.T) { run(t, "valid HTTPProxy.TCPProxy - plural", testcase{ objs: []any{proxyTCPValidIncludesChild, proxyTCPValidChild, fixture.ServiceRootsKuard, fixture.SecretRootsCert}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: proxyTCPValidIncludesChild.Name, - Namespace: proxyTCPValidIncludesChild.Namespace}: fixture.NewValidCondition().Valid(), - {Name: proxyTCPValidChild.Name, - Namespace: proxyTCPValidChild.Namespace}: fixture.NewValidCondition().Valid(), + { + Name: proxyTCPValidIncludesChild.Name, + Namespace: proxyTCPValidIncludesChild.Namespace, + }: fixture.NewValidCondition().Valid(), + { + Name: proxyTCPValidChild.Name, + Namespace: proxyTCPValidChild.Namespace, + }: fixture.NewValidCondition().Valid(), }, }) run(t, "valid HTTPProxy.TCPProxy", testcase{ objs: []any{proxyTCPValidIncludeChild, proxyTCPValidChild, fixture.ServiceRootsKuard, fixture.SecretRootsCert}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: proxyTCPValidIncludeChild.Name, - Namespace: proxyTCPValidIncludeChild.Namespace}: fixture.NewValidCondition().Valid(), - {Name: proxyTCPValidChild.Name, - Namespace: proxyTCPValidChild.Namespace}: fixture.NewValidCondition().Valid(), + { + Name: proxyTCPValidIncludeChild.Name, + Namespace: proxyTCPValidIncludeChild.Namespace, + }: fixture.NewValidCondition().Valid(), + { + Name: proxyTCPValidChild.Name, + Namespace: proxyTCPValidChild.Namespace, + }: fixture.NewValidCondition().Valid(), }, }) @@ -2683,8 +2744,10 @@ func TestDAGStatus(t *testing.T) { }, objs: []any{fallbackCertificate, fallbackCertDelegation, fixture.SecretRootsFallback, fixture.SecretRootsCert, fixture.ServiceRootsHome}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: fallbackCertificate.Name, - Namespace: fallbackCertificate.Namespace}: fixture.NewValidCondition(). + { + Name: fallbackCertificate.Name, + Namespace: fallbackCertificate.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeTLSError, "FallbackNotValid", `Spec.Virtualhost.TLS Secret "non-existing/non-existing" fallback certificate is invalid: Secret not found`), }, }) @@ -2696,8 +2759,10 @@ func TestDAGStatus(t *testing.T) { }, objs: []any{fallbackCertificate, fixture.SecretRootsFallback, fixture.SecretRootsCert, fixture.ServiceRootsHome}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: fallbackCertificate.Name, - Namespace: fallbackCertificate.Namespace}: fixture.NewValidCondition(). + { + Name: fallbackCertificate.Name, + Namespace: fallbackCertificate.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeTLSError, "FallbackNotDelegated", `Spec.VirtualHost.TLS Secret "not-delegated/not-delegated" is not configured for certificate delegation`), }, }) @@ -2705,8 +2770,10 @@ func TestDAGStatus(t *testing.T) { run(t, "fallback certificate requested but cert not configured in contour", testcase{ objs: []any{fallbackCertificate, fixture.SecretRootsFallback, fixture.SecretRootsCert, fixture.ServiceRootsHome}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: fallbackCertificate.Name, - Namespace: fallbackCertificate.Namespace}: fixture.NewValidCondition(). + { + Name: fallbackCertificate.Name, + Namespace: fallbackCertificate.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeTLSError, "FallbackNotPresent", "Spec.Virtualhost.TLS enabled fallback but the fallback Certificate Secret is not configured in Contour configuration file"), }, }) @@ -2739,8 +2806,10 @@ func TestDAGStatus(t *testing.T) { run(t, "clientValidation missing CA", testcase{ objs: []any{fallbackCertificateWithClientValidationNoCA, fixture.SecretRootsFallback, fixture.SecretRootsCert, fixture.ServiceRootsHome}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: fallbackCertificateWithClientValidationNoCA.Name, - Namespace: fallbackCertificateWithClientValidationNoCA.Namespace}: fixture.NewValidCondition(). + { + Name: fallbackCertificateWithClientValidationNoCA.Name, + Namespace: fallbackCertificateWithClientValidationNoCA.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeTLSError, "ClientValidationInvalid", "Spec.VirtualHost.TLS client validation is invalid: CA Secret must be specified"), }, }) @@ -2776,8 +2845,10 @@ func TestDAGStatus(t *testing.T) { run(t, "fallback certificate requested and clientValidation also configured", testcase{ objs: []any{fallbackCertificateWithClientValidation, fixture.SecretRootsFallback, fixture.SecretRootsCert, fixture.ServiceRootsHome}, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: fallbackCertificateWithClientValidation.Name, - Namespace: fallbackCertificateWithClientValidation.Namespace}: fixture.NewValidCondition(). + { + Name: fallbackCertificateWithClientValidation.Name, + Namespace: fallbackCertificateWithClientValidation.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeTLSError, "TLSIncompatibleFeatures", "Spec.Virtualhost.TLS fallback & client validation are incompatible"), }, }) @@ -4865,8 +4936,10 @@ func TestDAGStatus(t *testing.T) { clientValidationWithDelegatedCA, }, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: fallbackCertificate.Name, - Namespace: fallbackCertificate.Namespace}: fixture.NewValidCondition(). + { + Name: fallbackCertificate.Name, + Namespace: fallbackCertificate.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeTLSError, "DelegationNotPermitted", `Spec.VirtualHost.TLS CA Secret "delegated/delegated" is invalid: Certificate delegation not permitted`), }, }) @@ -4891,8 +4964,10 @@ func TestDAGStatus(t *testing.T) { }, }, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: fallbackCertificate.Name, - Namespace: fallbackCertificate.Namespace}: fixture.NewValidCondition(). + { + Name: fallbackCertificate.Name, + Namespace: fallbackCertificate.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeTLSError, "ClientValidationInvalid", `Spec.VirtualHost.TLS client validation is invalid: invalid CA Secret "delegated/delegated": Secret not found`), }, }) @@ -4943,8 +5018,10 @@ func TestDAGStatus(t *testing.T) { clientValidationWithDelegatedCRL, }, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: fallbackCertificate.Name, - Namespace: fallbackCertificate.Namespace}: fixture.NewValidCondition(). + { + Name: fallbackCertificate.Name, + Namespace: fallbackCertificate.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeTLSError, "DelegationNotPermitted", `Spec.VirtualHost.TLS CRL Secret "delegated/delegated" is invalid: Certificate delegation not permitted`), }, }) @@ -4970,8 +5047,10 @@ func TestDAGStatus(t *testing.T) { }, }, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ - {Name: fallbackCertificate.Name, - Namespace: fallbackCertificate.Namespace}: fixture.NewValidCondition(). + { + Name: fallbackCertificate.Name, + Namespace: fallbackCertificate.Namespace, + }: fixture.NewValidCondition(). WithError(contour_api_v1.ConditionTypeTLSError, "ClientValidationInvalid", `Spec.VirtualHost.TLS client validation is invalid: invalid CRL Secret "delegated/delegated": Secret not found`), }, }) @@ -5074,7 +5153,8 @@ func TestDAGStatus(t *testing.T) { ingressSharedService, tlsProtocolVersion, fixture.ServiceRootsHome, - fixture.SecretRootsCert}, + fixture.SecretRootsCert, + }, want: map[types.NamespacedName]contour_api_v1.DetailedCondition{ {Name: tlsProtocolVersion.Name, Namespace: tlsProtocolVersion.Namespace}: fixture.NewValidCondition(). WithGeneration(tlsProtocolVersion.Generation). @@ -5084,7 +5164,6 @@ func TestDAGStatus(t *testing.T) { ), }, }) - } func validGatewayStatusUpdate(listenerName string, listenerProtocol gatewayapi_v1beta1.ProtocolType, attachedRoutes int) []*status.GatewayStatusUpdate { @@ -5333,7 +5412,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -5381,7 +5461,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{{ @@ -5433,7 +5514,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{ { FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, @@ -5488,7 +5570,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -5534,7 +5617,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -5576,7 +5660,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -5623,7 +5708,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -5670,7 +5756,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -5717,7 +5804,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -5765,7 +5853,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -5813,7 +5902,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -5861,7 +5951,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -5914,7 +6005,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -5962,7 +6054,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -6007,7 +6100,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -6056,7 +6150,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("invalid-two", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -6102,7 +6197,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -6138,7 +6234,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { Matches: gatewayapi.HTTPRouteMatch(gatewayapi_v1.PathMatchPathPrefix, "/"), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -6185,7 +6282,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -6898,7 +6996,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { Matches: gatewayapi.HTTPRouteMatch(gatewayapi_v1.PathMatchPathPrefix, "/"), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -6940,7 +7039,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { Matches: gatewayapi.HTTPRouteMatch(gatewayapi_v1.PathMatchPathPrefix, "/"), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -6982,7 +7082,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { Matches: gatewayapi.HTTPRouteMatch(gatewayapi_v1.PathMatchPathPrefix, "/"), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -7021,7 +7122,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, gateway: &gatewayapi_v1beta1.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "contour", @@ -7132,7 +7234,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, gateway: &gatewayapi_v1beta1.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "contour", @@ -7248,7 +7351,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, gateway: &gatewayapi_v1beta1.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "contour", @@ -7338,7 +7442,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, gateway: &gatewayapi_v1beta1.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "contour", @@ -7652,20 +7757,23 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { Rules: []gatewayapi_v1beta1.HTTPRouteRule{{ Matches: gatewayapi.HTTPRouteMatch(gatewayapi_v1.PathMatchPathPrefix, "/"), BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), - Filters: []gatewayapi_v1.HTTPRouteFilter{{ - Type: gatewayapi_v1.HTTPRouteFilterRequestMirror, - RequestMirror: &gatewayapi_v1beta1.HTTPRequestMirrorFilter{ - BackendRef: gatewayapi.ServiceBackendObjectRef("kuard2", 8080), + Filters: []gatewayapi_v1.HTTPRouteFilter{ + { + Type: gatewayapi_v1.HTTPRouteFilterRequestMirror, + RequestMirror: &gatewayapi_v1beta1.HTTPRequestMirrorFilter{ + BackendRef: gatewayapi.ServiceBackendObjectRef("kuard2", 8080), + }, + }, { + Type: gatewayapi_v1.HTTPRouteFilterRequestMirror, + RequestMirror: &gatewayapi_v1beta1.HTTPRequestMirrorFilter{ + BackendRef: gatewayapi.ServiceBackendObjectRef("kuard3", 8080), + }, }, - }, { - Type: gatewayapi_v1.HTTPRouteFilterRequestMirror, - RequestMirror: &gatewayapi_v1beta1.HTTPRequestMirrorFilter{ - BackendRef: gatewayapi.ServiceBackendObjectRef("kuard3", 8080), - }}, }, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -7712,7 +7820,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }}, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -7760,7 +7869,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }}, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -7823,7 +7933,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }}, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -7875,7 +7986,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }}, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -7896,7 +8008,6 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { run(t, "HTTPRouteFilterRequestMirror not yet supported for httproute backendref", testcase{ objs: []any{ - kuardService, &gatewayapi_v1beta1.HTTPRoute{ ObjectMeta: metav1.ObjectMeta{ @@ -7924,7 +8035,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -7969,7 +8081,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }}, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -8015,7 +8128,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }}, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -8066,7 +8180,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -8114,7 +8229,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }}, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -8165,7 +8281,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -8207,7 +8324,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }}, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -8977,7 +9095,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { Selector: nil, }, }, - }}, + }, + }, }, }, wantGatewayStatusUpdate: []*status.GatewayStatusUpdate{{ @@ -9044,7 +9163,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }, }, }, - }}, + }, + }, }, }, wantGatewayStatusUpdate: []*status.GatewayStatusUpdate{{ @@ -9105,7 +9225,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { Selector: &metav1.LabelSelector{}, }, }, - }}, + }, + }, }, }, wantGatewayStatusUpdate: []*status.GatewayStatusUpdate{{ @@ -9169,7 +9290,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }, }, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -9207,7 +9329,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }, }, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -9241,7 +9364,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, gateway: &gatewayapi_v1beta1.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "contour", @@ -9343,13 +9467,13 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }, }, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ { - ParentRef: gatewayapi.GatewayParentRef("projectcontour", "contour"), Conditions: []metav1.Condition{ routeResolvedRefsCondition(), @@ -9387,7 +9511,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }, }, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -9425,7 +9550,8 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -9440,11 +9566,9 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) { }}, wantGatewayStatusUpdate: validGatewayStatusUpdate("http", gatewayapi_v1.HTTPProtocolType, 1), }) - } func TestGatewayAPITLSRouteDAGStatus(t *testing.T) { - type testcase struct { objs []any gateway *gatewayapi_v1beta1.Gateway @@ -9533,7 +9657,6 @@ func TestGatewayAPITLSRouteDAGStatus(t *testing.T) { if diff := cmp.Diff(tc.wantGatewayStatusUpdate, gotGatewayUpdates, ops...); diff != "" { t.Fatalf("expected gateway status: %v, got %v", tc.wantGatewayStatusUpdate, diff) } - }) } @@ -9596,7 +9719,8 @@ func TestGatewayAPITLSRouteDAGStatus(t *testing.T) { }, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -9637,7 +9761,8 @@ func TestGatewayAPITLSRouteDAGStatus(t *testing.T) { {BackendRefs: gatewayapi.TLSRouteBackendRef("invalid-two", 8080, nil)}, }, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -9687,7 +9812,8 @@ func TestGatewayAPITLSRouteDAGStatus(t *testing.T) { }, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -9728,7 +9854,8 @@ func TestGatewayAPITLSRouteDAGStatus(t *testing.T) { }, Hostnames: []gatewayapi_v1alpha2.Hostname{"test.projectcontour.io"}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -9769,7 +9896,8 @@ func TestGatewayAPITLSRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.TLSRouteBackendRef("kuard", 8080, nil), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -9812,7 +9940,8 @@ func TestGatewayAPITLSRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.TLSRouteBackendRef("kuard", 8080, nil), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -9855,7 +9984,8 @@ func TestGatewayAPITLSRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.TLSRouteBackendRef("kuard", 8080, nil), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -9896,7 +10026,8 @@ func TestGatewayAPITLSRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.TLSRouteBackendRef(kuardService.Name, 8080, ref.To(int32(0))), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -9944,7 +10075,8 @@ func TestGatewayAPITLSRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.TLSRouteBackendRef("invalid-one", 8080, nil), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -10010,7 +10142,8 @@ func TestGatewayAPITLSRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.TLSRouteBackendRef("kuard", 8080, nil), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -10235,7 +10368,8 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.GRPCRouteBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -10274,7 +10408,8 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.GRPCRouteBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -10317,7 +10452,8 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.GRPCRouteBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -10360,7 +10496,8 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) { BackendRefs: gatewayapi.GRPCRouteBackendRef("kuard", 8080, 1), }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -10612,16 +10749,18 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) { Method: gatewayapi.GRPCMethodMatch(gatewayapi_v1alpha2.GRPCMethodMatchExact, "com.example.service", "Login"), }}, BackendRefs: gatewayapi.GRPCRouteBackendRef("kuard", 8080, 1), - Filters: []gatewayapi_v1alpha2.GRPCRouteFilter{{ - Type: gatewayapi_v1alpha2.GRPCRouteFilterRequestMirror, - RequestMirror: &gatewayapi_v1beta1.HTTPRequestMirrorFilter{ - BackendRef: gatewayapi.ServiceBackendObjectRef("kuard2", 8080), + Filters: []gatewayapi_v1alpha2.GRPCRouteFilter{ + { + Type: gatewayapi_v1alpha2.GRPCRouteFilterRequestMirror, + RequestMirror: &gatewayapi_v1beta1.HTTPRequestMirrorFilter{ + BackendRef: gatewayapi.ServiceBackendObjectRef("kuard2", 8080), + }, + }, { + Type: gatewayapi_v1alpha2.GRPCRouteFilterRequestMirror, + RequestMirror: &gatewayapi_v1beta1.HTTPRequestMirrorFilter{ + BackendRef: gatewayapi.ServiceBackendObjectRef("kuard3", 8080), + }, }, - }, { - Type: gatewayapi_v1alpha2.GRPCRouteFilterRequestMirror, - RequestMirror: &gatewayapi_v1beta1.HTTPRequestMirrorFilter{ - BackendRef: gatewayapi.ServiceBackendObjectRef("kuard3", 8080), - }}, }, }}, }, @@ -10718,7 +10857,8 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) { }}, }}, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -10755,11 +10895,13 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) { Hostnames: []gatewayapi_v1beta1.Hostname{ "test.projectcontour.io", }, - Rules: []gatewayapi_v1alpha2.GRPCRouteRule{{ - Matches: []gatewayapi_v1alpha2.GRPCRouteMatch{{ - Method: gatewayapi.GRPCMethodMatch(gatewayapi_v1alpha2.GRPCMethodMatchExact, "com.example.service", "Login"), - }}, - BackendRefs: []gatewayapi_v1alpha2.GRPCBackendRef{}}, + Rules: []gatewayapi_v1alpha2.GRPCRouteRule{ + { + Matches: []gatewayapi_v1alpha2.GRPCRouteMatch{{ + Method: gatewayapi.GRPCMethodMatch(gatewayapi_v1alpha2.GRPCMethodMatchExact, "com.example.service", "Login"), + }}, + BackendRefs: []gatewayapi_v1alpha2.GRPCBackendRef{}, + }, }, }, }, @@ -10846,26 +10988,28 @@ func TestGatewayAPIGRPCRouteDAGStatus(t *testing.T) { Hostnames: []gatewayapi_v1beta1.Hostname{ "test.projectcontour.io", }, - Rules: []gatewayapi_v1alpha2.GRPCRouteRule{{ - Matches: []gatewayapi_v1alpha2.GRPCRouteMatch{{ - Method: gatewayapi.GRPCMethodMatch(gatewayapi_v1alpha2.GRPCMethodMatchExact, "com.example.service", "Login"), - }}, - BackendRefs: []gatewayapi_v1alpha2.GRPCBackendRef{ - { - BackendRef: gatewayapi_v1beta1.BackendRef{ - BackendObjectReference: gatewayapi.ServiceBackendObjectRef("kuard", 8080), - }, - Filters: []gatewayapi_v1alpha2.GRPCRouteFilter{{ - Type: gatewayapi_v1alpha2.GRPCRouteFilterRequestHeaderModifier, - RequestHeaderModifier: &gatewayapi_v1beta1.HTTPHeaderFilter{ - Set: []gatewayapi_v1beta1.HTTPHeader{ - {Name: "custom", Value: "duplicated"}, - {Name: "Custom", Value: "duplicated"}, - }, + Rules: []gatewayapi_v1alpha2.GRPCRouteRule{ + { + Matches: []gatewayapi_v1alpha2.GRPCRouteMatch{{ + Method: gatewayapi.GRPCMethodMatch(gatewayapi_v1alpha2.GRPCMethodMatchExact, "com.example.service", "Login"), + }}, + BackendRefs: []gatewayapi_v1alpha2.GRPCBackendRef{ + { + BackendRef: gatewayapi_v1beta1.BackendRef{ + BackendObjectReference: gatewayapi.ServiceBackendObjectRef("kuard", 8080), }, - }}, + Filters: []gatewayapi_v1alpha2.GRPCRouteFilter{{ + Type: gatewayapi_v1alpha2.GRPCRouteFilterRequestHeaderModifier, + RequestHeaderModifier: &gatewayapi_v1beta1.HTTPHeaderFilter{ + Set: []gatewayapi_v1beta1.HTTPHeader{ + {Name: "custom", Value: "duplicated"}, + {Name: "Custom", Value: "duplicated"}, + }, + }, + }}, + }, }, - }}, + }, }, }, }, @@ -11157,7 +11301,8 @@ func TestGatewayAPITCPRouteDAGStatus(t *testing.T) { }, }, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -11193,7 +11338,8 @@ func TestGatewayAPITCPRouteDAGStatus(t *testing.T) { {}, }, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -11226,7 +11372,8 @@ func TestGatewayAPITCPRouteDAGStatus(t *testing.T) { }, }, }, - }}, + }, + }, wantRouteConditions: []*status.RouteStatusUpdate{{ FullName: types.NamespacedName{Namespace: "default", Name: "basic"}, RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{ @@ -11269,6 +11416,7 @@ func routeAcceptedHTTPRouteCondition() metav1.Condition { Message: "Accepted HTTPRoute", } } + func routeAcceptedFalse(reason gatewayapi_v1.RouteConditionReason, message string) metav1.Condition { return metav1.Condition{ Type: string(gatewayapi_v1.RouteConditionAccepted), diff --git a/internal/debug/dot.go b/internal/debug/dot.go index d173e521279..95bd3a8db24 100644 --- a/internal/debug/dot.go +++ b/internal/debug/dot.go @@ -38,8 +38,10 @@ type pair struct { a, b any } -type nodeCollection map[any]bool -type edgeCollection map[pair]bool +type ( + nodeCollection map[any]bool + edgeCollection map[pair]bool +) func (dw *dotWriter) writeDot(w io.Writer) { nodes, edges := collectDag(dw.Builder) diff --git a/internal/envoy/bootstrap_test.go b/internal/envoy/bootstrap_test.go index 84c838d83eb..987058daea6 100644 --- a/internal/envoy/bootstrap_test.go +++ b/internal/envoy/bootstrap_test.go @@ -21,7 +21,6 @@ import ( ) func TestValidAdminAddress(t *testing.T) { - tests := []struct { name string address string diff --git a/internal/envoy/v3/accesslog.go b/internal/envoy/v3/accesslog.go index 7639eaf8872..094c911222c 100644 --- a/internal/envoy/v3/accesslog.go +++ b/internal/envoy/v3/accesslog.go @@ -26,7 +26,7 @@ import ( ) // FileAccessLogEnvoy returns a new file based access log filter -func FileAccessLogEnvoy(path string, format string, extensions []string, level contour_api_v1alpha1.AccessLogLevel) []*envoy_accesslog_v3.AccessLog { +func FileAccessLogEnvoy(path, format string, extensions []string, level contour_api_v1alpha1.AccessLogLevel) []*envoy_accesslog_v3.AccessLog { if level == contour_api_v1alpha1.LogLevelDisabled { return nil } @@ -164,7 +164,8 @@ func filterOnlyErrors(respCodeMin uint32) *envoy_accesslog_v3.AccessLogFilter { FilterSpecifier: &envoy_accesslog_v3.AccessLogFilter_ResponseFlagFilter{ ResponseFlagFilter: &envoy_accesslog_v3.ResponseFlagFilter{ // Left empty to match all response flags, they all represent errors. - }}, + }, + }, }, }, }, diff --git a/internal/envoy/v3/accesslog_test.go b/internal/envoy/v3/accesslog_test.go index 8b5738a4dfe..bc6534758d2 100644 --- a/internal/envoy/v3/accesslog_test.go +++ b/internal/envoy/v3/accesslog_test.go @@ -114,26 +114,27 @@ func TestJSONFileAccessLog(t *testing.T) { "only timestamp": { path: "/dev/stdout", headers: contour_api_v1alpha1.AccessLogJSONFields([]string{"@timestamp"}), - want: []*envoy_accesslog_v3.AccessLog{{ - Name: wellknown.FileAccessLog, - ConfigType: &envoy_accesslog_v3.AccessLog_TypedConfig{ - TypedConfig: protobuf.MustMarshalAny(&envoy_file_v3.FileAccessLog{ - Path: "/dev/stdout", - AccessLogFormat: &envoy_file_v3.FileAccessLog_LogFormat{ - LogFormat: &envoy_config_core_v3.SubstitutionFormatString{ - Format: &envoy_config_core_v3.SubstitutionFormatString_JsonFormat{ - JsonFormat: &structpb.Struct{ - Fields: map[string]*structpb.Value{ - "@timestamp": sv("%START_TIME%"), + want: []*envoy_accesslog_v3.AccessLog{ + { + Name: wellknown.FileAccessLog, + ConfigType: &envoy_accesslog_v3.AccessLog_TypedConfig{ + TypedConfig: protobuf.MustMarshalAny(&envoy_file_v3.FileAccessLog{ + Path: "/dev/stdout", + AccessLogFormat: &envoy_file_v3.FileAccessLog_LogFormat{ + LogFormat: &envoy_config_core_v3.SubstitutionFormatString{ + Format: &envoy_config_core_v3.SubstitutionFormatString_JsonFormat{ + JsonFormat: &structpb.Struct{ + Fields: map[string]*structpb.Value{ + "@timestamp": sv("%START_TIME%"), + }, }, }, }, }, - }, - }), + }), + }, }, }, - }, }, "custom fields should appear": { path: "/dev/stdout", @@ -144,30 +145,31 @@ func TestJSONFileAccessLog(t *testing.T) { "custom2=%DURATION%.0", "custom3=ST=%START_TIME(%s.%6f)%", }), - want: []*envoy_accesslog_v3.AccessLog{{ - Name: wellknown.FileAccessLog, - ConfigType: &envoy_accesslog_v3.AccessLog_TypedConfig{ - TypedConfig: protobuf.MustMarshalAny(&envoy_file_v3.FileAccessLog{ - Path: "/dev/stdout", - AccessLogFormat: &envoy_file_v3.FileAccessLog_LogFormat{ - LogFormat: &envoy_config_core_v3.SubstitutionFormatString{ - Format: &envoy_config_core_v3.SubstitutionFormatString_JsonFormat{ - JsonFormat: &structpb.Struct{ - Fields: map[string]*structpb.Value{ - "@timestamp": sv("%START_TIME%"), - "method": sv("%REQ(:METHOD)%"), - "custom1": sv("%REQ(X-CUSTOM-HEADER)%"), - "custom2": sv("%DURATION%.0"), - "custom3": sv("ST=%START_TIME(%s.%6f)%"), + want: []*envoy_accesslog_v3.AccessLog{ + { + Name: wellknown.FileAccessLog, + ConfigType: &envoy_accesslog_v3.AccessLog_TypedConfig{ + TypedConfig: protobuf.MustMarshalAny(&envoy_file_v3.FileAccessLog{ + Path: "/dev/stdout", + AccessLogFormat: &envoy_file_v3.FileAccessLog_LogFormat{ + LogFormat: &envoy_config_core_v3.SubstitutionFormatString{ + Format: &envoy_config_core_v3.SubstitutionFormatString_JsonFormat{ + JsonFormat: &structpb.Struct{ + Fields: map[string]*structpb.Value{ + "@timestamp": sv("%START_TIME%"), + "method": sv("%REQ(:METHOD)%"), + "custom1": sv("%REQ(X-CUSTOM-HEADER)%"), + "custom2": sv("%DURATION%.0"), + "custom3": sv("ST=%START_TIME(%s.%6f)%"), + }, }, }, }, }, - }, - }), + }), + }, }, }, - }, }, } for name, tc := range tests { @@ -179,7 +181,6 @@ func TestJSONFileAccessLog(t *testing.T) { } func TestAccessLogLevel(t *testing.T) { - tests := map[string]struct { level contour_api_v1alpha1.AccessLogLevel wantRespStatus uint32 @@ -229,7 +230,6 @@ func TestAccessLogLevel(t *testing.T) { }, }} protobuf.ExpectEqual(t, want, got) - }) } diff --git a/internal/envoy/v3/bootstrap.go b/internal/envoy/v3/bootstrap.go index 8ede43a630c..37a102f7490 100644 --- a/internal/envoy/v3/bootstrap.go +++ b/internal/envoy/v3/bootstrap.go @@ -58,7 +58,7 @@ func WriteBootstrap(c *envoy.BootstrapConfig) error { // Refer Issue: https://github.com/projectcontour/contour/issues/3264 // The secrets in this directory are "pointers" to actual secrets // mounted from Kubernetes secrets; that means the actual secrets aren't 0777 - if err := os.MkdirAll(path.Join(c.ResourcesDir, "sds"), 0777); err != nil { + if err := os.MkdirAll(path.Join(c.ResourcesDir, "sds"), 0o777); err != nil { return err } } diff --git a/internal/envoy/v3/bootstrap_test.go b/internal/envoy/v3/bootstrap_test.go index 1c5083df515..92bbb54be16 100644 --- a/internal/envoy/v3/bootstrap_test.go +++ b/internal/envoy/v3/bootstrap_test.go @@ -37,7 +37,8 @@ func TestBootstrap(t *testing.T) { "default configuration": { config: envoy.BootstrapConfig{ Path: "envoy.json", - Namespace: "testing-ns"}, + Namespace: "testing-ns", + }, wantedBootstrapConfig: `{ "static_resources": { "clusters": [ @@ -1981,7 +1982,8 @@ func TestBootstrap(t *testing.T) { } ] } - }`}, + }`, + }, } for name, tc := range tests { diff --git a/internal/envoy/v3/cluster.go b/internal/envoy/v3/cluster.go index 49811ba4c1d..515f353955f 100644 --- a/internal/envoy/v3/cluster.go +++ b/internal/envoy/v3/cluster.go @@ -304,7 +304,6 @@ func ClusterDiscoveryTypeForAddress(address string, t envoy_cluster_v3.Cluster_D // parseDNSLookupFamily parses the dnsLookupFamily string into a envoy_cluster_v3.Cluster_DnsLookupFamily func parseDNSLookupFamily(value string) envoy_cluster_v3.Cluster_DnsLookupFamily { - switch value { case "v4": return envoy_cluster_v3.Cluster_V4_ONLY diff --git a/internal/envoy/v3/cluster_test.go b/internal/envoy/v3/cluster_test.go index d5986704fda..bfedbc7924e 100644 --- a/internal/envoy/v3/cluster_test.go +++ b/internal/envoy/v3/cluster_test.go @@ -250,7 +250,7 @@ func TestCluster(t *testing.T) { "externalName service - dns-lookup-family not defined": { cluster: &dag.Cluster{ Upstream: service(s2), - //DNSLookupFamily: "auto", + // DNSLookupFamily: "auto", }, want: &envoy_cluster_v3.Cluster{ Name: "default/kuard/443/da39a3ee5e", @@ -1124,7 +1124,6 @@ func TestClustername(t *testing.T) { cluster: cluster1, want: "default/backend/80/50abc1400c", }) - } func TestLBPolicy(t *testing.T) { diff --git a/internal/envoy/v3/healthcheck_test.go b/internal/envoy/v3/healthcheck_test.go index 61099812c4b..7154a2d7f95 100644 --- a/internal/envoy/v3/healthcheck_test.go +++ b/internal/envoy/v3/healthcheck_test.go @@ -135,7 +135,6 @@ func TestHealthCheck(t *testing.T) { t.Run(name, func(t *testing.T) { got := httpHealthCheck(tc.cluster) protobuf.ExpectEqual(t, tc.want, got) - }) } } diff --git a/internal/envoy/v3/listener.go b/internal/envoy/v3/listener.go index efd18cef12e..b2b910ff4ca 100644 --- a/internal/envoy/v3/listener.go +++ b/internal/envoy/v3/listener.go @@ -291,7 +291,6 @@ func (b *httpConnectionManagerBuilder) HTTP2MaxConcurrentStreams(http2MaxConcurr } func (b *httpConnectionManagerBuilder) DefaultFilters() *httpConnectionManagerBuilder { - // Add a default set of ordered http filters. // The names are not required to match anything and are // identified by the TypeURL of each filter. @@ -442,7 +441,6 @@ func (b *httpConnectionManagerBuilder) Tracing(tracing *http.HttpConnectionManag // Validate runs builtin validation rules against the current builder state. func (b *httpConnectionManagerBuilder) Validate() error { - // It's not OK for the filters to be empty. if len(b.filters) == 0 { return errors.New("filter list is empty") @@ -665,7 +663,7 @@ func UnixSocketAddress(address string) *envoy_core_v3.Address { Address: &envoy_core_v3.Address_Pipe{ Pipe: &envoy_core_v3.Pipe{ Path: address, - Mode: 0644, + Mode: 0o644, }, }, } @@ -804,7 +802,6 @@ func FilterExternalAuthz(externalAuthorization *dag.ExternalAuthorization) *http AllowPartialMessage: externalAuthorization.AuthorizationServerWithRequestBody.AllowPartialMessage, PackAsBytes: externalAuthorization.AuthorizationServerWithRequestBody.PackAsBytes, } - } return &http.HttpFilter{ @@ -895,7 +892,6 @@ func FilterChainTLS(domain string, downstream *envoy_tls_v3.DownstreamTlsContext // Attach TLS data to this listener if provided. if downstream != nil { fc.TransportSocket = DownstreamTLSTransportSocket(downstream) - } return fc } diff --git a/internal/envoy/v3/listener_test.go b/internal/envoy/v3/listener_test.go index e6d97a5d01a..01a4854ac0b 100644 --- a/internal/envoy/v3/listener_test.go +++ b/internal/envoy/v3/listener_test.go @@ -1673,7 +1673,6 @@ func TestTCPProxy(t *testing.T) { } func TestFilterChainTLS_Match(t *testing.T) { - tests := map[string]struct { domain string downstream *envoy_tls_v3.DownstreamTlsContext @@ -1709,7 +1708,6 @@ func TestFilterChainTLS_Match(t *testing.T) { // TestBuilderValidation tests that validation checks that // DefaultFilters adds the required HTTP connection manager filters. func TestBuilderValidation(t *testing.T) { - require.Error(t, HTTPConnectionManagerBuilder().Validate(), "ConnectionManager with no filters should not pass validation") diff --git a/internal/envoy/v3/ratelimit_test.go b/internal/envoy/v3/ratelimit_test.go index e07c96d9913..20eb6ae6df9 100644 --- a/internal/envoy/v3/ratelimit_test.go +++ b/internal/envoy/v3/ratelimit_test.go @@ -241,7 +241,6 @@ func TestGlobalRateLimits(t *testing.T) { assert.Equal(t, tc.want, got) }) } - } func TestGlobalRateLimitFilter(t *testing.T) { diff --git a/internal/envoy/v3/route_test.go b/internal/envoy/v3/route_test.go index 75e826d9c10..3d0841732df 100644 --- a/internal/envoy/v3/route_test.go +++ b/internal/envoy/v3/route_test.go @@ -154,7 +154,6 @@ func TestRouteRoute(t *testing.T) { route: &dag.Route{ Websocket: true, Clusters: []*dag.Cluster{{ - Upstream: &dag.Service{ Weighted: dag.WeightedService{ Weight: 1, @@ -706,7 +705,8 @@ func TestRouteRoute(t *testing.T) { }, Weight: 100, }, - }}, + }, + }, want: &envoy_route_v3.Route_Route{ Route: &envoy_route_v3.RouteAction{ ClusterSpecifier: &envoy_route_v3.RouteAction_Cluster{ @@ -719,7 +719,8 @@ func TestRouteRoute(t *testing.T) { Numerator: 100, Denominator: envoy_type_v3.FractionalPercent_HUNDRED, }, - }}}, + }, + }}, }, }, }, @@ -763,7 +764,8 @@ func TestRouteRoute(t *testing.T) { }, Weight: 100, }, - }}, + }, + }, want: &envoy_route_v3.Route_Route{ Route: &envoy_route_v3.RouteAction{ ClusterSpecifier: &envoy_route_v3.RouteAction_Cluster{ @@ -1138,7 +1140,6 @@ func TestRouteConfiguration(t *testing.T) { virtualhosts []*envoy_route_v3.VirtualHost want *envoy_route_v3.RouteConfiguration }{ - "empty": { name: "ingress_http", want: &envoy_route_v3.RouteConfiguration{ @@ -1245,7 +1246,8 @@ func TestCORSVirtualHost(t *testing.T) { Exact: "*", }, IgnoreCase: true, - }}, + }, + }, AllowMethods: "GET,POST,PUT", }, want: &envoy_route_v3.VirtualHost{ @@ -1259,7 +1261,8 @@ func TestCORSVirtualHost(t *testing.T) { Exact: "*", }, IgnoreCase: true, - }}, + }, + }, AllowMethods: "GET,POST,PUT", }), }, @@ -1291,7 +1294,8 @@ func TestCORSPolicy(t *testing.T) { Exact: "*", }, IgnoreCase: true, - }}, + }, + }, AllowCredentials: wrapperspb.Bool(false), AllowPrivateNetworkAccess: wrapperspb.Bool(false), AllowMethods: "GET,POST,PUT", @@ -1339,7 +1343,8 @@ func TestCORSPolicy(t *testing.T) { Exact: "*", }, IgnoreCase: true, - }}, + }, + }, AllowCredentials: wrapperspb.Bool(true), AllowPrivateNetworkAccess: wrapperspb.Bool(false), AllowMethods: "GET,POST,PUT", @@ -1358,7 +1363,8 @@ func TestCORSPolicy(t *testing.T) { Exact: "*", }, IgnoreCase: true, - }}, + }, + }, AllowCredentials: wrapperspb.Bool(false), AllowPrivateNetworkAccess: wrapperspb.Bool(false), AllowMethods: "GET,POST,PUT", @@ -1378,7 +1384,8 @@ func TestCORSPolicy(t *testing.T) { Exact: "*", }, IgnoreCase: true, - }}, + }, + }, AllowCredentials: wrapperspb.Bool(false), AllowPrivateNetworkAccess: wrapperspb.Bool(false), AllowMethods: "GET,POST,PUT", @@ -1398,7 +1405,8 @@ func TestCORSPolicy(t *testing.T) { Exact: "*", }, IgnoreCase: true, - }}, + }, + }, AllowCredentials: wrapperspb.Bool(false), AllowPrivateNetworkAccess: wrapperspb.Bool(false), AllowMethods: "GET,POST,PUT", @@ -1418,7 +1426,8 @@ func TestCORSPolicy(t *testing.T) { Exact: "*", }, IgnoreCase: true, - }}, + }, + }, AllowCredentials: wrapperspb.Bool(false), AllowPrivateNetworkAccess: wrapperspb.Bool(false), AllowMethods: "GET,POST,PUT", @@ -1437,7 +1446,8 @@ func TestCORSPolicy(t *testing.T) { Exact: "*", }, IgnoreCase: true, - }}, + }, + }, AllowCredentials: wrapperspb.Bool(false), AllowPrivateNetworkAccess: wrapperspb.Bool(false), AllowMethods: "GET,POST,PUT", @@ -1457,7 +1467,8 @@ func TestCORSPolicy(t *testing.T) { Exact: "*", }, IgnoreCase: true, - }}, + }, + }, AllowPrivateNetworkAccess: wrapperspb.Bool(true), AllowCredentials: wrapperspb.Bool(false), AllowMethods: "GET,POST,PUT", diff --git a/internal/envoy/v3/stats.go b/internal/envoy/v3/stats.go index a6395e82491..ee9ba681bcf 100644 --- a/internal/envoy/v3/stats.go +++ b/internal/envoy/v3/stats.go @@ -26,8 +26,10 @@ import ( "google.golang.org/protobuf/types/known/wrapperspb" ) -const metricsServerCertSDSName = "metrics-tls-certificate" -const metricsCaBundleSDSName = "metrics-ca-certificate" +const ( + metricsServerCertSDSName = "metrics-tls-certificate" + metricsCaBundleSDSName = "metrics-ca-certificate" +) // StatsListeners returns an array of *envoy_listener_v3.Listeners, // either single HTTP listener or HTTP and HTTPS listeners depending on config. diff --git a/internal/envoy/v3/stats_test.go b/internal/envoy/v3/stats_test.go index 9fea6e9f02f..d48a69a8690 100644 --- a/internal/envoy/v3/stats_test.go +++ b/internal/envoy/v3/stats_test.go @@ -107,7 +107,8 @@ func TestStatsListeners(t *testing.T) { }, ), SocketOptions: NewSocketOptions().TCPKeepalive().Build(), - }}}) + }}, + }) run(t, "stats-over-https-and-health-over-http", testcase{ metrics: contour_api_v1alpha1.MetricsConfig{ @@ -120,7 +121,8 @@ func TestStatsListeners(t *testing.T) { }, health: contour_api_v1alpha1.HealthConfig{ Address: "127.0.0.127", - Port: 8124}, + Port: 8124, + }, want: []*envoy_listener_v3.Listener{{ Name: "stats", Address: SocketAddress("127.0.0.127", 8123), @@ -195,7 +197,8 @@ func TestStatsListeners(t *testing.T) { }, ), SocketOptions: NewSocketOptions().TCPKeepalive().Build(), - }}}) + }}, + }) run(t, "stats-over-https-with-client-auth-and-health-over-http", testcase{ metrics: contour_api_v1alpha1.MetricsConfig{ @@ -209,7 +212,8 @@ func TestStatsListeners(t *testing.T) { }, health: contour_api_v1alpha1.HealthConfig{ Address: "127.0.0.127", - Port: 8124}, + Port: 8124, + }, want: []*envoy_listener_v3.Listener{{ Name: "stats", Address: SocketAddress("127.0.0.127", 8123), @@ -291,7 +295,8 @@ func TestStatsListeners(t *testing.T) { }, ), SocketOptions: NewSocketOptions().TCPKeepalive().Build(), - }}}) + }}, + }) run(t, "stats-and-health-over-http-but-different-listeners", testcase{ metrics: contour_api_v1alpha1.MetricsConfig{ @@ -300,7 +305,8 @@ func TestStatsListeners(t *testing.T) { }, health: contour_api_v1alpha1.HealthConfig{ Address: "127.0.0.128", - Port: 8124}, + Port: 8124, + }, want: []*envoy_listener_v3.Listener{{ Name: "stats", Address: SocketAddress("127.0.0.127", 8123), @@ -361,8 +367,8 @@ func TestStatsListeners(t *testing.T) { }, ), SocketOptions: NewSocketOptions().TCPKeepalive().Build(), - }}}) - + }}, + }) } func TestStatsTLSSecrets(t *testing.T) { diff --git a/internal/featuretests/v3/authorization_test.go b/internal/featuretests/v3/authorization_test.go index 3e51070cba2..9388bb904fa 100644 --- a/internal/featuretests/v3/authorization_test.go +++ b/internal/featuretests/v3/authorization_test.go @@ -229,7 +229,7 @@ func authzOverrideDisabled(t *testing.T, rh ResourceEventHandlerWrapper, c *Cont const enabled = "enabled.projectcontour.io" const disabled = "disabled.projectcontour.io" - var extensionRef = contour_api_v1.ExtensionServiceReference{ + extensionRef := contour_api_v1.ExtensionServiceReference{ Namespace: "auth", Name: "extension", } diff --git a/internal/featuretests/v3/backendcavalidation_test.go b/internal/featuretests/v3/backendcavalidation_test.go index 0c779ac577e..ba2f6f5805c 100644 --- a/internal/featuretests/v3/backendcavalidation_test.go +++ b/internal/featuretests/v3/backendcavalidation_test.go @@ -174,5 +174,4 @@ func TestClusterServiceTLSBackendCAValidation(t *testing.T) { Resources: nil, TypeUrl: secretType, }) - } diff --git a/internal/featuretests/v3/backendclientauth_test.go b/internal/featuretests/v3/backendclientauth_test.go index 0cbe4d28e90..5b2f066b150 100644 --- a/internal/featuretests/v3/backendclientauth_test.go +++ b/internal/featuretests/v3/backendclientauth_test.go @@ -132,7 +132,6 @@ func TestBackendClientAuthenticationWithHTTPProxy(t *testing.T) { Resources: nil, TypeUrl: clusterType, }) - } func TestBackendClientAuthenticationWithIngress(t *testing.T) { @@ -211,7 +210,8 @@ func TestBackendClientAuthenticationWithExtensionService(t *testing.T) { Type: "kubernetes.io/tls", Data: map[string][]byte{dag.CACertificateKey: []byte(featuretests.CERTIFICATE)}, }}, - SubjectNames: []string{"subjname"}}, + SubjectNames: []string{"subjname"}, + }, "subjname", &dag.Secret{Object: sec1}, nil, diff --git a/internal/featuretests/v3/corspolicy_test.go b/internal/featuretests/v3/corspolicy_test.go index 54f025484ea..11adda20ddf 100644 --- a/internal/featuretests/v3/corspolicy_test.go +++ b/internal/featuretests/v3/corspolicy_test.go @@ -285,12 +285,13 @@ func TestCorsPolicy(t *testing.T) { envoy_v3.RouteConfiguration("ingress_http", envoy_v3.CORSVirtualHost("hello.world", &envoy_cors_v3.CorsPolicy{ - AllowOriginStringMatch: []*matcher.StringMatcher{{ - MatchPattern: &matcher.StringMatcher_Exact{ - Exact: "*", + AllowOriginStringMatch: []*matcher.StringMatcher{ + { + MatchPattern: &matcher.StringMatcher_Exact{ + Exact: "*", + }, + IgnoreCase: true, }, - IgnoreCase: true, - }, }, AllowCredentials: &wrapperspb.BoolValue{Value: true}, AllowPrivateNetworkAccess: &wrapperspb.BoolValue{Value: false}, @@ -466,5 +467,4 @@ func TestCorsPolicy(t *testing.T) { envoy_v3.RouteConfiguration("ingress_http")), TypeUrl: routeType, }).Status(invvhost).IsInvalid() - } diff --git a/internal/featuretests/v3/envoy.go b/internal/featuretests/v3/envoy.go index 139a8c18803..1f3bf079b2c 100644 --- a/internal/featuretests/v3/envoy.go +++ b/internal/featuretests/v3/envoy.go @@ -184,7 +184,7 @@ func cluster(name, servicename, statName string) *envoy_cluster_v3.Cluster { }) } -func tlsCluster(c *envoy_cluster_v3.Cluster, ca []byte, subjectName string, sni string, clientSecret *v1.Secret, upstreamTLS *dag.UpstreamTLS, alpnProtocols ...string) *envoy_cluster_v3.Cluster { +func tlsCluster(c *envoy_cluster_v3.Cluster, ca []byte, subjectName, sni string, clientSecret *v1.Secret, upstreamTLS *dag.UpstreamTLS, alpnProtocols ...string) *envoy_cluster_v3.Cluster { var secret *dag.Secret if clientSecret != nil { secret = &dag.Secret{Object: clientSecret} @@ -201,7 +201,8 @@ func tlsCluster(c *envoy_cluster_v3.Cluster, ca []byte, subjectName string, sni Type: "kubernetes.io/tls", Data: map[string][]byte{dag.CACertificateKey: ca}, }}, - SubjectNames: []string{subjectName}}, + SubjectNames: []string{subjectName}, + }, sni, secret, upstreamTLS, @@ -295,7 +296,8 @@ func withMirrorPolicy(route *envoy_route_v3.Route_Route, mirror string, weight i Numerator: uint32(weight), Denominator: envoy_type_v3.FractionalPercent_HUNDRED, }, - }}} + }, + }} return route } diff --git a/internal/featuretests/v3/externalname_test.go b/internal/featuretests/v3/externalname_test.go index 917a1753cb1..a8e28dfb898 100644 --- a/internal/featuretests/v3/externalname_test.go +++ b/internal/featuretests/v3/externalname_test.go @@ -322,7 +322,6 @@ func TestExternalNameService(t *testing.T) { func enableExternalNameService(t *testing.T) func(*dag.Builder) { return func(b *dag.Builder) { - log := fixture.NewTestLogger(t) log.SetLevel(logrus.DebugLevel) diff --git a/internal/featuretests/v3/featuretests.go b/internal/featuretests/v3/featuretests.go index 30f0bd72183..fe3f2b1548f 100644 --- a/internal/featuretests/v3/featuretests.go +++ b/internal/featuretests/v3/featuretests.go @@ -354,7 +354,7 @@ func (s *StatusResult) Like(want contour_api_v1.HTTPProxyStatus) *Contour { // HasError asserts that there is an error on the Valid Condition in the proxy // that matches the given values. -func (s *StatusResult) HasError(condType string, reason, message string) *Contour { +func (s *StatusResult) HasError(condType, reason, message string) *Contour { assert.Equal(s.T, string(status.ProxyStatusInvalid), s.Have.CurrentStatus) assert.Equal(s.T, "At least one error present, see Errors for details", s.Have.Description) validCond := s.Have.GetConditionFor(contour_api_v1.ValidConditionType) diff --git a/internal/featuretests/v3/global_authorization_test.go b/internal/featuretests/v3/global_authorization_test.go index d928bc2057e..a02d3a58b11 100644 --- a/internal/featuretests/v3/global_authorization_test.go +++ b/internal/featuretests/v3/global_authorization_test.go @@ -63,7 +63,7 @@ func globalExternalAuthorizationFilterExists(t *testing.T, rh ResourceEventHandl } rh.OnAdd(p) - var httpListener = defaultHTTPListener() + httpListener := defaultHTTPListener() // replace the default filter chains with an HCM that includes the global // extAuthz filter. @@ -101,7 +101,7 @@ func globalExternalAuthorizationFilterExistsTLS(t *testing.T, rh ResourceEventHa rh.OnAdd(p) - var httpListener = defaultHTTPListener() + httpListener := defaultHTTPListener() // replace the default filter chains with an HCM that includes the global // extAuthz filter. @@ -175,7 +175,7 @@ func globalExternalAuthorizationWithTLSGlobalAuthDisabled(t *testing.T, rh Resou rh.OnAdd(p) - var httpListener = defaultHTTPListener() + httpListener := defaultHTTPListener() // replace the default filter chains with an HCM that includes the global // extAuthz filter. @@ -239,7 +239,7 @@ func globalExternalAuthorizationWithMergedAuthPolicy(t *testing.T, rh ResourceEv } rh.OnAdd(p) - var httpListener = defaultHTTPListener() + httpListener := defaultHTTPListener() // replace the default filter chains with an HCM that includes the global // extAuthz filter. @@ -313,7 +313,7 @@ func globalExternalAuthorizationWithMergedAuthPolicyTLS(t *testing.T, rh Resourc rh.OnAdd(p) - var httpListener = defaultHTTPListener() + httpListener := defaultHTTPListener() // replace the default filter chains with an HCM that includes the global // extAuthz filter. @@ -434,7 +434,7 @@ func globalExternalAuthorizationWithTLSAuthOverride(t *testing.T, rh ResourceEve rh.OnAdd(p) - var httpListener = defaultHTTPListener() + httpListener := defaultHTTPListener() // replace the default filter chains with an HCM that includes the global // extAuthz filter. diff --git a/internal/featuretests/v3/globalratelimit_test.go b/internal/featuretests/v3/globalratelimit_test.go index 216d2c46ab5..121ba521e07 100644 --- a/internal/featuretests/v3/globalratelimit_test.go +++ b/internal/featuretests/v3/globalratelimit_test.go @@ -703,7 +703,8 @@ func globalRateLimitMultipleDescriptorsAndEntries(t *testing.T, rh ResourceEvent ActionSpecifier: &envoy_route_v3.RateLimit_Action_GenericKey_{ GenericKey: &envoy_route_v3.RateLimit_Action_GenericKey{ DescriptorKey: "generic-key-key", - DescriptorValue: "generic-key-value-2"}, + DescriptorValue: "generic-key-value-2", + }, }, }, }, @@ -716,7 +717,6 @@ func globalRateLimitMultipleDescriptorsAndEntries(t *testing.T, rh ResourceEvent TypeUrl: routeType, Resources: resources(t, envoy_v3.RouteConfiguration("ingress_http", envoy_v3.VirtualHost("foo.com", route))), }) - } type tlsConfig struct { diff --git a/internal/featuretests/v3/headercondition_test.go b/internal/featuretests/v3/headercondition_test.go index 13ec7289152..4c4eca82724 100644 --- a/internal/featuretests/v3/headercondition_test.go +++ b/internal/featuretests/v3/headercondition_test.go @@ -50,12 +50,13 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) { }, Spec: contour_api_v1.HTTPProxySpec{ VirtualHost: &contour_api_v1.VirtualHost{Fqdn: "hello.world"}, - Routes: []contour_api_v1.Route{{ - Services: []contour_api_v1.Service{{ - Name: "svc1", - Port: 80, - }}, - }, + Routes: []contour_api_v1.Route{ + { + Services: []contour_api_v1.Service{{ + Name: "svc1", + Port: 80, + }}, + }, { Conditions: matchconditions( prefixMatchCondition("/"), @@ -428,7 +429,8 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) { Name: "svc2", Port: 80, }}, - }}, + }, + }, }, ) @@ -487,7 +489,8 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) { Name: "svc2", Port: 80, }}, - }}, + }, + }, }, ) @@ -582,5 +585,4 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) { ), TypeUrl: routeType, }) - } diff --git a/internal/featuretests/v3/httpproxy.go b/internal/featuretests/v3/httpproxy.go index d46ed1a1ba9..ad55286f5c1 100644 --- a/internal/featuretests/v3/httpproxy.go +++ b/internal/featuretests/v3/httpproxy.go @@ -60,7 +60,7 @@ func headerExactMatchCondition(name, value string, ignoreCase bool) contour_api_ } } -func headerNotExactMatchCondition(name, value string, ignoreCase bool, treatMissingAsEmpty bool) contour_api_v1.MatchCondition { +func headerNotExactMatchCondition(name, value string, ignoreCase, treatMissingAsEmpty bool) contour_api_v1.MatchCondition { return contour_api_v1.MatchCondition{ Header: &contour_api_v1.HeaderMatchCondition{ Name: name, diff --git a/internal/featuretests/v3/internalredirectpolicy_test.go b/internal/featuretests/v3/internalredirectpolicy_test.go index e57f8ea9934..6eb1924637d 100644 --- a/internal/featuretests/v3/internalredirectpolicy_test.go +++ b/internal/featuretests/v3/internalredirectpolicy_test.go @@ -192,5 +192,4 @@ func TestInternalRedirectPolicy_HTTProxy(t *testing.T) { ), TypeUrl: routeType, }) - } diff --git a/internal/featuretests/v3/listeners_test.go b/internal/featuretests/v3/listeners_test.go index 85cf01e54e9..da83cc20a9a 100644 --- a/internal/featuretests/v3/listeners_test.go +++ b/internal/featuretests/v3/listeners_test.go @@ -99,7 +99,8 @@ func TestNonTLSListener(t *testing.T) { // i2 is the same as i1 but has the kubernetes.io/ingress.allow-http: "false" annotation i2 := &networking_v1.Ingress{ ObjectMeta: fixture.ObjectMetaWithAnnotations("default/simple", map[string]string{ - "kubernetes.io/ingress.allow-http": "false"}), + "kubernetes.io/ingress.allow-http": "false", + }), Spec: networking_v1.IngressSpec{ DefaultBackend: featuretests.IngressBackend(svc1), }, diff --git a/internal/featuretests/v3/queryparametercondition_test.go b/internal/featuretests/v3/queryparametercondition_test.go index 409688467c9..f9f83a8564a 100644 --- a/internal/featuretests/v3/queryparametercondition_test.go +++ b/internal/featuretests/v3/queryparametercondition_test.go @@ -444,7 +444,8 @@ func TestConditions_ContainsQueryParameter_HTTProxy(t *testing.T) { Name: "svc2", Port: 80, }}, - }}, + }, + }, }, ) diff --git a/internal/featuretests/v3/replaceprefix_test.go b/internal/featuretests/v3/replaceprefix_test.go index 5b6989ad44b..4578134c159 100644 --- a/internal/featuretests/v3/replaceprefix_test.go +++ b/internal/featuretests/v3/replaceprefix_test.go @@ -87,11 +87,10 @@ func basic(t *testing.T) { // Update the vhost to make the replacement ambiguous. This should remove the generated config. vhost = update(rh, vhost, func(vhost *contour_api_v1.HTTPProxy) { - vhost.Spec.Routes[0].PathRewritePolicy.ReplacePrefix = - []contour_api_v1.ReplacePrefix{ - {Replacement: "/api/v1"}, - {Replacement: "/api/v2"}, - } + vhost.Spec.Routes[0].PathRewritePolicy.ReplacePrefix = []contour_api_v1.ReplacePrefix{ + {Replacement: "/api/v1"}, + {Replacement: "/api/v2"}, + } }) c.Request(routeType).Equals(&envoy_discovery_v3.DiscoveryResponse{ @@ -104,11 +103,10 @@ func basic(t *testing.T) { // The replacement isn't ambiguous any more because only one of the prefixes matches. vhost = update(rh, vhost, func(vhost *contour_api_v1.HTTPProxy) { - vhost.Spec.Routes[0].PathRewritePolicy.ReplacePrefix = - []contour_api_v1.ReplacePrefix{ - {Prefix: "/foo", Replacement: "/api/v1"}, - {Prefix: "/api", Replacement: "/api/v2"}, - } + vhost.Spec.Routes[0].PathRewritePolicy.ReplacePrefix = []contour_api_v1.ReplacePrefix{ + {Prefix: "/foo", Replacement: "/api/v1"}, + {Prefix: "/api", Replacement: "/api/v2"}, + } }) c.Request(routeType).Equals(&envoy_discovery_v3.DiscoveryResponse{ @@ -133,11 +131,10 @@ func basic(t *testing.T) { // it ambiguous again. vhost = update(rh, vhost, func(vhost *contour_api_v1.HTTPProxy) { - vhost.Spec.Routes[0].PathRewritePolicy.ReplacePrefix = - []contour_api_v1.ReplacePrefix{ - {Prefix: "/foo", Replacement: "/api/v1"}, - {Prefix: "/foo", Replacement: "/api/v2"}, - } + vhost.Spec.Routes[0].PathRewritePolicy.ReplacePrefix = []contour_api_v1.ReplacePrefix{ + {Prefix: "/foo", Replacement: "/api/v1"}, + {Prefix: "/foo", Replacement: "/api/v2"}, + } }) c.Request(routeType).Equals(&envoy_discovery_v3.DiscoveryResponse{ @@ -150,11 +147,10 @@ func basic(t *testing.T) { // The "/api" prefix should have precedence over the empty prefix. vhost = update(rh, vhost, func(vhost *contour_api_v1.HTTPProxy) { - vhost.Spec.Routes[0].PathRewritePolicy.ReplacePrefix = - []contour_api_v1.ReplacePrefix{ - {Prefix: "/api", Replacement: "/api/full"}, - {Prefix: "", Replacement: "/api/empty"}, - } + vhost.Spec.Routes[0].PathRewritePolicy.ReplacePrefix = []contour_api_v1.ReplacePrefix{ + {Prefix: "/api", Replacement: "/api/full"}, + {Prefix: "", Replacement: "/api/empty"}, + } }) c.Request(routeType).Equals(&envoy_discovery_v3.DiscoveryResponse{ @@ -280,10 +276,9 @@ func multiInclude(t *testing.T) { // Remove one of the replacements, and one cluster loses the rewrite. update(rh, app, func(app *contour_api_v1.HTTPProxy) { - app.Spec.Routes[0].PathRewritePolicy.ReplacePrefix = - []contour_api_v1.ReplacePrefix{ - {Prefix: "/v1", Replacement: "/api/v1"}, - } + app.Spec.Routes[0].PathRewritePolicy.ReplacePrefix = []contour_api_v1.ReplacePrefix{ + {Prefix: "/v1", Replacement: "/api/v1"}, + } }) c.Request(routeType).Equals(&envoy_discovery_v3.DiscoveryResponse{ diff --git a/internal/featuretests/v3/route_test.go b/internal/featuretests/v3/route_test.go index 1e92c0f1d71..3dc5f5702ca 100644 --- a/internal/featuretests/v3/route_test.go +++ b/internal/featuretests/v3/route_test.go @@ -283,7 +283,8 @@ func TestEditIngressInPlace(t *testing.T) { // i3 is like i2, but adds the ingress.kubernetes.io/force-ssl-redirect: "true" annotation i3 := &networking_v1.Ingress{ ObjectMeta: fixture.ObjectMetaWithAnnotations("default/hello", map[string]string{ - "ingress.kubernetes.io/force-ssl-redirect": "true"}), + "ingress.kubernetes.io/force-ssl-redirect": "true", + }), Spec: networking_v1.IngressSpec{ Rules: []networking_v1.IngressRule{{ Host: "hello.example.com", @@ -338,7 +339,8 @@ func TestEditIngressInPlace(t *testing.T) { Name: "hello", Namespace: "default", Annotations: map[string]string{ - "ingress.kubernetes.io/force-ssl-redirect": "true"}, + "ingress.kubernetes.io/force-ssl-redirect": "true", + }, }, Spec: networking_v1.IngressSpec{ TLS: []networking_v1.IngressTLS{{ @@ -753,7 +755,6 @@ func TestRDSFilter(t *testing.T) { TypeUrl: routeType, Nonce: "5", }) - } // issue 404 @@ -1214,7 +1215,8 @@ func TestRouteWithTLS_InsecurePaths(t *testing.T) { Prefix: "/insecure", }}, PermitInsecure: true, - Services: []contour_api_v1.Service{{Name: "kuard", + Services: []contour_api_v1.Service{{ + Name: "kuard", Port: 80, }}, }, { @@ -1588,7 +1590,8 @@ func TestHTTPProxyRouteWithTLS_InsecurePaths(t *testing.T) { Routes: []contour_api_v1.Route{{ Conditions: conditions(prefixCondition("/insecure")), PermitInsecure: true, - Services: []contour_api_v1.Service{{Name: "kuard", + Services: []contour_api_v1.Service{{ + Name: "kuard", Port: 80, }}, }, { diff --git a/internal/featuretests/v3/timeoutpolicy_test.go b/internal/featuretests/v3/timeoutpolicy_test.go index a8cd9286294..422ef376099 100644 --- a/internal/featuretests/v3/timeoutpolicy_test.go +++ b/internal/featuretests/v3/timeoutpolicy_test.go @@ -234,7 +234,6 @@ func TestTimeoutPolicyIdleStreamTimeout(t *testing.T) { ), TypeUrl: routeType, }) - } func TestTimeoutPolicyIdleConnectionTimeout(t *testing.T) { diff --git a/internal/featuretests/v3/tlsprotocolversion_test.go b/internal/featuretests/v3/tlsprotocolversion_test.go index b05334ffb5e..14a9d09f0da 100644 --- a/internal/featuretests/v3/tlsprotocolversion_test.go +++ b/internal/featuretests/v3/tlsprotocolversion_test.go @@ -190,5 +190,4 @@ func TestTLSProtocolVersion(t *testing.T) { Resources: nil, TypeUrl: listenerType, }) - } diff --git a/internal/featuretests/v3/upstreamtls_test.go b/internal/featuretests/v3/upstreamtls_test.go index e6a67d69efe..6e10562decf 100644 --- a/internal/featuretests/v3/upstreamtls_test.go +++ b/internal/featuretests/v3/upstreamtls_test.go @@ -92,7 +92,6 @@ func TestUpstreamTLSWithHTTPProxy(t *testing.T) { ), TypeUrl: clusterType, }) - } func TestUpstreamTLSWithIngress(t *testing.T) { @@ -143,7 +142,6 @@ func TestUpstreamTLSWithIngress(t *testing.T) { } func TestUpstreamTLSWithExtensionService(t *testing.T) { - rh, c, done := setup(t, func(b *dag.Builder) { for _, processor := range b.Processors { if extensionServiceProcessor, ok := processor.(*dag.ExtensionServiceProcessor); ok { diff --git a/internal/featuretests/v3/websockets_test.go b/internal/featuretests/v3/websockets_test.go index 22cd3cda7eb..000a9b2a5cd 100644 --- a/internal/featuretests/v3/websockets_test.go +++ b/internal/featuretests/v3/websockets_test.go @@ -190,5 +190,4 @@ func TestWebsocketHTTPProxy(t *testing.T) { ), TypeUrl: routeType, }) - } diff --git a/internal/fixture/detailedcondition.go b/internal/fixture/detailedcondition.go index df3a5117567..8cbe5fdcf57 100644 --- a/internal/fixture/detailedcondition.go +++ b/internal/fixture/detailedcondition.go @@ -37,7 +37,6 @@ func (dcb *DetailedConditionBuilder) WithGeneration(gen int64) *DetailedConditio } func (dcb *DetailedConditionBuilder) Valid() v1.DetailedCondition { - dc := (*v1.DetailedCondition)(dcb) dc.Status = v1.ConditionTrue dc.Reason = "Valid" @@ -47,45 +46,36 @@ func (dcb *DetailedConditionBuilder) Valid() v1.DetailedCondition { } func (dcb *DetailedConditionBuilder) Orphaned() v1.DetailedCondition { - dc := (*v1.DetailedCondition)(dcb) dc.AddError(v1.ConditionTypeOrphanedError, "Orphaned", "this HTTPProxy is not part of a delegation chain from a root HTTPProxy") return *dc } -func (dcb *DetailedConditionBuilder) WithError(errorType string, reason, message string) v1.DetailedCondition { - +func (dcb *DetailedConditionBuilder) WithError(errorType, reason, message string) v1.DetailedCondition { dc := (*v1.DetailedCondition)(dcb) dc.AddError(errorType, reason, message) return *dc - } -func (dcb *DetailedConditionBuilder) WithErrorf(errorType string, reason, formatmsg string, args ...any) v1.DetailedCondition { - +func (dcb *DetailedConditionBuilder) WithErrorf(errorType, reason, formatmsg string, args ...any) v1.DetailedCondition { dc := (*v1.DetailedCondition)(dcb) dc.AddErrorf(errorType, reason, formatmsg, args...) return *dc - } func (dcb *DetailedConditionBuilder) WithWarning(errorType, reason, message string) v1.DetailedCondition { - dc := (*v1.DetailedCondition)(dcb) dc.AddWarning(errorType, reason, message) return *dc - } func (dcb *DetailedConditionBuilder) WithWarningf(warnType, reason, formatmsg string, args ...any) v1.DetailedCondition { - dc := (*v1.DetailedCondition)(dcb) dc.AddWarningf(warnType, reason, formatmsg, args...) return *dc - } diff --git a/internal/fixture/httpproxy.go b/internal/fixture/httpproxy.go index bb28a189c59..a1cebd1a681 100644 --- a/internal/fixture/httpproxy.go +++ b/internal/fixture/httpproxy.go @@ -46,13 +46,13 @@ func (b *ProxyBuilder) ensureTLS() { } // Annotate adds the given values as metadata annotations. -func (b *ProxyBuilder) Annotate(k string, v string) *ProxyBuilder { +func (b *ProxyBuilder) Annotate(k, v string) *ProxyBuilder { b.ObjectMeta.Annotations[k] = v return b } // Label adds the given values as metadata labels. -func (b *ProxyBuilder) Label(k string, v string) *ProxyBuilder { +func (b *ProxyBuilder) Label(k, v string) *ProxyBuilder { b.ObjectMeta.Labels[k] = v return b } diff --git a/internal/fixture/service.go b/internal/fixture/service.go index dbd0703d583..dbc5932cae6 100644 --- a/internal/fixture/service.go +++ b/internal/fixture/service.go @@ -30,7 +30,7 @@ func NewService(name string) *ServiceBuilder { } // Annotate adds the given values as metadata annotations. -func (s *ServiceBuilder) Annotate(k string, v string) *ServiceBuilder { +func (s *ServiceBuilder) Annotate(k, v string) *ServiceBuilder { s.ObjectMeta.Annotations[k] = v return s } diff --git a/internal/gatewayapi/helpers.go b/internal/gatewayapi/helpers.go index 27297a3a711..a5366ccd0bd 100644 --- a/internal/gatewayapi/helpers.go +++ b/internal/gatewayapi/helpers.go @@ -160,13 +160,14 @@ func GRPCRouteBackendRef(serviceName string, port int, weight int32) []gatewayap Name: gatewayapi_v1alpha2.ObjectName(serviceName), Port: ref.To(gatewayapi_v1beta1.PortNumber(port)), }, - Weight: &weight}, + Weight: &weight, + }, Filters: []gatewayapi_v1alpha2.GRPCRouteFilter{}, }, } } -func GRPCMethodMatch(matchType gatewayapi_v1alpha2.GRPCMethodMatchType, service string, method string) *gatewayapi_v1alpha2.GRPCMethodMatch { +func GRPCMethodMatch(matchType gatewayapi_v1alpha2.GRPCMethodMatchType, service, method string) *gatewayapi_v1alpha2.GRPCMethodMatch { return &gatewayapi_v1alpha2.GRPCMethodMatch{ Type: ref.To(matchType), Service: ref.To(service), diff --git a/internal/k8s/filter.go b/internal/k8s/filter.go index 53af86bfbdf..2cc3c5a8ee5 100644 --- a/internal/k8s/filter.go +++ b/internal/k8s/filter.go @@ -50,7 +50,6 @@ func (e *namespaceFilter) allowed(obj any) bool { } return true - } func (e *namespaceFilter) OnAdd(obj any, isInInitialList bool) { diff --git a/internal/k8s/filter_test.go b/internal/k8s/filter_test.go index 724131d2482..573d1e87295 100644 --- a/internal/k8s/filter_test.go +++ b/internal/k8s/filter_test.go @@ -66,5 +66,4 @@ func TestNamespaceFilter(t *testing.T) { filter.OnDelete(fixture.NewProxy("ns1/proxy")) assert.Equal(t, 1, counter.deleted) - } diff --git a/internal/k8s/helpers.go b/internal/k8s/helpers.go index a0ac86baddc..5356c8a2149 100644 --- a/internal/k8s/helpers.go +++ b/internal/k8s/helpers.go @@ -95,7 +95,6 @@ func isStatusEqual(objA, objB any) bool { // Make an attempt to avoid comparing full objects since it can be very CPU intensive. // Prefer comparing Generation when only interested in spec changes. func IsObjectEqual(oldObj, newObj client.Object) (bool, error) { - // Fast path for any object: when ResourceVersions are equal, the objects are equal. // NOTE: This optimizes the case when controller-runtime executes full sync and sends updates for all objects. if isResourceVersionEqual(oldObj, newObj) { diff --git a/internal/k8s/kind_test.go b/internal/k8s/kind_test.go index 39cd91d0a8b..027aa370bc0 100644 --- a/internal/k8s/kind_test.go +++ b/internal/k8s/kind_test.go @@ -49,11 +49,13 @@ func TestKindOf(t *testing.T) { {"Gateway", &gatewayapi_v1beta1.Gateway{}}, {"GatewayClass", &gatewayapi_v1beta1.GatewayClass{}}, {"ReferenceGrant", &gatewayapi_v1beta1.ReferenceGrant{}}, - {"Foo", &unstructured.Unstructured{ - Object: map[string]any{ - "apiVersion": "test.projectcontour.io/v1", - "kind": "Foo", - }}, + { + "Foo", &unstructured.Unstructured{ + Object: map[string]any{ + "apiVersion": "test.projectcontour.io/v1", + "kind": "Foo", + }, + }, }, } @@ -74,11 +76,13 @@ func TestVersionOf(t *testing.T) { {"projectcontour.io/v1", &contour_api_v1.HTTPProxy{}}, {"projectcontour.io/v1", &contour_api_v1.TLSCertificateDelegation{}}, {"projectcontour.io/v1alpha1", &v1alpha1.ExtensionService{}}, - {"test.projectcontour.io/v1", &unstructured.Unstructured{ - Object: map[string]any{ - "apiVersion": "test.projectcontour.io/v1", - "kind": "Foo", - }}, + { + "test.projectcontour.io/v1", &unstructured.Unstructured{ + Object: map[string]any{ + "apiVersion": "test.projectcontour.io/v1", + "kind": "Foo", + }, + }, }, } diff --git a/internal/k8s/objectmeta_test.go b/internal/k8s/objectmeta_test.go index 8b4b0c193b4..015856001e6 100644 --- a/internal/k8s/objectmeta_test.go +++ b/internal/k8s/objectmeta_test.go @@ -21,7 +21,7 @@ import ( ) func TestNamespacedNameFrom(t *testing.T) { - run := func(testName string, got types.NamespacedName, want types.NamespacedName) { + run := func(testName string, got, want types.NamespacedName) { t.Helper() t.Run(testName, func(t *testing.T) { t.Helper() diff --git a/internal/k8s/status.go b/internal/k8s/status.go index f1e137b215a..7f17bf6b586 100644 --- a/internal/k8s/status.go +++ b/internal/k8s/status.go @@ -161,9 +161,7 @@ func (suh *StatusUpdateHandler) Start(ctx context.Context) error { suh.apply(upd) } - } - } // Writer retrieves the interface that should be used to write to the StatusUpdateHandler. diff --git a/internal/k8s/statusaddress.go b/internal/k8s/statusaddress.go index 82cefcd066c..f06b9e5c69b 100644 --- a/internal/k8s/statusaddress.go +++ b/internal/k8s/statusaddress.go @@ -193,11 +193,9 @@ func (s *StatusAddressUpdater) OnAdd(obj any, _ bool) { } func (s *StatusAddressUpdater) OnUpdate(_, newObj any) { - // We only care about the new object, because we're only updating its status. // So, we can get away with just passing this call to OnAdd. s.OnAdd(newObj, false) - } func (s *StatusAddressUpdater) OnDelete(_ any) { diff --git a/internal/k8s/statuscache.go b/internal/k8s/statuscache.go index 77fcf9e6744..1272c9899f7 100644 --- a/internal/k8s/statuscache.go +++ b/internal/k8s/statuscache.go @@ -45,7 +45,6 @@ func (suc *StatusUpdateCacher) OnDelete(obj any) { default: panic(fmt.Sprintf("status caching not supported for object type %T", obj)) } - } } @@ -61,12 +60,10 @@ func (suc *StatusUpdateCacher) OnAdd(obj any) { default: panic(fmt.Sprintf("status caching not supported for object type %T", obj)) } - } // Get allows retrieval of objects from the cache. func (suc *StatusUpdateCacher) Get(name, namespace string) any { - if suc.objectCache == nil { suc.objectCache = make(map[string]client.Object) } @@ -76,7 +73,6 @@ func (suc *StatusUpdateCacher) Get(name, namespace string) any { return obj } return nil - } func (suc *StatusUpdateCacher) Add(name, namespace string, obj client.Object) bool { @@ -93,7 +89,6 @@ func (suc *StatusUpdateCacher) Add(name, namespace string, obj client.Object) bo suc.objectCache[prefix] = obj return true - } func (suc *StatusUpdateCacher) GetStatus(obj any) (*contour_api_v1.HTTPProxyStatus, error) { @@ -113,7 +108,6 @@ func (suc *StatusUpdateCacher) GetStatus(obj any) (*contour_api_v1.HTTPProxyStat } func (suc *StatusUpdateCacher) objKey(name, namespace string) string { - return fmt.Sprintf("%s/%s", namespace, name) } diff --git a/internal/protobuf/helpers.go b/internal/protobuf/helpers.go index 837d839ae26..eda795c7322 100644 --- a/internal/protobuf/helpers.go +++ b/internal/protobuf/helpers.go @@ -23,7 +23,7 @@ import ( ) // UInt32OrDefault returns a wrapped UInt32Value. If val is 0, def is wrapped and returned. -func UInt32OrDefault(val uint32, def uint32) *wrapperspb.UInt32Value { +func UInt32OrDefault(val, def uint32) *wrapperspb.UInt32Value { switch val { case 0: return wrapperspb.UInt32(def) diff --git a/internal/provisioner/controller/gateway.go b/internal/provisioner/controller/gateway.go index 310c73ab6a8..8907dbea37c 100644 --- a/internal/provisioner/controller/gateway.go +++ b/internal/provisioner/controller/gateway.go @@ -494,5 +494,4 @@ func (r *gatewayReconciler) getGatewayClassParams(ctx context.Context, gatewayCl } return gcParams, nil - } diff --git a/internal/provisioner/equality/equality_test.go b/internal/provisioner/equality/equality_test.go index 69d83973b5c..1f60ec92eb7 100644 --- a/internal/provisioner/equality/equality_test.go +++ b/internal/provisioner/equality/equality_test.go @@ -84,7 +84,8 @@ func TestDaemonSetConfigChanged(t *testing.T) { Path: "/foo", }, }, - }} + }, + } }, expect: true, }, @@ -179,7 +180,8 @@ func TestDeploymentConfigChanged(t *testing.T) { Path: "/foo", }, }, - }} + }, + } }, expect: true, }, diff --git a/internal/provisioner/objects/contourconfig/contourconfig.go b/internal/provisioner/objects/contourconfig/contourconfig.go index a3f5318f71f..7356129d577 100644 --- a/internal/provisioner/objects/contourconfig/contourconfig.go +++ b/internal/provisioner/objects/contourconfig/contourconfig.go @@ -85,5 +85,4 @@ func EnsureContourConfigDeleted(ctx context.Context, cli client.Client, contour } return objects.EnsureObjectDeleted(ctx, cli, obj, contour) - } diff --git a/internal/provisioner/objects/contourconfig/contourconfig_test.go b/internal/provisioner/objects/contourconfig/contourconfig_test.go index 428d55323c9..89188993c36 100644 --- a/internal/provisioner/objects/contourconfig/contourconfig_test.go +++ b/internal/provisioner/objects/contourconfig/contourconfig_test.go @@ -337,6 +337,5 @@ func TestEnsureContourConfigDeleted(t *testing.T) { require.NoError(t, err) } }) - } } diff --git a/internal/provisioner/objects/dataplane/dataplane.go b/internal/provisioner/objects/dataplane/dataplane.go index 765919aba98..a34e02fcc30 100644 --- a/internal/provisioner/objects/dataplane/dataplane.go +++ b/internal/provisioner/objects/dataplane/dataplane.go @@ -76,7 +76,6 @@ var defContainerResources = corev1.ResourceRequirements{ // EnsureDataPlane ensures an Envoy data plane (daemonset or deployment) exists for the given contour. func EnsureDataPlane(ctx context.Context, cli client.Client, contour *model.Contour, contourImage, envoyImage string) error { - switch contour.Spec.EnvoyWorkloadType { // If a Deployment was specified, provision a Deployment. case model.WorkloadTypeDeployment: @@ -151,7 +150,6 @@ func desiredContainers(contour *model.Contour, contourImage, envoyImage string) if contour.Spec.RuntimeSettings.Envoy.Metrics != nil && contour.Spec.RuntimeSettings.Envoy.Metrics.Port > 0 { metricsPort = int32(contour.Spec.RuntimeSettings.Envoy.Metrics.Port) - } if contour.Spec.RuntimeSettings.Envoy.Health != nil && diff --git a/internal/provisioner/objects/dataplane/dataplane_test.go b/internal/provisioner/objects/dataplane/dataplane_test.go index beb9dd8f6da..09d2579ad49 100644 --- a/internal/provisioner/objects/dataplane/dataplane_test.go +++ b/internal/provisioner/objects/dataplane/dataplane_test.go @@ -174,7 +174,6 @@ func checkDaemonSetHasVolume(t *testing.T, ds *appsv1.DaemonSet, vol corev1.Volu if !(hasVol && hasVolMount) { t.Errorf("daemonset has not found volume or volumeMount") } - } func checkDaemonSetHasResourceRequirements(t *testing.T, ds *appsv1.DaemonSet, expected corev1.ResourceRequirements) { @@ -185,6 +184,7 @@ func checkDaemonSetHasResourceRequirements(t *testing.T, ds *appsv1.DaemonSet, e } t.Errorf("daemonset has unexpected resource requirements %v", expected) } + func checkDaemonSetHasUpdateStrategy(t *testing.T, ds *appsv1.DaemonSet, expected appsv1.DaemonSetUpdateStrategy) { t.Helper() @@ -360,7 +360,6 @@ func TestDesiredDeployment(t *testing.T) { testEnvoyImage := "docker.io/envoyproxy/envoy:test" deploy := desiredDeployment(cntr, testContourImage, testEnvoyImage) checkDeploymentHasStrategy(t, deploy, cntr.Spec.EnvoyDeploymentStrategy) - } func TestNodePlacementDaemonSet(t *testing.T) { diff --git a/internal/provisioner/objects/deployment/deployment_test.go b/internal/provisioner/objects/deployment/deployment_test.go index c53fc85a189..ab5843ce9ff 100644 --- a/internal/provisioner/objects/deployment/deployment_test.go +++ b/internal/provisioner/objects/deployment/deployment_test.go @@ -76,7 +76,6 @@ func checkPodHasAnnotations(t *testing.T, tmpl *corev1.PodTemplateSpec, annotati t.Errorf("pod template has unexpected %q annotations", tmpl.Annotations) } } - } func checkContainerHasArg(t *testing.T, container *corev1.Container, arg string) { @@ -238,5 +237,4 @@ func TestNodePlacementDeployment(t *testing.T) { checkDeploymentHasNodeSelector(t, deploy, selectors) checkDeploymentHasTolerations(t, deploy, tolerations) - } diff --git a/internal/provisioner/objects/service/service.go b/internal/provisioner/objects/service/service.go index f74a8273291..71d972934e6 100644 --- a/internal/provisioner/objects/service/service.go +++ b/internal/provisioner/objects/service/service.go @@ -86,26 +86,24 @@ const ( EnvoyNodePortHTTPSPort = int32(30443) ) -var ( - // InternalLBAnnotations maps cloud providers to the provider's annotation - // key/value pair used for managing an internal load balancer. For additional - // details see: - // https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer - // - InternalLBAnnotations = map[model.LoadBalancerProviderType]map[string]string{ - model.AWSLoadBalancerProvider: { - awsInternalLBAnnotation: "true", - }, - model.AzureLoadBalancerProvider: { - // Azure load balancers are not customizable and are set to (2 fail @ 5s interval, 2 healthy) - azureInternalLBAnnotation: "true", - }, - model.GCPLoadBalancerProvider: { - gcpLBTypeAnnotation: "Internal", - gcpLBTypeAnnotationLegacy: "Internal", - }, - } -) +// InternalLBAnnotations maps cloud providers to the provider's annotation +// key/value pair used for managing an internal load balancer. For additional +// details see: +// +// https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer +var InternalLBAnnotations = map[model.LoadBalancerProviderType]map[string]string{ + model.AWSLoadBalancerProvider: { + awsInternalLBAnnotation: "true", + }, + model.AzureLoadBalancerProvider: { + // Azure load balancers are not customizable and are set to (2 fail @ 5s interval, 2 healthy) + azureInternalLBAnnotation: "true", + }, + model.GCPLoadBalancerProvider: { + gcpLBTypeAnnotation: "Internal", + gcpLBTypeAnnotationLegacy: "Internal", + }, +} // EnsureContourService ensures that a Contour Service exists for the given contour. func EnsureContourService(ctx context.Context, cli client.Client, contour *model.Contour) error { @@ -317,7 +315,6 @@ func updateContourServiceIfNeeded(ctx context.Context, cli client.Client, contou } return nil - } // updateEnvoyServiceIfNeeded updates an Envoy Service if current does not match desired, diff --git a/internal/sorter/sorter.go b/internal/sorter/sorter.go index 133273c5cd2..ae02c649de9 100644 --- a/internal/sorter/sorter.go +++ b/internal/sorter/sorter.go @@ -47,7 +47,7 @@ type headerMatchConditionSorter []dag.HeaderMatchCondition func (s headerMatchConditionSorter) Len() int { return len(s) } func (s headerMatchConditionSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s headerMatchConditionSorter) Less(i, j int) bool { - compareValue := func(a dag.HeaderMatchCondition, b dag.HeaderMatchCondition) bool { + compareValue := func(a, b dag.HeaderMatchCondition) bool { switch strings.Compare(a.Value, b.Value) { case -1: return true @@ -119,7 +119,7 @@ type queryParamMatchConditionSorter []dag.QueryParamMatchCondition func (s queryParamMatchConditionSorter) Len() int { return len(s) } func (s queryParamMatchConditionSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s queryParamMatchConditionSorter) Less(i, j int) bool { - compareValue := func(a dag.QueryParamMatchCondition, b dag.QueryParamMatchCondition) bool { + compareValue := func(a, b dag.QueryParamMatchCondition) bool { switch strings.Compare(a.Value, b.Value) { case -1: return true @@ -419,7 +419,6 @@ type filterChainSorter []*envoy_listener_v3.FilterChain func (s filterChainSorter) Len() int { return len(s) } func (s filterChainSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s filterChainSorter) Less(i, j int) bool { - // If i's ServerNames aren't defined, then it should not swap if len(s[i].FilterChainMatch.ServerNames) == 0 { return false diff --git a/internal/sorter/sorter_test.go b/internal/sorter/sorter_test.go index b28e61afa8d..a362a824c55 100644 --- a/internal/sorter/sorter_test.go +++ b/internal/sorter/sorter_test.go @@ -116,7 +116,7 @@ func invertHeaderMatch(h dag.HeaderMatchCondition) dag.HeaderMatchCondition { return h } -func regexHeader(name string, value string) dag.HeaderMatchCondition { +func regexHeader(name, value string) dag.HeaderMatchCondition { return dag.HeaderMatchCondition{ Name: name, MatchType: dag.HeaderMatchTypeRegex, @@ -124,7 +124,7 @@ func regexHeader(name string, value string) dag.HeaderMatchCondition { } } -func exactHeader(name string, value string) dag.HeaderMatchCondition { +func exactHeader(name, value string) dag.HeaderMatchCondition { return dag.HeaderMatchCondition{ Name: name, MatchType: dag.HeaderMatchTypeExact, @@ -132,7 +132,7 @@ func exactHeader(name string, value string) dag.HeaderMatchCondition { } } -func containsHeader(name string, value string) dag.HeaderMatchCondition { +func containsHeader(name, value string) dag.HeaderMatchCondition { return dag.HeaderMatchCondition{ Name: name, MatchType: dag.HeaderMatchTypeContains, @@ -152,7 +152,7 @@ func ignoreCaseQueryParam(h dag.QueryParamMatchCondition) dag.QueryParamMatchCon return h } -func exactQueryParam(name string, value string) dag.QueryParamMatchCondition { +func exactQueryParam(name, value string) dag.QueryParamMatchCondition { return dag.QueryParamMatchCondition{ Name: name, MatchType: dag.QueryParamMatchTypeExact, @@ -160,7 +160,7 @@ func exactQueryParam(name string, value string) dag.QueryParamMatchCondition { } } -func prefixQueryParam(name string, value string) dag.QueryParamMatchCondition { +func prefixQueryParam(name, value string) dag.QueryParamMatchCondition { return dag.QueryParamMatchCondition{ Name: name, MatchType: dag.QueryParamMatchTypePrefix, @@ -168,7 +168,7 @@ func prefixQueryParam(name string, value string) dag.QueryParamMatchCondition { } } -func suffixQueryParam(name string, value string) dag.QueryParamMatchCondition { +func suffixQueryParam(name, value string) dag.QueryParamMatchCondition { return dag.QueryParamMatchCondition{ Name: name, MatchType: dag.QueryParamMatchTypeSuffix, @@ -176,7 +176,7 @@ func suffixQueryParam(name string, value string) dag.QueryParamMatchCondition { } } -func regexQueryParam(name string, value string) dag.QueryParamMatchCondition { +func regexQueryParam(name, value string) dag.QueryParamMatchCondition { return dag.QueryParamMatchCondition{ Name: name, MatchType: dag.QueryParamMatchTypeRegex, @@ -184,7 +184,7 @@ func regexQueryParam(name string, value string) dag.QueryParamMatchCondition { } } -func containsQueryParam(name string, value string) dag.QueryParamMatchCondition { +func containsQueryParam(name, value string) dag.QueryParamMatchCondition { return dag.QueryParamMatchCondition{ Name: name, MatchType: dag.QueryParamMatchTypeContains, @@ -344,7 +344,6 @@ func TestSortRoutesMethod(t *testing.T) { }, } shuffleAndCheckSort(t, want) - } func TestSortRoutesLongestHeaders(t *testing.T) { diff --git a/internal/status/gatewaystatus.go b/internal/status/gatewaystatus.go index 38a63987eab..9e18444871f 100644 --- a/internal/status/gatewaystatus.go +++ b/internal/status/gatewaystatus.go @@ -44,7 +44,6 @@ func (gatewayUpdate *GatewayStatusUpdate) AddCondition( reason gatewayapi_v1beta1.GatewayConditionReason, message string, ) metav1.Condition { - if c, ok := gatewayUpdate.Conditions[cond]; ok { message = fmt.Sprintf("%s, %s", c.Message, message) } diff --git a/internal/status/proxystatus.go b/internal/status/proxystatus.go index dec24fd60ae..7d2457dd4d2 100644 --- a/internal/status/proxystatus.go +++ b/internal/status/proxystatus.go @@ -62,7 +62,6 @@ func (pu *ProxyUpdate) ConditionFor(cond ConditionType) *projectcontour.Detailed return newDc } return dc - } func (pu *ProxyUpdate) Mutate(obj client.Object) client.Object { @@ -116,5 +115,4 @@ func (pu *ProxyUpdate) Mutate(obj client.Object) client.Object { } return proxy - } diff --git a/internal/status/proxystatus_test.go b/internal/status/proxystatus_test.go index 70164d9bc42..447591b6e5c 100644 --- a/internal/status/proxystatus_test.go +++ b/internal/status/proxystatus_test.go @@ -56,7 +56,6 @@ func TestConditionFor(t *testing.T) { } gotEmpty := emptyProxyUpdate.ConditionFor(ValidCondition) assert.Equal(t, newDc, *gotEmpty) - } func TestStatusMutator(t *testing.T) { diff --git a/internal/xdscache/v3/endpointstranslator.go b/internal/xdscache/v3/endpointstranslator.go index 4c31b82c334..497bddd25e2 100644 --- a/internal/xdscache/v3/endpointstranslator.go +++ b/internal/xdscache/v3/endpointstranslator.go @@ -33,8 +33,10 @@ import ( "k8s.io/client-go/tools/cache" ) -type LocalityEndpoints = envoy_endpoint_v3.LocalityLbEndpoints -type LoadBalancingEndpoint = envoy_endpoint_v3.LbEndpoint +type ( + LocalityEndpoints = envoy_endpoint_v3.LocalityLbEndpoints + LoadBalancingEndpoint = envoy_endpoint_v3.LbEndpoint +) // RecalculateEndpoints generates a slice of LoadBalancingEndpoint // resources by matching the given service port to the given v1.Endpoints. diff --git a/internal/xdscache/v3/listener.go b/internal/xdscache/v3/listener.go index 3cba5ee2aa5..635d797bca0 100644 --- a/internal/xdscache/v3/listener.go +++ b/internal/xdscache/v3/listener.go @@ -612,7 +612,6 @@ func httpGlobalExternalAuthConfig(config *GlobalExternalAuthConfig) *http.HttpFi AuthorizationResponseTimeout: config.ExtensionServiceConfig.Timeout, AuthorizationServerWithRequestBody: config.WithRequestBody, }) - } func envoyGlobalRateLimitConfig(config *RateLimitConfig) *envoy_v3.GlobalRateLimitConfig { @@ -651,7 +650,7 @@ func envoyTracingConfigCustomTag(tags []*CustomTag) []*envoy_v3.CustomTag { if tags == nil { return nil } - var customTags = make([]*envoy_v3.CustomTag, len(tags)) + customTags := make([]*envoy_v3.CustomTag, len(tags)) for i, tag := range tags { customTags[i] = &envoy_v3.CustomTag{ TagName: tag.TagName, diff --git a/internal/xdscache/v3/listener_test.go b/internal/xdscache/v3/listener_test.go index c50baa84f52..d72ddc56814 100644 --- a/internal/xdscache/v3/listener_test.go +++ b/internal/xdscache/v3/listener_test.go @@ -212,7 +212,6 @@ func TestListenerVisit(t *testing.T) { objs []any want map[string]*envoy_listener_v3.Listener }{ - "nothing": { objs: nil, want: map[string]*envoy_listener_v3.Listener{}, @@ -1619,7 +1618,8 @@ func TestListenerVisit(t *testing.T) { TransportSocket: transportSocket("fallbacksecret", envoy_tls_v3.TlsParameters_TLSv1_2, envoy_tls_v3.TlsParameters_TLSv1_3, nil, "h2", "http/1.1"), Filters: envoy_v3.Filters(fallbackCertFilter), Name: "fallback-certificate", - }}, + }, + }, ListenerFilters: envoy_v3.ListenerFilters( envoy_v3.TLSInspector(), ), @@ -3237,7 +3237,6 @@ func TestListenerVisit(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - lc := ListenerCache{ Config: tc.ListenerConfig, } diff --git a/internal/xdscache/v3/route_test.go b/internal/xdscache/v3/route_test.go index ff167ff4ee8..daaeeff228d 100644 --- a/internal/xdscache/v3/route_test.go +++ b/internal/xdscache/v3/route_test.go @@ -3978,7 +3978,6 @@ func routecluster(cluster string) *envoy_route_v3.Route_Route { }, }, } - } func websocketroute(c string) *envoy_route_v3.Route_Route { @@ -3997,7 +3996,7 @@ func routetimeout(cluster string, timeout time.Duration) *envoy_route_v3.Route_R return r } -func routeretry(cluster string, retryOn string, numRetries uint32, perTryTimeout time.Duration) *envoy_route_v3.Route_Route { +func routeretry(cluster, retryOn string, numRetries uint32, perTryTimeout time.Duration) *envoy_route_v3.Route_Route { r := routecluster(cluster) r.Route.RetryPolicy = &envoy_route_v3.RetryPolicy{ RetryOn: retryOn, diff --git a/internal/xdscache/v3/server_test.go b/internal/xdscache/v3/server_test.go index e22e0d250c2..33f8d1d2d72 100644 --- a/internal/xdscache/v3/server_test.go +++ b/internal/xdscache/v3/server_test.go @@ -280,7 +280,8 @@ func TestGRPC(t *testing.T) { func sendreq(t *testing.T, stream interface { Send(*discovery.DiscoveryRequest) error -}, typeurl string) { +}, typeurl string, +) { t.Helper() err := stream.Send(&discovery.DiscoveryRequest{ TypeUrl: typeurl, @@ -290,7 +291,8 @@ func sendreq(t *testing.T, stream interface { func checkrecv(t *testing.T, stream interface { Recv() (*discovery.DiscoveryResponse, error) -}) { +}, +) { t.Helper() _, err := stream.Recv() require.NoError(t, err) @@ -298,7 +300,8 @@ func checkrecv(t *testing.T, stream interface { func checktimeout(t *testing.T, stream interface { Recv() (*discovery.DiscoveryResponse, error) -}) { +}, +) { t.Helper() _, err := stream.Recv() require.Errorf(t, err, "expected timeout") diff --git a/pkg/certs/certgen.go b/pkg/certs/certgen.go index eb9556ac8a1..6120358d48e 100644 --- a/pkg/certs/certgen.go +++ b/pkg/certs/certgen.go @@ -57,7 +57,6 @@ const ( // Configuration holds config parameters used for generating certificates. type Configuration struct { - // Lifetime is the number of days for which certificates will be valid. Lifetime uint @@ -90,7 +89,6 @@ type Certificates struct { // GenerateCerts generates a CA Certificate along with certificates for // Contour & Envoy returning them as a *Certificates struct or error if encountered. func GenerateCerts(config *Configuration) (*Certificates, error) { - // Check if the config is not passed, then default. if config == nil { config = &Configuration{} @@ -139,7 +137,6 @@ func GenerateCerts(config *Configuration) (*Certificates, error) { // of the Kubernetes DNS schema.) // The return values are cert, key, err. func newCert(caCertPEM, caKeyPEM []byte, expiry time.Time, service, namespace, dnsname string) ([]byte, []byte, error) { - caKeyPair, err := tls.X509KeyPair(caCertPEM, caKeyPEM) if err != nil { return nil, nil, err @@ -187,13 +184,11 @@ func newCert(caCertPEM, caKeyPEM []byte, expiry time.Time, service, namespace, d Bytes: newCert, }) return newCertPEM, newKeyPEM, nil - } // newCA generates a new CA, given the CA's CN and an expiry time. // The return order is cacert, cakey, error. func newCA(cn string, expiry time.Time) ([]byte, []byte, error) { - key, err := rsa.GenerateKey(rand.Reader, keySize) if err != nil { return nil, nil, err @@ -256,14 +251,14 @@ func serviceNames(service, namespace, dnsname string) []string { } } -func stringOrDefault(val string, defaultval string) string { +func stringOrDefault(val, defaultval string) string { if len(val) > 0 { return val } return defaultval } -func uint32OrDefault(val uint, defaultval uint) uint { +func uint32OrDefault(val, defaultval uint) uint { if val != 0 { return val } diff --git a/pkg/certs/certgen_test.go b/pkg/certs/certgen_test.go index 969e5410e30..0fb0c2b07ee 100644 --- a/pkg/certs/certgen_test.go +++ b/pkg/certs/certgen_test.go @@ -114,7 +114,6 @@ func TestGenerateCerts(t *testing.T) { } func TestGeneratedCertsValid(t *testing.T) { - now := time.Now() expiry := now.Add(24 * 365 * time.Hour) @@ -151,7 +150,6 @@ func TestGeneratedCertsValid(t *testing.T) { require.NoErrorf(t, err, "Validating %s failed", name) }) } - } func verifyCert(certPEM []byte, roots *x509.CertPool, dnsname string, currentTime time.Time) error { diff --git a/pkg/config/parameters.go b/pkg/config/parameters.go index 7d1eca4f99a..f2ec400039b 100644 --- a/pkg/config/parameters.go +++ b/pkg/config/parameters.go @@ -31,8 +31,10 @@ import ( // ServerType is the name of a xDS server implementation. type ServerType string -const ContourServerType ServerType = "contour" -const EnvoyServerType ServerType = "envoy" +const ( + ContourServerType ServerType = "contour" + EnvoyServerType ServerType = "envoy" +) // Validate the xDS server type. func (s ServerType) Validate() error { @@ -89,10 +91,12 @@ func (c ClusterDNSFamilyType) Validate() error { } } -const AutoClusterDNSFamily ClusterDNSFamilyType = "auto" -const IPv4ClusterDNSFamily ClusterDNSFamilyType = "v4" -const IPv6ClusterDNSFamily ClusterDNSFamilyType = "v6" -const AllClusterDNSFamily ClusterDNSFamilyType = "all" +const ( + AutoClusterDNSFamily ClusterDNSFamilyType = "auto" + IPv4ClusterDNSFamily ClusterDNSFamilyType = "v4" + IPv6ClusterDNSFamily ClusterDNSFamilyType = "v6" + AllClusterDNSFamily ClusterDNSFamilyType = "all" +) // ServerHeaderTransformation defines the action to be applied to the Server header on the response path type ServerHeaderTransformationType string @@ -106,9 +110,11 @@ func (s ServerHeaderTransformationType) Validate() error { } } -const OverwriteServerHeader ServerHeaderTransformationType = "overwrite" -const AppendIfAbsentServerHeader ServerHeaderTransformationType = "append_if_absent" -const PassThroughServerHeader ServerHeaderTransformationType = "pass_through" +const ( + OverwriteServerHeader ServerHeaderTransformationType = "overwrite" + AppendIfAbsentServerHeader ServerHeaderTransformationType = "append_if_absent" + PassThroughServerHeader ServerHeaderTransformationType = "pass_through" +) // AccessLogType is the name of a supported access logging mechanism. type AccessLogType string @@ -117,8 +123,10 @@ func (a AccessLogType) Validate() error { return contour_api_v1alpha1.AccessLogType(a).Validate() } -const EnvoyAccessLog AccessLogType = "envoy" -const JSONAccessLog AccessLogType = "json" +const ( + EnvoyAccessLog AccessLogType = "envoy" + JSONAccessLog AccessLogType = "json" +) type AccessLogFields []string @@ -153,8 +161,10 @@ func (h HTTPVersionType) Validate() error { } } -const HTTPVersion1 HTTPVersionType = "http/1.1" -const HTTPVersion2 HTTPVersionType = "http/2" +const ( + HTTPVersion1 HTTPVersionType = "http/1.1" + HTTPVersion2 HTTPVersionType = "http/2" +) // NamespacedName defines the namespace/name of the Kubernetes resource referred from the configuration file. // Used for Contour configuration YAML file parsing, otherwise we could use K8s types.NamespacedName. @@ -963,10 +973,12 @@ func (a AccessLogLevel) Validate() error { return contour_api_v1alpha1.AccessLogLevel(a).Validate() } -const LogLevelInfo AccessLogLevel = "info" // Default log level. -const LogLevelError AccessLogLevel = "error" -const LogLevelCritical AccessLogLevel = "critical" -const LogLevelDisabled AccessLogLevel = "disabled" +const ( + LogLevelInfo AccessLogLevel = "info" // Default log level. + LogLevelError AccessLogLevel = "error" + LogLevelCritical AccessLogLevel = "critical" + LogLevelDisabled AccessLogLevel = "disabled" +) // Validate verifies that the parameter values do not have any syntax errors. func (p *Parameters) Validate() error { @@ -1105,7 +1117,7 @@ func Parse(in io.Reader) (*Parameters, error) { } // GetenvOr reads an environment or return a default value -func GetenvOr(key string, defaultVal string) string { +func GetenvOr(key, defaultVal string) string { if value, exists := os.LookupEnv(key); exists { return value } diff --git a/pkg/config/parameters_test.go b/pkg/config/parameters_test.go index 1984091f568..60e8dda17e7 100644 --- a/pkg/config/parameters_test.go +++ b/pkg/config/parameters_test.go @@ -235,7 +235,6 @@ func TestValidateTimeoutParams(t *testing.T) { require.Error(t, TimeoutParameters{DelayedCloseTimeout: "bebop"}.Validate()) require.Error(t, TimeoutParameters{ConnectionShutdownGracePeriod: "bong"}.Validate()) require.Error(t, TimeoutParameters{ConnectTimeout: "infinite"}.Validate()) - } func TestTLSParametersValidation(t *testing.T) { @@ -386,7 +385,6 @@ default-http-versions: listener: connection-balancer: notexact `) - } func TestConfigFileDefaultOverrideImport(t *testing.T) { @@ -508,7 +506,6 @@ cluster: max-pending-requests: 43 max-requests: 44 `) - } func TestMetricsParametersValidation(t *testing.T) { @@ -565,7 +562,6 @@ func TestMetricsParametersValidation(t *testing.T) { }, } require.Error(t, tlsCAWithoutServerCert.Validate()) - } func TestListenerValidation(t *testing.T) { diff --git a/test/e2e/deployment.go b/test/e2e/deployment.go index 16227b8cc0a..dae0fce22f9 100644 --- a/test/e2e/deployment.go +++ b/test/e2e/deployment.go @@ -375,7 +375,7 @@ func (d *Deployment) WaitForEnvoyUpdated() error { return WaitForEnvoyDeploymentUpdated(d.EnvoyDeployment, d.client, d.contourImage) } -func (d *Deployment) EnsureRateLimitResources(namespace string, configContents string) error { +func (d *Deployment) EnsureRateLimitResources(namespace, configContents string) error { setNamespace := d.Namespace.Name if len(namespace) > 0 { setNamespace = namespace @@ -606,7 +606,6 @@ func (d *Deployment) DeleteResourcesForLocalContour() error { // file. Returns running Contour command and config file so we can clean them // up. func (d *Deployment) StartLocalContour(config *config.Parameters, contourConfiguration *contour_api_v1alpha1.ContourConfiguration, additionalArgs ...string) (*gexec.Session, string, error) { - var content []byte var configReferenceName string var contourServeArgs []string @@ -651,7 +650,7 @@ func (d *Deployment) StartLocalContour(config *config.Parameters, contourConfigu if err != nil { return nil, "", err } - if err := os.WriteFile(configFile.Name(), content, 0600); err != nil { + if err := os.WriteFile(configFile.Name(), content, 0o600); err != nil { return nil, "", err } diff --git a/test/e2e/framework.go b/test/e2e/framework.go index 2fd3252f591..7ab06cb85b3 100644 --- a/test/e2e/framework.go +++ b/test/e2e/framework.go @@ -280,9 +280,11 @@ func (f *Framework) T() ginkgo.GinkgoTInterface { return f.t } -type NamespacedGatewayTestBody func(ns string, gw types.NamespacedName) -type NamespacedTestBody func(string) -type TestBody func() +type ( + NamespacedGatewayTestBody func(ns string, gw types.NamespacedName) + NamespacedTestBody func(string) + TestBody func() +) func (f *Framework) NamespacedTest(namespace string, body NamespacedTestBody, additionalNamespaces ...string) { ginkgo.Context("with namespace: "+namespace, func() { @@ -499,7 +501,6 @@ func UsingContourConfigCRD() bool { // HTTPProxyValid returns true if the proxy has a .status.currentStatus // of "valid". func HTTPProxyValid(proxy *contourv1.HTTPProxy) bool { - if proxy == nil { return false } @@ -510,7 +511,6 @@ func HTTPProxyValid(proxy *contourv1.HTTPProxy) bool { cond := proxy.Status.GetConditionFor("Valid") return cond.Status == "True" - } // HTTPProxyInvalid returns true if the proxy has a .status.currentStatus diff --git a/test/e2e/gateway/tls_gateway_test.go b/test/e2e/gateway/tls_gateway_test.go index 29cde85f9f6..d6ed72a3cd3 100644 --- a/test/e2e/gateway/tls_gateway_test.go +++ b/test/e2e/gateway/tls_gateway_test.go @@ -53,7 +53,6 @@ func testTLSGateway(namespace string, gateway types.NamespacedName) { }, Rules: []gatewayapi_v1beta1.HTTPRouteRule{ { - Matches: gatewayapi.HTTPRouteMatch(gatewayapi_v1.PathMatchPathPrefix, "/"), BackendRefs: gatewayapi.HTTPBackendRef("echo-insecure", 80, 1), }, diff --git a/test/e2e/httpproxy/backend_tls_protocol_version_test.go b/test/e2e/httpproxy/backend_tls_protocol_version_test.go index 5575dafcf25..d3ae8a39221 100644 --- a/test/e2e/httpproxy/backend_tls_protocol_version_test.go +++ b/test/e2e/httpproxy/backend_tls_protocol_version_test.go @@ -97,6 +97,5 @@ func testBackendTLSProtocolVersion(namespace, protocolVersion string) { tlsInfo := new(responseTLSDetails) require.NoError(f.T(), json.Unmarshal(res.Body, tlsInfo)) assert.Equal(f.T(), tlsInfo.TLS.Version, protocolVersion) - }) } diff --git a/test/e2e/httpproxy/cel_validation_test.go b/test/e2e/httpproxy/cel_validation_test.go index 584af6017bf..3de95a80d92 100644 --- a/test/e2e/httpproxy/cel_validation_test.go +++ b/test/e2e/httpproxy/cel_validation_test.go @@ -64,6 +64,5 @@ func testCELValidation(namespace string) { return strings.Contains(err.Error(), "subjectNames[0] must equal subjectName if set") } assert.True(t, isExpectedErr(err)) - }) } diff --git a/test/e2e/httpproxy/client_cert_auth_test.go b/test/e2e/httpproxy/client_cert_auth_test.go index 553ca46e404..85e0f74c753 100644 --- a/test/e2e/httpproxy/client_cert_auth_test.go +++ b/test/e2e/httpproxy/client_cert_auth_test.go @@ -149,7 +149,6 @@ func testClientCertAuth(namespace string) { Name: "echo-no-auth-cert", }, Spec: certmanagerv1.CertificateSpec{ - Usages: []certmanagerv1.KeyUsage{ certmanagerv1.UsageServerAuth, }, @@ -192,7 +191,6 @@ func testClientCertAuth(namespace string) { Name: "echo-with-auth-skip-verify-cert", }, Spec: certmanagerv1.CertificateSpec{ - Usages: []certmanagerv1.KeyUsage{ certmanagerv1.UsageServerAuth, }, @@ -214,7 +212,6 @@ func testClientCertAuth(namespace string) { Name: "echo-with-auth-skip-verify-with-ca-cert", }, Spec: certmanagerv1.CertificateSpec{ - Usages: []certmanagerv1.KeyUsage{ certmanagerv1.UsageServerAuth, }, @@ -236,7 +233,6 @@ func testClientCertAuth(namespace string) { Name: "echo-with-optional-auth-cert", }, Spec: certmanagerv1.CertificateSpec{ - Usages: []certmanagerv1.KeyUsage{ certmanagerv1.UsageServerAuth, }, @@ -258,7 +254,6 @@ func testClientCertAuth(namespace string) { Name: "echo-with-optional-auth-no-ca-cert", }, Spec: certmanagerv1.CertificateSpec{ - Usages: []certmanagerv1.KeyUsage{ certmanagerv1.UsageServerAuth, }, diff --git a/test/e2e/httpproxy/client_cert_crl_test.go b/test/e2e/httpproxy/client_cert_crl_test.go index 7b2e7d1cd65..8a226b6e051 100644 --- a/test/e2e/httpproxy/client_cert_crl_test.go +++ b/test/e2e/httpproxy/client_cert_crl_test.go @@ -456,7 +456,6 @@ func testClientCertRevocation(namespace string) { require.NotNil(t, res, "expected 200 response code, request was never successful") assert.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode) - }) } diff --git a/test/e2e/httpproxy/direct_response_test.go b/test/e2e/httpproxy/direct_response_test.go index 5977f7a3243..254ac4f5548 100644 --- a/test/e2e/httpproxy/direct_response_test.go +++ b/test/e2e/httpproxy/direct_response_test.go @@ -47,7 +47,6 @@ func doDirectTest(namespace string, proxy *contour_api_v1.HTTPProxy, t GinkgoTIn assertDirectResponseRequest(t, proxy.Spec.VirtualHost.Fqdn, "/directresponse-notfound", "not found", 404) - } func assertDirectResponseRequest(t GinkgoTInterface, fqdn, path, expectedBody string, expectedStatusCode int) { diff --git a/test/e2e/httpproxy/fqdn_test.go b/test/e2e/httpproxy/fqdn_test.go index cb7b2a1fbed..881fed97b09 100644 --- a/test/e2e/httpproxy/fqdn_test.go +++ b/test/e2e/httpproxy/fqdn_test.go @@ -54,11 +54,9 @@ func testWildcardFQDN(namespace string) { err := f.CreateHTTPProxy(p) require.Error(t, err, "Expected invalid wildcard to be rejected.") }) - } func testWildcardSubdomainFQDN(namespace string) { - Specify("wildcard routing works", func() { t := f.T() diff --git a/test/e2e/httpproxy/header_condition_match_test.go b/test/e2e/httpproxy/header_condition_match_test.go index ca51d8ae892..d2db431beeb 100644 --- a/test/e2e/httpproxy/header_condition_match_test.go +++ b/test/e2e/httpproxy/header_condition_match_test.go @@ -167,7 +167,6 @@ func testHeaderConditionMatch(namespace string) { { Services: []contourv1.Service{ { - Name: "echo-header-exact-case-insensitive", Port: 80, }, diff --git a/test/e2e/httpproxy/httpproxy_test.go b/test/e2e/httpproxy/httpproxy_test.go index be030dfb3a0..7fdd2264a40 100644 --- a/test/e2e/httpproxy/httpproxy_test.go +++ b/test/e2e/httpproxy/httpproxy_test.go @@ -385,7 +385,6 @@ var _ = Describe("HTTPProxy", func() { testBackendTLSProtocolVersion(namespace, expectedProtocolVersion) }) - }) f.NamespacedTest("httpproxy-external-auth", testExternalAuth) @@ -857,5 +856,4 @@ descriptors: f.NamespacedTest("httpproxy-global-ext-auth-tls-disabled", withGlobalExtAuth(testGlobalExternalAuthTLSAuthDisabled)) }) - }) diff --git a/test/e2e/httpproxy/internal_redirect_test.go b/test/e2e/httpproxy/internal_redirect_test.go index 32e5068ea79..7dfa147a75a 100644 --- a/test/e2e/httpproxy/internal_redirect_test.go +++ b/test/e2e/httpproxy/internal_redirect_test.go @@ -101,7 +101,6 @@ func testInternalRedirectPolicy(namespace string) { } func doInternalRedirectTest(namespace string, proxy *contour_api_v1.HTTPProxy, t GinkgoTInterface) { - f.Fixtures.Echo.Deploy(namespace, "echo") envoyService := &corev1.Service{ @@ -235,7 +234,8 @@ func getInternalRedirectHTTPProxy(namespace string) *contour_api_v1.HTTPProxy { InternalRedirectPolicy: &contour_api_v1.HTTPInternalRedirectPolicy{ RedirectResponseCodes: []contour_api_v1.RedirectResponseCode{301}, }, - }}, + }, + }, }, } diff --git a/test/e2e/httpproxy/request_redirect_test.go b/test/e2e/httpproxy/request_redirect_test.go index a90f63fbdfe..d95d48564fe 100644 --- a/test/e2e/httpproxy/request_redirect_test.go +++ b/test/e2e/httpproxy/request_redirect_test.go @@ -44,7 +44,6 @@ func testRequestRedirectRuleNoService(namespace string) { func testRequestRedirectRuleInvalid(namespace string) { Specify("invalid policy specified on route rule", func() { - f.Fixtures.Echo.Deploy(namespace, "echo") proxy := getRedirectHTTPProxyInvalid(namespace) @@ -53,7 +52,6 @@ func testRequestRedirectRuleInvalid(namespace string) { } func doRedirectTest(namespace string, proxy *contour_api_v1.HTTPProxy, t GinkgoTInterface) { - f.Fixtures.Echo.Deploy(namespace, "echo") f.CreateHTTPProxyAndWaitFor(proxy, e2e.HTTPProxyValid) @@ -94,7 +92,6 @@ func assertRequest(t GinkgoTInterface, fqdn, path, expectedLocation string, expe } func getRedirectHTTPProxy(namespace string, removeServices bool) *contour_api_v1.HTTPProxy { - proxy := &contour_api_v1.HTTPProxy{ ObjectMeta: metav1.ObjectMeta{ Name: "redirect", @@ -177,7 +174,6 @@ func getRedirectHTTPProxy(namespace string, removeServices bool) *contour_api_v1 } func getRedirectHTTPProxyInvalid(namespace string) *contour_api_v1.HTTPProxy { - proxy := &contour_api_v1.HTTPProxy{ ObjectMeta: metav1.ObjectMeta{ Name: "invalid", diff --git a/test/e2e/infra/infra_test.go b/test/e2e/infra/infra_test.go index 8753fe55d48..22726a9f21a 100644 --- a/test/e2e/infra/infra_test.go +++ b/test/e2e/infra/infra_test.go @@ -53,7 +53,8 @@ var _ = BeforeSuite(func() { VolumeSource: v1.VolumeSource{ Secret: &v1.SecretVolumeSource{ SecretName: "metrics-server", - }}, + }, + }, }} require.NoError(f.T(), f.Deployment.EnsureResourcesForLocalContour()) diff --git a/test/e2e/ingress/ingress_test.go b/test/e2e/ingress/ingress_test.go index e6a536369cc..761dea5185b 100644 --- a/test/e2e/ingress/ingress_test.go +++ b/test/e2e/ingress/ingress_test.go @@ -251,6 +251,5 @@ var _ = Describe("Ingress", func() { f.NamespacedTest("global-headers-policy-apply-to-ingress-true", testGlobalHeadersPolicy(true)) }) - }) }) diff --git a/test/e2e/poller.go b/test/e2e/poller.go index c5f845fdab7..63f92c04223 100644 --- a/test/e2e/poller.go +++ b/test/e2e/poller.go @@ -34,7 +34,7 @@ type AppPoller struct { successfulRequests uint } -func StartAppPoller(address string, hostName string, expectedStatus int, errorWriter io.Writer) (*AppPoller, error) { +func StartAppPoller(address, hostName string, expectedStatus int, errorWriter io.Writer) (*AppPoller, error) { ctx, cancel := context.WithCancel(context.Background()) poller := &AppPoller{ diff --git a/test/e2e/upgrade/upgrade_test.go b/test/e2e/upgrade/upgrade_test.go index 49f794ac3c8..8aed3611564 100644 --- a/test/e2e/upgrade/upgrade_test.go +++ b/test/e2e/upgrade/upgrade_test.go @@ -137,7 +137,7 @@ var _ = Describe("When upgrading", func() { }) }) - var _ = Describe("the Gateway provisioner", func() { + _ = Describe("the Gateway provisioner", func() { const gatewayClassName = "upgrade-gc" BeforeEach(func() { diff --git a/test/e2e/waiter.go b/test/e2e/waiter.go index f4148d72a2c..5d46c1ddcf3 100644 --- a/test/e2e/waiter.go +++ b/test/e2e/waiter.go @@ -85,7 +85,7 @@ func WaitForEnvoyDeploymentUpdated(deployment *appsv1.Deployment, cli client.Cli return wait.PollUntilContextTimeout(context.Background(), time.Millisecond*50, time.Minute*3, true, updatedPods) } -func getPodsUpdatedWithContourImage(ctx context.Context, labelSelector labels.Selector, namespace string, image string, cli client.Client) int { +func getPodsUpdatedWithContourImage(ctx context.Context, labelSelector labels.Selector, namespace, image string, cli client.Client) int { pods := new(v1.PodList) opts := &client.ListOptions{ LabelSelector: labelSelector,