Repository: kumahq/kuma
Pull request #1390 (2021-01-06 15:55:42)

fix(kube-prometheus-sd) allow kuma-cp config to grpcs scheme
### Summary

The configuration validation was only allowing `grpc` schemes
in practice `grpc` and `grpcs` should both be allowed.

### Full changelog

* improve validation to allow grpcs scheme in the kube-prometheus-sd config

CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/kumahq/kuma?pullRequest=1390) <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/kumahq/kuma?pullRequest=1390) before we can accept your contribution.<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/kumahq/kuma?pullRequest=1390) it.</sub>

Patch:
diff --git a/pkg/config/app/kuma-prometheus-sd/config.go b/pkg/config/app/kuma-prometheus-sd/config.go
index 57dc7ba63..72083cead 100644
--- a/pkg/config/app/kuma-prometheus-sd/config.go
+++ b/pkg/config/app/kuma-prometheus-sd/config.go
@@ -94,8 +94,8 @@ func (c *MonitoringAssignmentClientConfig) Validate() (errs error) {
 		if !url.IsAbs() {
 			errs = multierr.Append(errs, errors.Errorf(".URL must be a valid absolute URI"))
 		}
-		if url.Scheme != "grpc" {
-			errs = multierr.Append(errs, errors.Errorf(".URL must start with grpc://"))
+		if url.Scheme != "grpc" && url.Scheme != "grpcs" {
+			errs = multierr.Append(errs, errors.Errorf(".URL must start with grpc:// or grpcs://"))
 		}
 	}
 	return
diff --git a/pkg/plugins/resources/k8s/native/api/v1alpha1/trafficlogging_types_helpers.go b/pkg/plugins/resources/k8s/native/api/v1alpha1/trafficlogging_types_helpers.go
index c45637457..59fcd8129 100644
--- a/pkg/plugins/resources/k8s/native/api/v1alpha1/trafficlogging_types_helpers.go
+++ b/pkg/plugins/resources/k8s/native/api/v1alpha1/trafficlogging_types_helpers.go
@@ -33,7 +33,7 @@ func (tp *TrafficLog) SetSpec(spec map[string]interface{}) {
 }
 
 func (tp *TrafficLog) Scope() model.Scope {
-	return model.ScopeNamespace
+	return model.ScopeCluster
 }
 
 func (l *TrafficLogList) GetItems() []model.KubernetesObject {


Test patch:
diff --git a/pkg/config/app/kuma-prometheus-sd/config_test.go b/pkg/config/app/kuma-prometheus-sd/config_test.go
index ea4e42799..f960948b7 100644
--- a/pkg/config/app/kuma-prometheus-sd/config_test.go
+++ b/pkg/config/app/kuma-prometheus-sd/config_test.go
@@ -98,6 +98,19 @@ var _ = Describe("Config", func() {
 		err := config.Load(filepath.Join("testdata", "invalid-config.input.yaml"), &cfg)
 
 		// then
-		Expect(err.Error()).To(Equal(`Invalid configuration: .MonitoringAssignment is not valid: .Client is not valid: .Name must be non-empty; .URL must be a valid absolute URI; .URL must start with grpc://; .Prometheus is not valid: .OutputFile must be non-empty`))
+		Expect(err.Error()).To(Equal(`Invalid configuration: .MonitoringAssignment is not valid: .Client is not valid: .Name must be non-empty; .URL must be a valid absolute URI; .URL must start with grpc:// or grpcs://; .Prometheus is not valid: .OutputFile must be non-empty`))
+	})
+
+	It("should allow grpcs", func() {
+		// given
+		cfg := kuma_promsd.Config{}
+
+		// when
+		err := config.Load(filepath.Join("testdata", "valid-grpcs-config.input.yaml"), &cfg)
+
+		// then
+		Expect(err).ToNot(HaveOccurred())
+		// and
+		Expect(cfg.MonitoringAssignment.Client.URL).To(Equal("grpcs://kuma-control-plane.internal:5682"))
 	})
 })
diff --git a/pkg/config/app/kuma-prometheus-sd/testdata/valid-grpcs-config.input.yaml b/pkg/config/app/kuma-prometheus-sd/testdata/valid-grpcs-config.input.yaml
new file mode 100644
index 000000000..1b812ac1b
--- /dev/null
+++ b/pkg/config/app/kuma-prometheus-sd/testdata/valid-grpcs-config.input.yaml
@@ -0,0 +1,6 @@
+monitoringAssignment:
+  client:
+    name: custom
+    url: grpcs://kuma-control-plane.internal:5682
+prometheus:
+  outputFile: /path/to/file