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

eviction doesn't work with cronjob pods if PodDisruptionBudget specifies percentage minAvailable/maxUnavailable #77383

Closed
rajusharma opened this issue May 3, 2019 · 24 comments
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling.

Comments

@rajusharma
Copy link

What happened:
PodDisruptionBudget is not working when CronJob and Deployment have same labels
Error:

kubectl get pdb
NAME                  MIN AVAILABLE   MAX UNAVAILABLE   ALLOWED DISRUPTIONS   AGE
{PDB name}   50%             N/A               0                     3m

kubectl describe pdb
Events:
  Type     Reason                           Age   From               Message
  ----     ------                           ----  ----               -------
  Warning  NoControllers                    16s   controllermanager  found no controllers for pod {CronJob pod name}
  Warning  CalculateExpectedPodCountFailed  16s   controllermanager  Failed to calculate the number of expected pods: found no controllers for pod {CronJob pod name}

What you expected to happen:
PDB should run

How to reproduce it (as minimally and precisely as possible):

  • Create CronJob and Deployment with same labels
  • Use those labels in PDB selector

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version):
kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.2", GitCommit:"cff46ab41ff0bb44d8584413b598ad8360ec1def", GitTreeState:"clean", BuildDate:"2019-01-13T23:15:13Z", GoVersion:"go1.11.4", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"11+", GitVersion:"v1.11.8-gke.6", GitCommit:"394ee507d00f15a63cef577a14026096c310698e", GitTreeState:"clean", BuildDate:"2019-03-30T19:31:43Z", GoVersion:"go1.10.8b4", Compiler:"gc", Platform:"linux/amd64"}
  • Cloud provider or hardware configuration:
    GKE
  • OS (e.g: cat /etc/os-release):
  • Kernel (e.g. uname -a):
  • Install tools:
  • Network plugin and version (if this is a network-related bug):
  • Others:
@rajusharma rajusharma added the kind/bug Categorizes issue or PR as related to a bug. label May 3, 2019
@k8s-ci-robot k8s-ci-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label May 3, 2019
@rajusharma
Copy link
Author

@kubernetes/sig-scheduling-bugs

@k8s-ci-robot k8s-ci-robot added sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels May 3, 2019
@k8s-ci-robot
Copy link
Contributor

@rajusharma: Reiterating the mentions to trigger a notification:
@kubernetes/sig-scheduling-bugs

In response to this:

@kubernetes/sig-scheduling-bugs

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tedyu
Copy link
Contributor

tedyu commented May 4, 2019

