Skip to content

Instantly share code, notes, and snippets.

@Becram
Last active May 7, 2022 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Becram/29f49c34de0524bd2e759e20e0b87ee1 to your computer and use it in GitHub Desktop.
Save Becram/29f49c34de0524bd2e759e20e0b87ee1 to your computer and use it in GitHub Desktop.
webhook-medium-2
// Mutate returns a new mutated pod according to lifespan tolerations rules
func (mpl containerResources) Mutate(pod *corev1.Pod) (*corev1.Pod, error) {
mpl.Logger = mpl.Logger.WithField("mutation", mpl.Name())
mpod := pod.DeepCopy()
resources, err := parseResources()
if err != nil {
return &corev1.Pod{}, err
}
tn := corev1.ResourceRequirements{
Limits: resources.Limits,
Requests: resources.Requests,
}
for index, n := range mpod.Spec.Containers {
mpl.Logger.WithField("container", n.Name).
Printf("applying default limits and request resource")
mpod.Spec.Containers[index].Resources = tn
}
return mpod, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment