mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 10:20:51 +00:00
test/integration: Use apps/v1 Deployment/ReplicaSet.
This must be done at the same time as the controller update, since they share code.
This commit is contained in:
parent
a6a5190494
commit
680bc4b4b5
@ -19,8 +19,8 @@ go_test(
|
||||
"//pkg/controller/deployment/util:go_default_library",
|
||||
"//pkg/util/pointer:go_default_library",
|
||||
"//test/integration/framework:go_default_library",
|
||||
"//vendor/k8s.io/api/apps/v1:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/api/extensions/v1beta1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
|
||||
@ -41,6 +41,7 @@ go_library(
|
||||
"//pkg/util/metrics:go_default_library",
|
||||
"//test/integration/framework:go_default_library",
|
||||
"//test/utils:go_default_library",
|
||||
"//vendor/k8s.io/api/apps/v1:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/api/extensions/v1beta1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
|
@ -22,8 +22,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
apps "k8s.io/api/apps/v1"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/api/extensions/v1beta1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
@ -47,7 +47,7 @@ func TestNewDeployment(t *testing.T) {
|
||||
|
||||
tester.deployment.Annotations = map[string]string{"test": "should-copy-to-replica-set", v1.LastAppliedConfigAnnotation: "should-not-copy-to-replica-set"}
|
||||
var err error
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment)
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create deployment %s: %v", tester.deployment.Name, err)
|
||||
}
|
||||
@ -128,14 +128,14 @@ func TestDeploymentRollingUpdate(t *testing.T) {
|
||||
tester := &deploymentTester{t: t, c: c, deployment: newDeployment(name, ns.Name, replicas)}
|
||||
tester.deployment.Spec.MinReadySeconds = 4
|
||||
quarter := intstr.FromString("25%")
|
||||
tester.deployment.Spec.Strategy.RollingUpdate = &v1beta1.RollingUpdateDeployment{
|
||||
tester.deployment.Spec.Strategy.RollingUpdate = &apps.RollingUpdateDeployment{
|
||||
MaxUnavailable: &quarter,
|
||||
MaxSurge: &quarter,
|
||||
}
|
||||
|
||||
// Create a deployment.
|
||||
var err error
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment)
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create deployment %s: %v", tester.deployment.Name, err)
|
||||
}
|
||||
@ -152,7 +152,7 @@ func TestDeploymentRollingUpdate(t *testing.T) {
|
||||
if oriImage == image {
|
||||
t.Fatalf("bad test setup, deployment %s roll out with the same image", tester.deployment.Name)
|
||||
}
|
||||
imageFn := func(update *v1beta1.Deployment) {
|
||||
imageFn := func(update *apps.Deployment) {
|
||||
update.Spec.Template.Spec.Containers[0].Image = image
|
||||
}
|
||||
tester.deployment, err = tester.updateDeployment(imageFn)
|
||||
@ -186,7 +186,7 @@ func TestDeploymentRollingUpdate(t *testing.T) {
|
||||
|
||||
// 3. Roll over a deployment before the previous rolling update finishes.
|
||||
image = "dont-finish"
|
||||
imageFn = func(update *v1beta1.Deployment) {
|
||||
imageFn = func(update *apps.Deployment) {
|
||||
update.Spec.Template.Spec.Containers[0].Image = image
|
||||
}
|
||||
tester.deployment, err = tester.updateDeployment(imageFn)
|
||||
@ -199,7 +199,7 @@ func TestDeploymentRollingUpdate(t *testing.T) {
|
||||
// We don't mark pods as ready so that rollout won't finish.
|
||||
// Before the rollout finishes, trigger another rollout.
|
||||
image = "rollover"
|
||||
imageFn = func(update *v1beta1.Deployment) {
|
||||
imageFn = func(update *apps.Deployment) {
|
||||
update.Spec.Template.Spec.Containers[0].Image = image
|
||||
}
|
||||
tester.deployment, err = tester.updateDeployment(imageFn)
|
||||
@ -212,7 +212,7 @@ func TestDeploymentRollingUpdate(t *testing.T) {
|
||||
if err := tester.waitForDeploymentCompleteAndCheckRollingAndMarkPodsReady(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, allOldRSs, err := deploymentutil.GetOldReplicaSets(tester.deployment, c.ExtensionsV1beta1())
|
||||
_, allOldRSs, err := deploymentutil.GetOldReplicaSets(tester.deployment, c.AppsV1())
|
||||
if err != nil {
|
||||
t.Fatalf("failed retrieving old replicasets of deployment %s: %v", tester.deployment.Name, err)
|
||||
}
|
||||
@ -232,13 +232,18 @@ func TestDeploymentSelectorImmutability(t *testing.T) {
|
||||
defer framework.DeleteTestingNamespace(ns, s, t)
|
||||
|
||||
tester := &deploymentTester{t: t, c: c, deployment: newDeployment(name, ns.Name, int32(20))}
|
||||
deploymentExtensionsV1beta1, err := c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment)
|
||||
var err error
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create extensions/v1beta1 deployment %s: %v", tester.deployment.Name, err)
|
||||
t.Fatalf("failed to create apps/v1 deployment %s: %v", tester.deployment.Name, err)
|
||||
}
|
||||
|
||||
// test to ensure extensions/v1beta1 selector is mutable
|
||||
newSelectorLabels := map[string]string{"name_extensions_v1beta1": "test_extensions_v1beta1"}
|
||||
deploymentExtensionsV1beta1, err := c.ExtensionsV1beta1().Deployments(ns.Name).Get(name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get extensions/v1beta deployment %s: %v", name, err)
|
||||
}
|
||||
deploymentExtensionsV1beta1.Spec.Selector.MatchLabels = newSelectorLabels
|
||||
deploymentExtensionsV1beta1.Spec.Template.Labels = newSelectorLabels
|
||||
updatedDeploymentExtensionsV1beta1, err := c.ExtensionsV1beta1().Deployments(ns.Name).Update(deploymentExtensionsV1beta1)
|
||||
@ -283,6 +288,22 @@ func TestDeploymentSelectorImmutability(t *testing.T) {
|
||||
if !strings.Contains(err.Error(), expectedErrType) || !strings.Contains(err.Error(), expectedErrDetail) {
|
||||
t.Errorf("error message does not match, expected type: %s, expected detail: %s, got: %s", expectedErrType, expectedErrDetail, err.Error())
|
||||
}
|
||||
|
||||
// test to ensure apps/v1 selector is immutable
|
||||
deploymentAppsV1, err := c.AppsV1().Deployments(ns.Name).Get(updatedDeploymentAppsV1beta1.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get apps/v1 deployment %s: %v", updatedDeploymentAppsV1beta1.Name, err)
|
||||
}
|
||||
newSelectorLabels = map[string]string{"name_apps_v1": "test_apps_v1"}
|
||||
deploymentAppsV1.Spec.Selector.MatchLabels = newSelectorLabels
|
||||
deploymentAppsV1.Spec.Template.Labels = newSelectorLabels
|
||||
_, err = c.AppsV1().Deployments(ns.Name).Update(deploymentAppsV1)
|
||||
if err == nil {
|
||||
t.Fatalf("failed to provide validation error when changing immutable selector when updating apps/v1 deployment %s", deploymentAppsV1.Name)
|
||||
}
|
||||
if !strings.Contains(err.Error(), expectedErrType) || !strings.Contains(err.Error(), expectedErrDetail) {
|
||||
t.Errorf("error message does not match, expected type: %s, expected detail: %s, got: %s", expectedErrType, expectedErrDetail, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// Paused deployment should not start new rollout
|
||||
@ -300,7 +321,7 @@ func TestPausedDeployment(t *testing.T) {
|
||||
tester.deployment.Spec.Template.Spec.TerminationGracePeriodSeconds = &tgps
|
||||
|
||||
var err error
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment)
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create deployment %s: %v", tester.deployment.Name, err)
|
||||
}
|
||||
@ -358,7 +379,7 @@ func TestPausedDeployment(t *testing.T) {
|
||||
|
||||
// Update the deployment template
|
||||
newTGPS := int64(0)
|
||||
tester.deployment, err = tester.updateDeployment(func(update *v1beta1.Deployment) {
|
||||
tester.deployment, err = tester.updateDeployment(func(update *apps.Deployment) {
|
||||
update.Spec.Template.Spec.TerminationGracePeriodSeconds = &newTGPS
|
||||
})
|
||||
if err != nil {
|
||||
@ -375,7 +396,7 @@ func TestPausedDeployment(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, allOldRs, err := deploymentutil.GetOldReplicaSets(tester.deployment, c.ExtensionsV1beta1())
|
||||
_, allOldRs, err := deploymentutil.GetOldReplicaSets(tester.deployment, c.AppsV1())
|
||||
if err != nil {
|
||||
t.Fatalf("failed retrieving old replicasets of deployment %s: %v", tester.deployment.Name, err)
|
||||
}
|
||||
@ -401,7 +422,7 @@ func TestScalePausedDeployment(t *testing.T) {
|
||||
tester.deployment.Spec.Template.Spec.TerminationGracePeriodSeconds = &tgps
|
||||
|
||||
var err error
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment)
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create deployment %s: %v", tester.deployment.Name, err)
|
||||
}
|
||||
@ -442,7 +463,7 @@ func TestScalePausedDeployment(t *testing.T) {
|
||||
|
||||
// Scale the paused deployment.
|
||||
newReplicas := int32(10)
|
||||
tester.deployment, err = tester.updateDeployment(func(update *v1beta1.Deployment) {
|
||||
tester.deployment, err = tester.updateDeployment(func(update *apps.Deployment) {
|
||||
update.Spec.Replicas = &newReplicas
|
||||
})
|
||||
if err != nil {
|
||||
@ -482,7 +503,7 @@ func TestDeploymentHashCollision(t *testing.T) {
|
||||
tester := &deploymentTester{t: t, c: c, deployment: newDeployment(name, ns.Name, replicas)}
|
||||
|
||||
var err error
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment)
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create deployment %s: %v", tester.deployment.Name, err)
|
||||
}
|
||||
@ -500,14 +521,14 @@ func TestDeploymentHashCollision(t *testing.T) {
|
||||
}
|
||||
|
||||
// Mock a hash collision
|
||||
newRS, err := deploymentutil.GetNewReplicaSet(tester.deployment, c.ExtensionsV1beta1())
|
||||
newRS, err := deploymentutil.GetNewReplicaSet(tester.deployment, c.AppsV1())
|
||||
if err != nil {
|
||||
t.Fatalf("failed getting new replicaset of deployment %s: %v", tester.deployment.Name, err)
|
||||
}
|
||||
if newRS == nil {
|
||||
t.Fatalf("unable to find new replicaset of deployment %s", tester.deployment.Name)
|
||||
}
|
||||
_, err = tester.updateReplicaSet(newRS.Name, func(update *v1beta1.ReplicaSet) {
|
||||
_, err = tester.updateReplicaSet(newRS.Name, func(update *apps.ReplicaSet) {
|
||||
*update.Spec.Template.Spec.TerminationGracePeriodSeconds = int64(5)
|
||||
})
|
||||
if err != nil {
|
||||
@ -516,7 +537,7 @@ func TestDeploymentHashCollision(t *testing.T) {
|
||||
|
||||
// Expect deployment collision counter to increment
|
||||
if err := wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
|
||||
d, err := c.ExtensionsV1beta1().Deployments(ns.Name).Get(tester.deployment.Name, metav1.GetOptions{})
|
||||
d, err := c.AppsV1().Deployments(ns.Name).Get(tester.deployment.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
@ -546,7 +567,7 @@ func TestRollbackDeploymentRSNoRevision(t *testing.T) {
|
||||
rs.Annotations = make(map[string]string)
|
||||
rs.Annotations["make"] = "difference"
|
||||
rs.Spec.Template.Spec.Containers[0].Image = "different-image"
|
||||
_, err := c.ExtensionsV1beta1().ReplicaSets(ns.Name).Create(rs)
|
||||
_, err := c.AppsV1().ReplicaSets(ns.Name).Create(rs)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create replicaset %s: %v", rsName, err)
|
||||
}
|
||||
@ -554,9 +575,13 @@ func TestRollbackDeploymentRSNoRevision(t *testing.T) {
|
||||
replicas := int32(1)
|
||||
tester := &deploymentTester{t: t, c: c, deployment: newDeployment(name, ns.Name, replicas)}
|
||||
oriImage := tester.deployment.Spec.Template.Spec.Containers[0].Image
|
||||
// Set absolute rollout limits (defaults changed to percentages)
|
||||
max := intstr.FromInt(1)
|
||||
tester.deployment.Spec.Strategy.RollingUpdate.MaxUnavailable = &max
|
||||
tester.deployment.Spec.Strategy.RollingUpdate.MaxSurge = &max
|
||||
|
||||
// Create a deployment which have different template than the replica set created above.
|
||||
if tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment); err != nil {
|
||||
if tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment); err != nil {
|
||||
t.Fatalf("failed to create deployment %s: %v", tester.deployment.Name, err)
|
||||
}
|
||||
|
||||
@ -595,7 +620,7 @@ func TestRollbackDeploymentRSNoRevision(t *testing.T) {
|
||||
|
||||
// 2. Update the deployment to revision 2.
|
||||
updatedImage := "update"
|
||||
tester.deployment, err = tester.updateDeployment(func(update *v1beta1.Deployment) {
|
||||
tester.deployment, err = tester.updateDeployment(func(update *apps.Deployment) {
|
||||
update.Spec.Template.Spec.Containers[0].Name = updatedImage
|
||||
update.Spec.Template.Spec.Containers[0].Image = updatedImage
|
||||
})
|
||||
@ -644,10 +669,10 @@ func TestRollbackDeploymentRSNoRevision(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func checkRSHashLabels(rs *v1beta1.ReplicaSet) (string, error) {
|
||||
hash := rs.Labels[v1beta1.DefaultDeploymentUniqueLabelKey]
|
||||
selectorHash := rs.Spec.Selector.MatchLabels[v1beta1.DefaultDeploymentUniqueLabelKey]
|
||||
templateLabelHash := rs.Spec.Template.Labels[v1beta1.DefaultDeploymentUniqueLabelKey]
|
||||
func checkRSHashLabels(rs *apps.ReplicaSet) (string, error) {
|
||||
hash := rs.Labels[apps.DefaultDeploymentUniqueLabelKey]
|
||||
selectorHash := rs.Spec.Selector.MatchLabels[apps.DefaultDeploymentUniqueLabelKey]
|
||||
templateLabelHash := rs.Spec.Template.Labels[apps.DefaultDeploymentUniqueLabelKey]
|
||||
|
||||
if hash != selectorHash || selectorHash != templateLabelHash {
|
||||
return "", fmt.Errorf("mismatching hash value found in replicaset %s: %#v", rs.Name, rs)
|
||||
@ -665,7 +690,7 @@ func checkPodsHashLabel(pods *v1.PodList) (string, error) {
|
||||
}
|
||||
var hash string
|
||||
for _, pod := range pods.Items {
|
||||
podHash := pod.Labels[v1beta1.DefaultDeploymentUniqueLabelKey]
|
||||
podHash := pod.Labels[apps.DefaultDeploymentUniqueLabelKey]
|
||||
if len(podHash) == 0 {
|
||||
return "", fmt.Errorf("found pod %s missing pod-template-hash label: %#v", pod.Name, pods)
|
||||
}
|
||||
@ -694,7 +719,7 @@ func TestFailedDeployment(t *testing.T) {
|
||||
tester := &deploymentTester{t: t, c: c, deployment: newDeployment(deploymentName, ns.Name, replicas)}
|
||||
tester.deployment.Spec.ProgressDeadlineSeconds = &three
|
||||
var err error
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment)
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create deployment %q: %v", deploymentName, err)
|
||||
}
|
||||
@ -712,7 +737,7 @@ func TestFailedDeployment(t *testing.T) {
|
||||
|
||||
// Pods are not marked as Ready, therefore the deployment progress will eventually timeout after progressDeadlineSeconds has passed.
|
||||
// Wait for the deployment to have a progress timeout condition.
|
||||
if err = tester.waitForDeploymentWithCondition(deploymentutil.TimedOutReason, v1beta1.DeploymentProgressing); err != nil {
|
||||
if err = tester.waitForDeploymentWithCondition(deploymentutil.TimedOutReason, apps.DeploymentProgressing); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -722,7 +747,7 @@ func TestFailedDeployment(t *testing.T) {
|
||||
}
|
||||
|
||||
// Wait for the deployment to have a progress complete condition.
|
||||
if err = tester.waitForDeploymentWithCondition(deploymentutil.NewRSAvailableReason, v1beta1.DeploymentProgressing); err != nil {
|
||||
if err = tester.waitForDeploymentWithCondition(deploymentutil.NewRSAvailableReason, apps.DeploymentProgressing); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -750,9 +775,9 @@ func TestOverlappingDeployments(t *testing.T) {
|
||||
|
||||
// Create 2 deployments with overlapping selectors
|
||||
var err error
|
||||
var rss []*v1beta1.ReplicaSet
|
||||
var rss []*apps.ReplicaSet
|
||||
for _, tester := range testers {
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment)
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment)
|
||||
dname := tester.deployment.Name
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create deployment %q: %v", dname, err)
|
||||
@ -784,7 +809,7 @@ func TestOverlappingDeployments(t *testing.T) {
|
||||
|
||||
// Scale only the first deployment by 1
|
||||
newReplicas := replicas + 1
|
||||
testers[0].deployment, err = testers[0].updateDeployment(func(update *v1beta1.Deployment) {
|
||||
testers[0].deployment, err = testers[0].updateDeployment(func(update *apps.Deployment) {
|
||||
update.Spec.Replicas = &newReplicas
|
||||
})
|
||||
if err != nil {
|
||||
@ -798,7 +823,7 @@ func TestOverlappingDeployments(t *testing.T) {
|
||||
|
||||
// Verify replicaset of both deployments has updated number of replicas
|
||||
for i, tester := range testers {
|
||||
rs, err := c.ExtensionsV1beta1().ReplicaSets(ns.Name).Get(rss[i].Name, metav1.GetOptions{})
|
||||
rs, err := c.AppsV1().ReplicaSets(ns.Name).Get(rss[i].Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get replicaset %q: %v", rss[i].Name, err)
|
||||
}
|
||||
@ -828,7 +853,7 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
||||
tester := &deploymentTester{t: t, c: c, deployment: newDeployment(name, ns.Name, replicas)}
|
||||
tester.deployment.Spec.Strategy.RollingUpdate.MaxSurge = intOrStrP(3)
|
||||
tester.deployment.Spec.Strategy.RollingUpdate.MaxUnavailable = intOrStrP(2)
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment)
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create deployment %q: %v", name, err)
|
||||
}
|
||||
@ -847,7 +872,7 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
||||
|
||||
// Update the deployment with another new image but do not mark the pods as ready to block new replicaset
|
||||
fakeImage2 := "fakeimage2"
|
||||
tester.deployment, err = tester.updateDeployment(func(update *v1beta1.Deployment) {
|
||||
tester.deployment, err = tester.updateDeployment(func(update *apps.Deployment) {
|
||||
update.Spec.Template.Spec.Containers[0].Image = fakeImage2
|
||||
})
|
||||
if err != nil {
|
||||
@ -858,7 +883,7 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify the deployment has minimum available replicas after 2nd rollout
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Get(name, metav1.GetOptions{})
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Get(name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get deployment %q: %v", name, err)
|
||||
}
|
||||
@ -868,7 +893,7 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
||||
}
|
||||
|
||||
// Wait for old replicaset of 1st rollout to have desired replicas
|
||||
firstRS, err = c.ExtensionsV1beta1().ReplicaSets(ns.Name).Get(firstRS.Name, metav1.GetOptions{})
|
||||
firstRS, err = c.AppsV1().ReplicaSets(ns.Name).Get(firstRS.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get replicaset %q: %v", firstRS.Name, err)
|
||||
}
|
||||
@ -888,7 +913,7 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
||||
// Scale up the deployment and update its image to another new image simultaneously (this time marks all pods as ready)
|
||||
newReplicas := int32(20)
|
||||
fakeImage3 := "fakeimage3"
|
||||
tester.deployment, err = tester.updateDeployment(func(update *v1beta1.Deployment) {
|
||||
tester.deployment, err = tester.updateDeployment(func(update *apps.Deployment) {
|
||||
update.Spec.Replicas = &newReplicas
|
||||
update.Spec.Template.Spec.Containers[0].Image = fakeImage3
|
||||
})
|
||||
@ -903,13 +928,13 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify every replicaset has correct desiredReplicas annotation after 3rd rollout
|
||||
thirdRS, err := deploymentutil.GetNewReplicaSet(tester.deployment, c.ExtensionsV1beta1())
|
||||
thirdRS, err := deploymentutil.GetNewReplicaSet(tester.deployment, c.AppsV1())
|
||||
if err != nil {
|
||||
t.Fatalf("failed getting new revision 3 replicaset for deployment %q: %v", name, err)
|
||||
}
|
||||
rss := []*v1beta1.ReplicaSet{firstRS, secondRS, thirdRS}
|
||||
rss := []*apps.ReplicaSet{firstRS, secondRS, thirdRS}
|
||||
for _, curRS := range rss {
|
||||
curRS, err = c.ExtensionsV1beta1().ReplicaSets(ns.Name).Get(curRS.Name, metav1.GetOptions{})
|
||||
curRS, err = c.AppsV1().ReplicaSets(ns.Name).Get(curRS.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get replicaset when checking desired replicas annotation: %v", err)
|
||||
}
|
||||
@ -924,7 +949,7 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
||||
|
||||
// Update the deployment with another new image but do not mark the pods as ready to block new replicaset
|
||||
fakeImage4 := "fakeimage4"
|
||||
tester.deployment, err = tester.updateDeployment(func(update *v1beta1.Deployment) {
|
||||
tester.deployment, err = tester.updateDeployment(func(update *apps.Deployment) {
|
||||
update.Spec.Template.Spec.Containers[0].Image = fakeImage4
|
||||
})
|
||||
if err != nil {
|
||||
@ -935,7 +960,7 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify the deployment has minimum available replicas after 4th rollout
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Get(name, metav1.GetOptions{})
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Get(name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get deployment %q: %v", name, err)
|
||||
}
|
||||
@ -945,7 +970,7 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
||||
}
|
||||
|
||||
// Wait for old replicaset of 3rd rollout to have desired replicas
|
||||
thirdRS, err = c.ExtensionsV1beta1().ReplicaSets(ns.Name).Get(thirdRS.Name, metav1.GetOptions{})
|
||||
thirdRS, err = c.AppsV1().ReplicaSets(ns.Name).Get(thirdRS.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get replicaset %q: %v", thirdRS.Name, err)
|
||||
}
|
||||
@ -965,7 +990,7 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
||||
// Scale down the deployment and update its image to another new image simultaneously (this time marks all pods as ready)
|
||||
newReplicas = int32(5)
|
||||
fakeImage5 := "fakeimage5"
|
||||
tester.deployment, err = tester.updateDeployment(func(update *v1beta1.Deployment) {
|
||||
tester.deployment, err = tester.updateDeployment(func(update *apps.Deployment) {
|
||||
update.Spec.Replicas = &newReplicas
|
||||
update.Spec.Template.Spec.Containers[0].Image = fakeImage5
|
||||
})
|
||||
@ -980,13 +1005,13 @@ func TestScaledRolloutDeployment(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify every replicaset has correct desiredReplicas annotation after 5th rollout
|
||||
fifthRS, err := deploymentutil.GetNewReplicaSet(tester.deployment, c.ExtensionsV1beta1())
|
||||
fifthRS, err := deploymentutil.GetNewReplicaSet(tester.deployment, c.AppsV1())
|
||||
if err != nil {
|
||||
t.Fatalf("failed getting new revision 5 replicaset for deployment %q: %v", name, err)
|
||||
}
|
||||
rss = []*v1beta1.ReplicaSet{thirdRS, fourthRS, fifthRS}
|
||||
rss = []*apps.ReplicaSet{thirdRS, fourthRS, fifthRS}
|
||||
for _, curRS := range rss {
|
||||
curRS, err = c.ExtensionsV1beta1().ReplicaSets(ns.Name).Get(curRS.Name, metav1.GetOptions{})
|
||||
curRS, err = c.AppsV1().ReplicaSets(ns.Name).Get(curRS.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get replicaset when checking desired replicas annotation: %v", err)
|
||||
}
|
||||
@ -1010,10 +1035,10 @@ func TestSpecReplicasChange(t *testing.T) {
|
||||
deploymentName := "deployment"
|
||||
replicas := int32(1)
|
||||
tester := &deploymentTester{t: t, c: c, deployment: newDeployment(deploymentName, ns.Name, replicas)}
|
||||
tester.deployment.Spec.Strategy.Type = v1beta1.RecreateDeploymentStrategyType
|
||||
tester.deployment.Spec.Strategy.Type = apps.RecreateDeploymentStrategyType
|
||||
tester.deployment.Spec.Strategy.RollingUpdate = nil
|
||||
var err error
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment)
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create deployment %q: %v", deploymentName, err)
|
||||
}
|
||||
@ -1039,7 +1064,7 @@ func TestSpecReplicasChange(t *testing.T) {
|
||||
// Add a template annotation change to test deployment's status does update
|
||||
// without .spec.replicas change
|
||||
var oldGeneration int64
|
||||
tester.deployment, err = tester.updateDeployment(func(update *v1beta1.Deployment) {
|
||||
tester.deployment, err = tester.updateDeployment(func(update *apps.Deployment) {
|
||||
oldGeneration = update.Generation
|
||||
update.Spec.RevisionHistoryLimit = pointer.Int32Ptr(4)
|
||||
})
|
||||
@ -1068,8 +1093,10 @@ func TestDeploymentAvailableCondition(t *testing.T) {
|
||||
tester := &deploymentTester{t: t, c: c, deployment: newDeployment(deploymentName, ns.Name, replicas)}
|
||||
// Assign a high value to the deployment's minReadySeconds
|
||||
tester.deployment.Spec.MinReadySeconds = 3600
|
||||
// progressDeadlineSeconds must be greater than minReadySeconds
|
||||
tester.deployment.Spec.ProgressDeadlineSeconds = pointer.Int32Ptr(7200)
|
||||
var err error
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment)
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create deployment %q: %v", deploymentName, err)
|
||||
}
|
||||
@ -1087,7 +1114,7 @@ func TestDeploymentAvailableCondition(t *testing.T) {
|
||||
}
|
||||
|
||||
// Wait for the deployment to have MinimumReplicasUnavailable reason because the pods are not marked as ready
|
||||
if err = tester.waitForDeploymentWithCondition(deploymentutil.MinimumReplicasUnavailable, v1beta1.DeploymentAvailable); err != nil {
|
||||
if err = tester.waitForDeploymentWithCondition(deploymentutil.MinimumReplicasUnavailable, apps.DeploymentAvailable); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -1107,7 +1134,7 @@ func TestDeploymentAvailableCondition(t *testing.T) {
|
||||
}
|
||||
|
||||
// Wait for the deployment to still have MinimumReplicasUnavailable reason within minReadySeconds period
|
||||
if err = tester.waitForDeploymentWithCondition(deploymentutil.MinimumReplicasUnavailable, v1beta1.DeploymentAvailable); err != nil {
|
||||
if err = tester.waitForDeploymentWithCondition(deploymentutil.MinimumReplicasUnavailable, apps.DeploymentAvailable); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -1117,7 +1144,7 @@ func TestDeploymentAvailableCondition(t *testing.T) {
|
||||
}
|
||||
|
||||
// Update the deployment's minReadySeconds to a small value
|
||||
tester.deployment, err = tester.updateDeployment(func(update *v1beta1.Deployment) {
|
||||
tester.deployment, err = tester.updateDeployment(func(update *apps.Deployment) {
|
||||
update.Spec.MinReadySeconds = 1
|
||||
})
|
||||
if err != nil {
|
||||
@ -1130,7 +1157,7 @@ func TestDeploymentAvailableCondition(t *testing.T) {
|
||||
}
|
||||
|
||||
// Wait for the deployment to have MinimumReplicasAvailable reason after minReadySeconds period
|
||||
if err = tester.waitForDeploymentWithCondition(deploymentutil.MinimumReplicasAvailable, v1beta1.DeploymentAvailable); err != nil {
|
||||
if err = tester.waitForDeploymentWithCondition(deploymentutil.MinimumReplicasAvailable, apps.DeploymentAvailable); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -1141,10 +1168,10 @@ func TestDeploymentAvailableCondition(t *testing.T) {
|
||||
}
|
||||
|
||||
// Wait for deployment to automatically patch incorrect ControllerRef of RS
|
||||
func testRSControllerRefPatch(t *testing.T, tester *deploymentTester, rs *v1beta1.ReplicaSet, ownerReference *metav1.OwnerReference, expectedOwnerReferenceNum int) {
|
||||
func testRSControllerRefPatch(t *testing.T, tester *deploymentTester, rs *apps.ReplicaSet, ownerReference *metav1.OwnerReference, expectedOwnerReferenceNum int) {
|
||||
ns := rs.Namespace
|
||||
rsClient := tester.c.ExtensionsV1beta1().ReplicaSets(ns)
|
||||
rs, err := tester.updateReplicaSet(rs.Name, func(update *v1beta1.ReplicaSet) {
|
||||
rsClient := tester.c.AppsV1().ReplicaSets(ns)
|
||||
rs, err := tester.updateReplicaSet(rs.Name, func(update *apps.ReplicaSet) {
|
||||
update.OwnerReferences = []metav1.OwnerReference{*ownerReference}
|
||||
})
|
||||
if err != nil {
|
||||
@ -1186,7 +1213,7 @@ func TestGeneralReplicaSetAdoption(t *testing.T) {
|
||||
replicas := int32(1)
|
||||
tester := &deploymentTester{t: t, c: c, deployment: newDeployment(deploymentName, ns.Name, replicas)}
|
||||
var err error
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment)
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create deployment %q: %v", deploymentName, err)
|
||||
}
|
||||
@ -1209,7 +1236,7 @@ func TestGeneralReplicaSetAdoption(t *testing.T) {
|
||||
}
|
||||
|
||||
// Get replicaset of the deployment
|
||||
rs, err := deploymentutil.GetNewReplicaSet(tester.deployment, c.ExtensionsV1beta1())
|
||||
rs, err := deploymentutil.GetNewReplicaSet(tester.deployment, c.AppsV1())
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get replicaset of deployment %q: %v", deploymentName, err)
|
||||
}
|
||||
@ -1233,7 +1260,7 @@ func TestGeneralReplicaSetAdoption(t *testing.T) {
|
||||
func testScalingUsingScaleSubresource(t *testing.T, tester *deploymentTester, replicas int32) {
|
||||
ns := tester.deployment.Namespace
|
||||
deploymentName := tester.deployment.Name
|
||||
deploymentClient := tester.c.ExtensionsV1beta1().Deployments(ns)
|
||||
deploymentClient := tester.c.AppsV1().Deployments(ns)
|
||||
deployment, err := deploymentClient.Get(deploymentName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to obtain deployment %q: %v", deploymentName, err)
|
||||
@ -1280,7 +1307,7 @@ func TestDeploymentScaleSubresource(t *testing.T) {
|
||||
replicas := int32(2)
|
||||
tester := &deploymentTester{t: t, c: c, deployment: newDeployment(deploymentName, ns.Name, replicas)}
|
||||
var err error
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment)
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create deployment %q: %v", deploymentName, err)
|
||||
}
|
||||
@ -1324,7 +1351,7 @@ func TestReplicaSetOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
|
||||
replicas := int32(1)
|
||||
tester := &deploymentTester{t: t, c: c, deployment: newDeployment(deploymentName, ns.Name, replicas)}
|
||||
var err error
|
||||
tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment)
|
||||
tester.deployment, err = c.AppsV1().Deployments(ns.Name).Create(tester.deployment)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create deployment %q: %v", deploymentName, err)
|
||||
}
|
||||
@ -1349,7 +1376,7 @@ func TestReplicaSetOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
|
||||
// Orphaning: deployment should remove OwnerReference from a RS when the RS's labels change to not match its labels
|
||||
|
||||
// Get replicaset of the deployment
|
||||
rs, err := deploymentutil.GetNewReplicaSet(tester.deployment, c.ExtensionsV1beta1())
|
||||
rs, err := deploymentutil.GetNewReplicaSet(tester.deployment, c.AppsV1())
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get replicaset of deployment %q: %v", deploymentName, err)
|
||||
}
|
||||
@ -1368,7 +1395,7 @@ func TestReplicaSetOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
|
||||
|
||||
// Change the replicaset's labels to not match the deployment's labels
|
||||
labelMap := map[string]string{"new-name": "new-test"}
|
||||
rs, err = tester.updateReplicaSet(rs.Name, func(update *v1beta1.ReplicaSet) {
|
||||
rs, err = tester.updateReplicaSet(rs.Name, func(update *apps.ReplicaSet) {
|
||||
update.Labels = labelMap
|
||||
})
|
||||
if err != nil {
|
||||
@ -1376,7 +1403,7 @@ func TestReplicaSetOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
|
||||
}
|
||||
|
||||
// Wait for the controllerRef of the replicaset to become nil
|
||||
rsClient := tester.c.ExtensionsV1beta1().ReplicaSets(ns.Name)
|
||||
rsClient := tester.c.AppsV1().ReplicaSets(ns.Name)
|
||||
if err = wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
|
||||
rs, err = rsClient.Get(rs.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
@ -1390,9 +1417,9 @@ func TestReplicaSetOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
|
||||
// Wait for the deployment to create a new replicaset
|
||||
// This will trigger collision avoidance due to deterministic nature of replicaset name
|
||||
// i.e., the new replicaset will have a name with different hash to preserve name uniqueness
|
||||
var newRS *v1beta1.ReplicaSet
|
||||
var newRS *apps.ReplicaSet
|
||||
if err = wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
|
||||
newRS, err = deploymentutil.GetNewReplicaSet(tester.deployment, c.ExtensionsV1beta1())
|
||||
newRS, err = deploymentutil.GetNewReplicaSet(tester.deployment, c.AppsV1())
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to get new replicaset of deployment %q after orphaning: %v", deploymentName, err)
|
||||
}
|
||||
@ -1407,7 +1434,7 @@ func TestReplicaSetOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
|
||||
// Adoption: deployment should add controllerRef to a RS when the RS's labels change to match its labels
|
||||
|
||||
// Change the old replicaset's labels to match the deployment's labels
|
||||
rs, err = tester.updateReplicaSet(rs.Name, func(update *v1beta1.ReplicaSet) {
|
||||
rs, err = tester.updateReplicaSet(rs.Name, func(update *apps.ReplicaSet) {
|
||||
update.Labels = testLabels()
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -23,8 +23,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
apps "k8s.io/api/apps/v1"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/api/extensions/v1beta1"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
@ -48,18 +49,18 @@ const (
|
||||
fakeImage = "fakeimage"
|
||||
)
|
||||
|
||||
var pauseFn = func(update *v1beta1.Deployment) {
|
||||
var pauseFn = func(update *apps.Deployment) {
|
||||
update.Spec.Paused = true
|
||||
}
|
||||
|
||||
var resumeFn = func(update *v1beta1.Deployment) {
|
||||
var resumeFn = func(update *apps.Deployment) {
|
||||
update.Spec.Paused = false
|
||||
}
|
||||
|
||||
type deploymentTester struct {
|
||||
t *testing.T
|
||||
c clientset.Interface
|
||||
deployment *v1beta1.Deployment
|
||||
deployment *apps.Deployment
|
||||
}
|
||||
|
||||
func testLabels() map[string]string {
|
||||
@ -67,22 +68,22 @@ func testLabels() map[string]string {
|
||||
}
|
||||
|
||||
// newDeployment returns a RollingUpdate Deployment with with a fake container image
|
||||
func newDeployment(name, ns string, replicas int32) *v1beta1.Deployment {
|
||||
return &v1beta1.Deployment{
|
||||
func newDeployment(name, ns string, replicas int32) *apps.Deployment {
|
||||
return &apps.Deployment{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Deployment",
|
||||
APIVersion: "extensions/v1beta1",
|
||||
APIVersion: "apps/v1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: ns,
|
||||
Name: name,
|
||||
},
|
||||
Spec: v1beta1.DeploymentSpec{
|
||||
Spec: apps.DeploymentSpec{
|
||||
Replicas: &replicas,
|
||||
Selector: &metav1.LabelSelector{MatchLabels: testLabels()},
|
||||
Strategy: v1beta1.DeploymentStrategy{
|
||||
Type: v1beta1.RollingUpdateDeploymentStrategyType,
|
||||
RollingUpdate: new(v1beta1.RollingUpdateDeployment),
|
||||
Strategy: apps.DeploymentStrategy{
|
||||
Type: apps.RollingUpdateDeploymentStrategyType,
|
||||
RollingUpdate: new(apps.RollingUpdateDeployment),
|
||||
},
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
@ -101,8 +102,8 @@ func newDeployment(name, ns string, replicas int32) *v1beta1.Deployment {
|
||||
}
|
||||
}
|
||||
|
||||
func newReplicaSet(name, ns string, replicas int32) *v1beta1.ReplicaSet {
|
||||
return &v1beta1.ReplicaSet{
|
||||
func newReplicaSet(name, ns string, replicas int32) *apps.ReplicaSet {
|
||||
return &apps.ReplicaSet{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "ReplicaSet",
|
||||
APIVersion: "extensions/v1beta1",
|
||||
@ -110,8 +111,9 @@ func newReplicaSet(name, ns string, replicas int32) *v1beta1.ReplicaSet {
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: ns,
|
||||
Name: name,
|
||||
Labels: testLabels(),
|
||||
},
|
||||
Spec: v1beta1.ReplicaSetSpec{
|
||||
Spec: apps.ReplicaSetSpec{
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: testLabels(),
|
||||
},
|
||||
@ -133,11 +135,11 @@ func newReplicaSet(name, ns string, replicas int32) *v1beta1.ReplicaSet {
|
||||
}
|
||||
}
|
||||
|
||||
func newDeploymentRollback(name string, annotations map[string]string, revision int64) *v1beta1.DeploymentRollback {
|
||||
return &v1beta1.DeploymentRollback{
|
||||
func newDeploymentRollback(name string, annotations map[string]string, revision int64) *extensions.DeploymentRollback {
|
||||
return &extensions.DeploymentRollback{
|
||||
Name: name,
|
||||
UpdatedAnnotations: annotations,
|
||||
RollbackTo: v1beta1.RollbackConfig{Revision: revision},
|
||||
RollbackTo: extensions.RollbackConfig{Revision: revision},
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,8 +158,8 @@ func dcSetup(t *testing.T) (*httptest.Server, framework.CloseFunc, *replicaset.R
|
||||
|
||||
metrics.UnregisterMetricAndUntrackRateLimiterUsage("deployment_controller")
|
||||
dc, err := deployment.NewDeploymentController(
|
||||
informers.Extensions().V1beta1().Deployments(),
|
||||
informers.Extensions().V1beta1().ReplicaSets(),
|
||||
informers.Apps().V1().Deployments(),
|
||||
informers.Apps().V1().ReplicaSets(),
|
||||
informers.Core().V1().Pods(),
|
||||
clientset.NewForConfigOrDie(restclient.AddUserAgent(&config, "deployment-controller")),
|
||||
)
|
||||
@ -256,7 +258,7 @@ func (d *deploymentTester) markUpdatedPodsReady(wg *sync.WaitGroup) {
|
||||
}
|
||||
|
||||
func (d *deploymentTester) deploymentComplete() (bool, error) {
|
||||
latest, err := d.c.ExtensionsV1beta1().Deployments(d.deployment.Namespace).Get(d.deployment.Name, metav1.GetOptions{})
|
||||
latest, err := d.c.AppsV1().Deployments(d.deployment.Namespace).Get(d.deployment.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -285,6 +287,8 @@ func (d *deploymentTester) waitForDeploymentCompleteAndCheckRollingAndMarkPodsRe
|
||||
// Manually mark updated Deployment pods as ready in a separate goroutine
|
||||
wg.Add(1)
|
||||
go d.markUpdatedPodsReady(&wg)
|
||||
// Wait for goroutine to finish, for all return paths.
|
||||
defer wg.Wait()
|
||||
|
||||
// Wait for the Deployment status to complete while Deployment pods are becoming ready
|
||||
err := d.waitForDeploymentCompleteAndCheckRolling()
|
||||
@ -292,9 +296,6 @@ func (d *deploymentTester) waitForDeploymentCompleteAndCheckRollingAndMarkPodsRe
|
||||
return fmt.Errorf("failed to wait for Deployment %s to complete: %v", d.deployment.Name, err)
|
||||
}
|
||||
|
||||
// Wait for goroutine to finish
|
||||
wg.Wait()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -319,7 +320,7 @@ func (d *deploymentTester) waitForDeploymentCompleteAndMarkPodsReady() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *deploymentTester) updateDeployment(applyUpdate testutil.UpdateDeploymentFunc) (*v1beta1.Deployment, error) {
|
||||
func (d *deploymentTester) updateDeployment(applyUpdate testutil.UpdateDeploymentFunc) (*apps.Deployment, error) {
|
||||
return testutil.UpdateDeploymentWithRetries(d.c, d.deployment.Namespace, d.deployment.Name, applyUpdate, d.t.Logf, pollInterval, pollTimeout)
|
||||
}
|
||||
|
||||
@ -330,12 +331,12 @@ func (d *deploymentTester) waitForObservedDeployment(desiredGeneration int64) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *deploymentTester) getNewReplicaSet() (*v1beta1.ReplicaSet, error) {
|
||||
deployment, err := d.c.ExtensionsV1beta1().Deployments(d.deployment.Namespace).Get(d.deployment.Name, metav1.GetOptions{})
|
||||
func (d *deploymentTester) getNewReplicaSet() (*apps.ReplicaSet, error) {
|
||||
deployment, err := d.c.AppsV1().Deployments(d.deployment.Namespace).Get(d.deployment.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed retrieving deployment %s: %v", d.deployment.Name, err)
|
||||
}
|
||||
rs, err := deploymentutil.GetNewReplicaSet(deployment, d.c.ExtensionsV1beta1())
|
||||
rs, err := deploymentutil.GetNewReplicaSet(deployment, d.c.AppsV1())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed retrieving new replicaset of deployment %s: %v", d.deployment.Name, err)
|
||||
}
|
||||
@ -353,7 +354,7 @@ func (d *deploymentTester) expectNoNewReplicaSet() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *deploymentTester) expectNewReplicaSet() (*v1beta1.ReplicaSet, error) {
|
||||
func (d *deploymentTester) expectNewReplicaSet() (*apps.ReplicaSet, error) {
|
||||
rs, err := d.getNewReplicaSet()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -364,12 +365,12 @@ func (d *deploymentTester) expectNewReplicaSet() (*v1beta1.ReplicaSet, error) {
|
||||
return rs, nil
|
||||
}
|
||||
|
||||
func (d *deploymentTester) updateReplicaSet(name string, applyUpdate testutil.UpdateExtensionsReplicaSetFunc) (*v1beta1.ReplicaSet, error) {
|
||||
return testutil.UpdateExtensionsReplicaSetWithRetries(d.c, d.deployment.Namespace, name, applyUpdate, d.t.Logf, pollInterval, pollTimeout)
|
||||
func (d *deploymentTester) updateReplicaSet(name string, applyUpdate testutil.UpdateReplicaSetFunc) (*apps.ReplicaSet, error) {
|
||||
return testutil.UpdateReplicaSetWithRetries(d.c, d.deployment.Namespace, name, applyUpdate, d.t.Logf, pollInterval, pollTimeout)
|
||||
}
|
||||
|
||||
func (d *deploymentTester) updateReplicaSetStatus(name string, applyStatusUpdate testutil.UpdateExtensionsReplicaSetFunc) (*v1beta1.ReplicaSet, error) {
|
||||
return testutil.UpdateExtensionsReplicaSetStatusWithRetries(d.c, d.deployment.Namespace, name, applyStatusUpdate, d.t.Logf, pollInterval, pollTimeout)
|
||||
func (d *deploymentTester) updateReplicaSetStatus(name string, applyStatusUpdate testutil.UpdateReplicaSetFunc) (*apps.ReplicaSet, error) {
|
||||
return testutil.UpdateReplicaSetStatusWithRetries(d.c, d.deployment.Namespace, name, applyStatusUpdate, d.t.Logf, pollInterval, pollTimeout)
|
||||
}
|
||||
|
||||
// waitForDeploymentRollbackCleared waits for deployment either started rolling back or doesn't need to rollback.
|
||||
@ -386,7 +387,7 @@ func (d *deploymentTester) waitForDeploymentUpdatedReplicasGTE(minUpdatedReplica
|
||||
return testutil.WaitForDeploymentUpdatedReplicasGTE(d.c, d.deployment.Namespace, d.deployment.Name, minUpdatedReplicas, d.deployment.Generation, pollInterval, pollTimeout)
|
||||
}
|
||||
|
||||
func (d *deploymentTester) waitForDeploymentWithCondition(reason string, condType v1beta1.DeploymentConditionType) error {
|
||||
func (d *deploymentTester) waitForDeploymentWithCondition(reason string, condType apps.DeploymentConditionType) error {
|
||||
return testutil.WaitForDeploymentWithCondition(d.c, d.deployment.Namespace, d.deployment.Name, reason, condType, d.t.Logf, pollInterval, pollTimeout)
|
||||
}
|
||||
|
||||
@ -417,13 +418,13 @@ func (d *deploymentTester) listUpdatedPods() ([]v1.Pod, error) {
|
||||
return ownedPods, nil
|
||||
}
|
||||
|
||||
func (d *deploymentTester) waitRSStable(replicaset *v1beta1.ReplicaSet) error {
|
||||
return testutil.WaitExtensionsRSStable(d.t, d.c, replicaset, pollInterval, pollTimeout)
|
||||
func (d *deploymentTester) waitRSStable(replicaset *apps.ReplicaSet) error {
|
||||
return testutil.WaitRSStable(d.t, d.c, replicaset, pollInterval, pollTimeout)
|
||||
}
|
||||
|
||||
func (d *deploymentTester) scaleDeployment(newReplicas int32) error {
|
||||
var err error
|
||||
d.deployment, err = d.updateDeployment(func(update *v1beta1.Deployment) {
|
||||
d.deployment, err = d.updateDeployment(func(update *apps.Deployment) {
|
||||
update.Spec.Replicas = &newReplicas
|
||||
})
|
||||
if err != nil {
|
||||
@ -447,7 +448,7 @@ func (d *deploymentTester) scaleDeployment(newReplicas int32) error {
|
||||
// waitForReadyReplicas waits for number of ready replicas to equal number of replicas.
|
||||
func (d *deploymentTester) waitForReadyReplicas() error {
|
||||
if err := wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
|
||||
deployment, err := d.c.ExtensionsV1beta1().Deployments(d.deployment.Namespace).Get(d.deployment.Name, metav1.GetOptions{})
|
||||
deployment, err := d.c.AppsV1().Deployments(d.deployment.Namespace).Get(d.deployment.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to get deployment %q: %v", d.deployment.Name, err)
|
||||
}
|
||||
@ -485,7 +486,7 @@ func (d *deploymentTester) markUpdatedPodsReadyWithoutComplete() error {
|
||||
// Verify all replicas fields of DeploymentStatus have desired count.
|
||||
// Immediately return an error when found a non-matching replicas field.
|
||||
func (d *deploymentTester) checkDeploymentStatusReplicasFields(replicas, updatedReplicas, readyReplicas, availableReplicas, unavailableReplicas int32) error {
|
||||
deployment, err := d.c.ExtensionsV1beta1().Deployments(d.deployment.Namespace).Get(d.deployment.Name, metav1.GetOptions{})
|
||||
deployment, err := d.c.AppsV1().Deployments(d.deployment.Namespace).Get(d.deployment.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get deployment %q: %v", d.deployment.Name, err)
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
"time"
|
||||
|
||||
apps "k8s.io/api/apps/v1"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
@ -53,33 +52,6 @@ func UpdateReplicaSetWithRetries(c clientset.Interface, namespace, name string,
|
||||
return rs, pollErr
|
||||
}
|
||||
|
||||
// TODO(#55714): Remove this after Deployment tests use apps/v1 ReplicaSet.
|
||||
type UpdateExtensionsReplicaSetFunc func(d *extensions.ReplicaSet)
|
||||
|
||||
// TODO(#55714): Remove this after Deployment tests use apps/v1 ReplicaSet.
|
||||
func UpdateExtensionsReplicaSetWithRetries(c clientset.Interface, namespace, name string, applyUpdate UpdateExtensionsReplicaSetFunc, logf LogfFn, pollInterval, pollTimeout time.Duration) (*extensions.ReplicaSet, error) {
|
||||
var rs *extensions.ReplicaSet
|
||||
var updateErr error
|
||||
pollErr := wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
|
||||
var err error
|
||||
if rs, err = c.ExtensionsV1beta1().ReplicaSets(namespace).Get(name, metav1.GetOptions{}); err != nil {
|
||||
return false, err
|
||||
}
|
||||
// Apply the update, then attempt to push it to the apiserver.
|
||||
applyUpdate(rs)
|
||||
if rs, err = c.ExtensionsV1beta1().ReplicaSets(namespace).Update(rs); err == nil {
|
||||
logf("Updating replica set %q", name)
|
||||
return true, nil
|
||||
}
|
||||
updateErr = err
|
||||
return false, nil
|
||||
})
|
||||
if pollErr == wait.ErrWaitTimeout {
|
||||
pollErr = fmt.Errorf("couldn't apply the provided updated to replicaset %q: %v", name, updateErr)
|
||||
}
|
||||
return rs, pollErr
|
||||
}
|
||||
|
||||
// Verify .Status.Replicas is equal to .Spec.Replicas
|
||||
func WaitRSStable(t *testing.T, clientSet clientset.Interface, rs *apps.ReplicaSet, pollInterval, pollTimeout time.Duration) error {
|
||||
desiredGeneration := rs.Generation
|
||||
@ -95,33 +67,17 @@ func WaitRSStable(t *testing.T, clientSet clientset.Interface, rs *apps.ReplicaS
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO(#55714): Remove after Deployment tests use apps/v1 ReplicaSet.
|
||||
func WaitExtensionsRSStable(t *testing.T, clientSet clientset.Interface, rs *extensions.ReplicaSet, pollInterval, pollTimeout time.Duration) error {
|
||||
desiredGeneration := rs.Generation
|
||||
if err := wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
|
||||
newRS, err := clientSet.ExtensionsV1beta1().ReplicaSets(rs.Namespace).Get(rs.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return newRS.Status.ObservedGeneration >= desiredGeneration && newRS.Status.Replicas == *rs.Spec.Replicas, nil
|
||||
}); err != nil {
|
||||
return fmt.Errorf("failed to verify .Status.Replicas is equal to .Spec.Replicas for replicaset %q: %v", rs.Name, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO(#55714): Remove after Deployment tests use apps/v1 ReplicaSet.
|
||||
func UpdateExtensionsReplicaSetStatusWithRetries(c clientset.Interface, namespace, name string, applyUpdate UpdateExtensionsReplicaSetFunc, logf LogfFn, pollInterval, pollTimeout time.Duration) (*extensions.ReplicaSet, error) {
|
||||
var rs *extensions.ReplicaSet
|
||||
func UpdateReplicaSetStatusWithRetries(c clientset.Interface, namespace, name string, applyUpdate UpdateReplicaSetFunc, logf LogfFn, pollInterval, pollTimeout time.Duration) (*apps.ReplicaSet, error) {
|
||||
var rs *apps.ReplicaSet
|
||||
var updateErr error
|
||||
pollErr := wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
|
||||
var err error
|
||||
if rs, err = c.ExtensionsV1beta1().ReplicaSets(namespace).Get(name, metav1.GetOptions{}); err != nil {
|
||||
if rs, err = c.AppsV1().ReplicaSets(namespace).Get(name, metav1.GetOptions{}); err != nil {
|
||||
return false, err
|
||||
}
|
||||
// Apply the update, then attempt to push it to the apiserver.
|
||||
applyUpdate(rs)
|
||||
if rs, err = c.ExtensionsV1beta1().ReplicaSets(namespace).UpdateStatus(rs); err == nil {
|
||||
if rs, err = c.AppsV1().ReplicaSets(namespace).UpdateStatus(rs); err == nil {
|
||||
logf("Updating replica set %q", name)
|
||||
return true, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user