MCPcopy
hub / github.com/FairwindsOps/goldilocks / vpaResourcePolicyForResource

Function vpaResourcePolicyForResource

pkg/vpa/vpa.go:420–444  ·  view source on GitHub ↗

vpaResourcePolicyForResource get the resource's annotation for the vpa pod resource policy key/value and the value is the json definition of the pod resource policy

(obj runtime.Object)

Source from the content-addressed store, hash-verified

418// vpaResourcePolicyForResource get the resource's annotation for the vpa pod resource policy
419// key/value and the value is the json definition of the pod resource policy
420func vpaResourcePolicyForResource(obj runtime.Object) (*vpav1.PodResourcePolicy, bool) {
421 explicit := false
422
423 resourcePolicyStr := ""
424 accessor, _ := meta.Accessor(obj)
425 if val, ok := accessor.GetAnnotations()[utils.VpaResourcePolicyAnnotation]; ok {
426 resourcePolicyStr = val
427 } else if val, ok := accessor.GetLabels()[utils.VpaResourcePolicyAnnotation]; ok {
428 resourcePolicyStr = val
429 }
430
431 if resourcePolicyStr == "" {
432 return nil, explicit
433 }
434
435 explicit = true
436 resourcePol := vpav1.PodResourcePolicy{}
437 err := json.NewDecoder(bytes.NewReader([]byte(resourcePolicyStr))).Decode(&resourcePol)
438 if err != nil {
439 klog.Error(err.Error())
440 return nil, explicit
441 }
442
443 return &resourcePol, explicit
444}
445
446// vpaMinReplicas sets the VPA minimum replicas required for eviction
447func vpaMinReplicasForResource(obj runtime.Object) (*int32, bool) {

Callers 8

Test_getVPAObjectFunction · 0.85
Test_createVPAFunction · 0.85
Test_deleteVPAFunction · 0.85
Test_updateVPAFunction · 0.85
Test_listVPAFunction · 0.85

Calls

no outgoing calls

Tested by 6

Test_getVPAObjectFunction · 0.68
Test_createVPAFunction · 0.68
Test_deleteVPAFunction · 0.68
Test_updateVPAFunction · 0.68
Test_listVPAFunction · 0.68