Skip to content

Commit 05e1796

Browse files
Merge pull request #183 from gabriel-samfira/force-remove-runner
Add force delete runner
2 parents 7f4f4bd + b9c7c93 commit 05e1796

29 files changed

+360
-105
lines changed

apiserver/controllers/instances.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"encoding/json"
1919
"log"
2020
"net/http"
21+
"strconv"
2122

2223
gErrors "github.com/cloudbase/garm-provider-common/errors"
2324
"github.com/cloudbase/garm/apiserver/params"
@@ -121,6 +122,12 @@ func (a *APIController) GetInstanceHandler(w http.ResponseWriter, r *http.Reques
121122
// in: path
122123
// required: true
123124
//
125+
// + name: forceRemove
126+
// description: If true GARM will ignore any provider error when removing the runner and will continue to remove the runner from github and the GARM database.
127+
// type: boolean
128+
// in: query
129+
// required: false
130+
//
124131
// Responses:
125132
// default: APIErrorResponse
126133
func (a *APIController) DeleteInstanceHandler(w http.ResponseWriter, r *http.Request) {
@@ -138,7 +145,8 @@ func (a *APIController) DeleteInstanceHandler(w http.ResponseWriter, r *http.Req
138145
return
139146
}
140147

141-
if err := a.r.ForceDeleteRunner(ctx, instanceName); err != nil {
148+
forceRemove, _ := strconv.ParseBool(r.URL.Query().Get("forceRemove"))
149+
if err := a.r.DeleteRunner(ctx, instanceName, forceRemove); err != nil {
142150
log.Printf("removing runner: %s", err)
143151
handleError(w, err)
144152
return

apiserver/swagger.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,10 @@ paths:
597597
name: instanceName
598598
required: true
599599
type: string
600+
- description: If true GARM will ignore any provider error when removing the runner and will continue to remove the runner from github and the GARM database.
601+
in: query
602+
name: forceRemove
603+
type: boolean
600604
responses:
601605
default:
602606
description: APIErrorResponse

client/instances/delete_instance_parameters.go

+35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/garm-cli/cmd/runner.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,9 @@ to either cancel the workflow or wait for it to finish.
187187
return fmt.Errorf("requires a runner name")
188188
}
189189

190-
if !forceRemove {
191-
return fmt.Errorf("use --force-remove-runner=true to remove a runner")
192-
}
193-
194190
deleteInstanceReq := apiClientInstances.NewDeleteInstanceParams()
195191
deleteInstanceReq.InstanceName = args[0]
192+
deleteInstanceReq.ForceRemove = &forceRemove
196193
if err := apiCli.Instances.DeleteInstance(deleteInstanceReq, authToken); err != nil {
197194
return err
198195
}
@@ -207,7 +204,7 @@ func init() {
207204
runnerListCmd.Flags().BoolVarP(&runnerAll, "all", "a", false, "List all runners, regardless of org or repo.")
208205
runnerListCmd.MarkFlagsMutuallyExclusive("repo", "org", "enterprise", "all")
209206

210-
runnerDeleteCmd.Flags().BoolVarP(&forceRemove, "force-remove-runner", "f", false, "Confirm you want to delete a runner")
207+
runnerDeleteCmd.Flags().BoolVarP(&forceRemove, "force-remove-runner", "f", false, "Forcefully remove a runner. If set to true, GARM will ignore provider errors when removing the runner.")
211208
runnerDeleteCmd.MarkFlagsMutuallyExclusive("force-remove-runner")
212209

213210
runnerCmd.AddCommand(

database/common/mocks/Store.go

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.20
44

55
require (
66
github.com/BurntSushi/toml v1.2.1
7-
github.com/cloudbase/garm-provider-common v0.1.0
7+
github.com/cloudbase/garm-provider-common v0.1.1-0.20231012061429-49001794e700
88
github.com/go-openapi/errors v0.20.4
99
github.com/go-openapi/runtime v0.26.0
1010
github.com/go-openapi/strfmt v0.21.7

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
2222
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
2323
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
2424
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
25-
github.com/cloudbase/garm-provider-common v0.1.0 h1:gc2n8nsLjt7G3InAfqZ+75iZjSIUkIx86d6/DFA2+jc=
26-
github.com/cloudbase/garm-provider-common v0.1.0/go.mod h1:igxJRT3OlykERYc6ssdRQXcb+BCaeSfnucg6I0OSoDc=
25+
github.com/cloudbase/garm-provider-common v0.1.1-0.20231012061429-49001794e700 h1:ZCJ1zZ2WI/37ffzpRsu7t5zzShAMThhYsXw7bBNKBR0=
26+
github.com/cloudbase/garm-provider-common v0.1.1-0.20231012061429-49001794e700/go.mod h1:igxJRT3OlykERYc6ssdRQXcb+BCaeSfnucg6I0OSoDc=
2727
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
2828
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
2929
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

runner/common/mocks/GithubClient.go

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runner/common/mocks/GithubEnterpriseClient.go

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runner/common/mocks/OrganizationHooks.go

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runner/common/mocks/PoolManager.go

+20-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runner/common/mocks/Provider.go

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runner/common/mocks/RepositoryHooks.go

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runner/common/pool.go

+33-1
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,54 @@ const (
3838

3939
//go:generate mockery --all
4040
type PoolManager interface {
41+
// ID returns the ID of the entity (repo, org, enterprise)
4142
ID() string
43+
// WebhookSecret returns the unencrypted webhook secret associated with the webhook installed
44+
// in GitHub for GARM. For GARM to receive webhook events for an entity, either the operator or
45+
// GARM will have to create a webhook in GitHub which points to the GARM API server. To authenticate
46+
// the webhook, a webhook secret is used. This function returns that secret.
4247
WebhookSecret() string
48+
// GithubRunnerRegistrationToken returns a new registration token for a github runner. This is used
49+
// for GHES installations that have not yet upgraded to a version >= 3.10. Starting with 3.10, we use
50+
// just-in-time runners, which no longer require exposing a runner registration token.
4351
GithubRunnerRegistrationToken() (string, error)
52+
// HandleWorkflowJob handles a workflow job meant for a particular entity. When a webhook is fired for
53+
// a repo, org or enterprise, we determine the destination of that webhook, retrieve the pool manager
54+
// for it and call this function with the WorkflowJob as a parameter.
4455
HandleWorkflowJob(job params.WorkflowJob) error
56+
// RefreshState allows us to update webhook secrets and configuration for a pool manager.
4557
RefreshState(param params.UpdatePoolStateParams) error
58+
// ForceDeleteRunner will attempt to remove a runner from the pool.
59+
//
60+
// Deprecated: FunctionName is deprecated. Use DeleteRunner instead.
4661
ForceDeleteRunner(runner params.Instance) error
4762

63+
// DeleteRunner will attempt to remove a runner from the pool. If forceRemove is true, any error
64+
// received from the provider will be ignored and we will procede to remove the runner from the database.
65+
// An error received while attempting to remove from GitHub (other than 404) will still stop the deletion
66+
// process. This can happen if the runner is already processing a job. At which point, you can simply cancel
67+
// the job in github. Doing so will prompt GARM to reap the runner automatically.
68+
DeleteRunner(runner params.Instance, forceRemove bool) error
69+
70+
// InstallWebhook will create a webhook in github for the entity associated with this pool manager.
4871
InstallWebhook(ctx context.Context, param params.InstallWebhookParams) (params.HookInfo, error)
72+
// GetWebhookInfo will return information about the webhook installed in github for the entity associated
4973
GetWebhookInfo(ctx context.Context) (params.HookInfo, error)
74+
// UninstallWebhook will remove the webhook installed in github for the entity associated with this pool manager.
5075
UninstallWebhook(ctx context.Context) error
5176

77+
// RootCABundle will return a CA bundle that must be installed on all runners in order to properly validate
78+
// x509 certificates used by various systems involved. This CA bundle is defined in the GARM config file and
79+
// can include multiple CA certificates for the GARM api server, GHES server and any provider API endpoint that
80+
// may use internal or self signed certificates.
5281
RootCABundle() (params.CertificateBundle, error)
5382

54-
// PoolManager lifecycle functions. Start/stop pool.
83+
// Start will start the pool manager and all associated workers.
5584
Start() error
85+
// Stop will stop the pool manager and all associated workers.
5686
Stop() error
87+
// Status will return the current status of the pool manager.
5788
Status() params.PoolManagerStatus
89+
// Wait will block until the pool manager has stopped.
5890
Wait() error
5991
}

0 commit comments

Comments
 (0)