This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 302
fleetctl: support overwrite command #1295
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/coreos/fleet/job" | ||
) | ||
|
||
var cmdOverwriteUnit = &Command{ | ||
Name: "overwrite", | ||
Summary: "Overwrite one or more units in the cluster", | ||
Usage: "UNIT...", | ||
Description: `Overwrite one or more running or submitted units from the cluster. | ||
|
||
Act as a procedure of stop-->destroy-->commit-->start(if needed) on unit(s)`, | ||
|
||
Run: runOverwriteUnits, | ||
} | ||
|
||
func runOverwriteUnits(args []string) (exit int) { | ||
for _, v := range args { | ||
v = maybeAppendDefaultUnitType(v) | ||
name := unitNameMangle(v) | ||
|
||
u, err := cAPI.Unit(name) | ||
if err != nil { | ||
stderr("error retrieving Unit(%s) from Registry: %v", name, err) | ||
return 1 | ||
} | ||
if u == nil { | ||
stdout("Unit(%s) in can not be found in Registry, nothing to do with it", name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the first "in" |
||
continue | ||
} | ||
|
||
hash_mismatch := warnOnDifferentLocalUnit(v, u) | ||
if hash_mismatch == false { | ||
stdout("Nothing different between Unit(%s) in registory and local unit file, just skip", name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace "just skip" with "ignoring" |
||
continue | ||
} | ||
|
||
stopping := make([]string, 0) | ||
stopping = append(stopping, u.Name) | ||
if job.JobState(u.CurrentState) == job.JobStateLaunched || suToGlobal(*u) { | ||
stdout("Stop Unit(%s) first, so that we can overwrite unit file", u.Name) | ||
cAPI.SetUnitTargetState(u.Name, string(job.JobStateLoaded)) | ||
errchan := waitForUnitStates(stopping, job.JobStateLoaded, 0, os.Stdout) | ||
for err := range errchan { | ||
stderr("Error waiting for units: %v", err) | ||
exit = 1 | ||
} | ||
} | ||
|
||
err = cAPI.DestroyUnit(name) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
recreating := make([]string, 0) | ||
recreating = append(recreating, v) | ||
stdout("Recreating unit(%s)", v) | ||
if err := lazyCreateUnits(recreating); err != nil { | ||
stderr("Error creating units: %v", err) | ||
return | ||
} | ||
if job.JobState(u.CurrentState) == job.JobStateInactive { | ||
continue | ||
} else if job.JobState(u.CurrentState) == job.JobStateLoaded { | ||
stdout("Rescheduling unit(%s)", v) | ||
triggered, err := lazyLoadUnits(recreating) | ||
if err != nil { | ||
stderr("Error loading units: %v", err) | ||
return 1 | ||
} | ||
|
||
var loading []string | ||
for _, u := range triggered { | ||
if suToGlobal(*u) { | ||
stdout("Triggered global unit %s load", u.Name) | ||
} else { | ||
loading = append(loading, u.Name) | ||
} | ||
} | ||
|
||
errchan := waitForUnitStates(loading, job.JobStateLoaded, sharedFlags.BlockAttempts, os.Stdout) | ||
for err := range errchan { | ||
stderr("Error waiting for units: %v", err) | ||
} | ||
} else if job.JobState(u.CurrentState) == job.JobStateLaunched { | ||
stdout("Restarting unit(%s)", v) | ||
triggered, err := lazyStartUnits(recreating) | ||
if err != nil { | ||
stderr("Error starting units: %v", err) | ||
return 1 | ||
} | ||
|
||
var starting []string | ||
for _, u := range triggered { | ||
if suToGlobal(*u) { | ||
stdout("Triggered global unit %s start", u.Name) | ||
} else { | ||
starting = append(starting, u.Name) | ||
} | ||
} | ||
|
||
errchan := waitForUnitStates(starting, job.JobStateLaunched, sharedFlags.BlockAttempts, os.Stdout) | ||
for err := range errchan { | ||
stderr("Error waiting for units: %v", err) | ||
exit = 1 | ||
} | ||
} | ||
|
||
} | ||
return | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace the description with this:
Overwrite stops (if needed), unload (if needed), and destroys, then submits, loads (if needed) and starts (if needed) the unit after replacing the unit file with that found on the local filesystem