diff --git a/tests/actions.go b/tests/actions.go index e3389f5055e..4ecfd0ffbaa 100644 --- a/tests/actions.go +++ b/tests/actions.go @@ -26,6 +26,7 @@ import ( "os/exec" "path/filepath" "reflect" + "sort" "strconv" "strings" "sync" @@ -457,6 +458,15 @@ func (oa *operatorActions) CleanOperatorOrDie(info *OperatorConfig) { func (oa *operatorActions) UpgradeOperator(info *OperatorConfig) error { glog.Infof("upgrading tidb-operator %s", info.ReleaseName) + + listOptions := metav1.ListOptions{ + LabelSelector: labels.SelectorFromSet( + label.New().Labels()).String(), + } + pods1, err := oa.kubeCli.CoreV1().Pods(metav1.NamespaceAll).List(listOptions) + if err != nil { + return err + } if err := oa.checkoutTag(info.Tag); err != nil { return err } @@ -469,7 +479,38 @@ func (oa *operatorActions) UpgradeOperator(info *OperatorConfig) error { if err != nil { return fmt.Errorf("failed to upgrade operator to: %s, %v, %s", info.Image, err, string(res)) } - return nil + + time.Sleep(5 * time.Minute) + pods2, err := oa.kubeCli.CoreV1().Pods(metav1.NamespaceAll).List(listOptions) + if err != nil { + return err + } + + return ensurePodsUnchanged(pods1, pods2) +} + +func ensurePodsUnchanged(pods1, pods2 *corev1.PodList) error { + if reflect.DeepEqual(getUID(pods1), getUID(pods2)) { + glog.V(4).Infof("%#v", pods1) + glog.V(4).Infof("%#v", pods2) + glog.V(4).Infof("pods unchanged after operator upgraded") + return nil + } + + glog.Infof("%#v", pods1) + glog.Infof("%#v", pods2) + return fmt.Errorf("some pods changed after operator upgraded") +} + +func getUID(pods *corev1.PodList) []string { + arr := make([]string, 0, len(pods.Items)) + + for _, pod := range pods.Items { + arr = append(arr, string(pod.UID)) + } + + sort.Strings(arr) + return arr } func (oa *operatorActions) UpgradeOperatorOrDie(info *OperatorConfig) { @@ -601,24 +642,34 @@ func (oa *operatorActions) CleanTidbCluster(info *TidbClusterConfig) error { afterPVCNames = append(afterPVCNames, pvc.GetName()) } glog.V(4).Info(afterPVCNames) - - pvList, err = oa.kubeCli.CoreV1().PersistentVolumes().List(metav1.ListOptions{LabelSelector: selector.String()}) - if err != nil { - return err - } - var afterPVNames []string - for _, pv := range pvList.Items { - afterPVNames = append(afterPVNames, pv.GetName()) - } - glog.V(4).Info(afterPVNames) - if !reflect.DeepEqual(beforePVCNames, afterPVCNames) { return fmt.Errorf("pvc changed when we delete cluster: %s/%s, before: %v, after: %v", ns, tcName, beforePVCNames, afterPVCNames) } - if !reflect.DeepEqual(beforePVNames, afterPVNames) { - return fmt.Errorf("pv changed when we delete cluster: %s/%s, before: %v, after: %v", - ns, tcName, beforePVNames, afterPVNames) + + waitPVFn := func() (done bool, err error) { + pvList, err = oa.kubeCli.CoreV1().PersistentVolumes().List(metav1.ListOptions{LabelSelector: selector.String()}) + if err != nil { + return false, nil + } + var afterPVNames []string + for _, pv := range pvList.Items { + afterPVNames = append(afterPVNames, pv.GetName()) + } + glog.V(4).Info(afterPVNames) + + if !reflect.DeepEqual(beforePVNames, afterPVNames) { + glog.Errorf("pv changed when we delete cluster: %s/%s, before: %v, after: %v", + ns, tcName, beforePVNames, afterPVNames) + return false, nil + } + + return true, nil + } + + err = wait.Poll(oa.pollInterval, DefaultPollTimeout, waitPVFn) + if err != nil { + return err } err = oa.kubeCli.CoreV1().Pods(info.Namespace).Delete(getBackupDirPodName, &metav1.DeleteOptions{}) diff --git a/tests/cluster_info.go b/tests/cluster_info.go index 5075f5cfc27..36da5473b2e 100644 --- a/tests/cluster_info.go +++ b/tests/cluster_info.go @@ -148,6 +148,6 @@ func (tc *TidbClusterConfig) BuildSubValues(path string) (string, error) { if err != nil { return "", err } - glog.Infof("subValues:\n %s", subValues) + glog.V(4).Infof("subValues:\n %s", subValues) return subVaulesPath, nil } diff --git a/tests/cmd/stability/main.go b/tests/cmd/stability/main.go index d801f1a1417..74d951d2494 100644 --- a/tests/cmd/stability/main.go +++ b/tests/cmd/stability/main.go @@ -318,7 +318,6 @@ func run() { ocfg.Image = cfg.UpgradeOperatorImage ocfg.Tag = cfg.UpgradeOperatorTag oa.UpgradeOperatorOrDie(ocfg) - time.Sleep(5 * time.Minute) postUpgrade := []*tests.TidbClusterConfig{ cluster3, cluster1,