mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Clear shutdown in deployment integration test
This commit is contained in:
parent
ca68691feb
commit
1fcc5d9eae
@ -54,11 +54,8 @@ func TestNewDeployment(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start informer and controllers
|
// Start informer and controllers
|
||||||
stopCh := make(chan struct{})
|
stopControllers := runControllersAndInformers(t, rm, dc, informers)
|
||||||
defer close(stopCh)
|
defer stopControllers()
|
||||||
informers.Start(stopCh)
|
|
||||||
go rm.Run(context.TODO(), 5)
|
|
||||||
go dc.Run(context.TODO(), 5)
|
|
||||||
|
|
||||||
// Wait for the Deployment to be updated to revision 1
|
// Wait for the Deployment to be updated to revision 1
|
||||||
if err := tester.waitForDeploymentRevisionAndImage("1", fakeImage); err != nil {
|
if err := tester.waitForDeploymentRevisionAndImage("1", fakeImage); err != nil {
|
||||||
@ -121,11 +118,8 @@ func TestDeploymentRollingUpdate(t *testing.T) {
|
|||||||
defer framework.DeleteTestingNamespace(ns, s, t)
|
defer framework.DeleteTestingNamespace(ns, s, t)
|
||||||
|
|
||||||
// Start informer and controllers
|
// Start informer and controllers
|
||||||
stopCh := make(chan struct{})
|
stopControllers := runControllersAndInformers(t, rm, dc, informers)
|
||||||
defer close(stopCh)
|
defer stopControllers()
|
||||||
informers.Start(stopCh)
|
|
||||||
go rm.Run(context.TODO(), 5)
|
|
||||||
go dc.Run(context.TODO(), 5)
|
|
||||||
|
|
||||||
replicas := int32(20)
|
replicas := int32(20)
|
||||||
tester := &deploymentTester{t: t, c: c, deployment: newDeployment(name, ns.Name, replicas)}
|
tester := &deploymentTester{t: t, c: c, deployment: newDeployment(name, ns.Name, replicas)}
|
||||||
@ -264,11 +258,8 @@ func TestPausedDeployment(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start informer and controllers
|
// Start informer and controllers
|
||||||
stopCh := make(chan struct{})
|
stopControllers := runControllersAndInformers(t, rm, dc, informers)
|
||||||
defer close(stopCh)
|
defer stopControllers()
|
||||||
informers.Start(stopCh)
|
|
||||||
go rm.Run(context.TODO(), 5)
|
|
||||||
go dc.Run(context.TODO(), 5)
|
|
||||||
|
|
||||||
// Verify that the paused deployment won't create new replica set.
|
// Verify that the paused deployment won't create new replica set.
|
||||||
if err := tester.expectNoNewReplicaSet(); err != nil {
|
if err := tester.expectNoNewReplicaSet(); err != nil {
|
||||||
@ -365,11 +356,8 @@ func TestScalePausedDeployment(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start informer and controllers
|
// Start informer and controllers
|
||||||
stopCh := make(chan struct{})
|
stopControllers := runControllersAndInformers(t, rm, dc, informers)
|
||||||
defer close(stopCh)
|
defer stopControllers()
|
||||||
informers.Start(stopCh)
|
|
||||||
go rm.Run(context.TODO(), 5)
|
|
||||||
go dc.Run(context.TODO(), 5)
|
|
||||||
|
|
||||||
// Wait for the Deployment to be updated to revision 1
|
// Wait for the Deployment to be updated to revision 1
|
||||||
if err := tester.waitForDeploymentRevisionAndImage("1", fakeImage); err != nil {
|
if err := tester.waitForDeploymentRevisionAndImage("1", fakeImage); err != nil {
|
||||||
@ -446,11 +434,8 @@ func TestDeploymentHashCollision(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start informer and controllers
|
// Start informer and controllers
|
||||||
stopCh := make(chan struct{})
|
stopControllers := runControllersAndInformers(t, rm, dc, informers)
|
||||||
defer close(stopCh)
|
defer stopControllers()
|
||||||
informers.Start(stopCh)
|
|
||||||
go rm.Run(context.TODO(), 5)
|
|
||||||
go dc.Run(context.TODO(), 5)
|
|
||||||
|
|
||||||
// Wait for the Deployment to be updated to revision 1
|
// Wait for the Deployment to be updated to revision 1
|
||||||
if err := tester.waitForDeploymentRevisionAndImage("1", fakeImage); err != nil {
|
if err := tester.waitForDeploymentRevisionAndImage("1", fakeImage); err != nil {
|
||||||
@ -549,11 +534,8 @@ func TestFailedDeployment(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start informer and controllers
|
// Start informer and controllers
|
||||||
stopCh := make(chan struct{})
|
stopControllers := runControllersAndInformers(t, rm, dc, informers)
|
||||||
defer close(stopCh)
|
defer stopControllers()
|
||||||
informers.Start(stopCh)
|
|
||||||
go rm.Run(context.TODO(), 5)
|
|
||||||
go dc.Run(context.TODO(), 5)
|
|
||||||
|
|
||||||
if err = tester.waitForDeploymentUpdatedReplicasGTE(replicas); err != nil {
|
if err = tester.waitForDeploymentUpdatedReplicasGTE(replicas); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -590,12 +572,10 @@ func TestOverlappingDeployments(t *testing.T) {
|
|||||||
{t: t, c: c, deployment: newDeployment(firstDeploymentName, ns.Name, replicas)},
|
{t: t, c: c, deployment: newDeployment(firstDeploymentName, ns.Name, replicas)},
|
||||||
{t: t, c: c, deployment: newDeployment(secondDeploymentName, ns.Name, replicas)},
|
{t: t, c: c, deployment: newDeployment(secondDeploymentName, ns.Name, replicas)},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start informer and controllers
|
// Start informer and controllers
|
||||||
stopCh := make(chan struct{})
|
stopControllers := runControllersAndInformers(t, rm, dc, informers)
|
||||||
defer close(stopCh)
|
defer stopControllers()
|
||||||
informers.Start(stopCh)
|
|
||||||
go rm.Run(context.TODO(), 5)
|
|
||||||
go dc.Run(context.TODO(), 5)
|
|
||||||
|
|
||||||
// Create 2 deployments with overlapping selectors
|
// Create 2 deployments with overlapping selectors
|
||||||
var err error
|
var err error
|
||||||
@ -665,11 +645,9 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
|||||||
ns := framework.CreateTestingNamespace(name, s, t)
|
ns := framework.CreateTestingNamespace(name, s, t)
|
||||||
defer framework.DeleteTestingNamespace(ns, s, t)
|
defer framework.DeleteTestingNamespace(ns, s, t)
|
||||||
|
|
||||||
stopCh := make(chan struct{})
|
// Start informer and controllers
|
||||||
defer close(stopCh)
|
stopControllers := runControllersAndInformers(t, rm, dc, informers)
|
||||||
informers.Start(stopCh)
|
defer stopControllers()
|
||||||
go rm.Run(context.TODO(), 5)
|
|
||||||
go dc.Run(context.TODO(), 5)
|
|
||||||
|
|
||||||
// Create a deployment with rolling update strategy, max surge = 3, and max unavailable = 2
|
// Create a deployment with rolling update strategy, max surge = 3, and max unavailable = 2
|
||||||
var err error
|
var err error
|
||||||
@ -868,11 +846,8 @@ func TestSpecReplicasChange(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start informer and controllers
|
// Start informer and controllers
|
||||||
stopCh := make(chan struct{})
|
stopControllers := runControllersAndInformers(t, rm, dc, informers)
|
||||||
defer close(stopCh)
|
defer stopControllers()
|
||||||
informers.Start(stopCh)
|
|
||||||
go rm.Run(context.TODO(), 5)
|
|
||||||
go dc.Run(context.TODO(), 5)
|
|
||||||
|
|
||||||
// Scale up/down deployment and verify its replicaset has matching .spec.replicas
|
// Scale up/down deployment and verify its replicaset has matching .spec.replicas
|
||||||
if err = tester.scaleDeployment(2); err != nil {
|
if err = tester.scaleDeployment(2); err != nil {
|
||||||
@ -926,11 +901,8 @@ func TestDeploymentAvailableCondition(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start informer and controllers
|
// Start informer and controllers
|
||||||
stopCh := make(chan struct{})
|
stopControllers := runControllersAndInformers(t, rm, dc, informers)
|
||||||
defer close(stopCh)
|
defer stopControllers()
|
||||||
informers.Start(stopCh)
|
|
||||||
go rm.Run(context.TODO(), 5)
|
|
||||||
go dc.Run(context.TODO(), 5)
|
|
||||||
|
|
||||||
// Wait for the deployment to be observed by the controller and has at least specified number of updated replicas
|
// Wait for the deployment to be observed by the controller and has at least specified number of updated replicas
|
||||||
if err = tester.waitForDeploymentUpdatedReplicasGTE(replicas); err != nil {
|
if err = tester.waitForDeploymentUpdatedReplicasGTE(replicas); err != nil {
|
||||||
@ -1043,11 +1015,8 @@ func TestGeneralReplicaSetAdoption(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start informer and controllers
|
// Start informer and controllers
|
||||||
stopCh := make(chan struct{})
|
stopControllers := runControllersAndInformers(t, rm, dc, informers)
|
||||||
defer close(stopCh)
|
defer stopControllers()
|
||||||
informers.Start(stopCh)
|
|
||||||
go rm.Run(context.TODO(), 5)
|
|
||||||
go dc.Run(context.TODO(), 5)
|
|
||||||
|
|
||||||
// Wait for the Deployment to be updated to revision 1
|
// Wait for the Deployment to be updated to revision 1
|
||||||
if err := tester.waitForDeploymentRevisionAndImage("1", fakeImage); err != nil {
|
if err := tester.waitForDeploymentRevisionAndImage("1", fakeImage); err != nil {
|
||||||
@ -1135,11 +1104,8 @@ func TestDeploymentScaleSubresource(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start informer and controllers
|
// Start informer and controllers
|
||||||
stopCh := make(chan struct{})
|
stopControllers := runControllersAndInformers(t, rm, dc, informers)
|
||||||
defer close(stopCh)
|
defer stopControllers()
|
||||||
informers.Start(stopCh)
|
|
||||||
go rm.Run(context.TODO(), 5)
|
|
||||||
go dc.Run(context.TODO(), 5)
|
|
||||||
|
|
||||||
// Wait for the Deployment to be updated to revision 1
|
// Wait for the Deployment to be updated to revision 1
|
||||||
if err := tester.waitForDeploymentRevisionAndImage("1", fakeImage); err != nil {
|
if err := tester.waitForDeploymentRevisionAndImage("1", fakeImage); err != nil {
|
||||||
@ -1179,11 +1145,8 @@ func TestReplicaSetOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start informer and controllers
|
// Start informer and controllers
|
||||||
stopCh := make(chan struct{})
|
stopControllers := runControllersAndInformers(t, rm, dc, informers)
|
||||||
defer close(stopCh)
|
defer stopControllers()
|
||||||
informers.Start(stopCh)
|
|
||||||
go rm.Run(context.TODO(), 5)
|
|
||||||
go dc.Run(context.TODO(), 5)
|
|
||||||
|
|
||||||
// Wait for the Deployment to be updated to revision 1
|
// Wait for the Deployment to be updated to revision 1
|
||||||
if err := tester.waitForDeploymentRevisionAndImage("1", fakeImage); err != nil {
|
if err := tester.waitForDeploymentRevisionAndImage("1", fakeImage); err != nil {
|
||||||
|
@ -146,6 +146,15 @@ func dcSimpleSetup(t *testing.T) (*httptest.Server, framework.CloseFunc, clients
|
|||||||
return s, closeFn, clientSet
|
return s, closeFn, clientSet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// runControllersAndInformers runs RS and deployment controllers and informers
|
||||||
|
func runControllersAndInformers(t *testing.T, rm *replicaset.ReplicaSetController, dc *deployment.DeploymentController, informers informers.SharedInformerFactory) func() {
|
||||||
|
ctx, cancelFn := context.WithCancel(context.Background())
|
||||||
|
informers.Start(ctx.Done())
|
||||||
|
go rm.Run(ctx, 5)
|
||||||
|
go dc.Run(ctx, 5)
|
||||||
|
return cancelFn
|
||||||
|
}
|
||||||
|
|
||||||
// addPodConditionReady sets given pod status to ready at given time
|
// addPodConditionReady sets given pod status to ready at given time
|
||||||
func addPodConditionReady(pod *v1.Pod, time metav1.Time) {
|
func addPodConditionReady(pod *v1.Pod, time metav1.Time) {
|
||||||
pod.Status = v1.PodStatus{
|
pod.Status = v1.PodStatus{
|
||||||
|
Loading…
Reference in New Issue
Block a user