Skip to content
Merged
Changes from 1 commit
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
24 changes: 19 additions & 5 deletions pkg/controller/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,32 @@ func getURLFromService(ctx context.Context, client client.Client, cluster *v1bet
switch k3kService.Spec.Type {
case v1.ServiceTypeNodePort:
ip = hostServerIP
port = k3kService.Spec.Ports[0].NodePort

if len(k3kService.Spec.Ports) == 0 {
logrus.Warn("No exposed port in NodePort service.")
} else {
port = k3kService.Spec.Ports[0].NodePort
}
case v1.ServiceTypeLoadBalancer:
ip = k3kService.Status.LoadBalancer.Ingress[0].IP
port = k3kService.Spec.Ports[0].Port
if len(k3kService.Status.LoadBalancer.Ingress) == 0 {
logrus.Warn("No ingress found in LoadBalancer service.")
} else {
ip = k3kService.Status.LoadBalancer.Ingress[0].IP
}

if len(k3kService.Spec.Ports) == 0 {
logrus.Warn("No exposed port in LoadBalancer service.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a different message from the one above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that it could be the same message, like "No exposed ports in service."?

I'm not even sure you can have a Service without a Port actually.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops...should've clarified this, you can't have a Service without a Port, spec.ports is a required value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, awesome. So should I drop the check altogether? I'm fine with this, it simplify the code, and it was not really the reason of the PR. 🙂

} else {
port = k3kService.Spec.Ports[0].Port
}
}

if serverPort != 0 {
port = int32(serverPort)
}

if !slices.Contains(cluster.Status.TLSSANs, ip) {
logrus.Warnf("ip %s not in tlsSANs", ip)
logrus.Warnf("IP %s not in tlsSANs.", ip)

if len(cluster.Spec.TLSSANs) > 0 {
logrus.Warnf("Using the first TLS SAN in the spec as a fallback: %s", cluster.Spec.TLSSANs[0])
Expand All @@ -133,7 +147,7 @@ func getURLFromService(ctx context.Context, client client.Client, cluster *v1bet

ip = cluster.Status.TLSSANs[0]
} else {
logrus.Warn("ip not found in tlsSANs. This could cause issue with the certificate validation.")
logrus.Warn("IP not found in tlsSANs. This could cause issue with the certificate validation.")
}
}

Expand Down
Loading