Skip to content

Commit

Permalink
fix(kuma-dp) probe path gets a / prepended if not supplied (#1326)
Browse files Browse the repository at this point in the history
When not adding a /-prefix to the readiness or liveness probe, we should add it automatically.

Fix #1288

Signed-off-by: Lennart Querter <[email protected]>
  • Loading branch information
lennartquerter authored Dec 17, 2020
1 parent 15f4754 commit 75ddff4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/plugins/runtime/k8s/probes/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ func (p KumaProbe) ToVirtual(virtualPort uint32) (KumaProbe, error) {
return KumaProbe{}, errors.Errorf("cannot override Pod's probes. Port for probe cannot "+
"be set to %d. It is reserved for the dataplane that will serve pods without mTLS.", virtualPort)
}
probePath := p.Path()
if !strings.HasPrefix(p.Path(), "/") {
probePath = fmt.Sprintf("/%s", p.Path())
}
return KumaProbe{
Handler: kube_core.Handler{
HTTPGet: &kube_core.HTTPGetAction{
Port: intstr.FromInt(int(virtualPort)),
Path: fmt.Sprintf("/%d%s", p.Port(), p.Path()),
Path: fmt.Sprintf("/%d%s", p.Port(), probePath),
},
},
}, nil
Expand Down
18 changes: 18 additions & 0 deletions pkg/plugins/runtime/k8s/probes/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,22 @@ var _ = Describe("KumaProbe", func() {
"to 9000. It is reserved for the dataplane that will serve pods without mTLS."))
})
})

Context("Prepend /", func() {
It("should convert to path with prepended /", func() {
podProbeYaml := `
httpGet:
path: c1/hc
port: 8080
`
probe := kube_core.Probe{}
err := yaml.Unmarshal([]byte(podProbeYaml), &probe)
Expect(err).ToNot(HaveOccurred())

virtual, err := probes.KumaProbe(probe).ToVirtual(9000)
Expect(err).ToNot(HaveOccurred())
Expect(virtual.Path()).To(Equal("/8080/c1/hc"))
Expect(virtual.Port()).To(Equal(uint32(9000)))
})
})
})

0 comments on commit 75ddff4

Please sign in to comment.