karmada-io / karmada

Open, Multi-Cloud, Multi-Cluster Kubernetes Orchestration
https://karmada.io
Apache License 2.0
4.51k stars 892 forks source link

Is there any plan to support sidecarContainers #5745

Open Monokaix opened 1 month ago

Monokaix commented 1 month ago

What would you like to be added: Add sidecarContainers support when compute resource requirements in resourceInterpreter. Why is this needed: sidecarContainer has been a beta feature and enabled by default in k8s v1.29, we should also support it to get a more accurate resources requirement. xrefs: https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/

Monokaix commented 1 month ago

Glad to contribute if it's acceptable.

Monokaix commented 1 month ago

/assign

RainbowMango commented 1 month ago

sidecarContainer has been a beta feature and enabled by default in k8s v1.29, we should also support it to get a more accurate resources requirement.

Can you give an example to explain the gaps we currently have? As far as I know, resource interpreters already consider sidecar containers when determining resource requirements. https://github.com/karmada-io/karmada/blob/38ee277de7aaaf4f93fec42d49bfc71cc4b0be76/pkg/util/helper/binding.go#L385-L405

Monokaix commented 1 month ago

sidecarContainer has been a beta feature and enabled by default in k8s v1.29, we should also support it to get a more accurate resources requirement.

Can you give an example to explain the gaps we currently have? As far as I know, resource interpreters already consider sidecar containers when determining resource requirements.

https://github.com/karmada-io/karmada/blob/38ee277de7aaaf4f93fec42d49bfc71cc4b0be76/pkg/util/helper/binding.go#L385-L405

Seems the func AddPodTemplateRequest is just copyed from old k8s version, and didn't consider the sidecarcontainers resources, sidecar container is a special init container with restartPolicy = Always, here is the logic of k8s when compute pod resource requests https://github.com/kubernetes/kubernetes/blob/b3cf9c6e5c7f7851529e17a4ebf51c2e98392cb4/staging/src/k8s.io/component-helpers/resource/helpers.go#L104

RainbowMango commented 1 month ago

Oh, I see. Thanks for the reminder, that makes sense to me.

PS: Link some materials about the SideCarContainer feature:

Monokaix commented 1 month ago

A little question need to be cleared, what if the featuregate of sidecareContaiener is enabled in karmada control plan but is disabled in member cluster or vice versa, to put it simply, the replicas calculation is not consistent between control plane and members. How does karmdada solve the problem of inconsistent featuregate switches?

RainbowMango commented 1 month ago

What would happen if we deploy a Deployment with sidecar container to a cluster where the SidecarContainers feature is disabled?

Monokaix commented 1 month ago

Sidecarcontainer is a special init container but will run last forever with main container, the pod request computation result is different with Sidecarcontainer disabled and enabled, it will affect scheduling result, if the SidecarContainers is enaled in control plane, the pod request resources computation result in control plane will be larger than in member clusters with SidecarContainers disabled, and the first level of scheduling may think the pod is not schedulable but actually it can be scheduled in member cluster. And if Sidecarcontainer is disabled in control plane while enabled in member cluster, the pod maybe schedulable but actually it cann't be schedulable in member cluster.