Skip to content

Bug 1765756: UPSTREAM: 80004: Prefer to delete doubled-up pods of a ReplicaSet#24057

Merged
openshift-merge-robot merged 3 commits intoopenshift:masterfrom
Miciah:UPSTREAM-80004-prefer-to-delete-doubled-up-pods-of-a-replicaset-2
Nov 7, 2019
Merged

Bug 1765756: UPSTREAM: 80004: Prefer to delete doubled-up pods of a ReplicaSet#24057
openshift-merge-robot merged 3 commits intoopenshift:masterfrom
Miciah:UPSTREAM-80004-prefer-to-delete-doubled-up-pods-of-a-replicaset-2

Conversation

@Miciah
Copy link
Contributor

@Miciah Miciah commented Oct 30, 2019

This commit brings back #23806, which was dropped during a rebase scuffle (see #24014 (comment)), and adds a fix for BZ#1765756.


UPSTREAM: 80004: Prefer to delete doubled-up pods of a ReplicaSet

When scaling down a ReplicaSet, delete doubled up replicas first, where a "doubled up replica" is defined as one that is on the same node as an active replica belonging to a related ReplicaSet. ReplicaSets are considered "related" if they have a common controller (typically a Deployment).

The intention of this change is to make a rolling update of a Deployment scale down the old ReplicaSet as it scales up the new ReplicaSet by deleting pods from the old ReplicaSet that are colocated with ready pods of the new ReplicaSet. This change in the behavior of rolling updates can be combined with pod affinity rules to preserve the locality of a Deployment's pods over rollout.

A specific scenario that benefits from this change is when a Deployment's pods are exposed by a Service that has type "LoadBalancer" and external traffic policy "Local". In this scenario, the load balancer uses health checks to determine whether it should forward traffic for the Service to a particular node. If the node has no local endpoints for the Service, the health check will fail for that node. Eventually, the load balancer will stop forwarding traffic to that node. In the meantime, the service proxy drops traffic for that Service. Thus, in order to reduce risk of dropping traffic during a rolling update, it is desirable preserve node locality of endpoints.

  • vendor/k8s.io/kubernetes/pkg/controller/controller_utils.go (ActivePodsWithRanks): New type to sort pods using a given ranking.
  • vendor/k8s.io/kubernetes/pkg/controller/controller_utils_test.go (TestSortingActivePodsWithRanks): New test for ActivePodsWithRanks.
  • vendor/k8s.io/kubernetes/pkg/controller/replicaset/replica_set.go
    (getReplicaSetsWithSameController): New method. Given a ReplicaSet, return all ReplicaSets that have the same owner.
    (manageReplicas): Call getIndirectlyRelatedPods, and pass its result to getPodsToDelete.
    (getIndirectlyRelatedPods): New method. Given a ReplicaSet, return all pods that are owned by any ReplicaSet with the same owner.
    (getPodsToDelete): Add an argument for related pods. Use related pods and the new getPodsRankedByRelatedPodsOnSameNode function to take into account whether the pod is doubled up when sorting pods for deletion.
    (getPodsRankedByRelatedPodsOnSameNode): New function. Return an ActivePodsWithRanks value that wraps the given slice of pods and computes ranks where each pod's rank is equal to the number of active related pods that are colocated on the same node.
  • vendor/k8s.io/kubernetes/pkg/controller/replicaset/replica_set_test.go (newReplicaSet): Set OwnerReferences on the ReplicaSet.
    (newPod): Set a unique UID on the pod.
    (byName): New type to sort pods by name.
    (TestRelatedPodsLookup): New test for getIndirectlyRelatedPods.
    (TestGetPodsToDelete): Augment the "various pod phases and conditions, diff = len(pods)" test case to ensure that scale-down still selects doubled-up pods if there are not enough other pods to scale down. Add a "various pod phases and conditions, diff = len(pods), relatedPods empty" test case to verify that getPodsToDelete works even if related pods could not be determined. Add a "ready and colocated with another ready pod vs not colocated, diff < len(pods)" test case to verify that a doubled-up pod gets preferred for deletion. Augment the "various pod phases and conditions, diff < len(pods)" test case to ensure that not-ready pods are preferred over ready but doubled-up pods.
  • vendor/k8s.io/kubernetes/pkg/controller/replicaset/BUILD: Regenerate.
  • vendor/k8s.io/kubernetes/test/e2e/apps/deployment.go (testRollingUpdateDeploymentWithLocalTrafficLoadBalancer): New end-to-end test. Create a deployment with a rolling update strategy and affinity rules and a load balancer with "Local" external traffic policy, and verify that set of nodes with local endponts for the service remains unchanged during rollouts.
    (setAffinity): New helper, used by testRollingUpdateDeploymentWithLocalTrafficLoadBalancer.
  • vendor/k8s.io/kubernetes/test/e2e/apps/types.go (AgnhostImageName, AgnhostImage): New constants for the agnhost image.
  • vendor/k8s.io/kubernetes/test/e2e/framework/service/jig.go (GetEndpointNodes): Factor building the set of node names out...
    (GetEndpointNodeNames): ...into this new method.

