Created
April 24, 2019 15:01
-
-
Save joedborg/1d3f17339a66103b48c8a074c404ec5b to your computer and use it in GitHub Desktop.
crictl Charm Installation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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