Created
April 24, 2019 15:01
-
-
Save joedborg/1d3f17339a66103b48c8a074c404ec5b to your computer and use it in GitHub Desktop.
Revisions
-
joedborg created this gist
Apr 24, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ @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')