From DisruptionController#getExpectedScale:

		for _, finder := range dc.finders() {
			var controllerNScale *controllerAndScale
			controllerNScale, err = finder(pod)

Looks like all the finders returned nil, nil

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 4, 2019
@rajusharma
Copy link
Author

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 5, 2019
@mortent
Copy link
Member

mortent commented Oct 14, 2019

/assign

@mortent
Copy link
Member

mortent commented Oct 14, 2019

So the issue here is that the PDB use minAvailable: 50% and also matches pods that belong to a controller that doesn't have a concept of scale. Removing the deployment from the example will result in the same error.

When a PDB specifies either maxUnavailable or minAvailable in percent, the disruption controller needs to look up the "expected" number of pods:

if pdb.Spec.MaxUnavailable != nil {
expectedCount, err = dc.getExpectedScale(pdb, pods)
if err != nil {
return
}
var maxUnavailable int
maxUnavailable, err = intstr.GetValueFromIntOrPercent(pdb.Spec.MaxUnavailable, int(expectedCount), true)
if err != nil {
return
}
desiredHealthy = expectedCount - int32(maxUnavailable)
if desiredHealthy < 0 {
desiredHealthy = 0
}
} else if pdb.Spec.MinAvailable != nil {
if pdb.Spec.MinAvailable.Type == intstr.Int {
desiredHealthy = pdb.Spec.MinAvailable.IntVal
expectedCount = int32(len(pods))
} else if pdb.Spec.MinAvailable.Type == intstr.String {
expectedCount, err = dc.getExpectedScale(pdb, pods)
if err != nil {
return
}
var minAvailable int
minAvailable, err = intstr.GetValueFromIntOrPercent(pdb.Spec.MinAvailable, int(expectedCount), true)
if err != nil {
return
}
desiredHealthy = int32(minAvailable)
}
}
return

This is not possible with cronjob, only with replicationcontrollers, deployments, replicasets, statefulsets and custom resources that implement the scale subresource.

If you want to set a PDB on a cronjob, it needs to use minAvailable with the actual number and not a percentage.

@rajusharma
Copy link
Author

If you want to set a PDB on a cronjob, it needs to use minAvailable with the actual number and not a percentage.

We don't want to set PDB on cronjobs. The issue is, we have some deployments and cronjobs with same labels and PDB doesn't work for those deployments which have same label as cronjobs.

@mortent
Copy link
Member

mortent commented Oct 15, 2019

Ah, I see. I think your best option here is to make sure the pods created by the deployments have a label set that makes it possible to target them in the PDB without also capturing the pods from the cronjobs.

@rajusharma
Copy link
Author

Yeah we are doing that now by setting different labels for deployment pods and job pods.
Do you think this will remain same or considering it as bug it will be fixed in near future?

@mortent
Copy link
Member

mortent commented Oct 16, 2019

I think this is working as intended. Using different labels is the right way to handle this.

@rajusharma
Copy link
Author

That means if by accident any cronjob have same labels like deployment, then PodDisruptionBudget for that deployment will not run. Even though there was no change on deployment side, cronjob can break the PDB of deployment. Is this intended 🤔

@mortent
Copy link
Member

mortent commented Oct 22, 2019

I don't think we want to prevent PDBs from working with pods with different controllers or prevent PDBs from working with CronJobs. But I agree that it could be useful to provide better feedback if the disruption controller for some reason (this issue highlights one way it can fail) are unable to reconcile a PDB resource.

@liggitt liggitt added this to Triage in PodDisruptionBudget Nov 13, 2019
@liggitt liggitt changed the title PodDisruptionBudget doesn't work if CronJob and Deployment have same labels eviction doesn't work with cronjob pods if PodDisruptionBudget specifies percentage minAvailable/maxUnavailable Nov 14, 2019
@liggitt liggitt moved this from Triage to GA blocking issues in PodDisruptionBudget Nov 14, 2019
@liggitt
Copy link
Member

liggitt commented Nov 14, 2019

what is the benefit to PDBs allowing a controller object they don't understand (and which doesn't support a generic scale subresource) to block eviction?

@mortent
Copy link
Member

mortent commented Nov 14, 2019

I can't think of many good reasons why someone would want to set PDBs on cronjob (or any other resource that doesn't support scale). Maybe there are some use cases around batch workloads? Are you suggesting we could remove support for PDBs on pods that doesn't have a known controller or the scale subresource?
For the particular situation in this issue this would mean that we could ignore the pods created by cronjob/job and the PDB will work as expected. The more general problem of PDBs capturing pods belonging to multiple controllers could still be an issue since it might lead to unexpected results.

@mortent
Copy link
Member

mortent commented Nov 22, 2019

After looking at the disruption controller in more detail, I think we can handle this better. In the situation described in this issue the controller can ignore the pods from the CronJob when computing the allowed disruptions, but create an event to notify the user that something isn't quite right. I think events are better than conditions for reporting this kind of issues to the user. I have created #85553 for this. More eyes on this would be great to make sure there aren't any scenarios I haven't considered.

The disruption controller also has a failsafe functionality where the allowedDisruptions are set to 0 if the controller encounters any issues. I think we can use conditions to make it clearer to users that this happened. Currently, there isn't any good way to see from the resource itself that allowedDisruptions are 0 because of this. I will try to address this in a separate PR.

