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

Method getVPAObject

pkg/vpa/vpa.go:338–378  ·  view source on GitHub ↗
(existingVPA *vpav1.VerticalPodAutoscaler, ns *corev1.Namespace, controller Controller, updateMode *vpav1.UpdateMode, resourcePolicy *vpav1.PodResourcePolicy, minReplicas *int32)

Source from the content-addressed store, hash-verified

336}
337
338func (r Reconciler) getVPAObject(existingVPA *vpav1.VerticalPodAutoscaler, ns *corev1.Namespace, controller Controller, updateMode *vpav1.UpdateMode, resourcePolicy *vpav1.PodResourcePolicy, minReplicas *int32) vpav1.VerticalPodAutoscaler {
339 var desiredVPA vpav1.VerticalPodAutoscaler
340
341 // create a brand new vpa with the correct information
342 if existingVPA == nil {
343 desiredVPA = vpav1.VerticalPodAutoscaler{
344 ObjectMeta: metav1.ObjectMeta{
345 Name: "goldilocks-" + controller.Name,
346 Namespace: ns.Name,
347 },
348 }
349 } else {
350 // or use the existing VPA as a template to update from
351 desiredVPA = *existingVPA
352 }
353
354 // update the labels on the VPA
355 desiredVPA.Labels = utils.VPALabels
356
357 // update the spec on the VPA
358 desiredVPA.Spec = vpav1.VerticalPodAutoscalerSpec{
359 TargetRef: &autoscaling.CrossVersionObjectReference{
360 APIVersion: controller.APIVersion,
361 Kind: controller.Kind,
362 Name: controller.Name,
363 },
364 UpdatePolicy: &vpav1.PodUpdatePolicy{
365 UpdateMode: updateMode,
366 },
367 ResourcePolicy: resourcePolicy,
368 }
369
370 if minReplicas != nil {
371 if *minReplicas > 0 {
372 desiredVPA.Spec.UpdatePolicy.MinReplicas = minReplicas
373 }
374
375 }
376
377 return desiredVPA
378}
379
380var allowedUpdateModes = []vpav1.UpdateMode{
381 vpav1.UpdateModeOff,

Callers 7

Test_getVPAObjectFunction · 0.80
Test_createVPAFunction · 0.80
Test_deleteVPAFunction · 0.80
Test_updateVPAFunction · 0.80
Test_listVPAFunction · 0.80

Calls

no outgoing calls

Tested by 6

Test_getVPAObjectFunction · 0.64
Test_createVPAFunction · 0.64
Test_deleteVPAFunction · 0.64
Test_updateVPAFunction · 0.64
Test_listVPAFunction · 0.64