Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e: use controller.GuaranteedUpdate to retry on version conflict (#1522) #1564

Merged
merged 1 commit into from
Jan 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions tests/e2e/tidbcluster/serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import (
asclientset "github.com/pingcap/advanced-statefulset/pkg/client/clientset/versioned"
"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/client/clientset/versioned"
"github.com/pingcap/tidb-operator/pkg/controller"
"github.com/pingcap/tidb-operator/pkg/label"
"github.com/pingcap/tidb-operator/pkg/scheme"
"github.com/pingcap/tidb-operator/tests"
e2econfig "github.com/pingcap/tidb-operator/tests/e2e/config"
utilimage "github.com/pingcap/tidb-operator/tests/e2e/util/image"
Expand All @@ -46,6 +48,7 @@ import (
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
e2esset "k8s.io/kubernetes/test/e2e/framework/statefulset"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func mustToString(set sets.Int32) string {
Expand Down Expand Up @@ -105,6 +108,7 @@ var _ = ginkgo.Describe("[tidb-operator][Serial]", func() {
ginkgo.Context("[Feature: AdvancedStatefulSet]", func() {
var ocfg *tests.OperatorConfig
var oa tests.OperatorActions
var genericCli client.Client

ginkgo.BeforeEach(func() {
ocfg = &tests.OperatorConfig{
Expand All @@ -128,6 +132,9 @@ var _ = ginkgo.Describe("[tidb-operator][Serial]", func() {
ginkgo.By("Installing tidb-operator")
oa.CleanOperatorOrDie(ocfg)
oa.DeployOperatorOrDie(ocfg)
var err error
genericCli, err = client.New(config, client.Options{Scheme: scheme.Scheme})
framework.ExpectNoError(err, "failed to create clientset")
})

ginkgo.AfterEach(func() {
Expand Down Expand Up @@ -221,22 +228,24 @@ var _ = ginkgo.Describe("[tidb-operator][Serial]", func() {
ginkgo.By(fmt.Sprintf("Scaling sts %s/%s to replicas %d and setting deleting pods to %v (old replicas: %d, old delete slots: %v)", ns, stsName, replicas, st.deleteSlots.List(), *sts.Spec.Replicas, helper.GetDeleteSlots(sts).List()))
tc, err := cli.PingcapV1alpha1().TidbClusters(ns).Get(clusterName, metav1.GetOptions{})
framework.ExpectNoError(err)
if tc.Annotations == nil {
tc.Annotations = map[string]string{}
}
if st.component == "tikv" {
tc.Annotations[label.AnnTiKVDeleteSlots] = mustToString(st.deleteSlots)
tc.Spec.TiKV.Replicas = replicas
} else if st.component == "pd" {
tc.Annotations[label.AnnPDDeleteSlots] = mustToString(st.deleteSlots)
tc.Spec.PD.Replicas = replicas
} else if st.component == "tidb" {
tc.Annotations[label.AnnTiDBDeleteSlots] = mustToString(st.deleteSlots)
tc.Spec.TiDB.Replicas = replicas
} else {
framework.Failf("unsupported component: %v", st.component)
}
tc, err = cli.PingcapV1alpha1().TidbClusters(ns).Update(tc)
err = controller.GuaranteedUpdate(genericCli, tc, func() error {
if tc.Annotations == nil {
tc.Annotations = map[string]string{}
}
if st.component == "tikv" {
tc.Annotations[label.AnnTiKVDeleteSlots] = mustToString(st.deleteSlots)
tc.Spec.TiKV.Replicas = replicas
} else if st.component == "pd" {
tc.Annotations[label.AnnPDDeleteSlots] = mustToString(st.deleteSlots)
tc.Spec.PD.Replicas = replicas
} else if st.component == "tidb" {
tc.Annotations[label.AnnTiDBDeleteSlots] = mustToString(st.deleteSlots)
tc.Spec.TiDB.Replicas = replicas
} else {
return fmt.Errorf("unsupported component: %v", st.component)
}
return nil
})
framework.ExpectNoError(err)

ginkgo.By(fmt.Sprintf("Waiting for all pods of tidb cluster component %s (sts: %s/%s) are in desired state (replicas: %d, delete slots: %v)", st.component, ns, stsName, st.replicas, st.deleteSlots.List()))
Expand Down