add replicaset upgrade test
This commit is contained in:
@@ -18,16 +18,14 @@ package framework
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||
deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
|
||||
testutils "k8s.io/kubernetes/test/utils"
|
||||
)
|
||||
@@ -57,48 +55,7 @@ func CheckNewRSAnnotations(c clientset.Interface, ns, deploymentName string, exp
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete a ReplicaSet and all pods it spawned
|
||||
func DeleteReplicaSet(clientset clientset.Interface, internalClientset internalclientset.Interface, ns, name string) error {
|
||||
By(fmt.Sprintf("deleting ReplicaSet %s in namespace %s", name, ns))
|
||||
rs, err := clientset.Extensions().ReplicaSets(ns).Get(name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if apierrs.IsNotFound(err) {
|
||||
Logf("ReplicaSet %s was already deleted: %v", name, err)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
startTime := time.Now()
|
||||
err = clientset.ExtensionsV1beta1().ReplicaSets(ns).Delete(name, &metav1.DeleteOptions{})
|
||||
if apierrs.IsNotFound(err) {
|
||||
Logf("ReplicaSet %s was already deleted: %v", name, err)
|
||||
return nil
|
||||
}
|
||||
deleteRSTime := time.Now().Sub(startTime)
|
||||
Logf("Deleting RS %s took: %v", name, deleteRSTime)
|
||||
if err == nil {
|
||||
err = waitForReplicaSetPodsGone(clientset, rs)
|
||||
}
|
||||
terminatePodTime := time.Now().Sub(startTime) - deleteRSTime
|
||||
Logf("Terminating ReplicaSet %s pods took: %v", name, terminatePodTime)
|
||||
return err
|
||||
}
|
||||
|
||||
// waitForReplicaSetPodsGone waits until there are no pods reported under a
|
||||
// ReplicaSet selector (because the pods have completed termination).
|
||||
func waitForReplicaSetPodsGone(c clientset.Interface, rs *extensions.ReplicaSet) error {
|
||||
return wait.PollImmediate(Poll, 2*time.Minute, func() (bool, error) {
|
||||
selector, err := metav1.LabelSelectorAsSelector(rs.Spec.Selector)
|
||||
ExpectNoError(err)
|
||||
options := metav1.ListOptions{LabelSelector: selector.String()}
|
||||
if pods, err := c.Core().Pods(rs.Namespace).List(options); err == nil && len(pods.Items) == 0 {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
}
|
||||
|
||||
// WaitForReadyReplicaSet waits until the replica set has all of its replicas ready.
|
||||
// WaitForReadyReplicaSet waits until the replicaset has all of its replicas ready.
|
||||
func WaitForReadyReplicaSet(c clientset.Interface, ns, name string) error {
|
||||
err := wait.Poll(Poll, pollShortTimeout, func() (bool, error) {
|
||||
rs, err := c.Extensions().ReplicaSets(ns).Get(name, metav1.GetOptions{})
|
||||
@@ -108,7 +65,7 @@ func WaitForReadyReplicaSet(c clientset.Interface, ns, name string) error {
|
||||
return *(rs.Spec.Replicas) == rs.Status.Replicas && *(rs.Spec.Replicas) == rs.Status.ReadyReplicas, nil
|
||||
})
|
||||
if err == wait.ErrWaitTimeout {
|
||||
err = fmt.Errorf("replica set %q never became ready", name)
|
||||
err = fmt.Errorf("replicaset %q never became ready", name)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -119,3 +76,35 @@ func RunReplicaSet(config testutils.ReplicaSetConfig) error {
|
||||
config.ContainerDumpFunc = LogFailedContainers
|
||||
return testutils.RunReplicaSet(config)
|
||||
}
|
||||
|
||||
func NewReplicaSet(name, namespace string, replicas int32, podLabels map[string]string, imageName, image string) *extensions.ReplicaSet {
|
||||
return &extensions.ReplicaSet{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "ReplicaSet",
|
||||
APIVersion: "extensions/v1beta1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: namespace,
|
||||
Name: name,
|
||||
},
|
||||
Spec: extensions.ReplicaSetSpec{
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: podLabels,
|
||||
},
|
||||
Replicas: &replicas,
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: podLabels,
|
||||
},
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Name: imageName,
|
||||
Image: image,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user