runway.env_mgr.kbenv module

Kubectl version management.

runway.env_mgr.kbenv.verify_kb_release(kb_url: str, download_dir: str, filename: str) None[source]

Compare checksum and exit if it doesn’t match.

Different releases provide varying checksum files. To account for this, start at SHA512 and work down to the first available checksum.

requests is used for downloading these small files because of difficulty in getting 404 status from urllib on py2. Once py2 support is dropped, downloads can be moved to urllib.

https://stackoverflow.com/questions/1308542/how-to-catch-404-error-in-urllib-urlretrieve

runway.env_mgr.kbenv.download_kb_release(version: str, versions_dir: Path, kb_platform: Optional[str] = None, arch: Optional[str] = None) None[source]

Download kubectl and return path to it.

class runway.env_mgr.kbenv.KBEnvManager[source]

Bases: runway.env_mgr.EnvManager

kubectl version management.

Designed to be compatible with https://github.com/alexppg/kbenv.

__init__(path: Optional[Path] = None, *, overlay_path: Optional[Path] = None) None[source]

Initialize class.

Parameters
  • path – Module path.

  • overlay_path – Path to Kustomize overlay.

property version: Optional[runway.utils._version.Version]

Terraform version.

property version_file: Optional[Path]

Find and return a “.kubectl-version” file if one is present.

Returns

Path to the kubectl version file.

get_version_from_file(file_path: Optional[Path] = None) Optional[str][source]

Get kubectl version from a file.

Parameters

file_path – Path to file that will be read.

install(version_requested: Optional[str] = None) str[source]

Ensure kubectl is available.

list_installed() Generator[Path, None, None][source]

List installed versions of kubectl.

Only lists versions of kubectl that have been installed by an instance if this class or by kbenv.

set_version(version: str) None[source]

Set current version.

Clears cached values as needed.

Parameters

version – Version string. Must be in the format of v<major>.<minor>.<patch> with an optional -<prerelease>.

classmethod parse_version_string(version: str) runway.utils._version.Version[source]

Parse version string into a Version.

Parameters

version – Version string to parse. Must be in the format of <major>.<minor>.<patch> with an optional -<prerelease>.

__new__(**kwargs)
property bin: pathlib.Path

Path to the version binary.

Returns

Path

property command_suffix: str

Return command suffix based on platform.system.

property env_dir: pathlib.Path

Return the directory used to store version binaries.

uninstall(version: Union[str, Version]) bool

Uninstall a version of the managed binary.

Parameters

version – Version of binary to uninstall.

Returns

Whether a version of the binary was uninstalled or not.

property versions_dir: pathlib.Path

Return the directory used to store binary.

When first used, the existence of the directory is checked and it is created if needed.