-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adds notional support for extracting the url into the hawtio.St…
…atus #100 * While the extraction of the route url is quite straightforward, the use of ingress path rules and no hosts makes the return of a single string quite difficult. This may well need work in the future to improve the value returned
- Loading branch information
1 parent
7e323e9
commit f1c359f
Showing
3 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"testing" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
networkingv1 "k8s.io/api/networking/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"github.com/hawtio/hawtio-operator/pkg/resources" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetIngressURL(t *testing.T) { | ||
annotations := map[string]string{} | ||
annotations["nginx.ingress.kubernetes.io/backend-protocol"] = "HTTPS" | ||
annotations["nginx.ingress.kubernetes.io/force-ssl-redirect"] = "true" | ||
annotations["nginx.ingress.kubernetes.io/rewrite-target"] = "/$1" | ||
|
||
labels := map[string]string{ | ||
resources.LabelAppKey: "hawtio", | ||
} | ||
pathPrefix := networkingv1.PathTypePrefix | ||
name := "hawtio-online" | ||
|
||
ingress := &networkingv1.Ingress{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: annotations, | ||
Labels: labels, | ||
Name: name, | ||
}, | ||
Spec: networkingv1.IngressSpec{ | ||
TLS: []networkingv1.IngressTLS{ | ||
{ | ||
SecretName: "some-tls-secret", | ||
}, | ||
}, | ||
Rules: []networkingv1.IngressRule{ | ||
{ | ||
IngressRuleValue: networkingv1.IngressRuleValue{ | ||
HTTP: &networkingv1.HTTPIngressRuleValue{ | ||
Paths: []networkingv1.HTTPIngressPath{{ | ||
Path: "/(.*)", | ||
PathType: &pathPrefix, | ||
Backend: networkingv1.IngressBackend{ | ||
Service: &networkingv1.IngressServiceBackend{ | ||
Name: name, | ||
Port: networkingv1.ServiceBackendPort{ | ||
Number: 443, | ||
}, | ||
}, | ||
}, | ||
}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Status: networkingv1.IngressStatus{ | ||
LoadBalancer: corev1.LoadBalancerStatus{ | ||
Ingress: []corev1.LoadBalancerIngress{ | ||
{ | ||
IP: "192.168.99.9", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
url := GetIngressURL(ingress) | ||
assert.Equal(t, "https://192.168.99.9/(.*)", url) | ||
} |