| 1 |
#!/usr/bin/env python |
| 2 |
# |
| 3 |
# Copyright 2017 Google Inc. |
| 4 |
# |
| 5 |
# Use of this source code is governed by a BSD-style license that can be |
| 6 |
# found in the LICENSE file. |
| 7 |
|
| 8 |
|
| 9 |
"""Create the asset.""" |
| 10 |
|
| 11 |
|
| 12 |
import argparse |
| 13 |
import requests |
| 14 |
import subprocess |
| 15 |
|
| 16 |
|
| 17 |
VERSION = 'v1.25.4' |
| 18 |
DOWNLOAD_URL = 'https://dl.k8s.io/release/%s/bin/linux/amd64/kubectl' % VERSION |
| 19 |
SHA256_URL = 'https://dl.k8s.io/%s/bin/linux/amd64/kubectl.sha256' % VERSION |
| 20 |
|
| 21 |
|
| 22 |
def create_asset(target_dir): |
| 23 |
"""Create the asset.""" |
| 24 |
subprocess.check_call(['curl', '-LO', DOWNLOAD_URL], cwd=target_dir) |
| 25 |
sha256 = requests.get(SHA256_URL).text |
| 26 |
p = subprocess.Popen( |
| 27 |
['sha256sum', '--check'], |
| 28 |
cwd=target_dir, |
| 29 |
stdout=subprocess.PIPE, |
| 30 |
stderr=subprocess.STDOUT, |
| 31 |
stdin=subprocess.PIPE) |
| 32 |
output = p.communicate( |
| 33 |
input=(sha256 + ' kubectl').encode('utf-8'))[0].decode('utf-8') |
| 34 |
if 'OK' not in output: |
| 35 |
raise ValueError('Got wrong checksum for kubectl: %s' % output) |
| 36 |
subprocess.check_call(['chmod', 'a+x', 'kubectl'], cwd=target_dir) |
| 37 |
|
| 38 |
|
| 39 |
def main(): |
| 40 |
parser = argparse.ArgumentParser() |
| 41 |
parser.add_argument('--target_dir', '-t', required=True) |
| 42 |
args = parser.parse_args() |
| 43 |
create_asset(args.target_dir) |
| 44 |
|
| 45 |
|
| 46 |
if __name__ == '__main__': |
| 47 |
main() |
| 48 |
|