mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 02:43:36 +00:00
vendor update for CSI 0.3.0
This commit is contained in:
3
vendor/k8s.io/kubernetes/test/integration/deployment/BUILD
generated
vendored
3
vendor/k8s.io/kubernetes/test/integration/deployment/BUILD
generated
vendored
@ -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",
|
||||
|
293
vendor/k8s.io/kubernetes/test/integration/deployment/deployment_test.go
generated
vendored
293
vendor/k8s.io/kubernetes/test/integration/deployment/deployment_test.go
generated
vendored
@ -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)
|
||||
}
|
||||
@ -81,6 +81,32 @@ func TestNewDeployment(t *testing.T) {
|
||||
if newRS.Annotations[v1.LastAppliedConfigAnnotation] != "" {
|
||||
t.Errorf("expected new ReplicaSet last-applied annotation not copied from Deployment %s", tester.deployment.Name)
|
||||
}
|
||||
|
||||
// New RS should contain pod-template-hash in its selector, label, and template label
|
||||
rsHash, err := checkRSHashLabels(newRS)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// All pods targeted by the deployment should contain pod-template-hash in their labels
|
||||
selector, err := metav1.LabelSelectorAsSelector(tester.deployment.Spec.Selector)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse deployment %s selector: %v", name, err)
|
||||
}
|
||||
pods, err := c.CoreV1().Pods(ns.Name).List(metav1.ListOptions{LabelSelector: selector.String()})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to list pods of deployment %s: %v", name, err)
|
||||
}
|
||||
if len(pods.Items) != int(replicas) {
|
||||
t.Errorf("expected %d pods, got %d pods", replicas, len(pods.Items))
|
||||
}
|
||||
podHash, err := checkPodsHashLabel(pods)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if rsHash != podHash {
|
||||
t.Errorf("found mismatching pod-template-hash value: rs hash = %s whereas pod hash = %s", rsHash, podHash)
|
||||
}
|
||||
}
|
||||
|
||||
// Deployments should support roll out, roll back, and roll over
|
||||
@ -102,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)
|
||||
}
|
||||
@ -126,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)
|
||||
@ -160,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)
|
||||
@ -173,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)
|
||||
@ -186,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)
|
||||
}
|
||||
@ -206,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)
|
||||
@ -257,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
|
||||
@ -274,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)
|
||||
}
|
||||
@ -332,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 {
|
||||
@ -349,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)
|
||||
}
|
||||
@ -375,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)
|
||||
}
|
||||
@ -416,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 {
|
||||
@ -456,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)
|
||||
}
|
||||
@ -474,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 {
|
||||
@ -490,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
|
||||
}
|
||||
@ -520,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)
|
||||
}
|
||||
@ -528,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)
|
||||
}
|
||||
|
||||
@ -569,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
|
||||
})
|
||||
@ -618,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)
|
||||
@ -639,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)
|
||||
}
|
||||
@ -654,104 +705,6 @@ func checkPodsHashLabel(pods *v1.PodList) (string, error) {
|
||||
return hash, nil
|
||||
}
|
||||
|
||||
// Deployment should label adopted ReplicaSets and Pods.
|
||||
func TestDeploymentLabelAdopted(t *testing.T) {
|
||||
s, closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
defer closeFn()
|
||||
name := "test-adopted-deployment"
|
||||
ns := framework.CreateTestingNamespace(name, s, t)
|
||||
defer framework.DeleteTestingNamespace(ns, s, t)
|
||||
|
||||
// Start informer and controllers
|
||||
stopCh := make(chan struct{})
|
||||
defer close(stopCh)
|
||||
informers.Start(stopCh)
|
||||
go rm.Run(5, stopCh)
|
||||
go dc.Run(5, stopCh)
|
||||
|
||||
// Create a RS to be adopted by the deployment.
|
||||
rsName := "test-adopted-controller"
|
||||
replicas := int32(1)
|
||||
rs := newReplicaSet(rsName, ns.Name, replicas)
|
||||
_, err := c.ExtensionsV1beta1().ReplicaSets(ns.Name).Create(rs)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create replicaset %s: %v", rsName, err)
|
||||
}
|
||||
// Mark RS pods as ready.
|
||||
selector, err := metav1.LabelSelectorAsSelector(rs.Spec.Selector)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse replicaset %s selector: %v", rsName, err)
|
||||
}
|
||||
if err = wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
|
||||
pods, err := c.CoreV1().Pods(ns.Name).List(metav1.ListOptions{LabelSelector: selector.String()})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(pods.Items) != int(replicas) {
|
||||
return false, nil
|
||||
}
|
||||
for _, pod := range pods.Items {
|
||||
if err = markPodReady(c, ns.Name, &pod); err != nil {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}); err != nil {
|
||||
t.Fatalf("failed to mark pods replicaset %s as ready: %v", rsName, err)
|
||||
}
|
||||
|
||||
// Create a Deployment to adopt the old rs.
|
||||
tester := &deploymentTester{t: t, c: c, deployment: newDeployment(name, ns.Name, replicas)}
|
||||
if tester.deployment, err = c.ExtensionsV1beta1().Deployments(ns.Name).Create(tester.deployment); err != nil {
|
||||
t.Fatalf("failed to create deployment %s: %v", tester.deployment.Name, err)
|
||||
}
|
||||
|
||||
// Wait for the Deployment to be updated to revision 1
|
||||
if err = tester.waitForDeploymentRevisionAndImage("1", fakeImage); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// The RS and pods should be relabeled after the Deployment finishes adopting it and completes.
|
||||
if err := tester.waitForDeploymentComplete(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// There should be no old RSes (overlapping RS)
|
||||
oldRSs, allOldRSs, newRS, err := deploymentutil.GetAllReplicaSets(tester.deployment, c.ExtensionsV1beta1())
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get all replicasets owned by deployment %s: %v", name, err)
|
||||
}
|
||||
if len(oldRSs) != 0 || len(allOldRSs) != 0 {
|
||||
t.Errorf("expected deployment to have no old replicasets, got %d old replicasets", len(allOldRSs))
|
||||
}
|
||||
|
||||
// New RS should be relabeled, i.e. contain pod-template-hash in its selector, label, and template label
|
||||
rsHash, err := checkRSHashLabels(newRS)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// All pods targeted by the deployment should contain pod-template-hash in their labels, and there should be only 3 pods
|
||||
selector, err = metav1.LabelSelectorAsSelector(tester.deployment.Spec.Selector)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse deployment %s selector: %v", name, err)
|
||||
}
|
||||
pods, err := c.CoreV1().Pods(ns.Name).List(metav1.ListOptions{LabelSelector: selector.String()})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to list pods of deployment %s: %v", name, err)
|
||||
}
|
||||
if len(pods.Items) != int(replicas) {
|
||||
t.Errorf("expected %d pods, got %d pods", replicas, len(pods.Items))
|
||||
}
|
||||
podHash, err := checkPodsHashLabel(pods)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if rsHash != podHash {
|
||||
t.Errorf("found mismatching pod-template-hash value: rs hash = %s whereas pod hash = %s", rsHash, podHash)
|
||||
}
|
||||
}
|
||||
|
||||
// Deployment should have a timeout condition when it fails to progress after given deadline.
|
||||
func TestFailedDeployment(t *testing.T) {
|
||||
s, closeFn, rm, dc, informers, c := dcSetup(t)
|
||||
@ -766,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)
|
||||
}
|
||||
@ -784,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)
|
||||
}
|
||||
|
||||
@ -794,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)
|
||||
}
|
||||
}
|
||||
@ -822,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)
|
||||
@ -856,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 {
|
||||
@ -870,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)
|
||||
}
|
||||
@ -900,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)
|
||||
}
|
||||
@ -919,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 {
|
||||
@ -930,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)
|
||||
}
|
||||
@ -940,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)
|
||||
}
|
||||
@ -960,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
|
||||
})
|
||||
@ -975,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)
|
||||
}
|
||||
@ -996,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 {
|
||||
@ -1007,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)
|
||||
}
|
||||
@ -1017,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)
|
||||
}
|
||||
@ -1037,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
|
||||
})
|
||||
@ -1052,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)
|
||||
}
|
||||
@ -1082,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)
|
||||
}
|
||||
@ -1111,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)
|
||||
})
|
||||
@ -1140,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)
|
||||
}
|
||||
@ -1159,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)
|
||||
}
|
||||
|
||||
@ -1179,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)
|
||||
}
|
||||
|
||||
@ -1189,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 {
|
||||
@ -1202,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)
|
||||
}
|
||||
|
||||
@ -1213,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 {
|
||||
@ -1258,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)
|
||||
}
|
||||
@ -1281,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)
|
||||
}
|
||||
@ -1305,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)
|
||||
@ -1352,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)
|
||||
}
|
||||
@ -1396,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)
|
||||
}
|
||||
@ -1421,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)
|
||||
}
|
||||
@ -1440,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 {
|
||||
@ -1448,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 {
|
||||
@ -1462,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)
|
||||
}
|
||||
@ -1479,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 {
|
||||
|
73
vendor/k8s.io/kubernetes/test/integration/deployment/util.go
generated
vendored
73
vendor/k8s.io/kubernetes/test/integration/deployment/util.go
generated
vendored
@ -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")),
|
||||
)
|
||||
@ -165,7 +167,7 @@ func dcSetup(t *testing.T) (*httptest.Server, framework.CloseFunc, *replicaset.R
|
||||
t.Fatalf("error creating Deployment controller: %v", err)
|
||||
}
|
||||
rm := replicaset.NewReplicaSetController(
|
||||
informers.Extensions().V1beta1().ReplicaSets(),
|
||||
informers.Apps().V1().ReplicaSets(),
|
||||
informers.Core().V1().Pods(),
|
||||
clientset.NewForConfigOrDie(restclient.AddUserAgent(&config, "replicaset-controller")),
|
||||
replicaset.BurstReplicas,
|
||||
@ -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,11 +365,11 @@ func (d *deploymentTester) expectNewReplicaSet() (*v1beta1.ReplicaSet, error) {
|
||||
return rs, nil
|
||||
}
|
||||
|
||||
func (d *deploymentTester) updateReplicaSet(name string, applyUpdate testutil.UpdateReplicaSetFunc) (*v1beta1.ReplicaSet, error) {
|
||||
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.UpdateReplicaSetFunc) (*v1beta1.ReplicaSet, error) {
|
||||
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)
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user