Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: deploytool/cmd/luci_deploy/manage.go

Issue 2963503003: [errors] Greatly simplify common/errors package. (Closed)
Patch Set: fix nits Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « deploytool/cmd/luci_deploy/layout.go ('k') | deploytool/cmd/luci_deploy/param.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "strconv" 9 "strconv"
10 "strings" 10 "strings"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 switch dep, comp, err := a.layout.getDeploymentComponent(name); { 79 switch dep, comp, err := a.layout.getDeploymentComponent(name); {
80 case err != nil: 80 case err != nil:
81 return nil, err 81 return nil, err
82 82
83 case comp != nil: 83 case comp != nil:
84 mApp.dp.addProjectComponent(comp) 84 mApp.dp.addProjectComponent(comp)
85 err := a.runWork(c, func(w *work) error { 85 err := a.runWork(c, func(w *work) error {
86 return mApp.dp.initialize(w, &a.layout) 86 return mApp.dp.initialize(w, &a.layout)
87 }) 87 })
88 if err != nil { 88 if err != nil {
89 » » » return nil, errors.Annotate(err).Reason("failed to initi alize deployment plan").Err() 89 » » » return nil, errors.Annotate(err, "failed to initialize d eployment plan").Err()
90 } 90 }
91 91
92 switch comp.GetComponent().(type) { 92 switch comp.GetComponent().(type) {
93 case *deploy.Component_AppengineModule: 93 case *deploy.Component_AppengineModule:
94 break 94 break
95 case *deploy.Component_GkePod: 95 case *deploy.Component_GkePod:
96 mApp.subcommands = append(mApp.subcommands, []*subcomman ds.Command{ 96 mApp.subcommands = append(mApp.subcommands, []*subcomman ds.Command{
97 { 97 {
98 UsageLine: "kubectl <args...>", 98 UsageLine: "kubectl <args...>",
99 ShortDesc: "run a kubectl command", 99 ShortDesc: "run a kubectl command",
(...skipping 29 matching lines...) Expand all
129 default: 129 default:
130 break 130 break
131 } 131 }
132 132
133 default: 133 default:
134 mApp.dp.addDeployment(dep) 134 mApp.dp.addDeployment(dep)
135 err := a.runWork(c, func(w *work) error { 135 err := a.runWork(c, func(w *work) error {
136 return mApp.dp.initialize(w, &a.layout) 136 return mApp.dp.initialize(w, &a.layout)
137 }) 137 })
138 if err != nil { 138 if err != nil {
139 » » » return nil, errors.Annotate(err).Reason("failed to initi alize deployment plan").Err() 139 » » » return nil, errors.Annotate(err, "failed to initialize d eployment plan").Err()
140 } 140 }
141 141
142 if cp := dep.cloudProject; cp != nil { 142 if cp := dep.cloudProject; cp != nil {
143 mApp.subcommands = append(mApp.subcommands, &subcommands .Command{ 143 mApp.subcommands = append(mApp.subcommands, &subcommands .Command{
144 UsageLine: "update_appengine", 144 UsageLine: "update_appengine",
145 ShortDesc: "update AppEngine parameters", 145 ShortDesc: "update AppEngine parameters",
146 LongDesc: "Update AppEngine cron, dispatch, ind ex, and queue configurations.", 146 LongDesc: "Update AppEngine cron, dispatch, ind ex, and queue configurations.",
147 CommandRun: func() subcommands.CommandRun { 147 CommandRun: func() subcommands.CommandRun {
148 return &updateGAECommandRun{ 148 return &updateGAECommandRun{
149 project: cp, 149 project: cp,
(...skipping 25 matching lines...) Expand all
175 bp, err := getPodBindingForCluster(cmd.comp, cmd.cluster) 175 bp, err := getPodBindingForCluster(cmd.comp, cmd.cluster)
176 if err != nil { 176 if err != nil {
177 logError(c, err, "Failed to identify cluster.") 177 logError(c, err, "Failed to identify cluster.")
178 return 1 178 return 1
179 } 179 }
180 180
181 var rv int 181 var rv int
182 err = a.runWork(c, func(w *work) error { 182 err = a.runWork(c, func(w *work) error {
183 kubeCtx, err := getContainerEngineKubernetesContext(w, bp.cluste r) 183 kubeCtx, err := getContainerEngineKubernetesContext(w, bp.cluste r)
184 if err != nil { 184 if err != nil {
185 » » » return errors.Annotate(err).Err() 185 » » » return errors.Annotate(err, "").Err()
186 } 186 }
187 187
188 kubectl, err := w.tools.kubectl(kubeCtx) 188 kubectl, err := w.tools.kubectl(kubeCtx)
189 if err != nil { 189 if err != nil {
190 » » » return errors.Annotate(err).Err() 190 » » » return errors.Annotate(err, "").Err()
191 } 191 }
192 192
193 rv, err = kubectl.exec(args...).forwardOutput().run(w) 193 rv, err = kubectl.exec(args...).forwardOutput().run(w)
194 return err 194 return err
195 }) 195 })
196 if err != nil { 196 if err != nil {
197 logError(c, err, "Failed to run kubectl command.") 197 logError(c, err, "Failed to run kubectl command.")
198 if rv == 0 { 198 if rv == 0 {
199 rv = 1 199 rv = 1
200 } 200 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 if cmd.dryRun { 245 if cmd.dryRun {
246 log.Infof(c, "(Dry run) Generated 'gcloud' command: gcloud %s", strings.Join(gcloudArgs, " ")) 246 log.Infof(c, "(Dry run) Generated 'gcloud' command: gcloud %s", strings.Join(gcloudArgs, " "))
247 return 0 247 return 0
248 } 248 }
249 249
250 var rv int 250 var rv int
251 err = a.runWork(c, func(w *work) (err error) { 251 err = a.runWork(c, func(w *work) (err error) {
252 cloudProjectName := bp.pod.comp.dep.cloudProject.Name 252 cloudProjectName := bp.pod.comp.dep.cloudProject.Name
253 gcloud, err := w.tools.gcloud(cloudProjectName) 253 gcloud, err := w.tools.gcloud(cloudProjectName)
254 if err != nil { 254 if err != nil {
255 » » » return errors.Annotate(err).Err() 255 » » » return errors.Annotate(err, "").Err()
256 } 256 }
257 257
258 if rv, err = gcloud.exec(gcloudArgs[0], gcloudArgs[1:]...).run(w ); err != nil { 258 if rv, err = gcloud.exec(gcloudArgs[0], gcloudArgs[1:]...).run(w ); err != nil {
259 » » » return errors.Annotate(err).Reason("failed to run 'gclou d' command").Err() 259 » » » return errors.Annotate(err, "failed to run 'gcloud' comm and").Err()
260 } 260 }
261 return nil 261 return nil
262 }) 262 })
263 if err != nil { 263 if err != nil {
264 logError(c, err, "Failed to run gcloud command.") 264 logError(c, err, "Failed to run gcloud command.")
265 if rv == 0 { 265 if rv == 0 {
266 rv = 1 266 rv = 1
267 } 267 }
268 } 268 }
269 return rv 269 return rv
270 } 270 }
271 271
272 func getPodBindingForCluster(comp *layoutDeploymentComponent, cluster string) (* layoutDeploymentGKEPodBinding, error) { 272 func getPodBindingForCluster(comp *layoutDeploymentComponent, cluster string) (* layoutDeploymentGKEPodBinding, error) {
273 var bp *layoutDeploymentGKEPodBinding 273 var bp *layoutDeploymentGKEPodBinding
274 switch { 274 switch {
275 case cluster != "": 275 case cluster != "":
276 cluster := comp.dep.cloudProject.gkeClusters[cluster] 276 cluster := comp.dep.cloudProject.gkeClusters[cluster]
277 if cluster == nil { 277 if cluster == nil {
278 » » » return nil, errors.Reason("invalid GKE cluster name: %(n ame)q"). 278 » » » return nil, errors.Reason("invalid GKE cluster name: %q" , cluster).Err()
279 » » » » D("name", cluster).
280 » » » » Err()
281 } 279 }
282 for _, gkeBP := range comp.gkePods { 280 for _, gkeBP := range comp.gkePods {
283 if gkeBP.cluster == cluster { 281 if gkeBP.cluster == cluster {
284 bp = gkeBP 282 bp = gkeBP
285 break 283 break
286 } 284 }
287 } 285 }
288 286
289 case len(comp.gkePods) == 0: 287 case len(comp.gkePods) == 0:
290 return nil, errors.New("pod is not bound to any clusters") 288 return nil, errors.New("pod is not bound to any clusters")
291 289
292 case len(comp.gkePods) == 1: 290 case len(comp.gkePods) == 1:
293 bp = comp.gkePods[0] 291 bp = comp.gkePods[0]
294 292
295 default: 293 default:
296 clusters := make([]string, len(comp.gkePods)) 294 clusters := make([]string, len(comp.gkePods))
297 for i, cluster := range comp.gkePods { 295 for i, cluster := range comp.gkePods {
298 clusters[i] = fmt.Sprintf("- %s", cluster.cluster.Name) 296 clusters[i] = fmt.Sprintf("- %s", cluster.cluster.Name)
299 } 297 }
300 298
301 return nil, errors.Reason("the Kubernetes pod is bound to multip le clusters. Specify one with -cluster"). 299 return nil, errors.Reason("the Kubernetes pod is bound to multip le clusters. Specify one with -cluster").
302 » » » D("clusters", clusters). 300 » » » InternalReason("clusters(%v)", clusters).Err()
303 » » » Err()
304 } 301 }
305 if bp == nil { 302 if bp == nil {
306 return nil, errors.New("Could not identify cluster for pod.") 303 return nil, errors.New("Could not identify cluster for pod.")
307 } 304 }
308 return bp, nil 305 return bp, nil
309 } 306 }
310 307
311 //////////////////////////////////////////////////////////////////////////////// 308 ////////////////////////////////////////////////////////////////////////////////
312 // Manage / GAE 309 // Manage / GAE
313 //////////////////////////////////////////////////////////////////////////////// 310 ////////////////////////////////////////////////////////////////////////////////
(...skipping 21 matching lines...) Expand all
335 err := a.runWork(c, func(w *work) error { 332 err := a.runWork(c, func(w *work) error {
336 a.dp.params.stage = deployCommit 333 a.dp.params.stage = deployCommit
337 return a.dp.deploy(w) 334 return a.dp.deploy(w)
338 }) 335 })
339 if err != nil { 336 if err != nil {
340 logError(c, err, "Failed to update GAE parameters.") 337 logError(c, err, "Failed to update GAE parameters.")
341 return 1 338 return 1
342 } 339 }
343 return rv 340 return rv
344 } 341 }
OLDNEW
« no previous file with comments | « deploytool/cmd/luci_deploy/layout.go ('k') | deploytool/cmd/luci_deploy/param.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698