Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/controller/workloaddeployment_federator.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ func (r *WorkloadDeploymentFederator) upsertDownstreamDeployment(
delete(kd.Labels, computev1alpha.RuntimeClassLabel)
}
kd.Spec = deployment.Spec
// The cell initializes an unset replica target to minReplicas. Send that
// same target through Karmada so it does not repeatedly undo the cell's
// initialization and trigger a spec/status update loop.
if kd.Spec.Replicas == nil {
kd.Spec.Replicas = new(kd.Spec.ScaleSettings.MinReplicas)
}
// Propagate controller-managed annotations from the project WD to the
// downstream WD. The cell reads the expected-referenced-data annotation
// to gate-clear instances; without this copy it would never arrive.
Expand Down
28 changes: 28 additions & 0 deletions internal/controller/workloaddeployment_federator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,34 @@ func testWorkloadDeployment(opts ...func(*computev1alpha.WorkloadDeployment)) *c
return wd
}

func TestUpsertDownstreamDeploymentReplicaTarget(t *testing.T) {
t.Parallel()

for _, tc := range []struct {
name string
replicas *int32
want int32
}{
{name: "defaults unset target to minimum", want: 3},
{name: "preserves explicit target", replicas: new(int32(5)), want: 5},
} {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
deployment := testWorkloadDeployment()
deployment.Spec.ScaleSettings.MinReplicas = 3
deployment.Spec.Replicas = tc.replicas
karmadaClient := newKarmadaFakeClient()
r := &WorkloadDeploymentFederator{}

got, err := r.upsertDownstreamDeployment(context.Background(), karmadaClient, deployment, testKarmadaNSStr, "")
require.NoError(t, err)
require.NotNil(t, got.Spec.Replicas)
assert.Equal(t, tc.want, *got.Spec.Replicas)
assert.Equal(t, tc.replicas, deployment.Spec.Replicas, "project deployment must stay unchanged")
})
}
}

// withFinalizer adds the federator finalizer to the WorkloadDeployment.
func withFinalizer(wd *computev1alpha.WorkloadDeployment) {
wd.Finalizers = append(wd.Finalizers, federatorFinalizer)
Expand Down
Loading