-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathupgrade.go
More file actions
195 lines (161 loc) · 5.32 KB
/
upgrade.go
File metadata and controls
195 lines (161 loc) · 5.32 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package cmd
import (
"bytes"
"fmt"
"io"
"sync"
"github.com/deis/deis/deisctl/backend"
"github.com/deis/deis/deisctl/config"
"github.com/deis/deis/deisctl/config/model"
)
// UpgradePrep stops and uninstalls all components except router and publisher
func UpgradePrep(stateless bool, b backend.Backend) error {
var wg sync.WaitGroup
b.Stop([]string{"database", "registry@*", "controller", "builder", "logger", "logspout"}, &wg, Stdout, Stderr)
wg.Wait()
b.Destroy([]string{"database", "registry@*", "controller", "builder", "logger", "logspout"}, &wg, Stdout, Stderr)
wg.Wait()
if !stateless {
b.Stop([]string{"store-volume", "store-gateway@*"}, &wg, Stdout, Stderr)
wg.Wait()
b.Destroy([]string{"store-volume", "store-gateway@*"}, &wg, Stdout, Stderr)
wg.Wait()
b.Stop([]string{"store-metadata"}, &wg, Stdout, Stderr)
wg.Wait()
b.Destroy([]string{"store-metadata"}, &wg, Stdout, Stderr)
wg.Wait()
b.Stop([]string{"store-daemon"}, &wg, Stdout, Stderr)
wg.Wait()
b.Destroy([]string{"store-daemon"}, &wg, Stdout, Stderr)
wg.Wait()
b.Stop([]string{"store-monitor"}, &wg, Stdout, Stderr)
wg.Wait()
b.Destroy([]string{"store-monitor"}, &wg, Stdout, Stderr)
wg.Wait()
}
fmt.Fprintln(Stdout, "The platform has been stopped, but applications are still serving traffic as normal.")
fmt.Fprintln(Stdout, "Your cluster is now ready for upgrade. Install a new deisctl version and run `deisctl upgrade-takeover`.")
fmt.Fprintln(Stdout, "For more details, see: http://docs.deis.io/en/latest/managing_deis/upgrading-deis/#graceful-upgrade")
return nil
}
func listPublishedServices(cb config.Backend) ([]*model.ConfigNode, error) {
nodes, err := cb.GetRecursive("deis/services")
if err != nil {
return nil, err
}
return nodes, nil
}
func republishServices(ttl uint64, nodes []*model.ConfigNode, cb config.Backend) error {
for _, node := range nodes {
_, err := cb.SetWithTTL(node.Key, node.Value, ttl)
if err != nil {
return err
}
}
return nil
}
// UpgradeTakeover gracefully starts a platform stopped with UpgradePrep
func UpgradeTakeover(stateless bool, b backend.Backend, cb config.Backend) error {
if err := doUpgradeTakeOver(stateless, b, cb); err != nil {
return err
}
return nil
}
func doUpgradeTakeOver(stateless bool, b backend.Backend, cb config.Backend) error {
var wg sync.WaitGroup
nodes, err := listPublishedServices(cb)
if err != nil {
return err
}
b.Stop([]string{"publisher"}, &wg, Stdout, Stderr)
wg.Wait()
b.Destroy([]string{"publisher"}, &wg, Stdout, Stderr)
wg.Wait()
if err := republishServices(1800, nodes, cb); err != nil {
return err
}
b.RollingRestart("router", &wg, Stdout, Stderr)
wg.Wait()
b.Create([]string{"publisher"}, &wg, Stdout, Stderr)
wg.Wait()
b.Start([]string{"publisher"}, &wg, Stdout, Stderr)
wg.Wait()
installUpgradeServices(b, stateless, &wg, Stdout, Stderr)
wg.Wait()
startUpgradeServices(b, stateless, &wg, Stdout, Stderr)
wg.Wait()
return nil
}
func installUpgradeServices(b backend.Backend, stateless bool, wg *sync.WaitGroup, out, err io.Writer) {
if !stateless {
fmt.Fprintln(out, "Storage subsystem...")
b.Create([]string{"store-daemon", "store-monitor", "store-metadata", "store-volume", "store-gateway@1"}, wg, out, err)
wg.Wait()
}
fmt.Fprintln(out, "Logging subsystem...")
if stateless {
b.Create([]string{"logspout"}, wg, out, err)
} else {
b.Create([]string{"logger", "logspout"}, wg, out, err)
}
wg.Wait()
fmt.Fprintln(out, "Control plane...")
if stateless {
b.Create([]string{"registry@1", "controller", "builder"}, wg, out, err)
} else {
b.Create([]string{"database", "registry@1", "controller", "builder"}, wg, out, err)
}
wg.Wait()
fmt.Fprintln(out, "Data plane...")
b.Create([]string{"publisher"}, wg, out, err)
wg.Wait()
}
func startUpgradeServices(b backend.Backend, stateless bool, wg *sync.WaitGroup, out, err io.Writer) {
// Wait for groups to come up.
// If we're running in stateless mode, we start only a subset of services.
if !stateless {
fmt.Fprintln(out, "Storage subsystem...")
b.Start([]string{"store-monitor"}, wg, out, err)
wg.Wait()
b.Start([]string{"store-daemon"}, wg, out, err)
wg.Wait()
b.Start([]string{"store-metadata"}, wg, out, err)
wg.Wait()
// we start gateway first to give metadata time to come up for volume
b.Start([]string{"store-gateway@*"}, wg, out, err)
wg.Wait()
b.Start([]string{"store-volume"}, wg, out, err)
wg.Wait()
}
// start logging subsystem first to collect logs from other components
fmt.Fprintln(out, "Logging subsystem...")
if !stateless {
b.Start([]string{"logger"}, wg, out, err)
wg.Wait()
}
b.Start([]string{"logspout"}, wg, out, err)
wg.Wait()
// Start these in parallel. This section can probably be removed now.
var bgwg sync.WaitGroup
var trash bytes.Buffer
batch := []string{
"database", "registry@*", "controller", "builder",
"publisher",
}
if stateless {
batch = []string{"registry@*", "controller", "builder", "publisher", "router@*"}
}
b.Start(batch, &bgwg, &trash, &trash)
fmt.Fprintln(Stdout, "Control plane...")
batch = []string{"database", "registry@*", "controller"}
if stateless {
batch = []string{"registry@*", "controller"}
}
b.Start(batch, wg, out, err)
wg.Wait()
b.Start([]string{"builder"}, wg, out, err)
wg.Wait()
fmt.Fprintln(out, "Data plane...")
b.Start([]string{"publisher"}, wg, out, err)
wg.Wait()
}