20
18
'kubectl': 'kubectl'}
22
20
self.version = version
23
self.kubernetes_file = kubernetes_file
21
self.kubernetes_file = path(kubernetes_file)
25
def install(self, output_dir='/opt/kubernetes/bin'):
23
def install(self, output_dir=path('/opt/kubernetes')):
26
24
""" Install kubernetes binary files from the tar file or gsutil. """
27
if os.path.isdir(output_dir):
28
# Remote old content to remain idempotent.
29
shutil.rmtree(output_dir)
30
# Create the output directory.
31
os.makedirs(output_dir)
33
if os.path.exists(self.kubernetes_file):
25
bindir = output_dir / 'bin'
27
for fp in bindir.files():
32
kubernetes_repo = 'http://github.com/GoogleCloudPlatform/kubernetes'
33
repo_dir = output_dir / 'kubernetes/src'
34
if not repo_dir.exists():
35
git_clone = 'git clone {0} {1}'.format(kubernetes_repo, repo_dir)
37
subprocess.check_call(git_clone.split())
39
if self.kubernetes_file.exists():
34
40
# Untar the file to the output directory.
35
41
command = 'tar -xvzf {0} -C {1}'.format(self.kubernetes_file,
38
44
output = subprocess.check_output(command, shell=True)
41
47
# Get the binaries from the gsutil command.
42
self.get_kubernetes_gsutil(output_dir)
48
self.get_kubernetes_gsutil(bindir)
44
50
# Create the symbolic links to the real kubernetes binaries.
45
51
# This can be removed if the code is changed to call real commands.
46
usr_local_bin = '/usr/local/bin'
52
usr_local_bin = path('/usr/local/bin')
47
53
for key, value in self.aliases.iteritems():
48
target = os.path.join(output_dir, key)
49
link = os.path.join(usr_local_bin, value)
50
ln_command = 'ln -s {0} {1}'.format(target, link)
51
command = ln_command.format(target, link)
53
subprocess.check_call(command.split())
55
link = usr_local_bin / value
55
60
def get_kubernetes_gsutil(self, directory):
56
61
""" Download the kubernetes binary objects from gsutil. """