Don't remove foreign runners
When garm starts up, it attempts to cleanup any orphaned runners from github. This, unfortunately ends up deleting manually set up runners. This change looks for our controller ID in the labels of the runners and only deleted runners that we created. Fixes: #40 Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
996102fd98
commit
49fbc110d5
1 changed files with 16 additions and 0 deletions
|
|
@ -63,6 +63,16 @@ type basePool struct {
|
|||
mux sync.Mutex
|
||||
}
|
||||
|
||||
func controllerIDFromLabels(labels []*github.RunnerLabels) string {
|
||||
for _, lbl := range labels {
|
||||
if lbl.Name != nil && strings.HasPrefix(*lbl.Name, controllerLabelPrefix) {
|
||||
labelName := *lbl.Name
|
||||
return labelName[len(controllerLabelPrefix):]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// cleanupOrphanedProviderRunners compares runners in github with local runners and removes
|
||||
// any local runners that are not present in Github. Runners that are "idle" in our
|
||||
// provider, but do not exist in github, will be removed. This can happen if the
|
||||
|
|
@ -143,6 +153,12 @@ func (r *basePool) reapTimedOutRunners(runners []*github.Runner) error {
|
|||
// first remove the instance from github, and then from our database.
|
||||
func (r *basePool) cleanupOrphanedGithubRunners(runners []*github.Runner) error {
|
||||
for _, runner := range runners {
|
||||
runnerControllerID := controllerIDFromLabels(runner.Labels)
|
||||
if runnerControllerID != r.controllerID {
|
||||
// Not a runner we manage. Do not remove foreign runner.
|
||||
continue
|
||||
}
|
||||
|
||||
status := runner.GetStatus()
|
||||
if status != "offline" {
|
||||
// Runner is online. Ignore it.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue