Allow bypassing Unauthorized error when deleting runner
This change allows users to bypass GitHub Unauthorized errors when removing github runners. This means that removing runners will now be possible even if the pool manager is stopped. There is a new flag added to the runner rm command and to the API that tells GARM to bypass pool being stopped and any 401 error returned by GitHub. This means you will be able to remove the runners from garm and your provider, but will mean that the runner will still exist in github as "offline" if the credentials are not updated or the runner manually removed. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
df72c4917e
commit
9a6770c3a3
19 changed files with 730 additions and 123 deletions
|
|
@ -388,9 +388,9 @@ func getInstance(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAuthInfoWrit
|
|||
return &getInstancesResponse.Payload, nil
|
||||
}
|
||||
|
||||
func deleteInstance(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAuthInfoWriter, instanceID string, forceRemove bool) error {
|
||||
func deleteInstance(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAuthInfoWriter, instanceID string, forceRemove, bypassGHUnauthorized bool) error {
|
||||
return apiCli.Instances.DeleteInstance(
|
||||
clientInstances.NewDeleteInstanceParams().WithInstanceName(instanceID).WithForceRemove(&forceRemove),
|
||||
clientInstances.NewDeleteInstanceParams().WithInstanceName(instanceID).WithForceRemove(&forceRemove).WithBypassGHUnauthorized(&bypassGHUnauthorized),
|
||||
apiAuthToken)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func GracefulCleanup() {
|
|||
panic(err)
|
||||
}
|
||||
for _, instance := range poolInstances {
|
||||
if err := deleteInstance(cli, authToken, instance.Name, false); err != nil {
|
||||
if err := deleteInstance(cli, authToken, instance.Name, false, false); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
slog.Info("Instance deletion initiated", "instance", instance.Name, "stage", "graceful_cleanup")
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ func waitInstanceStatus(name string, status commonParams.InstanceStatus, runnerS
|
|||
return nil, fmt.Errorf("timeout waiting for instance %s status to reach status %s and runner status %s", name, status, runnerStatus)
|
||||
}
|
||||
|
||||
func DeleteInstance(name string, forceRemove bool) {
|
||||
func DeleteInstance(name string, forceRemove, bypassGHUnauthorized bool) {
|
||||
slog.Info("Delete instance", "instance_name", name, "force_remove", forceRemove)
|
||||
if err := deleteInstance(cli, authToken, name, forceRemove); err != nil {
|
||||
if err := deleteInstance(cli, authToken, name, forceRemove, bypassGHUnauthorized); err != nil {
|
||||
slog.Error("Failed to delete instance", "instance_name", name, "error", err)
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,12 +124,12 @@ func main() {
|
|||
}
|
||||
repoPool2 = e2e.GetRepoPool(repo.ID, repoPool2.ID)
|
||||
e2e.DisableRepoPool(repo.ID, repoPool2.ID)
|
||||
e2e.DeleteInstance(repoPool2.Instances[0].Name, false)
|
||||
e2e.DeleteInstance(repoPool2.Instances[0].Name, false, false)
|
||||
err = e2e.WaitPoolInstances(repoPool2.ID, commonParams.InstancePendingDelete, params.RunnerPending, 1*time.Minute)
|
||||
if err != nil {
|
||||
slog.With(slog.Any("error", err)).Error("Failed to wait for instance to be running")
|
||||
}
|
||||
e2e.DeleteInstance(repoPool2.Instances[0].Name, true) // delete instance with forceRemove
|
||||
e2e.DeleteInstance(repoPool2.Instances[0].Name, true, false) // delete instance with forceRemove
|
||||
err = e2e.WaitInstanceToBeRemoved(repoPool2.Instances[0].Name, 1*time.Minute)
|
||||
if err != nil {
|
||||
slog.With(slog.Any("error", err)).Error("Failed to wait for instance to be removed")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue