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_etcd.go
54 lines (48 loc) · 1.5 KB
/
binary_etcd.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
// 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) extractEtcd() error {
glog.V(2).Infof("Extracting %s", e.binaryEtcd.archivePath)
b, err := exec.Command("tar", "-C", e.binABSPath, "-xzvf", e.binaryEtcd.archivePath, "--strip-components=1", "--warning=no-unknown-keyword",
fmt.Sprintf("etcd-v%s-linux-amd64/etcd", e.binaryEtcd.version)).CombinedOutput()
output := string(b)
if err != nil {
glog.Errorf("Cannot untar %s, %s: %v", e.binaryEtcd.archivePath, output, err)
_ = e.binaryEtcd.removeArchive()
return err
}
_, err = os.Stat(e.binaryEtcd.binaryABSPath)
if err != nil {
glog.Errorf("Unexpected error: %v after untar %s", err, output)
return err
}
glog.V(2).Infof("Successfully untar %s: %s", e.binaryEtcd.archivePath, output)
return err
}
func (e *Environment) setupBinaryEtcd() error {
_, err := os.Stat(e.binaryEtcd.binaryABSPath)
if err == nil && e.binaryEtcd.isUpToDate() {
glog.V(4).Infof("Etcd already setup and up to date: %s", e.binaryEtcd.binaryABSPath)
return nil
}
err = e.binaryEtcd.download()
if err != nil {
return err
}
err = e.extractEtcd()
if err != nil {
return err
}
if !e.binaryEtcd.isUpToDate() {
return fmt.Errorf("etcd %s is outdated", e.binaryEtcd.binaryABSPath)
}
return nil
}