Parse gitVersion to set cloud provider in apiserverinfo
Overview
Currently, the SetApiServerVersion function in cloudsupport/apiserverinfo.go captures the Kubernetes API server version metadata, but does not extract the underlying cloud provider from the version string.
Problem
Kubernetes distributions deployed on major cloud providers (like EKS, GKE, AKS) typically embed provider-specific identifiers directly into the API server's gitVersion string (e.g., v1.27.1-gke.100, v1.28.2-eks-abcd). There is a maintainer TODO in SetApiServerVersion to parse this string and automatically set the cloud provider, but it has not been implemented. This forces the system to rely on secondary fallback mechanisms to determine the cloud environment.
Solution
- Update
SetApiServerVersion(version *version.Info)incloudsupport/apiserverinfo.go. - Implement string matching on
version.GitVersion(e.g., check for-gke,-eks,-aks). - Call
apiServerInfo.SetProvider(provider)if a match is found. - Remove the
// TODO: Parse the gitVersion and set the providercomment.
Alternatives
Relying purely on node labels or cloud APIs for discovery. However, that requires more cluster permissions and takes more time than simply parsing the API server version string we already receive.
Additional context
- File location:
k8s-interface/cloudsupport/apiserverinfo.go:115 - This is a small but highly impactful enhancement that makes cloud discovery faster and more robust from the very first API server query.
Source: kubescape/kubescape