Skip to content

Instantly share code, notes, and snippets.

@joedborg
Created April 24, 2019 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joedborg/1d3f17339a66103b48c8a074c404ec5b to your computer and use it in GitHub Desktop.
Save joedborg/1d3f17339a66103b48c8a074c404ec5b to your computer and use it in GitHub Desktop.
crictl Charm Installation
@when('config.changed.crictl-version')
def crictl_version_changed():
"""
crictl version has changed.
:return: None
"""
remove_state('crictl.installed')
@when_not('crictl.installed')
def install_crictl():
"""
Install the crictl binary.
:return: None
"""
cfg = hookenv.config()
url = 'https://github.com/kubernetes-sigs/' \
'cri-tools/releases/download/v{0}/' \
'crictl-v{0}-linux-amd64.tar.gz'.format(
cfg.get('crictl-version'))
path = '/usr/bin/crictl'
if os.path.isfile(path):
os.remove(path)
# Download the archive into memory and extract straight into /usr/bin/.
with urlopen(url) as request:
with BytesIO(request.read()) as download:
with tarfile.open(fileobj=download, mode='r:gz') as tar:
tar.extract(
os.path.basename(path),
os.path.dirname(path)
)
set_state('crictl.installed')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment