Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ingress creation, use the ingress host in Kubeconfig when enabled #213

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -15,6 +15,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/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
Expand Down Expand Up @@ -73,6 +74,18 @@ func (k *KubeConfig) Extract(ctx context.Context, client client.Client, cluster
nodePort := k3kService.Spec.Ports[0].NodePort
url = fmt.Sprintf("https://%s:%d", hostServerIP, nodePort)
}
if cluster.Spec.Expose.Ingress.Enabled {
var k3kIngress networkingv1.Ingress
nn = types.NamespacedName{
Name: server.IngressName(cluster.Name),
Namespace: cluster.Namespace,
}

if err := client.Get(ctx, nn, &k3kIngress); err != nil {
return nil, err
}
url = fmt.Sprintf("https://%s", k3kIngress.Spec.Rules[0].Host)
}
kubeconfigData, err := kubeconfig(url, []byte(bootstrap.ServerCA.Content), adminCert, adminKey)
if err != nil {
return nil, err
Expand Down
Loading