bavarianbidi added a commit to bavarianbidi/charts that referenced this issue Dec 2, 2019
* add configurable PDB for minio
* change label for post-install-create-bucket-job because
  until kubernetes/kubernetes#85553 is merged,
  PDB will also detect the minio-create-bucket-job and
  PDB won't work correctly (kubernetes/kubernetes#77383)

Signed-off-by: Mario Constanti <github@constanti.de>
bavarianbidi added a commit to bavarianbidi/charts that referenced this issue Dec 3, 2019
* add configurable PDB for minio
* change label for post-install-create-bucket-job because
  until kubernetes/kubernetes#85553 is merged,
  PDB will also detect the minio-create-bucket-job and
  PDB won't work correctly (kubernetes/kubernetes#77383)

Signed-off-by: Mario Constanti <github@constanti.de>
bavarianbidi added a commit to bavarianbidi/charts that referenced this issue Dec 9, 2019
* add configurable PDB for minio
* change label for post-install-create-bucket-job because
  until kubernetes/kubernetes#85553 is merged,
  PDB will also detect the minio-create-bucket-job and
  PDB won't work correctly (kubernetes/kubernetes#77383)

Signed-off-by: Mario Constanti <github@constanti.de>
bavarianbidi added a commit to bavarianbidi/charts that referenced this issue Dec 9, 2019
* add configurable PDB for minio
* change label for post-install-create-bucket-job because
  until kubernetes/kubernetes#85553 is merged,
  PDB will also detect the minio-create-bucket-job and
  PDB won't work correctly (kubernetes/kubernetes#77383)

Signed-off-by: Mario Constanti <github@constanti.de>
bavarianbidi added a commit to bavarianbidi/charts that referenced this issue Dec 9, 2019
* add configurable PDB for minio
* change label for post-install-create-bucket-job because
  until kubernetes/kubernetes#85553 is merged,
  PDB will also detect the minio-create-bucket-job and
  PDB won't work correctly (kubernetes/kubernetes#77383)

Signed-off-by: Mario Constanti <github@constanti.de>
k8s-ci-robot pushed a commit to helm/charts that referenced this issue Dec 10, 2019
* add configurable PDB for minio
* change label for post-install-create-bucket-job because
  until kubernetes/kubernetes#85553 is merged,
  PDB will also detect the minio-create-bucket-job and
  PDB won't work correctly (kubernetes/kubernetes#77383)

Signed-off-by: Mario Constanti <github@constanti.de>
dargolith pushed a commit to dargolith/charts that referenced this issue Jan 10, 2020
* add configurable PDB for minio
* change label for post-install-create-bucket-job because
  until kubernetes/kubernetes#85553 is merged,
  PDB will also detect the minio-create-bucket-job and
  PDB won't work correctly (kubernetes/kubernetes#77383)

Signed-off-by: Mario Constanti <github@constanti.de>
@digitalronin
Copy link

digitalronin commented Jan 22, 2020

I can't think of many good reasons why someone would want to set PDBs on cronjob

How about setting a PDB on a cronjob to ensure that the job runs to completion in the event that another process tries to drain the node on which it's running, before it's finished?

arturrez pushed a commit to arturrez/stable-charts that referenced this issue Jan 28, 2020
* add configurable PDB for minio
* change label for post-install-create-bucket-job because
  until kubernetes/kubernetes#85553 is merged,
  PDB will also detect the minio-create-bucket-job and
  PDB won't work correctly (kubernetes/kubernetes#77383)

Signed-off-by: Mario Constanti <github@constanti.de>
Signed-off-by: Artur <artur@upbound.io>
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 21, 2020
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 21, 2020
@michaelgugino
Copy link
Contributor

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label May 28, 2020
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 26, 2020
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Sep 25, 2020
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling.
Projects
Development

No branches or pull requests

8 participants