UPSTREAM: 84339: Fix deployment e2e test at scale

UPSTREAM: 84568: test/e2e/apps: Skip or scale LB test per node count

Skip the "Deployment should not disrupt a cloud load-balancer's connectivity during rollout" test if the number of nodes is less than 2; otherwise, set the deployment's replicas equal to the lesser of 5 and the number of nodes.

The test would fail if there were fewer nodes than replicas, but the test needs at least 2 nodes, and the likelihood of failure absent the feature under test increases with the number of replicas, so it is desirable to set replicas to a higher value, within reason.

  • vendor/k8s.io/kubernetes/test/e2e/apps/deployment.go: Skip the load-balancer connectivity test unless there are at least 2 nodes.
    (testRollingUpdateDeploymentWithLocalTrafficLoadBalancer): Set replicas to the min of 5 and the number of nodes.

This PR supersedes #24047.

Miciah and others added 3 commits October 30, 2019 12:28
When scaling down a ReplicaSet, delete doubled up replicas first, where a
"doubled up replica" is defined as one that is on the same node as an
active replica belonging to a related ReplicaSet.  ReplicaSets are
considered "related" if they have a common controller (typically a
Deployment).

The intention of this change is to make a rolling update of a Deployment
scale down the old ReplicaSet as it scales up the new ReplicaSet by
deleting pods from the old ReplicaSet that are colocated with ready pods of
the new ReplicaSet.  This change in the behavior of rolling updates can be
combined with pod affinity rules to preserve the locality of a Deployment's
pods over rollout.

A specific scenario that benefits from this change is when a Deployment's
pods are exposed by a Service that has type "LoadBalancer" and external
traffic policy "Local".  In this scenario, the load balancer uses health
checks to determine whether it should forward traffic for the Service to a
particular node.  If the node has no local endpoints for the Service, the
health check will fail for that node.  Eventually, the load balancer will
stop forwarding traffic to that node.  In the meantime, the service proxy
drops traffic for that Service.  Thus, in order to reduce risk of dropping
traffic during a rolling update, it is desirable preserve node locality of
endpoints.

* vendor/k8s.io/kubernetes/pkg/controller/controller_utils.go
(ActivePodsWithRanks): New type to sort pods using a given ranking.
* vendor/k8s.io/kubernetes/pkg/controller/controller_utils_test.go
(TestSortingActivePodsWithRanks): New test for ActivePodsWithRanks.
* vendor/k8s.io/kubernetes/pkg/controller/replicaset/replica_set.go
(getReplicaSetsWithSameController): New method.  Given a ReplicaSet, return
all ReplicaSets that have the same owner.
(manageReplicas): Call getIndirectlyRelatedPods, and pass its result to
getPodsToDelete.
(getIndirectlyRelatedPods): New method.  Given a ReplicaSet, return all
pods that are owned by any ReplicaSet with the same owner.
(getPodsToDelete): Add an argument for related pods.  Use related pods and
the new getPodsRankedByRelatedPodsOnSameNode function to take into account
whether the pod is doubled up when sorting pods for deletion.
(getPodsRankedByRelatedPodsOnSameNode): New function.  Return an
ActivePodsWithRanks value that wraps the given slice of pods and computes
ranks where each pod's rank is equal to the number of active related pods
that are colocated on the same node.
* vendor/k8s.io/kubernetes/pkg/controller/replicaset/replica_set_test.go
(newReplicaSet): Set OwnerReferences on the ReplicaSet.
(newPod): Set a unique UID on the pod.
(byName): New type to sort pods by name.
(TestRelatedPodsLookup): New test for getIndirectlyRelatedPods.
(TestGetPodsToDelete): Augment the "various pod phases and conditions, diff
= len(pods)" test case to ensure that scale-down still selects doubled-up
pods if there are not enough other pods to scale down.  Add a "various pod
phases and conditions, diff = len(pods), relatedPods empty" test case to
verify that getPodsToDelete works even if related pods could not be
determined.  Add a "ready and colocated with another ready pod vs not
colocated, diff < len(pods)" test case to verify that a doubled-up pod gets
preferred for deletion.  Augment the "various pod phases and conditions,
diff < len(pods)" test case to ensure that not-ready pods are preferred
over ready but doubled-up pods.
* vendor/k8s.io/kubernetes/pkg/controller/replicaset/BUILD: Regenerate.
* vendor/k8s.io/kubernetes/test/e2e/apps/deployment.go
(testRollingUpdateDeploymentWithLocalTrafficLoadBalancer): New end-to-end
test.  Create a deployment with a rolling update strategy and affinity
rules and a load balancer with "Local" external traffic policy, and verify
that set of nodes with local endponts for the service remains unchanged
during rollouts.
(setAffinity): New helper, used by
testRollingUpdateDeploymentWithLocalTrafficLoadBalancer.
* vendor/k8s.io/kubernetes/test/e2e/apps/types.go (AgnhostImageName)
(AgnhostImage): New constants for the agnhost image.
*
vendor/k8s.io/kubernetes/test/e2e/framework/service/jig.go
(GetEndpointNodes): Factor building the set of node names out...
(GetEndpointNodeNames): ...into this new method.
Skip the "Deployment should not disrupt a cloud load-balancer's
connectivity during rollout" test if the number of nodes is less than 2;
otherwise, set the deployment's replicas equal to the lesser of 5 and the
number of nodes.

The test would fail if there were fewer nodes than replicas, but the test
needs at least 2 nodes, and the likelihood of failure absent the feature
under test increases with the number of replicas, so it is desirable to set
replicas to a higher value, within reason.

Follow-up to commit 980b640.

* vendor/k8s.io/kubernetes/test/e2e/apps/deployment.go: Skip the
load-balancer connectivity test unless there are at least 2 nodes.
(testRollingUpdateDeploymentWithLocalTrafficLoadBalancer): Set replicas to
the min of 5 and the number of nodes.
@openshift-ci-robot openshift-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 30, 2019
@Miciah Miciah changed the title UPSTREAM: 80004: Prefer to delete doubled-up pods of a ReplicaSet 80004 prefer to delete doubled up pods of a replicaset 2 UPSTREAM: 80004: Prefer to delete doubled-up pods of a ReplicaSet Oct 30, 2019
@knobunc
Copy link
Contributor

knobunc commented Nov 1, 2019

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 1, 2019
@Miciah Miciah changed the title UPSTREAM: 80004: Prefer to delete doubled-up pods of a ReplicaSet Bug 1765756: UPSTREAM: 80004: Prefer to delete doubled-up pods of a ReplicaSet Nov 1, 2019
@openshift-ci-robot
Copy link

@Miciah: This pull request references Bugzilla bug 1765756, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Bug 1765756: UPSTREAM: 80004: Prefer to delete doubled-up pods of a ReplicaSet

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.

@openshift-ci-robot openshift-ci-robot added the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Nov 1, 2019
@openshift-ci-robot
Copy link

@Miciah: This pull request references Bugzilla bug 1765756, which is valid.

Details

In response to this:

Bug 1765756: UPSTREAM: 80004: Prefer to delete doubled-up pods of a ReplicaSet

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.

@Miciah
Copy link
Contributor Author

Miciah commented Nov 1, 2019

I wonder whether I can do this:
/test e2e-aws-scaleup-rhel7-4.3

@Miciah
Copy link
Contributor Author

Miciah commented Nov 1, 2019

/test e2e-aws-scaleup-rhel7

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: knobunc, Miciah, soltysh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 5, 2019
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 193c7d7 into openshift:master Nov 7, 2019
@openshift-ci-robot
Copy link

@Miciah: All pull requests linked via external trackers have merged. Bugzilla bug 1765756 has been moved to the MODIFIED state.

Details

In response to this:

Bug 1765756: UPSTREAM: 80004: Prefer to delete doubled-up pods of a ReplicaSet

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

approved Indicates a PR has been approved by an approver from all required OWNERS files. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants