diff --git a/pkg/controller/cluster/server/ingress.go b/pkg/controller/cluster/server/ingress.go index ce52696..39c5dd5 100644 --- a/pkg/controller/cluster/server/ingress.go +++ b/pkg/controller/cluster/server/ingress.go @@ -91,3 +91,6 @@ func configureIngressOptions(ingress *networkingv1.Ingress, ingressClassName str ingress.Annotations[nginxBackendProtocolAnnotation] = "HTTPS" } } +func IngressName(clusterName string) string { + return controller.SafeConcatNameWithPrefix(clusterName, "ingress") +} diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index b6f3747..357028d 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -70,8 +70,8 @@ func Addresses(ctx context.Context, client ctrlruntimeclient.Client) ([]string, } addresses := make([]string, len(nodeList.Items)) - for _, node := range nodeList.Items { - addresses = append(addresses, nodeAddress(&node)) + for i, node := range nodeList.Items { + addresses[i] = nodeAddress(&node) } return addresses, nil diff --git a/pkg/controller/kubeconfig/kubeconfig.go b/pkg/controller/kubeconfig/kubeconfig.go index 2161f1c..01be1a4 100644 --- a/pkg/controller/kubeconfig/kubeconfig.go +++ b/pkg/controller/kubeconfig/kubeconfig.go @@ -13,6 +13,7 @@ import ( "github.com/rancher/k3k/pkg/controller/cluster/server" "github.com/rancher/k3k/pkg/controller/cluster/server/bootstrap" v1 "k8s.io/api/core/v1" + networkingv1 "k8s.io/api/networking/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apiserver/pkg/authentication/user" clientcmdapi "k8s.io/client-go/tools/clientcmd/api" @@ -105,6 +106,18 @@ func getURLFromService(ctx context.Context, client client.Client, cluster *v1alp nodePort := k3kService.Spec.Ports[0].NodePort url = fmt.Sprintf("https://%s:%d", hostServerIP, nodePort) } + if cluster.Spec.Expose.Ingress != nil && cluster.Spec.Expose.Ingress.Enabled { + var k3kIngress networkingv1.Ingress + ingressKey := types.NamespacedName{ + Name: server.IngressName(cluster.Name), + Namespace: cluster.Namespace, + } + + if err := client.Get(ctx, ingressKey, &k3kIngress); err != nil { + return "", err + } + url = fmt.Sprintf("https://%s", k3kIngress.Spec.Rules[0].Host) + } return url, nil }