Repository navigation
Add PVC retention policy to WorkerPool #1851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -409,6 +409,92 @@ func TestWorkerPoolReconciler_UpdatesReplicas(t *testing.T) { | |
| assert.Equal(t, int32(3), *sts.Spec.Replicas) | ||
| } | ||
|
|
||
| func reconcileWorkerPoolStatefulSet(t *testing.T, objs ...client.Object) appsv1.StatefulSet { | ||
| t.Helper() | ||
| scheme := newWorkerPoolTestScheme() | ||
| cl := fake.NewClientBuilder(). | ||
| WithScheme(scheme). | ||
| WithStatusSubresource(&kelos.WorkerPool{}). | ||
| WithObjects(objs...). | ||
| Build() | ||
|
|
||
| r := newWorkerPoolReconciler(cl, scheme) | ||
| _, err := r.Reconcile(context.Background(), ctrl.Request{ | ||
| NamespacedName: types.NamespacedName{Name: "my-pool", Namespace: "default"}, | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| var sts appsv1.StatefulSet | ||
| require.NoError(t, cl.Get(context.Background(), types.NamespacedName{Name: "wp-my-pool", Namespace: "default"}, &sts)) | ||
| return sts | ||
| } | ||
|
|
||
| func TestWorkerPoolReconciler_PVCRetentionPolicyUnsetOnCreate(t *testing.T) { | ||
| pool := newTestWorkerPool("my-pool", "default", 1) | ||
|
|
||
| sts := reconcileWorkerPoolStatefulSet(t, pool, newTestWorkspace("default")) | ||
|
|
||
| assert.Nil(t, sts.Spec.PersistentVolumeClaimRetentionPolicy) | ||
| } | ||
|
|
||
| func TestWorkerPoolReconciler_PVCRetentionPolicyPropagatedOnCreate(t *testing.T) { | ||
| pool := newTestWorkerPool("my-pool", "default", 1) | ||
| pool.Spec.PersistentVolumeClaimRetentionPolicy = &appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{ | ||
| WhenDeleted: appsv1.DeletePersistentVolumeClaimRetentionPolicyType, | ||
| WhenScaled: appsv1.DeletePersistentVolumeClaimRetentionPolicyType, | ||
| } | ||
|
|
||
| sts := reconcileWorkerPoolStatefulSet(t, pool, newTestWorkspace("default")) | ||
|
|
||
| assert.Equal(t, &appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{ | ||
| WhenDeleted: appsv1.DeletePersistentVolumeClaimRetentionPolicyType, | ||
| WhenScaled: appsv1.DeletePersistentVolumeClaimRetentionPolicyType, | ||
| }, sts.Spec.PersistentVolumeClaimRetentionPolicy) | ||
| } | ||
|
|
||
| func TestWorkerPoolReconciler_PVCRetentionPolicyUpdatesExistingStatefulSet(t *testing.T) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The PR says removing a previously set policy reverts to the default, but no reconcile test covers that path. Add a test where the existing StatefulSet has Delete/Delete and the pool's Prompt for AI agents |
||
| pool := newTestWorkerPool("my-pool", "default", 1) | ||
| pool.Spec.PersistentVolumeClaimRetentionPolicy = &appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{ | ||
| WhenDeleted: appsv1.DeletePersistentVolumeClaimRetentionPolicyType, | ||
| WhenScaled: appsv1.RetainPersistentVolumeClaimRetentionPolicyType, | ||
| } | ||
|
|
||
| // Build the StatefulSet as the controller would for the same pool, but | ||
| // with the API server's Retain/Retain default, so the retention policy is | ||
| // the only difference. | ||
| scheme := newWorkerPoolTestScheme() | ||
| r := newWorkerPoolReconciler(fake.NewClientBuilder().WithScheme(scheme).Build(), scheme) | ||
| ws := newTestWorkspace("default") | ||
| existingSTS, err := r.buildStatefulSet(pool, "wp-my-pool", "wp-my-pool", &ws.Spec, nil) | ||
| require.NoError(t, err) | ||
| existingSTS.Spec.PersistentVolumeClaimRetentionPolicy = &appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{ | ||
| WhenDeleted: appsv1.RetainPersistentVolumeClaimRetentionPolicyType, | ||
| WhenScaled: appsv1.RetainPersistentVolumeClaimRetentionPolicyType, | ||
| } | ||
|
|
||
| sts := reconcileWorkerPoolStatefulSet(t, pool, ws, existingSTS) | ||
|
|
||
| assert.Equal(t, &appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{ | ||
| WhenDeleted: appsv1.DeletePersistentVolumeClaimRetentionPolicyType, | ||
| WhenScaled: appsv1.RetainPersistentVolumeClaimRetentionPolicyType, | ||
| }, sts.Spec.PersistentVolumeClaimRetentionPolicy) | ||
| } | ||
|
|
||
| func TestPVCRetentionPolicyEqual_TreatsUnsetAsRetain(t *testing.T) { | ||
| retainAll := &appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{ | ||
| WhenDeleted: appsv1.RetainPersistentVolumeClaimRetentionPolicyType, | ||
| WhenScaled: appsv1.RetainPersistentVolumeClaimRetentionPolicyType, | ||
| } | ||
| deleteOnScale := &appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{ | ||
| WhenScaled: appsv1.DeletePersistentVolumeClaimRetentionPolicyType, | ||
| } | ||
|
|
||
| assert.True(t, pvcRetentionPolicyEqual(nil, retainAll)) | ||
| assert.True(t, pvcRetentionPolicyEqual(&appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{}, retainAll)) | ||
| assert.False(t, pvcRetentionPolicyEqual(nil, deleteOnScale)) | ||
| assert.False(t, pvcRetentionPolicyEqual(retainAll, deleteOnScale)) | ||
| } | ||
|
|
||
| func TestWorkerPoolReconciler_StatusPhases(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: A retention-only change now reaches the shared StatefulSet update path, which still logs and emits the event "Updated StatefulSet %s to %d replicas". That message reports a replica count even when only the PVC retention policy changed. Make the message name what changed, or make it generic.
Prompt for AI agents