Don't allow managed workers to be deleted (#3254)

This also adds checks to ensure the tag cannot be added to workers via
the API.
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2023-05-31 14:23:57 -04:00
1 parent 84b96f89a7
commit 3d5bed9ce8
3 files changed
+88 -11

No files matched your search

+17
View File
@@ -81,3 +81,20 @@ func (w WorkerList) Filtered(eval *bexpr.Evaluator) (WorkerList, error) {
}
return ret, nil
}
// SeparateManagedWorkers divides the incoming workers into managed and
// unmanaged workers, respectively
func SeparateManagedWorkers(workers WorkerList) (managedWorkers, nonManagedWorkers WorkerList) {
// Build a set of managed and unmanaged workers
managedWorkers = make([]*server.Worker, 0, len(workers))
nonManagedWorkers = make([]*server.Worker, 0, len(workers))
for _, worker := range workers {
tags := worker.CanonicalTags()
if len(tags[ManagedWorkerTag]) != 0 {
managedWorkers = append(managedWorkers, worker)
} else {
nonManagedWorkers = append(nonManagedWorkers, worker)
}
}
return managedWorkers, nonManagedWorkers
}