From 077795047e2ad88eacf71beafa1bf8737ee5e7cb Mon Sep 17 00:00:00 2001 From: "David J. M. Karlsen" Date: Tue, 30 Aug 2022 09:54:55 +0200 Subject: [PATCH] Make it possible to conditionally delete evicted pods --- controllers/githubactionrunner_controller.go | 5 ++++- controllers/githubapi/runnerapi.go | 4 ++-- go.mod | 1 + go.sum | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/controllers/githubactionrunner_controller.go b/controllers/githubactionrunner_controller.go index 8ece1fdf..e00fd8fc 100644 --- a/controllers/githubactionrunner_controller.go +++ b/controllers/githubactionrunner_controller.go @@ -24,6 +24,8 @@ import ( "strings" "time" + env "github.com/caitlinelfring/go-env-default" + garov1alpha1 "github.com/evryfs/github-actions-runner-operator/api/v1alpha1" "github.com/evryfs/github-actions-runner-operator/controllers/githubapi" "github.com/go-logr/logr" @@ -47,6 +49,7 @@ const finalizer = "garo.tietoevry.com/runner-registration" const registrationTokenKey = "RUNNER_TOKEN" const registrationTokenExpiresAtAnnotation = "garo.tietoevry.com/expiryTimestamp" const regTokenPostfix = "regtoken" +const deleteEvictedPodsEnvVarName = "GARO_DELETE_EVICED_PODS" // GithubActionRunnerReconciler reconciles a GithubActionRunner object type GithubActionRunnerReconciler struct { @@ -364,7 +367,7 @@ func (r *GithubActionRunnerReconciler) handleFinalization(ctx context.Context, c if err := r.unregisterRunner(ctx, cr, item); err != nil { return err } - if isEvicted(&item.pod) { + if isEvicted(&item.pod) && env.GetBoolDefault(deleteEvictedPodsEnvVarName, true) { logr.FromContextOrDiscard(ctx).Info("Deleting evicted pod", "podname", item.pod.Name) err := r.DeleteResourceIfExists(ctx, &item.pod) if err != nil { diff --git a/controllers/githubapi/runnerapi.go b/controllers/githubapi/runnerapi.go index 7eeb5246..56c88021 100644 --- a/controllers/githubapi/runnerapi.go +++ b/controllers/githubapi/runnerapi.go @@ -7,7 +7,7 @@ import ( "github.com/palantir/go-githubapp/githubapp" ) -//IRunnerAPI is a service towards GitHubs runners +// IRunnerAPI is a service towards GitHubs runners type IRunnerAPI interface { GetRunners(ctx context.Context, organization string, repository string, token string) ([]*github.Runner, error) UnregisterRunner(ctx context.Context, organization string, repository string, token string, runnerID int64) error @@ -18,7 +18,7 @@ type runnerAPI struct { clientCreator githubapp.ClientCreator } -//NewRunnerAPI gets a new instance of the API. +// NewRunnerAPI gets a new instance of the API. func NewRunnerAPI() (runnerAPI, error) { config := githubapp.Config{ V3APIURL: "https://api.github.com", diff --git a/go.mod b/go.mod index 46cce09c..532f98c2 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/evryfs/github-actions-runner-operator go 1.19 require ( + github.com/caitlinelfring/go-env-default v1.1.0 github.com/go-logr/logr v1.2.3 github.com/google/go-github/v45 v45.2.0 github.com/gophercloud/gophercloud v1.0.0 diff --git a/go.sum b/go.sum index 1eaf676f..439f0296 100644 --- a/go.sum +++ b/go.sum @@ -89,6 +89,8 @@ github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqO github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/bradleyfalzon/ghinstallation/v2 v2.1.0 h1:5+NghM1Zred9Z078QEZtm28G/kfDfZN/92gkDlLwGVA= github.com/bradleyfalzon/ghinstallation/v2 v2.1.0/go.mod h1:Xg3xPRN5Mcq6GDqeUVhFbjEWMb4JHCyWEeeBGEYQoTU= +github.com/caitlinelfring/go-env-default v1.1.0 h1:bhDfXmUolvcIGfQCX8qevQX8wxC54NGz0aimoUnhvDM= +github.com/caitlinelfring/go-env-default v1.1.0/go.mod h1:tESXPr8zFPP/cRy3cwxrHBmjJIf2A1x/o4C9CET2rEk= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA=