Skip to content

Commit

Permalink
fix: Prevent scaling from deleting pods
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Aug 12, 2021
1 parent 0e4d849 commit 3ba7708
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha1/step_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@ func (in StepSpec) CalculateReplicas(pending int) int {
}
return in.Scale.Calculate(pending)
}

func (in StepSpec) WithOutReplicas() StepSpec {
x := *in.DeepCopy()
x.Replicas = 0
return x
}
13 changes: 13 additions & 0 deletions api/v1alpha1/step_spec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package v1alpha1

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestStepSpec_WithOutReplicas(t *testing.T) {
in := StepSpec{Replicas: 1, Name: "foo"}.WithOutReplicas()
assert.Zero(t, in.Replicas)
assert.Equal(t, "foo", in.Name)
}
7 changes: 3 additions & 4 deletions manager/controllers/step_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ type hash struct {

var (
clusterName = os.Getenv(dfv1.EnvClusterName)
debug = os.Getenv(dfv1.EnvDebug) == "true"
debug = os.Getenv(dfv1.EnvDebug) == "true"
)


func init() {
logger.Info("config", "clusterName", clusterName, "debug", debug)
}
Expand Down Expand Up @@ -129,7 +128,7 @@ func (r *StepReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
}

selector, _ := labels.Parse(dfv1.KeyPipelineName + "=" + pipelineName + "," + dfv1.KeyStepName + "=" + stepName)
hash := util.MustHash(hash{runnerImage, step.Spec})
hash := util.MustHash(hash{runnerImage, step.Spec.WithOutReplicas()}) // we must remove data (e.g. replicas) which does not change the pod, otherwise it would cause the pod to be re-created all the time
oldStatus := step.Status.DeepCopy()
step.Status.Phase, step.Status.Reason, step.Status.Message = dfv1.StepUnknown, "", ""
step.Status.Selector = selector.String()
Expand Down Expand Up @@ -179,7 +178,7 @@ func (r *StepReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
Spec: step.GetPodSpec(
dfv1.GetPodSpecReq{
ClusterName: clusterName,
Debug: debug,
Debug: debug,
PipelineName: pipelineName,
Namespace: step.Namespace,
Replica: int32(replica),
Expand Down

0 comments on commit 3ba7708

Please sign in to comment.