diff --git a/internal/kuberesource/mutators.go b/internal/kuberesource/mutators.go index c56aa4fce..84838c156 100644 --- a/internal/kuberesource/mutators.go +++ b/internal/kuberesource/mutators.go @@ -7,6 +7,7 @@ import ( "errors" applyappsv1 "k8s.io/client-go/applyconfigurations/apps/v1" + applybatchv1 "k8s.io/client-go/applyconfigurations/batch/v1" applycorev1 "k8s.io/client-go/applyconfigurations/core/v1" ) @@ -93,3 +94,27 @@ func AddServiceMesh( ) return deployment, nil } + +// MapPodSpec applies a function to a PodSpec in a Kubernetes resource. +func MapPodSpec(resource any, f func(spec *applycorev1.PodSpecApplyConfiguration) *applycorev1.PodSpecApplyConfiguration) any { + if resource == nil { + return nil + } + switch r := resource.(type) { + case *applyappsv1.DaemonSetApplyConfiguration: + r.Spec.Template.Spec = f(r.Spec.Template.Spec) + case *applyappsv1.DeploymentApplyConfiguration: + r.Spec.Template.Spec = f(r.Spec.Template.Spec) + case *applybatchv1.JobApplyConfiguration: + r.Spec.Template.Spec = f(r.Spec.Template.Spec) + case *applycorev1.PodApplyConfiguration: + r.Spec = f(r.Spec) + case *applyappsv1.ReplicaSetApplyConfiguration: + r.Spec.Template.Spec = f(r.Spec.Template.Spec) + case *applycorev1.ReplicationControllerApplyConfiguration: + r.Spec.Template.Spec = f(r.Spec.Template.Spec) + case *applyappsv1.StatefulSetApplyConfiguration: + r.Spec.Template.Spec = f(r.Spec.Template.Spec) + } + return resource +}