-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Sidecar KEP API implementation #919
Conversation
Hi @Joseph-Irving. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/kind api-change |
This PR may require API review. If so, when the changes are ready, complete the pre-review checklist and request an API review. Status of requested reviews is tracked in the API Review project. |
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.
I'm fine with this. It's consistent with guidance.
keps/sig-apps/sidecarcontainers.md
Outdated
@@ -88,7 +88,7 @@ spec: | |||
command: ['do something'] | |||
- name: sidecar | |||
image: sidecar-image | |||
sidecar: true | |||
containerLifecycle: Sidecar |
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.
s/containerLifecycle/lifecycle/g
It's already nested under "containers[]"
disagree?
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.
@thockin yeah I would've preferred that but lifecycle
is already a field in the container spec, where PostStart and PreStop are defined.
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.
Even though lifecycle
up until now has only been used to specify lifecycle hooks, my opinion is that it's better to extend it with something like type: Sidecar
or behavior: Sidecar
instead of introducing an additional lifecycle
field (one called containerLifecycle
).
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.
I think using lifecycle
is definitely cleaner, the struct is currently just used for lifecycle hooks, but the name is more generic than that. So unless people think it would cause confusion to add a new non hook field to it, might be the best solution.
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.
Adding a field under the existing lifecycle:
struct makes sense to me. It would only need a slight rewording of the documented purpose of the lifecycle section, which is a bit hook-specific right now.
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.
Ok, seems reasonable, I can rework this to be within the Lifecycle struct. In regards to what the field should be called, I originally liked behaviour
, but then I remembered that Americans spell that in their own way, so maybe type
is a bit more internationally friendly.
keps/sig-apps/sidecarcontainers.md
Outdated
//One of Standard, Sidecar. | ||
//Defaults to Standard | ||
//+optional | ||
ContainerLifecycle ContainerLifecycle `json:"containerLifecycle,omitempty" protobuf:"bytes,22,opt,name=containerLifecycle,casttype=ContainerLifecycle"` |
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.
InitContainers are also using type Container - this is meaningless for them, right?
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.
There are use-cases where you want to have a sidecar running during the pod init phase. For example, you might want to run the Envoy proxy as a sidecar during init in case any init containers try to perform network calls and you'd like to shape that network traffic also (in the same way you do with regular containers).
keps/sig-apps/sidecarcontainers.md
Outdated
@@ -156,9 +181,9 @@ Please view this [video](https://youtu.be/4hC8t6_8bTs) if you want to see what t | |||
|
|||
### Risks and Mitigations | |||
|
|||
You could set all containers to be `sidecar: true`, this would cause strange behaviour in regards to shutting down the sidecars when all the non-sidecars have exited. To solve this the api could do a validation check that at least one container is not a sidecar. | |||
You could set all containers to be `containerLifecycle: Sidecar`, this would cause strange behaviour in regards to shutting down the sidecars when all the non-sidecars have exited. To solve this the api could do a validation check that at least one container is not a sidecar. |
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.
I think requiring at least one non-sidecar makes sense.
keps/sig-apps/sidecarcontainers.md
Outdated
|
||
Init containers would be able to have `sidecar: true` applied to them as it's an additional field to the container spec, this doesn't currently make sense as init containers are ran sequentially. We could get around this by having the api throw a validation error if you try to use this field on an init container or just ignore the field. | ||
Init containers would be able to have `containerLifecycle: Sidecar` applied to them as it's an additional field to the container spec, this doesn't currently make sense as init containers are ran sequentially. We could get around this by having the api throw a validation error if you try to use this field on an init container or just ignore the field. |
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.
Not exactly your problem, but maybe we should just not be sharing the base type?
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.
e.g.
--- a/pkg/apis/core/types.go
+++ b/pkg/apis/core/types.go
@@ -1932,7 +1932,7 @@ type ResourceRequirements struct {
}
// Container represents a single container that is expected to be run on the host.
-type Container struct {
+type BaseContainer struct {
// Required: This must be a DNS_LABEL. Each container in a pod must
// have a unique name.
Name string
@@ -1993,6 +1993,9 @@ type Container struct {
// If set, the fields of SecurityContext override the equivalent fields of PodSecurityContext.
// +optional
SecurityContext *SecurityContext
+}
+type Container struct {
+ BaseContainer // Embed
// Variables for interactive containers, these have very specialized use-cases (e.g. debugging)
// and shouldn't be used for general purpose containers.
@@ -2003,6 +2006,9 @@ type Container struct {
// +optional
TTY bool
}
+type InitContainer struct {
+ BaseContainer // Embed
+}
This has wide-ranging code impact and probably openapi impact, but may be worth doing anyway...
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.
I don't think refactoring fields into a nested struct a level deeper is wire-compatible with our proto serializations
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.
This is the direction we're heading for ephemeral containers, but the primary motivator is to have separate docs so we can label some fields as "this doesn't work with ephemeral containers".
Separating fields would mean we wouldn't need to do this and an EphemeralContainer
would only have fields allow for ephemeral containers, but complexity would increase with the differences between container types. Something like:
type BaseContainer struct {
// All containers have a name
Name string
...
}
type ServingContainer struct {
// Only serving containers have ports, probes, etc.
Ports []ContainerPorts
ReadinessProbe *Probe
Lifecycle *Lifecycle
...
}
type InteractiveContainer struct {
TTY bool
...
}
type Container {
BaseContainer
ServingContainer
InteractiveContainer
}
type InitContainer {
BaseContainer
ServingContainer
}
type EphemeralContainer {
BaseContainer
InteractiveContainer
}
It would be painful if we added a new container type or if we wanted to add a previously-disallowed field to EphemeralContainer or add a new container type that doesn't fit in these categories, especially considering @liggitt's point about proto serialization.
5e7e4cf
to
542634b
Compare
Ok, I've updated this to be nested in So it would now be
Let me know what you think |
Sorry to lose this, I wasn't assigned. Will look as soon as I can, but I am crushed with KubeCon prep :( |
@verb Are ephemeral containers going to have to deal with sidecar status? Since ephemeral is a little further ahead of sidecar, I'd like you to indicate whether an ephemeral container has "lifecycle type" or not. |
Actually, both ephemeral and sidecar containers have parallel api concerns. The current discussion with ephemeral around how the docs change - I would also expect the docs for sidecar containers to change. The current argument with ephemeral containers is that field can change over the lifetime of the pod, while init and regular containers cannot. Right now, I might argue ephemeral containers have a different lifecycle type, but are still in a separate field. But I'd like to hear good arguments for/against folding ephemeral containers into regular containers and lifecycleType being |
Replying to @smarterclayton:
Since we're defining a lifecycle type, we should either:
I suggest the third option.
The primary motivation for the API change for ephemeral containers is the desire for most of containers spec to remain immutable. I think there's general consensus on this point that this encourages best practices and doesn't disturb long standing assumptions in code. This is easiest with a separate Arguments for:
Arguments against:
I'll reflect on it a bit more, but so far I'm leaning towards separate list of ephemeral containers. Not to kick the can down the road, but I'm starting to become curious how a |
@Joseph-Irving @smarterclayton @liggitt I'm no API reviewer, but I have bandwidth and this seems to have some overlap with ephemeral containers. Let me know if I can help with first-level reviews or anything to speed along sidecar lifecycle. |
@verb any help with reviews, etc is most appreciated :) If you like you could look at the POC branch over here kubernetes/kubernetes#75099, it's very much a first draft and hasn't been touched in a while as I'm waiting for us to settle on the API before continuing development, but any comments on the general implementation would be handy. |
The strongest argument you didn't mention is that disabling the field (for alpha) is a requirement, and filtering out ephemeral containers from We need to consider that for sidecars as well (alpha disablement), especially when it comes to sidecars in run once pods. Since lifecycle type will be ignored, there would be no way to have a long running sidecar, but that's less of an issue. |
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.
As an API this seems fine tome -- I hope this is not blocking the actual work?
When you have API code changes, we can do an API review properly, even before the full impl is done
Thanks!
/lgtm
/approve
542634b
to
55f20bb
Compare
/approve |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JoelSpeed, Joseph-Irving, kow3ns, thockin The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This is my suggestion for how we could implement the API for defining the sidecars #753.
Having a bool was not very popular, having an enum instead seemed to have more support so I'm suggesting we have
lifecycle.type: Sidecar
I'm not sure what the default value should be for
type
, I suggestedStandard
here but some other suggestions could beDefault
,Main
,Primary
./sig apps
/sig node
/assign @kow3ns @enisoc