{"record":{"id":"1d3a09b6e96ca288","repo":"rancher/rancher","slug":"kubernetes-version-of-the-cluster-cannot-be-determ","errorCode":null,"errorMessage":"kubernetes version of the cluster cannot be determined","messagePattern":"kubernetes version of the cluster cannot be determined","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/api/norman/customization/aks/listers.go","lineNumber":239,"sourceCode":"}\n\n// listKubernetesUpgradeVersions lists all kubernetes versions listed by AKS Container Service and marks which ones the\n// given cluster can be upgraded to.  A version's `Enabled` flag is true if the cluster can be upgraded to the version\n// in its current state.\nfunc listKubernetesUpgradeVersions(ctx context.Context, clusterLister mgmtv3.ClusterCache, cap *Capabilities) ([]byte, int, error) {\n\tvar resp UpgradeVersionsResponse\n\n\t// load the target cluster, if the cluster is not found we cannot proceed\n\tcluster, err := clusterLister.Get(cap.ClusterID)\n\tif err != nil {\n\t\treturn nil, http.StatusBadRequest, fmt.Errorf(\"invalid cluster id\")\n\t}\n\n\tif cluster.Spec.AKSConfig.KubernetesVersion != nil {\n\t\tresp.CurrentVersion = *cluster.Spec.AKSConfig.KubernetesVersion\n\t} else {\n\t\tif cluster.Status.AKSStatus.UpstreamSpec == nil || cluster.Status.AKSStatus.UpstreamSpec.KubernetesVersion == nil {\n\t\t\treturn nil, http.StatusBadRequest, fmt.Errorf(\"kubernetes version of the cluster cannot be determined\")\n\t\t}\n\t\tresp.CurrentVersion = *cluster.Status.AKSStatus.UpstreamSpec.KubernetesVersion\n\t}\n\n\t// get the client for aks container service\n\tclient, err := NewManagedClustersClient(cap)\n\tif err != nil {\n\t\treturn nil, http.StatusInternalServerError, err\n\t}\n\n\tres, err := client.ListKubernetesVersions(ctx, cap.ResourceLocation, nil)\n\tif err != nil {\n\t\treturn nil, http.StatusBadRequest, fmt.Errorf(\"failed to get Kubernetes versions: %w\", err)\n\t}\n\n\tif len(res.Values) == 0 {\n\t\treturn nil, http.StatusBadRequest, fmt.Errorf(\"no versions were returned: %w\", err)\n\t}","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/rancher/rancher/blob/932558d4e68565aff2d2f36e89ec4a391b06e7c5/pkg/api/norman/customization/aks/listers.go#L221-L257","documentation":"listKubernetesUpgradeVersions reads the current version from cluster.Spec.AKSConfig.KubernetesVersion, falling back to cluster.Status.AKSStatus.UpstreamSpec.KubernetesVersion. If the spec pointer is nil AND (UpstreamSpec is nil or its KubernetesVersion is nil), the version cannot be determined and a 400 is returned (listers.go:238-240).","triggerScenarios":"An AKS cluster registered/imported into Rancher whose status has not yet been filled by aks-operator (UpstreamSpec still empty); a cluster object created seconds ago; a cluster whose AKSConfig was reset; in rare cases a cluster whose spec version was explicitly cleared awaiting reconciliation.","commonSituations":"Opening the upgrade-versions wizard immediately after cluster registration; aks-operator pod crash-looping so UpstreamSpec never populates; Rancher restored from backup with stale cluster status.","solutions":["Wait for the AKS operator to sync the cluster, then retry: kubectl get cluster <id> -o yaml should show status.akSStatus.upstreamSpec.kubernetesVersion","Check aks-operator logs (cattle-system / aks-operator pod) if status stays empty","Ensure spec.akSConfig.kubernetesVersion is set on provisioned clusters rather than relying on upstream status"],"exampleFix":"# before: retry loop fires immediately after registration\n# after: poll until version is populated\nkubectl get cluster c-m-xxxxx -o jsonpath='{.status.akSStatus.upstreamSpec.kubernetesVersion}'\n# retry the GET /v3/aksKubernetesUpgradeVersions call only once this returns non-empty","handlingStrategy":"retry","validationCode":"// poll the cluster until its version is populated, then call the endpoint\nasync function untilVersionKnown(clusterId, tries = 12) {\n  for (let i = 0; i < tries; i++) {\n    const c = await (await fetch(`/v3/clusters/${clusterId}`)).json();\n    const v = c.spec?.akSConfig?.kubernetesVersion ?? c.status?.akSStatus?.upstreamSpec?.kubernetesVersion;\n    if (v) return v;\n    await sleep(5000);\n  }\n  throw new Error('cluster version not populated - check aks-operator');\n}","typeGuard":"function clusterVersionKnown(c) {\n  return !!(c?.spec?.akSConfig?.kubernetesVersion ?? c?.status?.akSStatus?.upstreamSpec?.kubernetesVersion);\n}","tryCatchPattern":"const resp = await fetch(upgradeUrl);\nif (resp.status === 400) {\n  const { error } = await resp.json();\n  if (/kubernetes version of the cluster cannot be determined/.test(error)) {\n    await untilVersionKnown(clusterId); await fetch(upgradeUrl); // retry after sync\n  }\n}","preventionTips":["Gate the upgrade wizard on clusterVersionKnown(cluster) in the UI","Watch aks-operator health right after registering AKS clusters","Set spec.akSConfig.kubernetesVersion on provisioned clusters so the spec path is used"],"tags":["aks","cluster-status","kubernetes-version","operator-sync","rancher"],"backgroundTag":null,"analyzedSha":"932558d4e68565aff2d2f36e89ec4a391b06e7c5","analyzedAt":"2026-08-16T04:37:02.125Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}