Skip to content

Commit

Permalink
Merge pull request #213 from jp-gouin/fix-ingress
Browse files Browse the repository at this point in the history
fix ingress creation, use the ingress host in Kubeconfig when enabled
  • Loading branch information
jp-gouin authored Feb 4, 2025
2 parents 2a7541c + 2019dec commit 3df5a5b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/controller/cluster/server/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
4 changes: 2 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions pkg/controller/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit 3df5a5b

Please sign in to comment.