vmware-tanzu-labs / educates-training-platform

A platform for hosting interactive workshop environments in Kubernetes, or on top of a local container runtime.
https://docs.educates.dev
Apache License 2.0
72 stars 18 forks source link

Lookup of kubernetes.default.svc may not return FQDN. #361

Closed GrahamDumpleton closed 4 months ago

GrahamDumpleton commented 4 months ago

Describe the bug

In session manager config startup it uses:

CLUSTER_DOMAIN = socket.getaddrinfo("kubernetes.default.svc", 0, flags=socket.AI_CANONNAME)[0][3]
CLUSTER_DOMAIN = CLUSTER_DOMAIN.replace("kubernetes.default.svc.", "")

to work out the internal cluster domain, eg., cluster.local.

In more recent versions of Loft virtual clusters, this is returning kubernetes alone, rather than kubernetes.svc.cluster.local. Thus is not possible to calculate correct cluster domain and CLUSTER_DOMAIN is being set to kubernetes.

The calculation should check if returned name actually starts with kubernetes.default.svc and if it doesn't then override it to cluster.local.

To cope with any other strange unexpected values, it should also be possible to manually override clusterDomain via the Educates data values when deploying it.

Additional information

No response

GrahamDumpleton commented 4 months ago

Perhaps should use:

>>> socket.gethostbyaddr(os.environ["KUBERNETES_SERVICE_HOST"])
('kubernetes.default.svc.cluster.local', [], ['10.96.0.1'])

instead.

For now keep looking up kubernetes.default.svc but possible change later if need be.

GrahamDumpleton commented 4 months ago

In future should perhaps add clusterDomain variable to Educates configuration so this can be overridden.