Utility Functions

k9.core.set_run_output(output_mode=True)[source]

Sets flag to indicate whether outputs from the run_command should be printed to the console or not. :param output_mode: True if stdout should be printed to console. Default is True

k9.core.run_command(*params)[source]

This is a helper function to make it easier to run shell commands in a consistent manner.

Calls the subprocess.run() command with the following options:

capture_output=True Which provides stdout and stderr check=True Which throws an exception if an error occurs. The exception type subprocess.CalledProcessError

Parameters

params – a variable list of parameters

Returns

A named tuple version of subprocess.CompletedProcess that translates the stdout and stderr with str( ‘utf-8’)

Example Call

result = run_command('ls', '-la')
print(f'result.args: {result.args}')
print(f'result.returncode: {result.returncode}')
print(f'result.stdout: {result.stdout}')
print(f'result.stderr: {result.stderr}')
k9.core.last_word(value: str)[source]

Splits out the word after the last slash in a string. K8 objects are expressed in a path style name

Example

>>> last_word('pods/my-pod')
'my-pod'
k9.core.view_yaml(fn: str)[source]

Dumps out yaml file in JSON format for easy viewing. This is useful when constructing the body of a request that matches a known yaml format.

Example

>>> view_yaml('tomcat-deploy-dev.yml')
k9.core.read_yaml(fn: str)[source]

Reads a YAML file and returns the resulting the object.

Example

>>> read_yaml('tomcat-deploy-dev.yml')
k9.core.get_age(creation_time: datetime)[source]

Given a creation timestamp, return the difference in time from now.

Parameters

creation_time – The time we want to measure age from

Returns

timedelta - the amount of time since creation_time