MCPcopy Index your code
hub / github.com/devspace-sh/devspace / applyPodPatches

Function applyPodPatches

pkg/devspace/services/podreplace/builder.go:509–548  ·  view source on GitHub ↗
(pod *corev1.PodTemplateSpec, devPod *latest.DevPod)

Source from the content-addressed store, hash-verified

507}
508
509func applyPodPatches(pod *corev1.PodTemplateSpec, devPod *latest.DevPod) (*corev1.PodTemplateSpec, error) {
510 if len(devPod.Patches) == 0 {
511 return pod.DeepCopy(), nil
512 }
513
514 podBytes, err := yaml.Marshal(pod)
515 if err != nil {
516 return nil, err
517 }
518
519 podRaw := map[string]interface{}{}
520 err = yaml.Unmarshal(podBytes, &podRaw)
521 if err != nil {
522 return nil, err
523 }
524
525 raw, err := loader.ApplyPatchesOnObject(podRaw, devPod.Patches)
526 if err != nil {
527 return nil, err
528 }
529
530 // convert back
531 rawJSON, err := json.Marshal(raw)
532 if err != nil {
533 return nil, err
534 }
535
536 retPod := &corev1.PodTemplateSpec{
537 ObjectMeta: metav1.ObjectMeta{
538 Annotations: make(map[string]string),
539 Labels: make(map[string]string),
540 },
541 }
542
543 err = json.Unmarshal(rawJSON, retPod)
544 if err != nil {
545 return nil, err
546 }
547 return retPod, nil
548}

Callers 1

buildDeploymentFunction · 0.85

Calls 2

ApplyPatchesOnObjectFunction · 0.92
DeepCopyMethod · 0.65

Tested by

no test coverage detected