Skip to content

Commit 16312db

Browse files
authored
Merge pull request #171 from kmala/rel
feat(maintenance): Add support for maintenance mode for apps
2 parents 36df5d4 + 73a541b commit 16312db

6 files changed

Lines changed: 197 additions & 14 deletions

File tree

cmd/maintenance.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/deis/controller-sdk-go/api"
7+
"github.com/deis/controller-sdk-go/appsettings"
8+
)
9+
10+
// MaintenanceInfo tells the informations about app's maintenance status
11+
func MaintenanceInfo(appID string) error {
12+
s, appID, err := load(appID)
13+
14+
if err != nil {
15+
return err
16+
}
17+
18+
appSettings, err := appsettings.List(s.Client, appID)
19+
if checkAPICompatibility(s.Client, err) != nil {
20+
return err
21+
}
22+
23+
if *appSettings.Maintenance {
24+
fmt.Println("Maintenance mode is on.")
25+
} else {
26+
fmt.Println("Maintenance mode is off.")
27+
}
28+
return nil
29+
}
30+
31+
// MaintenanceEnable turns on the maintenance for the app.
32+
func MaintenanceEnable(appID string) error {
33+
s, appID, err := load(appID)
34+
35+
if err != nil {
36+
return err
37+
}
38+
39+
fmt.Printf("Enabling maintenance mode for %s... ", appID)
40+
41+
quit := progress()
42+
b := true
43+
_, err = appsettings.Set(s.Client, appID, api.AppSettings{Maintenance: &b})
44+
45+
quit <- true
46+
<-quit
47+
48+
if err != nil {
49+
return err
50+
}
51+
52+
fmt.Print("done\n\n")
53+
return nil
54+
}
55+
56+
// MaintenanceDisable turns off the maintenance for the app.
57+
func MaintenanceDisable(appID string) error {
58+
s, appID, err := load(appID)
59+
60+
if err != nil {
61+
return err
62+
}
63+
64+
fmt.Printf("Disabling maintenance mode for %s... ", appID)
65+
66+
quit := progress()
67+
b := false
68+
_, err = appsettings.Set(s.Client, appID, api.AppSettings{Maintenance: &b})
69+
70+
quit <- true
71+
<-quit
72+
73+
if err != nil {
74+
return err
75+
}
76+
77+
fmt.Print("done\n\n")
78+
return nil
79+
}

cmd/routing.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55

66
"github.com/deis/controller-sdk-go/api"
7-
"github.com/deis/controller-sdk-go/config"
7+
"github.com/deis/controller-sdk-go/appsettings"
88
)
99

1010
func RoutingInfo(appID string) error {
@@ -14,12 +14,12 @@ func RoutingInfo(appID string) error {
1414
return err
1515
}
1616

17-
config, err := config.List(s.Client, appID)
17+
appSettings, err := appsettings.List(s.Client, appID)
1818
if checkAPICompatibility(s.Client, err) != nil {
1919
return err
2020
}
2121

22-
if *config.Routable {
22+
if *appSettings.Routable {
2323
fmt.Println("Routing is enabled.")
2424
} else {
2525
fmt.Println("Routing is disabled.")
@@ -38,8 +38,8 @@ func RoutingEnable(appID string) error {
3838
fmt.Printf("Enabling routing for %s... ", appID)
3939

4040
quit := progress()
41-
configObj := api.Config{Routable: api.NewRoutable()}
42-
_, err = config.Set(s.Client, appID, configObj)
41+
appSettings := api.AppSettings{Routable: api.NewRoutable()}
42+
_, err = appsettings.Set(s.Client, appID, appSettings)
4343

4444
quit <- true
4545
<-quit
@@ -63,9 +63,9 @@ func RoutingDisable(appID string) error {
6363
fmt.Printf("Disabling routing for %s... ", appID)
6464

6565
quit := progress()
66-
configObj := api.Config{Routable: api.NewRoutable()}
67-
*configObj.Routable = false
68-
_, err = config.Set(s.Client, appID, configObj)
66+
appSettings := api.AppSettings{Routable: api.NewRoutable()}
67+
*appSettings.Routable = false
68+
_, err = appsettings.Set(s.Client, appID, appSettings)
6969

7070
quit <- true
7171
<-quit

deis.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Subcommands, use 'deis help [subcommand]' to learn more::
5252
registry manage private registry information for your application
5353
releases manage releases of an application
5454
routing manage routability of an application
55+
maintenance manage maintenance mode of an application
5556
tags manage tags for application containers
5657
users manage users
5758
version display client version
@@ -120,6 +121,8 @@ Use 'git push deis master' to deploy to an application.
120121
err = parser.Releases(argv)
121122
case "routing":
122123
err = parser.Routing(argv)
124+
case "maintenance":
125+
err = parser.Maintenance(argv)
123126
case "shortcuts":
124127
err = parser.Shortcuts(argv)
125128
case "tags":

glide.lock

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ import:
1616
- package: github.com/olekukonko/tablewriter
1717
- package: github.com/arschles/assert
1818
- package: github.com/deis/controller-sdk-go
19-
version: d71c8ccf0e9076da84644ce31f359dfedc88c3f3
19+
version: a28a40b255a81d59a3e071ce7203d845094bdd6c

parser/maintenance.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package parser
2+
3+
import (
4+
"github.com/deis/workflow-cli/cmd"
5+
docopt "github.com/docopt/docopt-go"
6+
)
7+
8+
// Maintenance displays all relevant commands for `deis maintenance`.
9+
func Maintenance(argv []string) error {
10+
usage := `
11+
Valid commands for maintenance:
12+
13+
maintenance:info view maintenance mode of an application
14+
maintenance:on turn on maintenance for an app
15+
maintenance:off turn off maintenance for an app
16+
17+
Use 'deis help [command]' to learn more.
18+
`
19+
20+
switch argv[0] {
21+
case "maintenance:info":
22+
return maintenanceInfo(argv)
23+
case "maintenance:on":
24+
return maintenanceEnable(argv)
25+
case "maintenance:off":
26+
return maintenanceDisable(argv)
27+
default:
28+
if printHelp(argv, usage) {
29+
return nil
30+
}
31+
32+
if argv[0] == "maintenance" {
33+
argv[0] = "maintenance:info"
34+
return maintenanceInfo(argv)
35+
}
36+
37+
PrintUsage()
38+
return nil
39+
}
40+
}
41+
42+
func maintenanceInfo(argv []string) error {
43+
usage := `
44+
Prints info about the current application's maintenance state.
45+
46+
Usage: deis maintenance:info [options]
47+
48+
Options:
49+
-a --app=<app>
50+
the uniquely identifiable name for the application.
51+
`
52+
53+
args, err := docopt.Parse(usage, argv, true, "", false, true)
54+
55+
if err != nil {
56+
return err
57+
}
58+
59+
return cmd.MaintenanceInfo(safeGetValue(args, "--app"))
60+
}
61+
62+
func maintenanceEnable(argv []string) error {
63+
usage := `
64+
Enables maintenance mode for an app.
65+
66+
Usage: deis maintenance:on [options]
67+
68+
Options:
69+
-a --app=<app>
70+
the uniquely identifiable name of the application.
71+
`
72+
73+
args, err := docopt.Parse(usage, argv, true, "", false, true)
74+
75+
if err != nil {
76+
return err
77+
}
78+
79+
return cmd.MaintenanceEnable(safeGetValue(args, "--app"))
80+
}
81+
82+
func maintenanceDisable(argv []string) error {
83+
usage := `
84+
Disables maintenance mode for an app.
85+
86+
Usage: deis maintenance:off [options]
87+
88+
Options:
89+
-a --app=<app>
90+
the uniquely identifiable name of the application.
91+
`
92+
93+
args, err := docopt.Parse(usage, argv, true, "", false, true)
94+
95+
if err != nil {
96+
return err
97+
}
98+
99+
return cmd.MaintenanceDisable(safeGetValue(args, "--app"))
100+
}

0 commit comments

Comments
 (0)