func resolveVersion()

in pkg/clusters/versions.go [196:221]


func resolveVersion(desired, def string, valid []string) (string, error) {
	if len(valid) == 0 {
		// Should not happen, but protects from out-of-bounds error.
		return "", fmt.Errorf("list of valid versions is empty: %v", valid)
	}
	if def == "" {
		// Should not happen, but protects from unforeseen input return values.
		return "", fmt.Errorf("default version is missing: desired version %s", desired)
	}

	if desired == DefaultVersion {
		return def, nil
	}
	if desired == LatestVersion {
		return valid[0], nil
	}

	// Versions are in descending order, so select the first match.
	for _, v := range valid {
		if strings.HasPrefix(v, desired) {
			return v, nil
		}
	}

	return "", fmt.Errorf("desired version %q could not be resolved; valid versions: %v", desired, valid)
}