mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-09 05:01:46 +00:00
deployment controller: use contextual logging
This commit is contained in:
@@ -23,12 +23,13 @@ import (
|
||||
"testing"
|
||||
|
||||
apps "k8s.io/api/apps/v1"
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/client-go/util/retry"
|
||||
"k8s.io/klog/v2/ktesting"
|
||||
deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
|
||||
"k8s.io/kubernetes/test/integration/framework"
|
||||
testutil "k8s.io/kubernetes/test/utils"
|
||||
@@ -36,7 +37,11 @@ import (
|
||||
)
|
||||
|
||||
func TestNewDeployment(t *testing.T) {
|
||||
closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
closeFn, rm, dc, informers, c := dcSetup(ctx, t)
|
||||
defer closeFn()
|
||||
name := "test-new-deployment"
|
||||
|
||||
@@ -112,7 +117,11 @@ func TestNewDeployment(t *testing.T) {
|
||||
// TODO: drop the rollback portions of this test when extensions/v1beta1 is no longer served
|
||||
// and rollback endpoint is no longer supported.
|
||||
func TestDeploymentRollingUpdate(t *testing.T) {
|
||||
closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
closeFn, rm, dc, informers, c := dcSetup(ctx, t)
|
||||
defer closeFn()
|
||||
|
||||
name := "test-rolling-update-deployment"
|
||||
@@ -242,7 +251,11 @@ func TestDeploymentSelectorImmutability(t *testing.T) {
|
||||
|
||||
// Paused deployment should not start new rollout
|
||||
func TestPausedDeployment(t *testing.T) {
|
||||
closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
closeFn, rm, dc, informers, c := dcSetup(ctx, t)
|
||||
defer closeFn()
|
||||
|
||||
name := "test-paused-deployment"
|
||||
@@ -342,7 +355,11 @@ func TestPausedDeployment(t *testing.T) {
|
||||
|
||||
// Paused deployment can be scaled
|
||||
func TestScalePausedDeployment(t *testing.T) {
|
||||
closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
closeFn, rm, dc, informers, c := dcSetup(ctx, t)
|
||||
defer closeFn()
|
||||
|
||||
name := "test-scale-paused-deployment"
|
||||
@@ -423,7 +440,11 @@ func TestScalePausedDeployment(t *testing.T) {
|
||||
|
||||
// Deployment rollout shouldn't be blocked on hash collisions
|
||||
func TestDeploymentHashCollision(t *testing.T) {
|
||||
closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
closeFn, rm, dc, informers, c := dcSetup(ctx, t)
|
||||
defer closeFn()
|
||||
|
||||
name := "test-hash-collision-deployment"
|
||||
@@ -522,7 +543,11 @@ func checkPodsHashLabel(pods *v1.PodList) (string, error) {
|
||||
|
||||
// Deployment should have a timeout condition when it fails to progress after given deadline.
|
||||
func TestFailedDeployment(t *testing.T) {
|
||||
closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
closeFn, rm, dc, informers, c := dcSetup(ctx, t)
|
||||
defer closeFn()
|
||||
|
||||
name := "test-failed-deployment"
|
||||
@@ -566,7 +591,11 @@ func TestFailedDeployment(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOverlappingDeployments(t *testing.T) {
|
||||
closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
closeFn, rm, dc, informers, c := dcSetup(ctx, t)
|
||||
defer closeFn()
|
||||
|
||||
name := "test-overlapping-deployments"
|
||||
@@ -647,7 +676,11 @@ func TestOverlappingDeployments(t *testing.T) {
|
||||
|
||||
// Deployment should not block rollout when updating spec replica number and template at the same time.
|
||||
func TestScaledRolloutDeployment(t *testing.T) {
|
||||
closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
closeFn, rm, dc, informers, c := dcSetup(ctx, t)
|
||||
defer closeFn()
|
||||
|
||||
name := "test-scaled-rollout-deployment"
|
||||
@@ -749,7 +782,7 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get replicaset when checking desired replicas annotation: %v", err)
|
||||
}
|
||||
desired, ok := deploymentutil.GetDesiredReplicasAnnotation(curRS)
|
||||
desired, ok := deploymentutil.GetDesiredReplicasAnnotation(logger, curRS)
|
||||
if !ok {
|
||||
t.Fatalf("failed to retrieve desiredReplicas annotation for replicaset %q", curRS.Name)
|
||||
}
|
||||
@@ -826,7 +859,7 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get replicaset when checking desired replicas annotation: %v", err)
|
||||
}
|
||||
desired, ok := deploymentutil.GetDesiredReplicasAnnotation(curRS)
|
||||
desired, ok := deploymentutil.GetDesiredReplicasAnnotation(logger, curRS)
|
||||
if !ok {
|
||||
t.Fatalf("failed to retrieve desiredReplicas annotation for replicaset %q", curRS.Name)
|
||||
}
|
||||
@@ -837,7 +870,11 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSpecReplicasChange(t *testing.T) {
|
||||
closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
closeFn, rm, dc, informers, c := dcSetup(ctx, t)
|
||||
defer closeFn()
|
||||
|
||||
name := "test-spec-replicas-change"
|
||||
@@ -891,7 +928,11 @@ func TestSpecReplicasChange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeploymentAvailableCondition(t *testing.T) {
|
||||
closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
closeFn, rm, dc, informers, c := dcSetup(ctx, t)
|
||||
defer closeFn()
|
||||
|
||||
name := "test-deployment-available-condition"
|
||||
@@ -1010,7 +1051,11 @@ func testRSControllerRefPatch(t *testing.T, tester *deploymentTester, rs *apps.R
|
||||
}
|
||||
|
||||
func TestGeneralReplicaSetAdoption(t *testing.T) {
|
||||
closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
closeFn, rm, dc, informers, c := dcSetup(ctx, t)
|
||||
defer closeFn()
|
||||
|
||||
name := "test-general-replicaset-adoption"
|
||||
@@ -1100,7 +1145,11 @@ func testScalingUsingScaleSubresource(t *testing.T, tester *deploymentTester, re
|
||||
}
|
||||
|
||||
func TestDeploymentScaleSubresource(t *testing.T) {
|
||||
closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
closeFn, rm, dc, informers, c := dcSetup(ctx, t)
|
||||
defer closeFn()
|
||||
|
||||
name := "test-deployment-scale-subresource"
|
||||
@@ -1142,7 +1191,11 @@ func TestDeploymentScaleSubresource(t *testing.T) {
|
||||
// is orphaned, even without PodTemplateSpec change. Refer comment below for more info:
|
||||
// https://github.com/kubernetes/kubernetes/pull/59212#discussion_r166465113
|
||||
func TestReplicaSetOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
|
||||
closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
closeFn, rm, dc, informers, c := dcSetup(ctx, t)
|
||||
defer closeFn()
|
||||
|
||||
name := "test-replicaset-orphaning-and-adoption-when-labels-change"
|
||||
|
@@ -103,7 +103,7 @@ func newDeployment(name, ns string, replicas int32) *apps.Deployment {
|
||||
}
|
||||
|
||||
// dcSetup sets up necessities for Deployment integration test, including control plane, apiserver, informers, and clientset
|
||||
func dcSetup(t *testing.T) (kubeapiservertesting.TearDownFunc, *replicaset.ReplicaSetController, *deployment.DeploymentController, informers.SharedInformerFactory, clientset.Interface) {
|
||||
func dcSetup(ctx context.Context, t *testing.T) (kubeapiservertesting.TearDownFunc, *replicaset.ReplicaSetController, *deployment.DeploymentController, informers.SharedInformerFactory, clientset.Interface) {
|
||||
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||
server := kubeapiservertesting.StartTestServerOrDie(t, nil, []string{"--disable-admission-plugins=ServiceAccount"}, framework.SharedEtcd())
|
||||
logger, _ := ktesting.NewTestContext(t)
|
||||
@@ -117,6 +117,7 @@ func dcSetup(t *testing.T) (kubeapiservertesting.TearDownFunc, *replicaset.Repli
|
||||
informers := informers.NewSharedInformerFactory(clientset.NewForConfigOrDie(restclient.AddUserAgent(config, "deployment-informers")), resyncPeriod)
|
||||
|
||||
dc, err := deployment.NewDeploymentController(
|
||||
ctx,
|
||||
informers.Apps().V1().Deployments(),
|
||||
informers.Apps().V1().ReplicaSets(),
|
||||
informers.Core().V1().Pods(),
|
||||
|
Reference in New Issue
Block a user