Repository: kumahq/kuma
Pull request #4077 (2022-03-29 16:08:02)

chore(kumactl): prefix MeshGatewayRoutes with ROUTE in inspect dataplane output
### Summary

The output is otherwise confusing if the route's name doesn't make it clear it's a route.

codecov-commenter: # [Codecov](https://codecov.io/gh/kumahq/kuma/pull/4077?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq) Report
> Merging [#4077](https://codecov.io/gh/kumahq/kuma/pull/4077?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq) (25359fe) into [master](https://codecov.io/gh/kumahq/kuma/commit/3533601bfcad82b40828d4419c3c9a3f35bbfe29?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq) (3533601) will **decrease** coverage by `0.01%`.
> The diff coverage is `n/a`.

```diff
@@            Coverage Diff             @@
##           master    #4077      +/-   ##
==========================================
- Coverage   55.84%   55.82%   -0.02%     
==========================================
  Files         922      922              
  Lines       55451    55451              
==========================================
- Hits        30966    30958       -8     
- Misses      22034    22040       +6     
- Partials     2451     2453       +2     
```


| [Impacted Files](https://codecov.io/gh/kumahq/kuma/pull/4077?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq) | Coverage Δ | |
|---|---|---|
| [app/kumactl/cmd/inspect/inspect\_dataplane.go](https://codecov.io/gh/kumahq/kuma/pull/4077/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-YXBwL2t1bWFjdGwvY21kL2luc3BlY3QvaW5zcGVjdF9kYXRhcGxhbmUuZ28=) | `61.53% <ø> (ø)` | |
| [pkg/xds/cache/once/cache.go](https://codecov.io/gh/kumahq/kuma/pull/4077/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-cGtnL3hkcy9jYWNoZS9vbmNlL2NhY2hlLmdv) | `87.17% <0.00%> (-7.70%)` | :arrow_down: |
| [pkg/defaults/components.go](https://codecov.io/gh/kumahq/kuma/pull/4077/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-cGtnL2RlZmF1bHRzL2NvbXBvbmVudHMuZ28=) | `85.18% <0.00%> (-3.71%)` | :arrow_down: |
| [pkg/core/resources/manager/cache.go](https://codecov.io/gh/kumahq/kuma/pull/4077/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-cGtnL2NvcmUvcmVzb3VyY2VzL21hbmFnZXIvY2FjaGUuZ28=) | `83.11% <0.00%> (-2.60%)` | :arrow_down: |
| [pkg/xds/generator/direct\_access\_proxy\_generator.go](https://codecov.io/gh/kumahq/kuma/pull/4077/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-cGtnL3hkcy9nZW5lcmF0b3IvZGlyZWN0X2FjY2Vzc19wcm94eV9nZW5lcmF0b3IuZ28=) | `89.65% <0.00%> (-1.15%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/kumahq/kuma/pull/4077?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/kumahq/kuma/pull/4077?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq). Last update [3533601...25359fe](https://codecov.io/gh/kumahq/kuma/pull/4077?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq).


Patch:
diff --git a/app/kumactl/cmd/inspect/inspect_dataplane.go b/app/kumactl/cmd/inspect/inspect_dataplane.go
index 8035cff61..9efea2057 100644
--- a/app/kumactl/cmd/inspect/inspect_dataplane.go
+++ b/app/kumactl/cmd/inspect/inspect_dataplane.go
@@ -24,7 +24,7 @@ var dataplaneInspectTemplate = `{{ with IsSidecar . }}{{ range $num, $item := .I
 {{ end }}
 {{ range .Listeners }}LISTENER ({{ .Protocol }}:{{ .Port }}):
 {{ range .Hosts }}  {{ .HostName }}:
-{{ range .Routes }}    {{ .Route }}:
+{{ range .Routes }}    ROUTE {{ .Route }}:
 {{ range .Destinations }}      {{ FormatTags .Tags }}:
 {{ range $typ, $policy := .Policies }}        {{ $typ }}
           {{ .Meta.Name }}
diff --git a/pkg/defaults/mesh/circuit_breaker.go b/pkg/defaults/mesh/circuit_breaker.go
index b0eb94d7e..932f1cf0b 100644
--- a/pkg/defaults/mesh/circuit_breaker.go
+++ b/pkg/defaults/mesh/circuit_breaker.go
@@ -3,24 +3,27 @@ package mesh
 import (
 	mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
 	core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
+	"github.com/kumahq/kuma/pkg/core/resources/model"
 	util_proto "github.com/kumahq/kuma/pkg/util/proto"
 )
 
-var defaultCircuitBreakerResource = &core_mesh.CircuitBreakerResource{
-	Spec: &mesh_proto.CircuitBreaker{
-		Sources: []*mesh_proto.Selector{{
-			Match: mesh_proto.MatchAnyService(),
-		}},
-		Destinations: []*mesh_proto.Selector{{
-			Match: mesh_proto.MatchAnyService(),
-		}},
-		Conf: &mesh_proto.CircuitBreaker_Conf{
-			Thresholds: &mesh_proto.CircuitBreaker_Conf_Thresholds{
-				MaxConnections:     util_proto.UInt32(1024),
-				MaxPendingRequests: util_proto.UInt32(1024),
-				MaxRequests:        util_proto.UInt32(1024),
-				MaxRetries:         util_proto.UInt32(3),
+var defaultCircuitBreakerResource = func() model.Resource {
+	return &core_mesh.CircuitBreakerResource{
+		Spec: &mesh_proto.CircuitBreaker{
+			Sources: []*mesh_proto.Selector{{
+				Match: mesh_proto.MatchAnyService(),
+			}},
+			Destinations: []*mesh_proto.Selector{{
+				Match: mesh_proto.MatchAnyService(),
+			}},
+			Conf: &mesh_proto.CircuitBreaker_Conf{
+				Thresholds: &mesh_proto.CircuitBreaker_Conf_Thresholds{
+					MaxConnections:     util_proto.UInt32(1024),
+					MaxPendingRequests: util_proto.UInt32(1024),
+					MaxRequests:        util_proto.UInt32(1024),
+					MaxRetries:         util_proto.UInt32(3),
+				},
 			},
 		},
-	},
+	}
 }
diff --git a/pkg/defaults/mesh/mesh.go b/pkg/defaults/mesh/mesh.go
index 0d189ebd0..155e8e5f2 100644
--- a/pkg/defaults/mesh/mesh.go
+++ b/pkg/defaults/mesh/mesh.go
@@ -30,7 +30,7 @@ func EnsureDefaultMeshResources(ctx context.Context, resManager manager.Resource
 
 	log.Info("ensuring default resources for Mesh exist", "mesh", meshName)
 
-	defaultResources := map[string]model.Resource{
+	defaultResourceBuilders := map[string]func() model.Resource{
 		"allow-all":           defaultTrafficPermissionResource,
 		"route-all":           defaultTrafficRouteResource,
 		"timeout-all":         defaultTimeoutResource,
@@ -38,12 +38,12 @@ func EnsureDefaultMeshResources(ctx context.Context, resManager manager.Resource
 		"retry-all":           defaultRetryResource,
 	}
 
-	for prefix, resource := range defaultResources {
+	for prefix, resourceBuilder := range defaultResourceBuilders {
 		key := model.ResourceKey{
 			Mesh: meshName,
 			Name: fmt.Sprintf("%s-%s", prefix, meshName),
 		}
-
+		resource := resourceBuilder()
 		err, created := ensureDefaultResource(ctx, resManager, resource, key)
 		if err != nil {
 			return errors.Wrapf(err, "could not create default %s %q", resource.Descriptor().Name, key.Name)
diff --git a/pkg/defaults/mesh/retry.go b/pkg/defaults/mesh/retry.go
index 2e7b23770..017783543 100644
--- a/pkg/defaults/mesh/retry.go
+++ b/pkg/defaults/mesh/retry.go
@@ -5,45 +5,48 @@ import (
 
 	mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
 	core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
+	"github.com/kumahq/kuma/pkg/core/resources/model"
 	util_proto "github.com/kumahq/kuma/pkg/util/proto"
 )
 
-var defaultRetryResource = &core_mesh.RetryResource{
-	Spec: &mesh_proto.Retry{
-		Sources: []*mesh_proto.Selector{
-			{
-				Match: map[string]string{
-					mesh_proto.ServiceTag: "*",
+var defaultRetryResource = func() model.Resource {
+	return &core_mesh.RetryResource{
+		Spec: &mesh_proto.Retry{
+			Sources: []*mesh_proto.Selector{
+				{
+					Match: map[string]string{
+						mesh_proto.ServiceTag: "*",
+					},
 				},
 			},
-		},
-		Destinations: []*mesh_proto.Selector{
-			{
-				Match: map[string]string{
-					mesh_proto.ServiceTag: "*",
+			Destinations: []*mesh_proto.Selector{
+				{
+					Match: map[string]string{
+						mesh_proto.ServiceTag: "*",
+					},
 				},
 			},
-		},
-		Conf: &mesh_proto.Retry_Conf{
-			Http: &mesh_proto.Retry_Conf_Http{
-				NumRetries:    util_proto.UInt32(5),
-				PerTryTimeout: util_proto.Duration(16 * time.Second),
-				BackOff: &mesh_proto.Retry_Conf_BackOff{
-					BaseInterval: util_proto.Duration(25 * time.Millisecond),
-					MaxInterval:  util_proto.Duration(250 * time.Millisecond),
+			Conf: &mesh_proto.Retry_Conf{
+				Http: &mesh_proto.Retry_Conf_Http{
+					NumRetries:    util_proto.UInt32(5),
+					PerTryTimeout: util_proto.Duration(16 * time.Second),
+					BackOff: &mesh_proto.Retry_Conf_BackOff{
+						BaseInterval: util_proto.Duration(25 * time.Millisecond),
+						MaxInterval:  util_proto.Duration(250 * time.Millisecond),
+					},
 				},
-			},
-			Tcp: &mesh_proto.Retry_Conf_Tcp{
-				MaxConnectAttempts: 5,
-			},
-			Grpc: &mesh_proto.Retry_Conf_Grpc{
-				NumRetries:    util_proto.UInt32(5),
-				PerTryTimeout: util_proto.Duration(16 * time.Second),
-				BackOff: &mesh_proto.Retry_Conf_BackOff{
-					BaseInterval: util_proto.Duration(25 * time.Millisecond),
-					MaxInterval:  util_proto.Duration(250 * time.Millisecond),
+				Tcp: &mesh_proto.Retry_Conf_Tcp{
+					MaxConnectAttempts: 5,
+				},
+				Grpc: &mesh_proto.Retry_Conf_Grpc{
+					NumRetries:    util_proto.UInt32(5),
+					PerTryTimeout: util_proto.Duration(16 * time.Second),
+					BackOff: &mesh_proto.Retry_Conf_BackOff{
+						BaseInterval: util_proto.Duration(25 * time.Millisecond),
+						MaxInterval:  util_proto.Duration(250 * time.Millisecond),
+					},
 				},
 			},
 		},
-	},
+	}
 }
diff --git a/pkg/defaults/mesh/timeout.go b/pkg/defaults/mesh/timeout.go
index ca062ac41..239a54bf8 100644
--- a/pkg/defaults/mesh/timeout.go
+++ b/pkg/defaults/mesh/timeout.go
@@ -5,29 +5,32 @@ import (
 
 	mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
 	core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
+	"github.com/kumahq/kuma/pkg/core/resources/model"
 	util_proto "github.com/kumahq/kuma/pkg/util/proto"
 )
 
-var defaultTimeoutResource = &core_mesh.TimeoutResource{
-	Spec: &mesh_proto.Timeout{
-		Sources: []*mesh_proto.Selector{{
-			Match: mesh_proto.MatchAnyService(),
-		}},
-		Destinations: []*mesh_proto.Selector{{
-			Match: mesh_proto.MatchAnyService(),
-		}},
-		Conf: &mesh_proto.Timeout_Conf{
-			ConnectTimeout: util_proto.Duration(5 * time.Second),
-			Tcp: &mesh_proto.Timeout_Conf_Tcp{
-				IdleTimeout: util_proto.Duration(1 * time.Hour),
-			},
-			Http: &mesh_proto.Timeout_Conf_Http{
-				IdleTimeout:    util_proto.Duration(1 * time.Hour),
-				RequestTimeout: util_proto.Duration(15 * time.Second),
-			},
-			Grpc: &mesh_proto.Timeout_Conf_Grpc{
-				StreamIdleTimeout: util_proto.Duration(5 * time.Minute),
+var defaultTimeoutResource = func() model.Resource {
+	return &core_mesh.TimeoutResource{
+		Spec: &mesh_proto.Timeout{
+			Sources: []*mesh_proto.Selector{{
+				Match: mesh_proto.MatchAnyService(),
+			}},
+			Destinations: []*mesh_proto.Selector{{
+				Match: mesh_proto.MatchAnyService(),
+			}},
+			Conf: &mesh_proto.Timeout_Conf{
+				ConnectTimeout: util_proto.Duration(5 * time.Second),
+				Tcp: &mesh_proto.Timeout_Conf_Tcp{
+					IdleTimeout: util_proto.Duration(1 * time.Hour),
+				},
+				Http: &mesh_proto.Timeout_Conf_Http{
+					IdleTimeout:    util_proto.Duration(1 * time.Hour),
+					RequestTimeout: util_proto.Duration(15 * time.Second),
+				},
+				Grpc: &mesh_proto.Timeout_Conf_Grpc{
+					StreamIdleTimeout: util_proto.Duration(5 * time.Minute),
+				},
 			},
 		},
-	},
+	}
 }
diff --git a/pkg/defaults/mesh/traffic_permission.go b/pkg/defaults/mesh/traffic_permission.go
index 6c2eda06a..ed86cc6a6 100644
--- a/pkg/defaults/mesh/traffic_permission.go
+++ b/pkg/defaults/mesh/traffic_permission.go
@@ -3,23 +3,26 @@ package mesh
 import (
 	mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
 	core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
+	"github.com/kumahq/kuma/pkg/core/resources/model"
 )
 
-var defaultTrafficPermissionResource = &core_mesh.TrafficPermissionResource{
-	Spec: &mesh_proto.TrafficPermission{
-		Sources: []*mesh_proto.Selector{
-			{
-				Match: map[string]string{
-					mesh_proto.ServiceTag: "*",
+var defaultTrafficPermissionResource = func() model.Resource {
+	return &core_mesh.TrafficPermissionResource{
+		Spec: &mesh_proto.TrafficPermission{
+			Sources: []*mesh_proto.Selector{
+				{
+					Match: map[string]string{
+						mesh_proto.ServiceTag: "*",
+					},
 				},
 			},
-		},
-		Destinations: []*mesh_proto.Selector{
-			{
-				Match: map[string]string{
-					mesh_proto.ServiceTag: "*",
+			Destinations: []*mesh_proto.Selector{
+				{
+					Match: map[string]string{
+						mesh_proto.ServiceTag: "*",
+					},
 				},
 			},
 		},
-	},
+	}
 }
diff --git a/pkg/defaults/mesh/traffic_route.go b/pkg/defaults/mesh/traffic_route.go
index bd4a54c4d..b6f9ebf65 100644
--- a/pkg/defaults/mesh/traffic_route.go
+++ b/pkg/defaults/mesh/traffic_route.go
@@ -3,21 +3,25 @@ package mesh
 import (
 	mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
 	core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
+	"github.com/kumahq/kuma/pkg/core/resources/model"
 )
 
-var defaultTrafficRouteResource = &core_mesh.TrafficRouteResource{
-	Spec: &mesh_proto.TrafficRoute{
-		Sources: []*mesh_proto.Selector{{
-			Match: mesh_proto.MatchAnyService(),
-		}},
-		Destinations: []*mesh_proto.Selector{{
-			Match: mesh_proto.MatchAnyService(),
-		}},
-		Conf: &mesh_proto.TrafficRoute_Conf{
-			Destination: mesh_proto.MatchAnyService(),
-			LoadBalancer: &mesh_proto.TrafficRoute_LoadBalancer{
-				LbType: &mesh_proto.TrafficRoute_LoadBalancer_RoundRobin_{},
+var defaultTrafficRouteResource = func() model.Resource {
+	return &core_mesh.TrafficRouteResource{
+		Spec: &mesh_proto.TrafficRoute{
+			Sources: []*mesh_proto.Selector{{
+				Match: mesh_proto.MatchAnyService(),
+			}},
+			Destinations: []*mesh_proto.Selector{{
+				Match: mesh_proto.MatchAnyService(),
+			}},
+			Conf: &mesh_proto.TrafficRoute_Conf{
+				Destination: mesh_proto.MatchAnyService(),
+				LoadBalancer: &mesh_proto.TrafficRoute_LoadBalancer{
+					LbType: &mesh_proto.TrafficRoute_LoadBalancer_RoundRobin_{},
+				},
 			},
 		},
-	},
+	}
+
 }


Test patch:
diff --git a/app/kumactl/cmd/inspect/testdata/inspect-gateway-dataplane.golden.txt b/app/kumactl/cmd/inspect/testdata/inspect-gateway-dataplane.golden.txt
index 5c74ddf04..914774190 100644
--- a/app/kumactl/cmd/inspect/testdata/inspect-gateway-dataplane.golden.txt
+++ b/app/kumactl/cmd/inspect/testdata/inspect-gateway-dataplane.golden.txt
@@ -6,7 +6,7 @@ MESHGATEWAY:
 
 LISTENER (HTTP:80):
   *:
-    route-1:
+    ROUTE route-1:
       SERVICE backend:
         HealthCheck
           hc-1
diff --git a/test/e2e/deploy/e2e_suite_test.go b/test/e2e/deploy/e2e_suite_test.go
index 6841c9172..257263309 100644
--- a/test/e2e/deploy/e2e_suite_test.go
+++ b/test/e2e/deploy/e2e_suite_test.go
@@ -16,3 +16,4 @@ func TestE2E(t *testing.T) {
 var _ = Describe("Test Zone and Global", deploy.ZoneAndGlobal)
 var _ = Describe("Test Universal deployment", deploy.UniversalDeployment)
 var _ = Describe("Test Universal Transparent Proxy deployment", deploy.UniversalTransparentProxyDeployment)
+var _ = Describe("Test Kubernetes deployment", deploy.KubernetesDeployment)
diff --git a/test/e2e/deploy/kuma_deploy_kubernetes.go b/test/e2e/deploy/kuma_deploy_kubernetes.go
new file mode 100644
index 000000000..68b08c0b5
--- /dev/null
+++ b/test/e2e/deploy/kuma_deploy_kubernetes.go
@@ -0,0 +1,60 @@
+package deploy
+
+import (
+	"strings"
+
+	"github.com/gruntwork-io/terratest/modules/k8s"
+	. "github.com/onsi/ginkgo/v2"
+	. "github.com/onsi/gomega"
+
+	config_core "github.com/kumahq/kuma/pkg/config/core"
+	. "github.com/kumahq/kuma/test/framework"
+)
+
+func KubernetesDeployment() {
+	var k8sCluster Cluster
+	BeforeEach(func() {
+		k8sClusters, err := NewK8sClusters([]string{Kuma1}, Silent)
+		Expect(err).ToNot(HaveOccurred())
+
+		k8sCluster = k8sClusters.GetCluster(Kuma1)
+		Expect(Kuma(config_core.Standalone)(k8sCluster)).To(Succeed())
+	})
+
+	E2EAfterEach(func() {
+		Expect(k8sCluster.DeleteKuma()).To(Succeed())
+		Expect(k8sCluster.DismissCluster()).To(Succeed())
+	})
+
+	policyCreated := func(typ, name string) func() bool {
+		return func() bool {
+			output, err := k8s.RunKubectlAndGetOutputE(k8sCluster.GetTesting(), k8sCluster.GetKubectlOptions("default"), "get", typ)
+			if err != nil {
+				return false
+			}
+			return strings.Contains(output, name)
+		}
+	}
+
+	It("should create default policies for default mesh", func() {
+		Eventually(policyCreated("trafficpermission", "allow-all-default"), "5s", "500ms").Should(BeTrue())
+		Eventually(policyCreated("trafficroute", "route-all-default"), "5s", "500ms").Should(BeTrue())
+		Eventually(policyCreated("timeout", "timeout-all-default"), "5s", "500ms").Should(BeTrue())
+		Eventually(policyCreated("circuitbreaker", "circuit-breaker-all-default"), "5s", "500ms").Should(BeTrue())
+		Eventually(policyCreated("retry", "retry-all-default"), "5s", "500ms").Should(BeTrue())
+	})
+
+	It("should create default policies for non-default mesh", func() {
+		Expect(YamlK8s(`
+apiVersion: kuma.io/v1alpha1
+kind: Mesh
+metadata:
+  name: non-default`)(k8sCluster)).To(Succeed())
+
+		Eventually(policyCreated("trafficpermission", "allow-all-non-default"), "5s", "500ms").Should(BeTrue())
+		Eventually(policyCreated("trafficroute", "route-all-non-default"), "5s", "500ms").Should(BeTrue())
+		Eventually(policyCreated("timeout", "timeout-all-non-default"), "5s", "500ms").Should(BeTrue())
+		Eventually(policyCreated("circuitbreaker", "circuit-breaker-all-non-default"), "5s", "500ms").Should(BeTrue())
+		Eventually(policyCreated("retry", "retry-all-non-default"), "5s", "500ms").Should(BeTrue())
+	})
+}