This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
binary_hyperkube.go
69 lines (63 loc) · 1.96 KB
/
binary_hyperkube.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2018 Datadog, Inc.
package setup
import (
"fmt"
"os"
"os/exec"
"github.com/golang/glog"
)
func (e *Environment) extractHyperkube() error {
glog.V(2).Infof("Extracting %s", e.binaryHyperkube.archivePath)
b, err := exec.Command("tar", "-C", e.binABSPath, "-xzvf", e.binaryHyperkube.archivePath, "--strip-components=3", "kubernetes/server/bin/hyperkube").CombinedOutput()
output := string(b)
if err != nil {
glog.Errorf("Cannot untar %s, %s: %v", e.binaryHyperkube.archivePath, output, err)
return err
}
_, err = os.Stat(e.binaryHyperkube.binaryABSPath)
if err != nil {
glog.Errorf("Unexpected error: %v after untar %s", err, output)
}
glog.V(2).Infof("Successfully untar %s: %s", e.binaryHyperkube.archivePath, output)
wd, err := os.Getwd()
if err != nil {
glog.Errorf("Cannot get wd: %v", err)
return err
}
defer os.Chdir(wd)
err = os.Chdir(e.binABSPath)
if err != nil {
glog.Errorf("Cannot chdir: %v", err)
return err
}
b, err = exec.Command(e.GetHyperkubePath(), "--make-symlinks").CombinedOutput()
output = string(b)
if err != nil {
glog.Warningf("Cannot generate links for hyperkube: %v %s", err, output)
return nil
}
glog.V(2).Infof("Generated links for hyperkube in %s", e.binABSPath)
return nil
}
func (e *Environment) setupBinaryHyperkube() error {
_, err := os.Stat(e.binaryHyperkube.binaryABSPath)
if err == nil && e.binaryHyperkube.isUpToDate() {
glog.V(4).Infof("Hyperkube already setup and up to date: %s", e.binaryHyperkube.binaryABSPath)
return nil
}
err = e.binaryHyperkube.download()
if err != nil {
return err
}
err = e.extractHyperkube()
if err != nil {
return err
}
if !e.binaryHyperkube.isUpToDate() {
return fmt.Errorf("hyperkube %s is outdated", e.binaryHyperkube.binaryABSPath)
}
return nil
}