@@ -87,20 +87,9 @@ func PsRestart(appID, target string) error {
8787 return err
8888 }
8989
90- psType := ""
91- psName := ""
92-
90+ psType , psName := "" , ""
9391 if target != "" {
94- if strings .Contains (target , "-" ) {
95- replaced := strings .Replace (target , appID + "-" , "" , 1 )
96- parts := strings .Split (replaced , "-" )
97- // the API requires the type, for now
98- psType = parts [0 ]
99- // process name is the full pod
100- psName = target
101- } else {
102- psType = target
103- }
92+ psType , psName = parseType (target , appID )
10493 }
10594
10695 fmt .Printf ("Restarting processes... but first, %s!\n " , drinkOfChoice ())
@@ -139,3 +128,26 @@ func printProcesses(appID string, processes []api.Pods) {
139128 }
140129 }
141130}
131+
132+ func parseType (target string , appID string ) (string , string ) {
133+ psType , psName := "" , ""
134+
135+ if strings .Contains (target , "-" ) {
136+ replaced := strings .Replace (target , appID + "-" , "" , 1 )
137+ parts := strings .Split (replaced , "-" )
138+ // the API requires the type, for now
139+ // regex matches against how Deployment pod name is constructed
140+ regex := regexp .MustCompile ("[0-9]{8,10}-[a-z0-9]{5}$" )
141+ if regex .MatchString (replaced ) {
142+ psType = parts [0 ]
143+ } else {
144+ psType = parts [1 ]
145+ }
146+ // process name is the full pod
147+ psName = target
148+ } else {
149+ psType = target
150+ }
151+
152+ return psType , psName
153+ }
0 commit comments