kubernetes / client-go

Go client for Kubernetes.
Apache License 2.0
8.78k stars 2.9k forks source link

Shared Informer Return mostly null values for ADD Pod event #1305

Closed zainjava closed 3 months ago

zainjava commented 8 months ago

Hi Team, I have noticed that when using Shared Informer, when I receive events for Pod Informer I get mostly null values from the K8 API Lib 0.28.2. What am I missing when calling the Shared Informer , Is it a bug in the Informer Lib ?

func SetupSharedInformer(cluster *K8sCluster,key int) {
    dur := GetCacheInterval()
    cluster.InformerFactory = inform.NewSharedInformerFactory(cluster.ClientSet, dur)
    cluster.InformerFactory.Start(wait.NeverStop)
    k8staConfig.K8sClusters[key].InformerFactory = cluster.InformerFactory
}
podInformer := cluster.InformerFactory.Core().V1().Pods().Informer()
podInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
    AddFunc: func(obj interface{}) {
        pod := obj.(v1.Object)

        if IsNamespaceOfIngest(cluster, pod.GetNamespace()) {
            AddPod(cluster, pod)
func AddPod(cluster K8sCluster, obj interface{}) {
    VVlog("AddPod")
    pod := obj.(*corev1.Pod)

    var rPod corev1.PodList
    rPod.Items = make([]corev1.Pod, 1)
    rPod.Items[0] = *pod

Attached it the Event Received from the Informer API

&Pod{ObjectMeta: {omc-web-85ccbc97cd-dvh8d omc-web-85ccbc97cd- omc  b5c5fb7f-f713-4763-b053-da1a2395277e 575335017 0 2023-10-13 12: 07: 20 +0000 UTC <nil> <nil> map[app:omc-web pod-template-hash: 85ccbc97cd
        ] map[container.apparmor.security.beta.kubernetes.io/omc-web:runtime/default
        ] [
            {apps/v1 ReplicaSet omc-web-85ccbc97cd 18c8b1b4-f84b-48b1-a81d-fea3427231ad 0xc0098e6897 0xc0098e6898
            }
        ] []  [
            {kube-controller-manager Update v1 2023-10-13 12: 07: 20 +0000 UTC FieldsV1 {
                    "f:metadata": {
                        "f:annotations": {
                            ".": {},
                            "f:container.apparmor.security.beta.kubernetes.io/omc-web": {}
                        },
                        "f:generateName": {},
                        "f:labels": {
                            ".": {},
                            "f:app": {},
                            "f:pod-template-hash": {}
                        },
                        "f:ownerReferences": {
                            ".": {},
                            "k:{\"uid\":\"18c8b1b4-f84b-48b1-a81d-fea3427231ad\"}": {}
                        }
                    },
                    "f:spec": {
                        "f:containers": {
                            "k:{\"name\":\"omc-web\"}": {
                                ".": {},
                                "f:image": {},
                                "f:imagePullPolicy": {},
                                "f:name": {},
                                "f:resources": {
                                    ".": {},
                                    "f:limits": {
                                        ".": {},
                                        "f:cpu": {},
                                        "f:memory": {}
                                    },
                                    "f:requests": {
                                        ".": {},
                                        "f:cpu": {},
                                        "f:memory": {}
                                    }
                                },
                                "f:securityContext": {
                                    ".": {},
                                    "f:allowPrivilegeEscalation": {},
                                    "f:capabilities": {
                                        ".": {},
                                        "f:drop": {}
                                    },
                                    "f:privileged": {},
                                    "f:readOnlyRootFilesystem": {},
                                    "f:runAsNonRoot": {},
                                    "f:seccompProfile": {
                                        ".": {},
                                        "f:type": {}
                                    }
                                },
                                "f:terminationMessagePath": {},
                                "f:terminationMessagePolicy": {},
                                "f:volumeMounts": {
                                    ".": {},
                                    "k:{\"mountPath\":\"/etc/nginx\"}": {
                                        ".": {},
                                        "f:mountPath": {},
                                        "f:name": {}
                                    },
                                    "k:{\"mountPath\":\"/tmp/nginx\"}": {
                                        ".": {},
                                        "f:mountPath": {},
                                        "f:name": {}
                                    },
                                    "k:{\"mountPath\":\"/var/cache/nginx\"}": {
                                        ".": {},
                                        "f:mountPath": {},
                                        "f:name": {}
                                    },
                                    "k:{\"mountPath\":\"/var/lib/nginx\"}": {
                                        ".": {},
                                        "f:mountPath": {},
                                        "f:name": {}
                                    },
                                    "k:{\"mountPath\":\"/var/run\"}": {
                                        ".": {},
                                        "f:mountPath": {},
                                        "f:name": {}
                                    }
                                }
                            }
                        },
                        "f:dnsPolicy": {},
                        "f:enableServiceLinks": {},
                        "f:imagePullSecrets": {
                            ".": {},
                            "k:{\"name\":\"k8s-registry-secret\"}": {}
                        },
                        "f:restartPolicy": {},
                        "f:schedulerName": {},
                        "f:securityContext": {},
                        "f:serviceAccount": {},
                        "f:serviceAccountName": {},
                        "f:terminationGracePeriodSeconds": {},
                        "f:volumes": {
                            ".": {},
                            "k:{\"name\":\"cache\"}": {
                                ".": {},
                                "f:emptyDir": {},
                                "f:name": {}
                            },
                            "k:{\"name\":\"nginx-tmp\"}": {
                                ".": {},
                                "f:emptyDir": {},
                                "f:name": {}
                            },
                            "k:{\"name\":\"omc-web-conf\"}": {
                                ".": {},
                                "f:name": {},
                                "f:projected": {
                                    ".": {},
                                    "f:defaultMode": {},
                                    "f:sources": {}
                                }
                            },
                            "k:{\"name\":\"pid-volume\"}": {
                                ".": {},
                                "f:emptyDir": {},
                                "f:name": {}
                            },
                            "k:{\"name\":\"tmp\"}": {
                                ".": {},
                                "f:emptyDir": {},
                                "f:name": {}
                            }
                        }
                    }
                }
            }
        ]
    },Spec:PodSpec{Volumes: []Volume{Volume{Name:omc-web-conf,VolumeSource:VolumeSource{HostPath:nil,EmptyDir:nil,GCEPersistentDisk:nil,AWSElasticBlockStore:nil,GitRepo:nil,Secret:nil,NFS:nil,ISCSI:nil,Glusterfs:nil,PersistentVolumeClaim:nil,RBD:nil,FlexVolume:nil,Cinder:nil,CephFS:nil,Flocker:nil,DownwardAPI:nil,FC:nil,AzureFile:nil,ConfigMap:nil,VsphereVolume:nil,Quobyte:nil,AzureDisk:nil,PhotonPersistentDisk:nil,PortworxVolume:nil,ScaleIO:nil,Projected:&ProjectedVolumeSource{Sources: []VolumeProjection{VolumeProjection{Secret:nil,DownwardAPI:nil,ConfigMap:&ConfigMapProjection{LocalObjectReference:LocalObjectReference{Name:omc-web-conf,
                                    },Items: []KeyToPath{},Optional:nil,
                                },ServiceAccountToken:nil,
                            },
                        },DefaultMode:*420,
                    },StorageOS:nil,CSI:nil,Ephemeral:nil,
                },
            },Volume{Name:pid-volume,VolumeSource:VolumeSource{HostPath:nil,EmptyDir:&EmptyDirVolumeSource{Medium: ,SizeLimit:<nil>,
                    },GCEPersistentDisk:nil,AWSElasticBlockStore:nil,GitRepo:nil,Secret:nil,NFS:nil,ISCSI:nil,Glusterfs:nil,PersistentVolumeClaim:nil,RBD:nil,FlexVolume:nil,Cinder:nil,CephFS:nil,Flocker:nil,DownwardAPI:nil,FC:nil,AzureFile:nil,ConfigMap:nil,VsphereVolume:nil,Quobyte:nil,AzureDisk:nil,PhotonPersistentDisk:nil,PortworxVolume:nil,ScaleIO:nil,Projected:nil,StorageOS:nil,CSI:nil,Ephemeral:nil,
                },
            },Volume{Name:cache,VolumeSource:VolumeSource{HostPath:nil,EmptyDir:&EmptyDirVolumeSource{Medium: ,SizeLimit:<nil>,
                    },GCEPersistentDisk:nil,AWSElasticBlockStore:nil,GitRepo:nil,Secret:nil,NFS:nil,ISCSI:nil,Glusterfs:nil,PersistentVolumeClaim:nil,RBD:nil,FlexVolume:nil,Cinder:nil,CephFS:nil,Flocker:nil,DownwardAPI:nil,FC:nil,AzureFile:nil,ConfigMap:nil,VsphereVolume:nil,Quobyte:nil,AzureDisk:nil,PhotonPersistentDisk:nil,PortworxVolume:nil,ScaleIO:nil,Projected:nil,StorageOS:nil,CSI:nil,Ephemeral:nil,
                },
            },Volume{Name:tmp,VolumeSource:VolumeSource{HostPath:nil,EmptyDir:&EmptyDirVolumeSource{Medium: ,SizeLimit:<nil>,
                    },GCEPersistentDisk:nil,AWSElasticBlockStore:nil,GitRepo:nil,Secret:nil,NFS:nil,ISCSI:nil,Glusterfs:nil,PersistentVolumeClaim:nil,RBD:nil,FlexVolume:nil,Cinder:nil,CephFS:nil,Flocker:nil,DownwardAPI:nil,FC:nil,AzureFile:nil,ConfigMap:nil,VsphereVolume:nil,Quobyte:nil,AzureDisk:nil,PhotonPersistentDisk:nil,PortworxVolume:nil,ScaleIO:nil,Projected:nil,StorageOS:nil,CSI:nil,Ephemeral:nil,
                },
            },Volume{Name:nginx-tmp,VolumeSource:VolumeSource{HostPath:nil,EmptyDir:&EmptyDirVolumeSource{Medium: ,SizeLimit:<nil>,
                    },GCEPersistentDisk:nil,AWSElasticBlockStore:nil,GitRepo:nil,Secret:nil,NFS:nil,ISCSI:nil,Glusterfs:nil,PersistentVolumeClaim:nil,RBD:nil,FlexVolume:nil,Cinder:nil,CephFS:nil,Flocker:nil,DownwardAPI:nil,FC:nil,AzureFile:nil,ConfigMap:nil,VsphereVolume:nil,Quobyte:nil,AzureDisk:nil,PhotonPersistentDisk:nil,PortworxVolume:nil,ScaleIO:nil,Projected:nil,StorageOS:nil,CSI:nil,Ephemeral:nil,
                },
            },Volume{Name:kube-api-access-4tws2,VolumeSource:VolumeSource{HostPath:nil,EmptyDir:nil,GCEPersistentDisk:nil,AWSElasticBlockStore:nil,GitRepo:nil,Secret:nil,NFS:nil,ISCSI:nil,Glusterfs:nil,PersistentVolumeClaim:nil,RBD:nil,FlexVolume:nil,Cinder:nil,CephFS:nil,Flocker:nil,DownwardAPI:nil,FC:nil,AzureFile:nil,ConfigMap:nil,VsphereVolume:nil,Quobyte:nil,AzureDisk:nil,PhotonPersistentDisk:nil,PortworxVolume:nil,ScaleIO:nil,Projected:&ProjectedVolumeSource{Sources: []VolumeProjection{VolumeProjection{Secret:nil,DownwardAPI:nil,ConfigMap:nil,ServiceAccountToken:&ServiceAccountTokenProjection{Audience: ,ExpirationSeconds:*3607,Path:token,
                                },
                            },VolumeProjection{Secret:nil,DownwardAPI:nil,ConfigMap:&ConfigMapProjection{LocalObjectReference:LocalObjectReference{Name:kube-root-ca.crt,
                                    },Items: []KeyToPath{KeyToPath{Key:ca.crt,Path:ca.crt,Mode:nil,
                                        },
                                    },Optional:nil,
                                },ServiceAccountToken:nil,
                            },VolumeProjection{Secret:nil,DownwardAPI:&DownwardAPIProjection{Items: []DownwardAPIVolumeFile{DownwardAPIVolumeFile{Path:namespace,FieldRef:&ObjectFieldSelector{APIVersion:v1,FieldPath:metadata.namespace,
                                            },ResourceFieldRef:nil,Mode:nil,
                                        },
                                    },
                                },ConfigMap:nil,ServiceAccountToken:nil,
                            },
                        },DefaultMode:*420,
                    },StorageOS:nil,CSI:nil,Ephemeral:nil,
                },
            },
        },Containers: []Container{Container{Name:omc-web,Image:k8s-registry.eccd.local/proj-omc-drop/omc-web: 2.3.0-15,Command: [],Args: [],WorkingDir: ,Ports: []ContainerPort{},Env: []EnvVar{},Resources:ResourceRequirements{Limits:ResourceList{cpu: {
                            {
                                2 0
                            } {<nil>
                            } 2 DecimalSI
                        },memory: {
                            {
                                2097152000 0
                            } {<nil>
                            }  BinarySI
                        },
                    },Requests:ResourceList{cpu: {
                            {
                                500 -3
                            } {<nil>
                            } 500m DecimalSI
                        },memory: {
                            {
                                1048576000 0
                            } {<nil>
                            }  BinarySI
                        },
                    },
                },VolumeMounts: []VolumeMount{VolumeMount{Name:omc-web-conf,ReadOnly: false,MountPath:/etc/nginx,SubPath: ,MountPropagation:nil,SubPathExpr: ,
                    },VolumeMount{Name:pid-volume,ReadOnly: false,MountPath:/var/run,SubPath: ,MountPropagation:nil,SubPathExpr: ,
                    },VolumeMount{Name:cache,ReadOnly: false,MountPath:/var/cache/nginx,SubPath: ,MountPropagation:nil,SubPathExpr: ,
                    },VolumeMount{Name:tmp,ReadOnly: false,MountPath:/tmp/nginx,SubPath: ,MountPropagation:nil,SubPathExpr: ,
                    },VolumeMount{Name:nginx-tmp,ReadOnly: false,MountPath:/var/lib/nginx,SubPath: ,MountPropagation:nil,SubPathExpr: ,
                    },VolumeMount{Name:kube-api-access-4tws2,ReadOnly: true,MountPath:/var/run/secrets/kubernetes.io/serviceaccount,SubPath: ,MountPropagation:nil,SubPathExpr: ,
                    },
                },LivenessProbe:nil,ReadinessProbe:nil,Lifecycle:nil,TerminationMessagePath:/dev/termination-log,ImagePullPolicy:IfNotPresent,SecurityContext:&SecurityContext{Capabilities:&Capabilities{Add: [],Drop: [all
                        ],
                    },Privileged:*false,SELinuxOptions:nil,RunAsUser:nil,RunAsNonRoot:*true,ReadOnlyRootFilesystem:*true,AllowPrivilegeEscalation:*false,RunAsGroup:nil,ProcMount:nil,WindowsOptions:nil,SeccompProfile:&SeccompProfile{Type:RuntimeDefault,LocalhostProfile:nil,
                    },
                },Stdin: false,StdinOnce: false,TTY: false,EnvFrom: []EnvFromSource{},TerminationMessagePolicy:File,VolumeDevices: []VolumeDevice{},StartupProbe:nil,
            },
        },RestartPolicy:Always,TerminationGracePeriodSeconds:*30,ActiveDeadlineSeconds:nil,DNSPolicy:ClusterFirst,NodeSelector:map[string
        ]string{},ServiceAccountName:omc-web,DeprecatedServiceAccount:omc-web,NodeName: ,HostNetwork: false,HostPID: false,HostIPC: false,SecurityContext:&PodSecurityContext{SELinuxOptions:nil,RunAsUser:nil,RunAsNonRoot:nil,SupplementalGroups: [],FSGroup:nil,RunAsGroup:nil,Sysctls: []Sysctl{},WindowsOptions:nil,FSGroupChangePolicy:nil,SeccompProfile:nil,
        },ImagePullSecrets: []LocalObjectReference{LocalObjectReference{Name:k8s-registry-secret,
            },
        },Hostname: ,Subdomain: ,Affinity:nil,SchedulerName:default-scheduler,InitContainers: []Container{},AutomountServiceAccountToken:nil,Tolerations: []Toleration{Toleration{Key:node.kubernetes.io/not-ready,Operator:Exists,Value: ,Effect:NoExecute,TolerationSeconds:*300,
            },Toleration{Key:node.kubernetes.io/unreachable,Operator:Exists,Value: ,Effect:NoExecute,TolerationSeconds:*300,
            },
        },HostAliases: []HostAlias{},PriorityClassName: ,Priority:*0,DNSConfig:nil,ShareProcessNamespace:nil,ReadinessGates: []PodReadinessGate{},RuntimeClassName:nil,EnableServiceLinks:*true,PreemptionPolicy:*PreemptLowerPriority,Overhead:ResourceList{},TopologySpreadConstraints: []TopologySpreadConstraint{},EphemeralContainers: []EphemeralContainer{},SetHostnameAsFQDN:nil,
    },Status:PodStatus{Phase:Pending,Conditions: []PodCondition{},Message: ,Reason: ,HostIP: ,PodIP: ,StartTime:<nil>,ContainerStatuses: []ContainerStatus{},QOSClass:Burstable,InitContainerStatuses: []ContainerStatus{},NominatedNodeName: ,PodIPs: []PodIP{},EphemeralContainerStatuses: []ContainerStatus{},
    },
}
k8s-triage-robot commented 5 months ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 4 months ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot commented 3 months ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-ci-robot commented 3 months ago

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to [this](https://github.com/kubernetes/client-go/issues/1305#issuecomment-2027959606): >The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. > >This bot triages issues according to the following rules: >- After 90d of inactivity, `lifecycle/stale` is applied >- After 30d of inactivity since `lifecycle/stale` was applied, `lifecycle/rotten` is applied >- After 30d of inactivity since `lifecycle/rotten` was applied, the issue is closed > >You can: >- Reopen this issue with `/reopen` >- Mark this issue as fresh with `/remove-lifecycle rotten` >- Offer to help out with [Issue Triage][1] > >Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community). > >/close not-planned > >[1]: https://www.kubernetes.dev/docs/guide/issue-triage/ Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.