Skip to content

Commit

Permalink
fix(kube-prometheus-sd) allow kuma-cp config to grpcs scheme (#1390) (#…
Browse files Browse the repository at this point in the history
…1392)

The configuration validation was only allowing `grpc` schemes
in practice `grpc` and `grpcs` should both be allowed.

* improve validation to allow grpcs scheme in the kube-prometheus-sd config

Signed-off-by: Charly Molter <charly@koyeb.com>
(cherry picked from commit 1df77f3)

Co-authored-by: Charly Molter <charly.molter@gmail.com>
  • Loading branch information
mergify[bot] and lahabana authored Jan 7, 2021
1 parent e1b6755 commit 45acbdc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/config/app/kuma-prometheus-sd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion pkg/config/app/kuma-prometheus-sd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
monitoringAssignment:
client:
name: custom
url: grpcs://kuma-control-plane.internal:5682
prometheus:
outputFile: /path/to/file

0 comments on commit 45acbdc

Please sign in to comment.