Skip to content
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

feat:adding sidecar #3589

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/features/volcano_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const (

// ResourceTopology supports resources like cpu/memory topology aware.
ResourceTopology featuregate.Feature = "ResourceTopology"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add comment and reference documents to let users know the context of this feature gate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SidecarContainers is a kubernetes intree feature and has already a definition,and now we have imported other features like https://github.com/volcano-sh/volcano/blob/224ca98ab097d7788fc17ae5a6bbb0ba7a191653/pkg/scheduler/plugins/predicates/predicates.go#L291,so we doesn't need to re-define the feature.

SidecarContainers featuregate.Feature = "SidecarContainers"
)

func init() {
Expand All @@ -56,6 +58,7 @@ var defaultVolcanoFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec
QueueCommandSync: {Default: true, PreRelease: featuregate.Alpha},
PriorityClass: {Default: true, PreRelease: featuregate.Alpha},
// CSIStorage is explicitly set to false by default.
CSIStorage: {Default: false, PreRelease: featuregate.Alpha},
ResourceTopology: {Default: true, PreRelease: featuregate.Alpha},
CSIStorage: {Default: false, PreRelease: featuregate.Alpha},
ResourceTopology: {Default: true, PreRelease: featuregate.Alpha},
SidecarContainers: {Default: false, PreRelease: featuregate.Alpha},
}
40 changes: 38 additions & 2 deletions pkg/scheduler/api/pod_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,29 @@ import (

// GetPodResourceRequest returns all the resource required for that pod
func GetPodResourceRequest(pod *v1.Pod) *Resource {
req := v1.ResourceList{}
restartableInitContainerReqs := v1.ResourceList{}
initContainerReqs := v1.ResourceList{}

result := GetPodResourceWithoutInitContainers(pod)

// take max_resource(sum_pod, any_init_container)
for _, container := range pod.Spec.InitContainers {
result.SetMaxResource(NewResource(container.Resources.Requests))
containerReq := container.Resources.Requests

if container.RestartPolicy != nil && *container.RestartPolicy == v1.ContainerRestartPolicyAlways {
// and add them to the resulting cumulative container requests
addResourceList(req, containerReq)

// track our cumulative restartable init container resources
addResourceList(restartableInitContainerReqs, containerReq)
containerReq = restartableInitContainerReqs
} else {
tmp := v1.ResourceList{}
addResourceList(tmp, containerReq)
addResourceList(tmp, restartableInitContainerReqs)
containerReq = tmp
}
maxResourceList(initContainerReqs, containerReq)
}
result.AddScalar(v1.ResourcePods, 1)

Expand Down Expand Up @@ -154,3 +172,21 @@ func GetPodResourceWithoutInitContainers(pod *v1.Pod) *Resource {

return result
}
func addResourceList(list, newList v1.ResourceList) {
for name, quantity := range newList {
if value, ok := list[name]; !ok {
list[name] = quantity.DeepCopy()
} else {
value.Add(quantity)
list[name] = value
}
}
}

func maxResourceList(list, newList v1.ResourceList) {
for name, quantity := range newList {
if value, ok := list[name]; !ok || quantity.Cmp(value) > 0 {
list[name] = quantity.DeepCopy()
}
}
}