0

I am trying to set a fixed resource value to my kubernetes container. When I try the following:

//cont = v1.Container
log.Println("Before", cont.Resources.Requests.Memory())
cont.Resources.Requests.Memory().SetMilli(512) //new wanted value
log.Println("After", cont.Resources.Requests.Memory())

log.Println("Before", cont.Resources.Requests.Cpu())
cont.Resources.Requests.Cpu().SetScaled(2, resource.Giga) //new wanted value
log.Println("After", cont.Resources.Requests.Cpu())

I get this:

Before 0
After 0
Before 0
After 0

Why doesn't Set update my values to the newer ones? How can I set the CPU & RAM resources properly?

4

1 回答 1

0

感谢Dim 的回答,我设法找到了解决方案。似乎在没有设置资源的情况下,无法在 Memory() 返回的数据结构中设置新值。正确的做法是这样的:

cont.Resources.Requests = make(map[v1core.ResourceName]resource.Quantity)
cont.Resources.Requests[v1core.ResourceMemory] = *resource.NewQuantity(int64(512), resource.BinarySI)
cont.Resources.Requests[v1core.ResourceCPU] = *resource.NewQuantity(int64(4), resource.BinarySI)

干杯!

于 2017-12-16T04:37:48.327 回答