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

Function vpaUpdateModeForResource

pkg/vpa/vpa.go:390–416  ·  view source on GitHub ↗

vpaUpdateModeForResource searches the resource's annotations and labels for a vpa-update-mode key/value and uses that key/value to return the proper UpdateMode type

(obj runtime.Object)

Source from the content-addressed store, hash-verified

388// vpaUpdateModeForResource searches the resource's annotations and labels for a vpa-update-mode
389// key/value and uses that key/value to return the proper UpdateMode type
390func vpaUpdateModeForResource(obj runtime.Object) (*vpav1.UpdateMode, bool) {
391 requestedVPAMode := vpav1.UpdateModeOff
392 explicit := false
393
394 requestStr := ""
395 accessor, _ := meta.Accessor(obj)
396 if val, ok := accessor.GetAnnotations()[utils.VpaUpdateModeKey]; ok {
397 requestStr = val
398 } else if val, ok := accessor.GetLabels()[utils.VpaUpdateModeKey]; ok {
399 requestStr = val
400 }
401 if requestStr != "" {
402 requestStrLower := strings.ToLower(requestStr)
403 for _, mode := range allowedUpdateModes {
404 if requestStrLower == strings.ToLower(string(mode)) {
405 requestedVPAMode = mode
406 explicit = true
407 break
408 }
409 }
410 if !explicit {
411 klog.Warningf("Invalid vpa-update-mode value: %s, defaulting to Off", requestStr)
412 }
413 }
414
415 return &requestedVPAMode, explicit
416}
417
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

Callers 9

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 7

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