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

Add Get ingressBurst and egressBurst #10546

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
37 changes: 30 additions & 7 deletions internal/cri/bandwidth/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,54 @@ func validateBandwidthIsReasonable(rsrc *resource.Quantity) error {
}

// ExtractPodBandwidthResources extracts the ingress and egress from the given pod annotations
func ExtractPodBandwidthResources(podAnnotations map[string]string) (ingress, egress *resource.Quantity, err error) {
func ExtractPodBandwidthResources(podAnnotations map[string]string) (ingress, egress, ingressBurst, egressBurst *resource.Quantity, err error) {
if podAnnotations == nil {
return nil, nil, nil
return nil, nil, nil, nil, nil
}
str, found := podAnnotations["kubernetes.io/ingress-bandwidth"]
if found {
ingressValue, err := resource.ParseQuantity(str)
if err != nil {
return nil, nil, err
return nil, nil, nil, nil, err
}
ingress = &ingressValue
if err := validateBandwidthIsReasonable(ingress); err != nil {
return nil, nil, err
return nil, nil, nil, nil, err
}
}
str, found = podAnnotations["kubernetes.io/egress-bandwidth"]
if found {
egressValue, err := resource.ParseQuantity(str)
if err != nil {
return nil, nil, err
return nil, nil, nil, nil, err
}
egress = &egressValue
if err := validateBandwidthIsReasonable(egress); err != nil {
return nil, nil, err
return nil, nil, nil, nil, err
}
}
return ingress, egress, nil

str, found = podAnnotations["kubernetes.io/ingress-bandwidth-burst"]
if found {
ingressBurstValue, err := resource.ParseQuantity(str)
if err != nil {
return nil, nil, nil, nil, err
}
ingressBurst = &ingressBurstValue
if err := validateBandwidthIsReasonable(ingress); err != nil {
return nil, nil, nil, nil, err
}
}
str, found = podAnnotations["kubernetes.io/egress-bandwidth-burst"]
if found {
egressBurstValue, err := resource.ParseQuantity(str)
if err != nil {
return nil, nil, nil, nil, err
}
egressBurst = &egressBurstValue
if err := validateBandwidthIsReasonable(egress); err != nil {
return nil, nil, nil, nil, err
}
}
return ingress, egress, ingressBurst, egressBurst, nil
}
10 changes: 9 additions & 1 deletion internal/cri/server/sandbox_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func toCNILabels(id string, config *runtime.PodSandboxConfig) map[string]string

// toCNIBandWidth converts CRI annotations to CNI bandwidth.
func toCNIBandWidth(annotations map[string]string) (*cni.BandWidth, error) {
ingress, egress, err := bandwidth.ExtractPodBandwidthResources(annotations)
ingress, egress, ingressBurst, egressBurst, err := bandwidth.ExtractPodBandwidthResources(annotations)
if err != nil {
return nil, fmt.Errorf("reading pod bandwidth annotations: %w", err)
}
Expand All @@ -556,6 +556,14 @@ func toCNIBandWidth(annotations map[string]string) (*cni.BandWidth, error) {
bandWidth.EgressBurst = math.MaxUint32
}

if ingressBurst != nil && uint64(ingress.Value()) <= uint64(ingressBurst.Value()) {
bandWidth.IngressBurst = uint64(ingressBurst.Value())
}

if egressBurst != nil && uint64(egress.Value()) <= uint64(egressBurst.Value()) {
bandWidth.EgressBurst = uint64(egressBurst.Value())
}

return bandWidth, nil
}

Expand Down
Loading