Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Handle overlapping deployments gracefully#30730

Merged
k8s-github-robot merged 2 commits into
kubernetes:masterfrom
janetkuo:prevent-overlapping-deployment
Aug 26, 2016
Merged

Handle overlapping deployments gracefully#30730
k8s-github-robot merged 2 commits into
kubernetes:masterfrom
janetkuo:prevent-overlapping-deployment

Conversation

@janetkuo
Copy link
Copy Markdown
Member

@janetkuo janetkuo commented Aug 17, 2016

Fixes #30028

This change is Reviewable

@janetkuo janetkuo self-assigned this Aug 17, 2016
@k8s-github-robot k8s-github-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. release-note-label-needed labels Aug 17, 2016
@adohe-zz
Copy link
Copy Markdown

@janetkuo should we print the overlapping deployments names, thus user knows which deployment should be updated.

@janetkuo janetkuo force-pushed the prevent-overlapping-deployment branch from 4253e18 to 1ee1e95 Compare August 17, 2016 19:59
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 17, 2016
@janetkuo janetkuo force-pushed the prevent-overlapping-deployment branch from 1ee1e95 to 60f057d Compare August 17, 2016 20:43
@janetkuo janetkuo added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-label-needed labels Aug 17, 2016
@janetkuo janetkuo assigned pwittrock and unassigned janetkuo Aug 17, 2016
@pwittrock
Copy link
Copy Markdown
Member

@adohe want to review this with me?

@janetkuo
Copy link
Copy Markdown
Member Author

cc @kubernetes/deployment

@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 17, 2016
@adohe-zz
Copy link
Copy Markdown

adohe-zz commented Aug 17, 2016

@pwittrock I will review it today.

@pwittrock
Copy link
Copy Markdown
Member

Reviewed 1 of 4 files at r3.
Review status: 1 of 4 files reviewed at latest revision, 3 unresolved discussions.


pkg/controller/deployment/deployment_controller.go, line 434 [r3] (raw file):

  // overlaps, as well as all deployments that overlap this deployments, and sorting them.

  // Relist all deployment for overlaps, and avoid syncing the old overlapping ones

I thought we avoid syncing the new overlapping ones?


pkg/controller/deployment/util/deployment_util.go, line 62 [r3] (raw file):

  RollbackDone = "DeploymentRollback"
  // OverlapAnnotation marks deployments with overlapping selector with other deployments
  OverlapAnnotation = "deployment.kubernetes.io/overlap-with"

lets make this a little more in-your-face. Maybe deployment.kubernetes.io/error-overlapping-selectors or deployment.kubernetes.io/selector-overlap-error


test/e2e/deployment.go, line 1196 [r4] (raw file):

  d := newDeployment(deploymentName, replicas, podLabels, redisImageName, redisImage, extensions.RollingUpdateDeploymentStrategyType, nil)
  deploy, err := c.Extensions().Deployments(ns).Create(d)
  Expect(err).NotTo(HaveOccurred())

It is helpful to add a string here stating what you were trying to do when the error occurred.


Comments from Reviewable

@adohe-zz
Copy link
Copy Markdown

