kubernetes/kops · error

cannot parse kubernetes version %q

Error message

cannot parse kubernetes version %q

What it means

After fetching the server version, RunApplyChannel parses GitVersion with semver.ParseTolerant. If the reported version string cannot be parsed even tolerantly (no recognizable MAJOR.MINOR.PATCH anywhere), it fails with this message including the raw version string. This guards downstream feature-gating comparisons against unparsable versions.

Source

Thrown at channels/pkg/cmd/apply_channel.go:195

	dynamicClient, err := f.DynamicClient()
	if err != nil {
		return fmt.Errorf("building dynamic client: %w", err)
	}

	restMapper, err := f.RESTMapper()
	if err != nil {
		return err
	}

	kubernetesVersionInfo, err := k8sClient.Discovery().ServerVersion()
	if err != nil {
		return fmt.Errorf("error querying kubernetes version: %v", err)
	}

	kubernetesVersion, err := semver.ParseTolerant(kubernetesVersionInfo.GitVersion)
	if err != nil {
		return fmt.Errorf("cannot parse kubernetes version %q", kubernetesVersionInfo.GitVersion)
	}

	// Remove Pre and Patch, as they make semver comparisons impractical
	kubernetesVersion.Pre = nil

	if len(args) == 0 {
		return fmt.Errorf("at least one channel URL is required")
	}

	var merr error
	for _, channelLocation := range args {
		menu, err := buildMenu(f.VFSContext(), kubernetesVersion, channelLocation)
		if err != nil {
			merr = multierr.Append(merr, fmt.Errorf("building menu for %q: %w", channelLocation, err))
			continue
		}
		if err := applyMenu(ctx, menu, f.VFSContext(), k8sClient, cmClient, dynamicClient, restMapper, options.Yes); err != nil {
			merr = multierr.Append(merr, fmt.Errorf("applying %q: %w", channelLocation, err))

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Inspect the actual version: `kubectl version -o json` and check GitVersion
  2. Fix or bypass the proxy/LB answering the /version request instead of the apiserver
  3. Use a standard Kubernetes build so GitVersion is proper semver
  4. If unavoidable, patch the version string at the source (apiserver build) — kops expects semver-compatible GitVersion

Example fix

// before (custom build)
GitVersion: "my-fork"
// after
GitVersion: "v1.28.3"
Defensive patterns

Strategy: validation

Validate before calling

// Go: check the version string looks parseable before invoking
v, _ := clientset.Discovery().ServerVersion()
if !regexp.MustCompile(`\d+\.\d+(\.\d+)?`).MatchString(v.GitVersion) {
	return fmt.Errorf("non-semver GitVersion %q; fix cluster/proxy", v.GitVersion)
}

Prevention

When it happens

Trigger: The apiserver's GitVersion is not a standard semver string: custom/rebuilt kube-apiserver binaries reporting e.g. 'dev' or a vendor string without digits, a proxy returning an HTML error page as version info, or a badly patched apiserver.

Common situations: Clusters fronted by a misconfigured load balancer/proxy that answers version requests itself; forked or locally-built Kubernetes reporting non-standard versions; mocks/stubs in testing environments.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/8eb75a205f0677e6. Report an issue: GitHub.