Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Revert 'Make errands and auto-errands work'
Browse files Browse the repository at this point in the history
This is code specific to quarks-operator. The env vars can be assigned
when creating the qjob templates.
  • Loading branch information
Mario Manno authored and Mario Manno committed Nov 19, 2020
1 parent f51879b commit 3680f98
Showing 1 changed file with 0 additions and 50 deletions.
50 changes: 0 additions & 50 deletions pkg/kube/controllers/quarksjob/errand_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"time"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -24,16 +23,6 @@ var _ reconcile.Reconciler = &ErrandReconciler{}
const (
// ReconcileSkipDuration is the duration of merging consecutive triggers.
ReconcileSkipDuration = 10 * time.Second
// EnvKubeAz is set by available zone name
EnvKubeAz = "KUBE_AZ"
// EnvBoshAz is set by available zone name
EnvBoshAz = "BOSH_AZ"
// EnvReplicas describes the number of replicas in the quarks job
EnvReplicas = "REPLICAS"
// EnvCFOperatorAZIndex is set by available zone index
EnvCFOperatorAZIndex = "AZ_INDEX"
// EnvPodOrdinal is the pod's index
EnvPodOrdinal = "POD_ORDINAL"
)

// NewErrandReconciler returns a new reconciler for errand jobs.
Expand Down Expand Up @@ -117,7 +106,6 @@ func (r *ErrandReconciler) Reconcile(request reconcile.Request) (reconcile.Resul
}
}

r.injectContainerEnv(&qJob.Spec.Template.Spec.Template.Spec)
if retry, err := r.jobCreator.Create(ctx, *qJob); err != nil {
return reconcile.Result{}, ctxlog.WithEvent(qJob, "CreateJobError").Errorf(ctx, "Failed to create job '%s': %s", qJob.GetNamespacedName(), err)
} else if retry {
Expand All @@ -142,41 +130,3 @@ func (r *ErrandReconciler) Reconcile(request reconcile.Request) (reconcile.Resul

return reconcile.Result{}, nil
}

// injectContainerEnv injects AZ info to container envs
// errands always have an AZ_INDEX of 1
func (r *ErrandReconciler) injectContainerEnv(podSpec *corev1.PodSpec) {

containers := []*corev1.Container{}
for i := 0; i < len(podSpec.Containers); i++ {
containers = append(containers, &podSpec.Containers[i])
}
for i := 0; i < len(podSpec.InitContainers); i++ {
containers = append(containers, &podSpec.InitContainers[i])
}
for _, container := range containers {
envs := container.Env

// Default to zone 1, with 1 replica
envs = upsertEnvs(envs, EnvCFOperatorAZIndex, "1")
envs = upsertEnvs(envs, EnvReplicas, "1")
envs = upsertEnvs(envs, EnvPodOrdinal, "0")

container.Env = envs
}
}

func upsertEnvs(envs []corev1.EnvVar, name string, value string) []corev1.EnvVar {
for idx, env := range envs {
if env.Name == name {
envs[idx].Value = value
return envs
}
}

envs = append(envs, corev1.EnvVar{
Name: name,
Value: value,
})
return envs
}

0 comments on commit 3680f98

Please sign in to comment.