change bandwidth units from Kb to b

Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
This commit is contained in:
Bruce Ma 2019-03-18 21:22:34 +08:00
parent 364b18cb9e
commit 183247ca5c
2 changed files with 6 additions and 3 deletions

View File

@ -398,11 +398,14 @@ func (plugin *cniNetworkPlugin) buildCNIRuntimeConf(podName string, podNs string
if ingress != nil || egress != nil { if ingress != nil || egress != nil {
bandwidthParam := cniBandwidthEntry{} bandwidthParam := cniBandwidthEntry{}
if ingress != nil { if ingress != nil {
bandwidthParam.IngressRate = int(ingress.Value() / 1000) // see: https://github.com/containernetworking/cni/blob/master/CONVENTIONS.md and
// https://github.com/containernetworking/plugins/blob/master/plugins/meta/bandwidth/README.md
// Rates are in bits per second, burst values are in bits.
bandwidthParam.IngressRate = int(ingress.Value())
bandwidthParam.IngressBurst = math.MaxInt32 // no limit bandwidthParam.IngressBurst = math.MaxInt32 // no limit
} }
if egress != nil { if egress != nil {
bandwidthParam.EgressRate = int(egress.Value() / 1000) bandwidthParam.EgressRate = int(egress.Value())
bandwidthParam.EgressBurst = math.MaxInt32 // no limit bandwidthParam.EgressBurst = math.MaxInt32 // no limit
} }
rt.CapabilityArgs["bandwidth"] = bandwidthParam rt.CapabilityArgs["bandwidth"] = bandwidthParam

View File

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