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

Reduce load on etcd/kube-apiserver on pod eviction #949

Merged
merged 2 commits into from
Oct 28, 2024

Conversation

thiyyakat
Copy link
Contributor

@thiyyakat thiyyakat commented Oct 21, 2024

What this PR does / why we need it:

The PR changes the way pods are listed before eviction, by using a PodInformer which uses a local cache rather than directly querying the kube-apiserver/etcd. The pods are listed only after the cache has synced.

Which issue(s) this PR fixes:
Fixes #703

Special notes for your reviewer:

Impact of changes tested by running pods configuring a PDB with maxUnavailable set to 0, on a cluster with 20 machines, and deleting all the machines, thereby initiating drain. Without change, peak traffic recorded was 8.51 MB/s. With change, peak traffic recorded was 1.48 MB/s.

Screenshot 2024-10-21 at 1 10 05 PM

Integration tests run for providers AWS and Azure completed successfully.

Additionally, to manually check if cache for podInformer syncs successfully before the podLister.List() call,time.Sleep( 30 * time.Second) was introduced before calling RunCordonOrUncordon(), and a new pod (default/nginx-pod2 ) was deployed during the sleep period. Logs were added to print the names of all pods on the node returned by the podLister. After triggering the deletion of the machine, the machine entered the drain flow, and after the sleep the new pod's name was logged.

I1023 16:13:08.044770   91923 machine_util.go:1182] (drainNode) Invoking RunDrain, forceDeleteMachine: false, forceDeletePods: false, timeOutDuration: 5m0s
I1023 16:13:08.044894   91923 drain.go:238] ABOUT TO SLEEP for 30s
I1023 16:13:43.861554   91923 drain.go:369] Found pod default/nginx-pod2 

Release note:

MCM will use an `informer` instead of the`clientset` to list pods in the drain logic. This will reduce the load on etcd/kube-apiserver.

@thiyyakat thiyyakat requested a review from a team as a code owner October 21, 2024 08:35
@gardener-robot gardener-robot added needs/review Needs review size/s Size of pull request is small (see gardener-robot robot/bots/size.py) labels Oct 21, 2024
@gardener-robot-ci-3
Copy link
Contributor

Thank you @thiyyakat for your contribution. Before I can start building your PR, a member of the organization must set the required label(s) {'reviewed/ok-to-test'}. Once started, you can check the build status in the PR checks section below.

@thiyyakat thiyyakat self-assigned this Oct 21, 2024
@rishabh-11 rishabh-11 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Oct 21, 2024
@gardener-robot-ci-3 gardener-robot-ci-3 added needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Oct 21, 2024
@@ -232,20 +239,26 @@ func (o *Options) RunDrain(ctx context.Context) error {
klog.Errorf("Drain Error: Cordoning of node failed with error: %v", err)
return err
}
stopCh := make(chan struct{})
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not construct an empty stopCh here as it becomes useless for signalling. We should use a channel obtained from context.WithTimeout using the drain timeout passed to NewDrainOptions. And then use the Done() method on the returned context to get the stopCh.

Copy link
Contributor

Choose a reason for hiding this comment

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

PS: There is already a context created for this a little later in RunDrain. drainContext, cancelFn := context.WithDeadline(ctx, o.drainStartedOn.Add(o.Timeout))

We should use the Done() channel from this.

if w != nil {
ws[w.string] = append(ws[w.string], pod.Name)
for _, pod := range podList {
if pod.Spec.NodeName == o.nodeName {
Copy link
Contributor

@elankath elankath Oct 22, 2024

Choose a reason for hiding this comment

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

Just use a not check here and continue instead of nesting.

Copy link
Contributor

@elankath elankath left a comment

Choose a reason for hiding this comment

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

looks good. small changes requested.

@gardener-robot gardener-robot added the needs/changes Needs (more) changes label Oct 22, 2024
@@ -279,6 +279,7 @@ func StartControllers(s *options.MCServer,
targetCoreInformerFactory.Storage().V1().VolumeAttachments(),
machineSharedInformers.MachineClasses(),
machineSharedInformers.Machines(),
targetCoreInformerFactory.Core().V1().Pods(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Can you move this a few lines up so that all InformerFactorys are together?

@rishabh-11 rishabh-11 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Oct 22, 2024
@gardener-robot-ci-1 gardener-robot-ci-1 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Oct 22, 2024
if err != nil {
return pods, err
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

minor nit: with named return params, you don't need explicit valued return. Just a bare return is sufficient.

Copy link
Contributor

@elankath elankath left a comment

Choose a reason for hiding this comment

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

/lgtm . Please run IT.

@gardener-robot gardener-robot added reviewed/lgtm Has approval for merging and removed needs/changes Needs (more) changes needs/review Needs review labels Oct 23, 2024
@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Oct 23, 2024
@gardener-robot-ci-3 gardener-robot-ci-3 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Oct 23, 2024
Copy link
Contributor

@rishabh-11 rishabh-11 left a comment

Choose a reason for hiding this comment

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

/lgtm

@rishabh-11 rishabh-11 merged commit 31834e2 into gardener:master Oct 28, 2024
8 checks passed
@gardener-robot gardener-robot added the status/closed Issue is closed (either delivered or triaged) label Oct 28, 2024
acumino pushed a commit to acumino/machine-controller-manager that referenced this pull request Nov 25, 2024
* Reduce etcd traffic by using SharedInformer to list pods for drain logic

* Address review comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) reviewed/lgtm Has approval for merging size/s Size of pull request is small (see gardener-robot robot/bots/size.py) status/closed Issue is closed (either delivered or triaged)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reduce load on kube-apiserver / ETCD on pod eviction for termination machines
7 participants