Skip to content

Commit

Permalink
Filtering informerFactory to return relevant PodSpec information
Browse files Browse the repository at this point in the history
  • Loading branch information
halimsam committed Dec 17, 2024
1 parent 909db59 commit 8d01e2c
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions pkg/cloud_provider/clientset/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,41 @@ 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)
}
}

currentObjSpec := obj.(*corev1.Pod).Spec

Check failure on line 88 in pkg/cloud_provider/clientset/clientset.go

View workflow job for this annotation

GitHub Actions / verify

type assertion must be checked (forcetypeassert)
var newContainers []corev1.Container
for _, cont := range currentObjSpec.Containers {
container := corev1.Container{
Name: cont.Name,
SecurityContext: cont.SecurityContext,
VolumeMounts: cont.VolumeMounts,
}
newContainers = append(newContainers, container)
}

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

obj.(*corev1.Pod).Spec = corev1.PodSpec{

Check failure on line 109 in pkg/cloud_provider/clientset/clientset.go

View workflow job for this annotation

GitHub Actions / verify

type assertion must be checked (forcetypeassert)
NodeName: currentObjSpec.NodeName,
Volumes: currentObjSpec.Volumes,
Containers: newContainers,
InitContainers: newInitContainers,
}

return obj, nil
}

Expand All @@ -94,7 +122,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

0 comments on commit 8d01e2c

Please sign in to comment.