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 #212

Closed
wants to merge 1 commit into from
Closed
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: 1 addition & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@ func Addresses(ctx context.Context, client ctrlruntimeclient.Client) ([]string,
if err := client.List(ctx, &nodeList); err != nil {
return nil, err
}

addresses := make([]string, len(nodeList.Items))
addresses := []string{}
for _, node := range nodeList.Items {
addresses = append(addresses, nodeAddress(&node))
}

return addresses, nil
}

Expand Down
14 changes: 13 additions & 1 deletion 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 @@ -62,7 +63,6 @@ func (k *KubeConfig) Extract(ctx context.Context, client client.Client, cluster
Name: server.ServiceName(cluster.Name),
Namespace: cluster.Namespace,
}

var k3kService v1.Service
if err := client.Get(ctx, nn, &k3kService); err != nil {
return nil, err
Expand All @@ -73,6 +73,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