diff --git a/api/v1alpha1/step_spec.go b/api/v1alpha1/step_spec.go index 751e4fc7..497938a0 100644 --- a/api/v1alpha1/step_spec.go +++ b/api/v1alpha1/step_spec.go @@ -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 +} diff --git a/api/v1alpha1/step_spec_test.go b/api/v1alpha1/step_spec_test.go new file mode 100644 index 00000000..076286c5 --- /dev/null +++ b/api/v1alpha1/step_spec_test.go @@ -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) +} diff --git a/manager/controllers/step_controller.go b/manager/controllers/step_controller.go index 448c2dda..f097925f 100644 --- a/manager/controllers/step_controller.go +++ b/manager/controllers/step_controller.go @@ -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) } @@ -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() @@ -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),