Mapping ExternalNames to custom ports
This commit is contained in:
parent
5a1d2aa4b6
commit
c37b040217
2 changed files with 52 additions and 7 deletions
|
@ -105,11 +105,11 @@ func TestBuildService(t *testing.T) {
|
||||||
assert.EqualValues(t, sampleService1(), actual1)
|
assert.EqualValues(t, sampleService1(), actual1)
|
||||||
|
|
||||||
actual2 := buildService(
|
actual2 := buildService(
|
||||||
sName("service3"),
|
sName("service2"),
|
||||||
sNamespace("testing"),
|
sNamespace("testing"),
|
||||||
sUID("3"),
|
sUID("2"),
|
||||||
sSpec(
|
sSpec(
|
||||||
clusterIP("10.0.0.3"),
|
clusterIP("10.0.0.2"),
|
||||||
sType("ExternalName"),
|
sType("ExternalName"),
|
||||||
sExternalName("example.com"),
|
sExternalName("example.com"),
|
||||||
sPorts(
|
sPorts(
|
||||||
|
@ -120,6 +120,23 @@ func TestBuildService(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.EqualValues(t, sampleService2(), actual2)
|
assert.EqualValues(t, sampleService2(), actual2)
|
||||||
|
|
||||||
|
actual3 := buildService(
|
||||||
|
sName("service3"),
|
||||||
|
sNamespace("testing"),
|
||||||
|
sUID("3"),
|
||||||
|
sSpec(
|
||||||
|
clusterIP("10.0.0.3"),
|
||||||
|
sType("ExternalName"),
|
||||||
|
sExternalName("example.com"),
|
||||||
|
sPorts(
|
||||||
|
sPort(8080, "http"),
|
||||||
|
sPort(8443, "https"),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
assert.EqualValues(t, sampleService3(), actual3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sampleService1() *corev1.Service {
|
func sampleService1() *corev1.Service {
|
||||||
|
@ -143,12 +160,12 @@ func sampleService1() *corev1.Service {
|
||||||
func sampleService2() *corev1.Service {
|
func sampleService2() *corev1.Service {
|
||||||
return &corev1.Service{
|
return &corev1.Service{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "service3",
|
Name: "service2",
|
||||||
UID: "3",
|
UID: "2",
|
||||||
Namespace: "testing",
|
Namespace: "testing",
|
||||||
},
|
},
|
||||||
Spec: corev1.ServiceSpec{
|
Spec: corev1.ServiceSpec{
|
||||||
ClusterIP: "10.0.0.3",
|
ClusterIP: "10.0.0.2",
|
||||||
Type: "ExternalName",
|
Type: "ExternalName",
|
||||||
ExternalName: "example.com",
|
ExternalName: "example.com",
|
||||||
Ports: []corev1.ServicePort{
|
Ports: []corev1.ServicePort{
|
||||||
|
@ -164,3 +181,28 @@ func sampleService2() *corev1.Service {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sampleService3() *corev1.Service {
|
||||||
|
return &corev1.Service{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "service3",
|
||||||
|
UID: "3",
|
||||||
|
Namespace: "testing",
|
||||||
|
},
|
||||||
|
Spec: corev1.ServiceSpec{
|
||||||
|
ClusterIP: "10.0.0.3",
|
||||||
|
Type: "ExternalName",
|
||||||
|
ExternalName: "example.com",
|
||||||
|
Ports: []corev1.ServicePort{
|
||||||
|
{
|
||||||
|
Name: "http",
|
||||||
|
Port: 8080,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "https",
|
||||||
|
Port: 8443,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -270,13 +270,16 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
|
||||||
protocol := label.DefaultProtocol
|
protocol := label.DefaultProtocol
|
||||||
for _, port := range service.Spec.Ports {
|
for _, port := range service.Spec.Ports {
|
||||||
if equalPorts(port, pa.Backend.ServicePort) {
|
if equalPorts(port, pa.Backend.ServicePort) {
|
||||||
if port.Port == 443 {
|
if port.Port == 443 || strings.HasPrefix(port.Name, "https") {
|
||||||
protocol = "https"
|
protocol = "https"
|
||||||
}
|
}
|
||||||
|
|
||||||
if service.Spec.Type == "ExternalName" {
|
if service.Spec.Type == "ExternalName" {
|
||||||
url := protocol + "://" + service.Spec.ExternalName
|
url := protocol + "://" + service.Spec.ExternalName
|
||||||
name := url
|
name := url
|
||||||
|
if port.Port != 443 && port.Port != 80 {
|
||||||
|
url = fmt.Sprintf("%s:%d", url, port.Port)
|
||||||
|
}
|
||||||
|
|
||||||
templateObjects.Backends[baseName].Servers[name] = types.Server{
|
templateObjects.Backends[baseName].Servers[name] = types.Server{
|
||||||
URL: url,
|
URL: url,
|
||||||
|
|
Loading…
Reference in a new issue