Skip to content

Commit

Permalink
Make it possible to conditionally delete evicted pods (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkarlsen authored Aug 30, 2022
1 parent b83a37e commit 43c51db
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion controllers/githubactionrunner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions controllers/githubapi/runnerapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 43c51db

Please sign in to comment.