forked from kubernetes/kops
/
kube_boot_task.go
157 lines (152 loc) · 3.77 KB
/
kube_boot_task.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package protokube
//
//import (
// "encoding/json"
// "fmt"
// "github.com/golang/glog"
// "io"
// "io/ioutil"
// "os"
// "os/exec"
// "path"
// "strings"
// "sync"
// "time"
//)
//
//const BootstrapDir = "/etc/kubernetes/bootstrap"
//
//type BootstrapTask struct {
// Command []string `json:"command"`
//}
//
//func (b *BootstrapTask) String() string {
// return DebugString(b)
//}
//
//// RunKubelet runs the bootstrap tasks, and watches them until they exit
//// Currently only one task is supported / will work properly
//func (k *KubeBoot) RunBootstrapTasks() error {
// bootstrapDir := pathFor(BootstrapDir)
//
// var dirs []os.FileInfo
// var err error
//
// for {
// dirs, err = ioutil.ReadDir(bootstrapDir)
// if err != nil {
// if os.IsNotExist(err) {
// dirs = nil
// } else {
// return fmt.Errorf("error listing %q: %v", bootstrapDir, err)
// }
// }
// if len(dirs) != 0 {
// break
// }
// glog.Infof("No entries found in %q", BootstrapDir)
// time.Sleep(10 * time.Second)
// }
//
// for _, dir := range dirs {
// if !dir.IsDir() {
// continue
// }
//
// p := path.Join(bootstrapDir, dir.Name())
// files, err := ioutil.ReadDir(p)
// if err != nil {
// return fmt.Errorf("error listing %q: %v", p, err)
// }
//
// if len(files) == 0 {
// glog.Infof("No files in %q; ignoring", p)
// continue
// }
//
// // TODO: Support more than one bootstrap task?
//
// // TODO: Have multiple proto-kubelet configurations to support recovery?
// // i.e. launch newest version that stays up?
//
// fp := path.Join(p, files[0].Name())
// err = k.runBootstrapTask(fp)
// if err != nil {
// return fmt.Errorf("error running bootstrap task %q: %v", fp, err)
// }
// }
//
// return nil
//}
//
//// RunKubelet runs a bootstrap task and watches it until it exits
//func (k *KubeBoot) runBootstrapTask(path string) error {
// // TODO: Use a file lock or similar to only start proto-kubelet if real-kubelet is not running?
//
// data, err := ioutil.ReadFile(path)
// if err != nil {
// return fmt.Errorf("error reading task %q: %v", path, err)
// }
//
// task := &BootstrapTask{}
//
// err = json.Unmarshal(data, task)
// if err != nil {
// return fmt.Errorf("error parsing task %q: %v", path, err)
// }
//
// name := task.Command[0]
// args := task.Command[1:]
//
// cmd := exec.Command(name, args...)
//
// stdout, err := cmd.StdoutPipe()
// if err != nil {
// return fmt.Errorf("error building stdout pipe: %v", err)
// }
// stderr, err := cmd.StderrPipe()
// if err != nil {
// return fmt.Errorf("error building stderr pipe: %v", err)
// }
//
// wg := new(sync.WaitGroup)
// wg.Add(2)
//
// err = cmd.Start()
// if err != nil {
// return fmt.Errorf("error starting command %q: %v", strings.Join(task.Command, " "), err)
// }
//
// go copyStream(os.Stdout, stdout, wg)
// go copyStream(os.Stderr, stderr, wg)
//
// wg.Wait()
//
// err = cmd.Wait()
// if err != nil {
// return fmt.Errorf("error from command %q: %v", task.Command, err)
// }
//
// return nil
//}
//
//func copyStream(dst io.Writer, src io.ReadCloser, waitGroup *sync.WaitGroup) {
// _, err := io.Copy(dst, src)
// if err != nil {
// // Not entirely sure if we need to do something special in this case?
// glog.Warningf("error copying stream: %v", err)
// }
// waitGroup.Done()
//}