Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Fix the list calls to use informer #358

Merged
merged 10 commits into from
Aug 26, 2019
Merged

Fix the list calls to use informer #358

merged 10 commits into from
Aug 26, 2019

Conversation

kkmsft
Copy link
Contributor

@kkmsft kkmsft commented Aug 23, 2019

Reason for Change:

Fix the list calls to use informer. It was found during scale tests that API Server was getting a large number of LIST calls for various CRDS. Investigations revealed a bug - currently we use list watch directly, instead of using informer for LIST calls for CRDs and pods(in some code paths).

Issue Fixed:

Notes for Reviewers:

@kkmsft kkmsft requested a review from aramase August 23, 2019 02:14
@kkmsft kkmsft changed the title Fix the list calls to use informer [WIP] Fix the list calls to use informer Aug 23, 2019
Copy link
Member

@aramase aramase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add watch verb in clusterrole in here (https://github.com/Azure/aad-pod-identity/tree/master/deploy) as well

pkg/crd/crd.go Outdated
@@ -23,13 +23,11 @@ import (

// Client represents all the watchers and informers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this comment also to say Client represents all informers

pkg/crd/crd.go Outdated
func newAssignedIDInformer(lw *cache.ListWatch) (cache.SharedInformer, error) {
azAssignedIDInformer := cache.NewSharedInformer(lw, &aadpodid.AzureAssignedIdentity{}, time.Minute*10)
if azAssignedIDInformer == nil {
return nil, fmt.Errorf("could not create %s nformer", aadpodid.AzureAssignedIDResource)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: %s/nformer/informer

pkg/crd/crd.go Outdated
func newPodIdentityExceptionInformer(lw *cache.ListWatch) (cache.SharedInformer, error) {
azPodIDExceptionInformer := cache.NewSharedInformer(lw, &aadpodid.AzurePodIdentityException{}, time.Minute*10)
if azPodIDExceptionInformer == nil {
return nil, fmt.Errorf("could not create %s nformer", aadpodid.AzureIdentityExceptionResource)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: %s/nformer/informer

pkg/crd/crd.go Outdated
// Note: List items returned from cache have empty Kind and API version..
// Work around this issue since we need that for event recording to work.
if o.Kind == "" {
o.Kind = reflect.TypeOf(*o).String()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are setting the kind based on object type we can generalize this into a function - pass the obj, crd group and crdversion so we can use it later if we have another version too.

pkg/crd/crd.go Outdated
}

resList = append(resList, *o)
glog.V(6).Infof("Appending binding: %s/%s to list.", o.Name, o.Namespace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be namespace/name

Suggested change
glog.V(6).Infof("Appending binding: %s/%s to list.", o.Name, o.Namespace)
glog.V(6).Infof("Appending binding: %s/%s to list.", o.Namespace, o.Name)

pkg/crd/crd.go Outdated
o.APIVersion = aadpodid.CRDGroup + "/" + aadpodid.CRDVersion
}
resList = append(resList, *o)
glog.V(6).Infof("Appending Assigned ID: %s/%s to list.", o.Name, o.Namespace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be namespace/name

Suggested change
glog.V(6).Infof("Appending Assigned ID: %s/%s to list.", o.Name, o.Namespace)
glog.V(6).Infof("Appending Assigned ID: %s/%s to list.", o.Namespace, o.Name)

pkg/crd/crd.go Outdated
o.APIVersion = aadpodid.CRDGroup + "/" + aadpodid.CRDVersion
}
resList = append(resList, *o)
glog.V(6).Infof("Appending Identity: %s/%s to list.", o.Name, o.Namespace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be namespace/name

Suggested change
glog.V(6).Infof("Appending Identity: %s/%s to list.", o.Name, o.Namespace)
glog.V(6).Infof("Appending Identity: %s/%s to list.", o.Namespace, o.Name)

pkg/crd/crd.go Outdated
o.APIVersion = aadpodid.CRDGroup + "/" + aadpodid.CRDVersion
}
resList = append(resList, *o)
glog.V(6).Infof("Appending exception: %s/%s to list.", o.Name, o.Namespace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be namespace/name

Suggested change
glog.V(6).Infof("Appending exception: %s/%s to list.", o.Name, o.Namespace)
glog.V(6).Infof("Appending exception: %s/%s to list.", o.Namespace, o.Name)

@kkmsft kkmsft changed the title [WIP] Fix the list calls to use informer Fix the list calls to use informer Aug 26, 2019
listObject, err := c.PodListWatch.List(metav1.ListOptions{
FieldSelector: "status.podIP==" + podip + phaseStatusFilter,
})
func isPhaseValid(p v1.PodPhase) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a comment here saying we also allowing Pending state to account for init containers. We can do it in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will add in future PR.


func (c *KubeClient) getPodList(podip string) ([]*v1.Pod, error) {
list, err := c.PodInformer.Lister().List(labels.Everything())
Copy link
Member

@aramase aramase Aug 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to explicitly pass labels.Everything() only for this informer list call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podInformer is from SharedInformerFactory. This has specific listers instead of generic listers like the SharedInformers (which is used for custom types like CRDs). Hence the listing uses labels which is specific to the pod lister.

@kkmsft kkmsft merged commit 050a513 into Azure:master Aug 26, 2019
@kkmsft kkmsft deleted the go-client branch August 26, 2019 23:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants