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_cni.go
58 lines (52 loc) · 1.51 KB
/
binary_cni.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
// 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"
"strings"
"github.com/golang/glog"
)
func (e *Environment) extractCNI() error {
glog.V(2).Infof("Extracting %s", e.binaryCNI.archivePath)
b, err := exec.Command("tar", "-C", e.binABSPath, "-xzvf", e.binaryCNI.archivePath).CombinedOutput()
output := string(b)
if err != nil {
glog.Errorf("Cannot untar %s, %s: %v", e.binaryCNI.archivePath, output, err)
_ = e.binaryCNI.removeArchive()
return err
}
_, err = os.Stat(e.binaryCNI.binaryABSPath)
if err != nil {
glog.Errorf("Unexpected error: %v after untar %s", err, output)
return err
}
output = strings.Replace(output, "./", "", -1)
output = strings.Replace(output, "\n", " ", -1)
output = strings.TrimPrefix(output, " ")
glog.V(2).Infof("Successfully untar %s: %s", e.binaryCNI.archivePath, output)
return err
}
func (e *Environment) setupBinaryCNI() error {
_, err := os.Stat(e.binaryCNI.binaryABSPath)
if err == nil {
glog.V(4).Infof("CNI already setup: %s", e.binaryCNI.binaryABSPath)
return nil
}
err = e.binaryCNI.download()
if err != nil {
return err
}
err = e.extractCNI()
if err != nil {
return err
}
_, err = os.Stat(e.binaryCNI.binaryABSPath)
if err != nil {
return fmt.Errorf("cni %s is not here: %v", e.binaryCNI.binaryABSPath, err)
}
return nil
}