pkg/controller/deployment/deployment_controller.go, line 456 [r4] (raw file):

      }
  }
  if !overlapping {

Nice catch.


Comments from Reviewable

@adohe-zz
Copy link
Copy Markdown

pkg/controller/deployment/util/deployment_util.go, line 62 [r3] (raw file):

Previously, pwittrock (Phillip Wittrock) wrote…

lets make this a little more in-your-face. Maybe deployment.kubernetes.io/error-overlapping-selectors or deployment.kubernetes.io/selector-overlap-error

Earlier I noticed this issue #30822 , maybe we should think more about this annotation.

Comments from Reviewable

if len(deployments) > 1 {
sort.Sort(byCreationTimestamp(deployments))
glog.Errorf("user error! more than one deployment is selecting replica set %s/%s with labels: %#v, returning %s/%s", rs.Namespace, rs.Name, rs.Labels, deployments[0].Namespace, deployments[0].Name)
glog.V(4).Infof("More than one deployment is selecting replica set %s/%s: %#v", rs.Namespace, rs.Name, deployments)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any value to this log since you already log it above?

@janetkuo
Copy link
Copy Markdown
Member Author

Review status: 1 of 5 files reviewed at latest revision, 9 unresolved discussions.


pkg/controller/deployment/deployment_controller.go, line 435 [r4] (raw file):

Previously, deads2k (David Eads) wrote…

This is too expensive to happen on every enqueue. @deads2k got any ideas for fighting overlapping selectors here? How about indexing deployments with a StringSelectorIndex and skip enqueueing every time dc.dStore.ByIndex(StringSelectorIndex, deployment.Spec.Selector) returns deployments of the same namespace?

I agree that this is too expensive, but only finding ones with the same index doesn't do the same thing since you can overlap without being the same.

Limiting to deployments in the same namespace and doing the check when work is going to be performed (on dequeue so that duplicate enqueues don't pay the tax multiple times) is probably enough.

Done.

pkg/controller/deployment/deployment_controller.go, line 438 [r4] (raw file):

Previously, deads2k (David Eads) wrote…

utilruntime.HandleError

Done.

pkg/controller/deployment/deployment_controller.go, line 448 [r4] (raw file):

Previously, AdoHe (TonyAdo) wrote…

update selector should still be allowed. simply check creation timestamp is not enough to decide whether we can skip.

Done.

pkg/controller/deployment/deployment_controller.go, line 450 [r4] (raw file):

Previously, deads2k (David Eads) wrote…

People who can see the controller logs aren't likely to mess with user deployments and users who have messed up their selectors aren't likely to be able to see the controller logs. Seems like this should be either high verbosity or not at all.

Done.

pkg/controller/deployment/util/deployment_util.go, line 62 [r3] (raw file):

Previously, AdoHe (TonyAdo) wrote…

Earlier I noticed this issue #30822 , maybe we should think more about this annotation.

This annotation is an inexpensive way for users to see they messed up the deployment selector (they can't see controller logs) (we can consume this in `kubectl describe`). Do you think we should hold on adding this annotation until we have a convention?

test/e2e/deployment.go, line 1196 [r4] (raw file):

Previously, pwittrock (Phillip Wittrock) wrote…

It is helpful to add a string here stating what you were trying to do when the error occurred.

Is the above `By()`enough to see where the error's from?

Comments from Reviewable

@janetkuo
Copy link
Copy Markdown
Member Author

Thank you all for the comments; code updated, ptal @pwittrock @adohe @Kargakis @deads2k

@janetkuo janetkuo force-pushed the prevent-overlapping-deployment branch 2 times, most recently from cd9a928 to 1cf3412 Compare August 22, 2016 18:18
@k8s-bot
Copy link
Copy Markdown

k8s-bot commented Aug 22, 2016

GCE e2e build/test passed for commit cd9a9283c72e1ddc438769fdab250ae07190ebb6.

@k8s-bot
Copy link
Copy Markdown

k8s-bot commented Aug 22, 2016

GCE e2e build/test passed for commit 1cf3412.

@janetkuo
Copy link
Copy Markdown
Member Author

ptal

// RollbackDone is the done rollback event reason
RollbackDone = "DeploymentRollback"
// OverlapAnnotation marks deployments with overlapping selector with other deployments
// TODO: Delete this annotation when we gracefully handle overlapping selectors.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How are we going to do this? Is there any issue open?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

With controller reference and/or auto-generated selectors, see #2210

@0xmichalis
Copy link
Copy Markdown
Contributor

Two more questions, LGTM otherwise

@janetkuo janetkuo force-pushed the prevent-overlapping-deployment branch from 1cf3412 to 3e43414 Compare August 23, 2016 21:13
1. When overlapping deployments are discovered, annotate them
2. Expose those overlapping annotations as warnings in kubectl describe
3. Only respect the earliest updated one (skip syncing all other overlapping deployments)
4. Use indexer instead of store for deployment lister
@janetkuo janetkuo force-pushed the prevent-overlapping-deployment branch from 3e43414 to c5cef18 Compare August 23, 2016 21:33
@janetkuo janetkuo changed the title Print errors for overlapping deployments, and only respect the old one Handle overlapping deployments gracefully Aug 23, 2016
@pwittrock
Copy link
Copy Markdown
Member

+lgtm


Reviewed 1 of 7 files at r9, 4 of 5 files at r12, 1 of 3 files at r14, 4 of 4 files at r15.
Review status: all files reviewed at latest revision, 25 unresolved discussions.


pkg/client/cache/listers.go, line 305 [r14] (raw file):

Previously, janetkuo (Janet Kuo) wrote…

Sounds good

Good idea. If this isn't in validation already we should add it later.

Comments from Reviewable

@pwittrock pwittrock added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 23, 2016
@k8s-bot
Copy link
Copy Markdown

k8s-bot commented Aug 23, 2016

GCE e2e build/test passed for commit 3e4341456918e6effe0977ebb86f1afeacf3f214.

@k8s-bot
Copy link
Copy Markdown

k8s-bot commented Aug 23, 2016

GCE e2e build/test passed for commit c5cef18.

@adohe-zz
Copy link
Copy Markdown

:lgtm:


Comments from Reviewable

@adohe-zz
Copy link
Copy Markdown

Also please don't forget squash before merge.

@janetkuo
Copy link
Copy Markdown
Member Author

Yeah already squashed

@k8s-github-robot
Copy link
Copy Markdown

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link
Copy Markdown

k8s-bot commented Aug 25, 2016

GCE e2e build/test passed for commit c5cef18.

@janetkuo
Copy link
Copy Markdown
Member Author

@k8s-bot node e2e test this issue: #31201

@k8s-github-robot
Copy link
Copy Markdown

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link
Copy Markdown

k8s-bot commented Aug 26, 2016

GCE e2e build/test passed for commit c5cef18.

@k8s-github-robot
Copy link
Copy Markdown

Automatic merge from submit-queue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants