Merge pull request #380 from errm/k8s-ref-ports-by-name
Allow k8s ports to be referenced by name as well as number
This commit is contained in:
commit
f6c860afc0
2 changed files with 14 additions and 3 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
@ -200,12 +201,12 @@ func (provider *Kubernetes) loadIngresses(k8sClient k8s.Client) (*types.Configur
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
protocol := "http"
|
protocol := "http"
|
||||||
for _, port := range service.Spec.Ports {
|
for _, port := range service.Spec.Ports {
|
||||||
if port.Port == pa.Backend.ServicePort.IntValue() {
|
if equalPorts(port, pa.Backend.ServicePort) {
|
||||||
if port.Port == 443 {
|
if port.Port == 443 {
|
||||||
protocol = "https"
|
protocol = "https"
|
||||||
}
|
}
|
||||||
templateObjects.Backends[r.Host+pa.Path].Servers[string(service.UID)] = types.Server{
|
templateObjects.Backends[r.Host+pa.Path].Servers[string(service.UID)] = types.Server{
|
||||||
URL: protocol + "://" + service.Spec.ClusterIP + ":" + pa.Backend.ServicePort.String(),
|
URL: protocol + "://" + service.Spec.ClusterIP + ":" + strconv.Itoa(port.Port),
|
||||||
Weight: 1,
|
Weight: 1,
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
@ -218,6 +219,16 @@ func (provider *Kubernetes) loadIngresses(k8sClient k8s.Client) (*types.Configur
|
||||||
return &templateObjects, nil
|
return &templateObjects, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func equalPorts(servicePort k8s.ServicePort, ingressPort k8s.IntOrString) bool {
|
||||||
|
if servicePort.Port == ingressPort.IntValue() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if servicePort.Name != "" && servicePort.Name == ingressPort.String() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (provider *Kubernetes) getPassHostHeader() bool {
|
func (provider *Kubernetes) getPassHostHeader() bool {
|
||||||
if provider.disablePassHostHeaders {
|
if provider.disablePassHostHeaders {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -21,7 +21,7 @@ func TestLoadIngresses(t *testing.T) {
|
||||||
Path: "/bar",
|
Path: "/bar",
|
||||||
Backend: k8s.IngressBackend{
|
Backend: k8s.IngressBackend{
|
||||||
ServiceName: "service1",
|
ServiceName: "service1",
|
||||||
ServicePort: k8s.FromInt(801),
|
ServicePort: k8s.FromString("http"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue