Skip to content

Commit bf0a33d

Browse files
committed
Use EphemeralContainers for storage validation
When updating ephemeral containers, convert Pod to EphemeralContainers in storage validation. This resolves a bug where admission webhook validation fails for ephemeral container updates because the webhook client cannot perform the conversion. Also enable the EphemeralContainers feature gate for the admission control integration test, which would have caught this bug.
1 parent c3b888f commit bf0a33d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pkg/registry/core/pod/storage/storage.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,26 @@ func (r *EphemeralContainersREST) Update(ctx context.Context, name string, objIn
346346
return newPod, nil
347347
})
348348

349-
obj, _, err = r.store.Update(ctx, name, updatedPodInfo, createValidation, updateValidation, false, options)
349+
// Validation should be passed the API kind (EphemeralContainers) rather than the storage kind.
350+
obj, _, err = r.store.Update(ctx, name, updatedPodInfo, toEphemeralContainersCreateValidation(createValidation), toEphemeralContainersUpdateValidation(updateValidation), false, options)
350351
if err != nil {
351352
return nil, false, err
352353
}
353354
return ephemeralContainersInPod(obj.(*api.Pod)), false, err
354355
}
355356

357+
func toEphemeralContainersCreateValidation(f rest.ValidateObjectFunc) rest.ValidateObjectFunc {
358+
return func(ctx context.Context, obj runtime.Object) error {
359+
return f(ctx, ephemeralContainersInPod(obj.(*api.Pod)))
360+
}
361+
}
362+
363+
func toEphemeralContainersUpdateValidation(f rest.ValidateObjectUpdateFunc) rest.ValidateObjectUpdateFunc {
364+
return func(ctx context.Context, obj, old runtime.Object) error {
365+
return f(ctx, ephemeralContainersInPod(obj.(*api.Pod)), ephemeralContainersInPod(old.(*api.Pod)))
366+
}
367+
}
368+
356369
// Extract the list of Ephemeral Containers from a Pod
357370
func ephemeralContainersInPod(pod *api.Pod) *api.EphemeralContainers {
358371
ephemeralContainers := pod.Spec.EphemeralContainers

test/integration/apiserver/admissionwebhook/admission_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ func testWebhookAdmission(t *testing.T, watchCache bool) {
480480
"--disable-admission-plugins=ServiceAccount,StorageObjectInUseProtection",
481481
// force enable all resources so we can check storage.
482482
"--runtime-config=api/all=true",
483+
// enable feature-gates that protect resources to check their storage, too.
484+
"--feature-gates=EphemeralContainers=true",
483485
}, etcdConfig)
484486
defer server.TearDownFn()
485487

0 commit comments

Comments
 (0)