Skip to content

Instantly share code, notes, and snippets.

@joedborg
Created April 24, 2019 15:01
Show Gist options
  • Select an option

  • Save joedborg/1d3f17339a66103b48c8a074c404ec5b to your computer and use it in GitHub Desktop.

Select an option

Save joedborg/1d3f17339a66103b48c8a074c404ec5b to your computer and use it in GitHub Desktop.

Revisions

  1. joedborg created this gist Apr 24, 2019.
    37 changes: 37 additions & 0 deletions crictl_install.py
    Original 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')