Switch ephemeralcontainers SR to Pod Kind

This changes the `/ephemeralcontainers` subresource of `/pods` to use
the `Pod` kind rather than `EphemeralContainers`.

When designing this API initially it seemed preferable to create a new
kind containing only the pod's ephemeral containers, similar to how
binding and scaling work.

It later became clear that this made admission control more difficult
because the controller wouldn't be presented with the entire Pod, so we
updated this to operate on the entire Pod, similar to how `/status`
works.

Kubernetes-commit: d22dc5cb72a627341f4004b5d58d275f3d8773b3
This commit is contained in:
Lee Verberne 2021-04-09 13:53:13 +02:00 committed by Kubernetes Publisher
parent d696ff0aad
commit 0e8029b277

View File

@ -258,31 +258,72 @@ func (c *pods) ApplyStatus(ctx context.Context, pod *corev1.PodApplyConfiguratio
return return
} }
func ephemeralContainersInPod(pod *v1.Pod) *v1.EphemeralContainers {
ephemeralContainers := pod.Spec.EphemeralContainers
if ephemeralContainers == nil {
ephemeralContainers = []v1.EphemeralContainer{}
}
return &v1.EphemeralContainers{
ObjectMeta: metav1.ObjectMeta{
Name: pod.Name,
Namespace: pod.Namespace,
UID: pod.UID,
ResourceVersion: pod.ResourceVersion,
CreationTimestamp: pod.CreationTimestamp,
},
EphemeralContainers: ephemeralContainers,
}
}
// GetEphemeralContainers takes name of the pod, and returns the corresponding v1.EphemeralContainers object, and an error if there is any. // GetEphemeralContainers takes name of the pod, and returns the corresponding v1.EphemeralContainers object, and an error if there is any.
func (c *pods) GetEphemeralContainers(ctx context.Context, podName string, options metav1.GetOptions) (result *v1.EphemeralContainers, err error) { func (c *pods) GetEphemeralContainers(ctx context.Context, podName string, options metav1.GetOptions) (*v1.EphemeralContainers, error) {
result = &v1.EphemeralContainers{} pod := &v1.Pod{}
err = c.client.Get(). err := c.client.Get().
Namespace(c.ns). Namespace(c.ns).
Resource("pods"). Resource("pods").
Name(podName). Name(podName).
SubResource("ephemeralcontainers"). SubResource("ephemeralcontainers").
VersionedParams(&options, scheme.ParameterCodec). VersionedParams(&options, scheme.ParameterCodec).
Do(ctx). Do(ctx).
Into(result) Into(pod)
return
if err != nil {
return nil, err
}
return ephemeralContainersInPod(pod), nil
} }
// UpdateEphemeralContainers takes the top resource name and the representation of a ephemeralContainers and updates it. Returns the server's representation of the ephemeralContainers, and an error, if there is any. // UpdateEphemeralContainers takes the top resource name and the representation of a ephemeralContainers and updates it. Returns the server's representation of the ephemeralContainers, and an error, if there is any.
func (c *pods) UpdateEphemeralContainers(ctx context.Context, podName string, ephemeralContainers *v1.EphemeralContainers, opts metav1.UpdateOptions) (result *v1.EphemeralContainers, err error) { func (c *pods) UpdateEphemeralContainers(ctx context.Context, podName string, ephemeralContainers *v1.EphemeralContainers, opts metav1.UpdateOptions) (*v1.EphemeralContainers, error) {
result = &v1.EphemeralContainers{} pod := &v1.Pod{}
err := c.client.Get().
Namespace(c.ns).
Resource("pods").
Name(podName).
SubResource("ephemeralcontainers").
VersionedParams(&metav1.GetOptions{}, scheme.ParameterCodec).
Do(ctx).
Into(pod)
if err != nil {
return nil, err
}
result := &v1.Pod{}
pod.Spec.EphemeralContainers = ephemeralContainers.EphemeralContainers
err = c.client.Put(). err = c.client.Put().
Namespace(c.ns). Namespace(c.ns).
Resource("pods"). Resource("pods").
Name(podName). Name(podName).
SubResource("ephemeralcontainers"). SubResource("ephemeralcontainers").
VersionedParams(&opts, scheme.ParameterCodec). VersionedParams(&opts, scheme.ParameterCodec).
Body(ephemeralContainers). Body(pod).
Do(ctx). Do(ctx).
Into(result) Into(result)
return if err != nil {
return nil, err
}
return ephemeralContainersInPod(pod), nil
} }