Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering informerFactory to only return relevant PodSpec information #413

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions pkg/cloud_provider/clientset/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,50 @@ func New(kubeconfigPath string, informerResyncDurationSec int) (Interface, error
}

func (c *Clientset) ConfigurePodLister(nodeName string) {
trimManagedFields := func(obj interface{}) (interface{}, error) {
trim := func(obj interface{}) (interface{}, error) {
if accessor, err := meta.Accessor(obj); err == nil {
if accessor.GetManagedFields() != nil {
accessor.SetManagedFields(nil)
}
}

// We are filtering only for relevant PodSpec info to optimize memory usage.
// Relevant info is for NodePublishVolume calls:
// https://github.com/GoogleCloudPlatform/gcs-fuse-csi-driver/blob/547cab9a9aea4cdbda581885880020fb9266dc03/pkg/csi_driver/node.go#L85
podObj, ok := obj.(*corev1.Pod)
if !ok {
return obj, nil
}

saikat-royc marked this conversation as resolved.
Show resolved Hide resolved
var newContainers []corev1.Container
for _, cont := range podObj.Spec.Containers {
container := corev1.Container{
Name: cont.Name,
SecurityContext: cont.SecurityContext,
VolumeMounts: cont.VolumeMounts,
}
newContainers = append(newContainers, container)
}

var newInitContainers []corev1.Container
for _, cont := range podObj.Spec.InitContainers {
container := corev1.Container{
Name: cont.Name,
SecurityContext: cont.SecurityContext,
VolumeMounts: cont.VolumeMounts,
}
newInitContainers = append(newInitContainers, container)
}

nodeName := podObj.Spec.NodeName
volumes := podObj.Spec.Volumes
podObj.Spec = corev1.PodSpec{
NodeName: nodeName,
Volumes: volumes,
Containers: newContainers,
InitContainers: newInitContainers,
}

return obj, nil
}

Expand All @@ -94,7 +131,7 @@ func (c *Clientset) ConfigurePodLister(nodeName string) {
informers.WithTweakListOptions(func(options *metav1.ListOptions) {
options.FieldSelector = "spec.nodeName=" + nodeName
}),
informers.WithTransform(trimManagedFields),
informers.WithTransform(trim),
)
podLister := informerFactory.Core().V1().Pods().Lister()

Expand Down