cni: rate and limit must be both set

Fix #70014
pull/58/head
Yongkun Gui 2018-10-23 15:39:43 -07:00
parent 1fe288ec02
commit b573cce595
2 changed files with 4 additions and 2 deletions

View File

@ -19,6 +19,7 @@ package cni
import (
"errors"
"fmt"
"math"
"sort"
"strings"
"sync"
@ -377,11 +378,11 @@ func (plugin *cniNetworkPlugin) buildCNIRuntimeConf(podName string, podNs string
bandwidthParam := cniBandwidthEntry{}
if ingress != nil {
bandwidthParam.IngressRate = int(ingress.Value() / 1000)
bandwidthParam.IngressBurst = 0 // default to no limit
bandwidthParam.IngressBurst = math.MaxInt32 // no limit
}
if egress != nil {
bandwidthParam.EgressRate = int(egress.Value() / 1000)
bandwidthParam.EgressBurst = 0 // default to no limit
bandwidthParam.EgressBurst = math.MaxInt32 // no limit
}
rt.CapabilityArgs["bandwidth"] = bandwidthParam
}

View File

@ -291,6 +291,7 @@ func TestCNIPlugin(t *testing.T) {
}
expectedBandwidth := map[string]interface{}{
"ingressRate": 1000.0, "egressRate": 1000.0,
"ingressBurst": 2147483647.0, "egressBurst": 2147483647.0,
}
if !reflect.DeepEqual(inputConfig.RuntimeConfig.Bandwidth, expectedBandwidth) {
t.Errorf("mismatch in expected bandwidth. expected %v got %v", expectedBandwidth, inputConfig.RuntimeConfig.Bandwidth)