Repository: kumahq/kuma
Pull request #1392 (2021-01-06 17:55:54)

fix(kube-prometheus-sd) allow kuma-cp config to grpcs scheme (bp #1390)
This is an automated backport of pull request #1390 done by Mergify
---


<details>
<summary>Mergify commands and options</summary>

<br />

More conditions and actions can be found in the [documentation](https://docs.mergify.io/).

You can also trigger Mergify actions by commenting on this pull request:

- `@Mergifyio refresh` will re-evaluate the rules
- `@Mergifyio rebase` will rebase this PR on its base branch
- `@Mergifyio update` will merge the base branch into this PR
- `@Mergifyio backport <destination>` will backport this PR on `<destination>` branch

Additionally, on Mergify [dashboard](https://dashboard.mergify.io/) you can:

- look at your merge queues
- generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.io/
</details>



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


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