Skip to content

Commit

Permalink
Don't compare runner connetion token at restart need check (#227)
Browse files Browse the repository at this point in the history
Fixes #143
  • Loading branch information
Hi-Fi authored Dec 7, 2020
1 parent 85c29a9 commit f710a54
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion controllers/runner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,20 @@ func (r *RunnerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
return ctrl.Result{}, nil
}

if !runnerBusy && (!reflect.DeepEqual(pod.Spec.Containers[0].Env, newPod.Spec.Containers[0].Env) || pod.Spec.Containers[0].Image != newPod.Spec.Containers[0].Image) {
// Filter out token that is changed hourly.
currentEnvValues := filterEnvVars(pod.Spec.Containers[0].Env, "RUNNER_TOKEN")
newEnvValues := filterEnvVars(newPod.Spec.Containers[0].Env, "RUNNER_TOKEN")

if !runnerBusy && (!reflect.DeepEqual(currentEnvValues, newEnvValues) || pod.Spec.Containers[0].Image != newPod.Spec.Containers[0].Image) {
restart = true
}

// Don't do anything if there's no need to restart the runner
if !restart {
return ctrl.Result{}, err
}

// Delete current pod if recreation is needed
if err := r.Delete(ctx, &pod); err != nil {
log.Error(err, "Failed to delete pod resource")
return ctrl.Result{}, err
Expand Down
14 changes: 14 additions & 0 deletions controllers/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package controllers

import (
corev1 "k8s.io/api/core/v1"
)

func filterEnvVars(envVars []corev1.EnvVar, filter string) (filtered []corev1.EnvVar) {
for _, envVar := range envVars {
if envVar.Name != filter {
filtered = append(filtered, envVar)
}
}
return filtered
}

0 comments on commit f710a54

Please sign in to comment.