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: add retry logic for LabelNodes function #735

Merged
merged 4 commits into from
Aug 12, 2019
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
24 changes: 18 additions & 6 deletions tests/dt.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (
"time"

"github.com/golang/glog"

"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/tidb-operator/pkg/label"
"github.com/pingcap/tidb-operator/tests/slack"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/wait"
)

const (
Expand Down Expand Up @@ -67,12 +67,24 @@ func (oa *operatorActions) LabelNodes() error {
}

for i, node := range nodes.Items {
index := i % RackNum
node.Labels[RackLabel] = fmt.Sprintf("rack%d", index)
_, err = oa.kubeCli.CoreV1().Nodes().Update(&node)
err := wait.Poll(3*time.Second, time.Minute, func() (bool, error) {
n, err := oa.kubeCli.CoreV1().Nodes().Get(node.Name, metav1.GetOptions{})
if err != nil {
glog.Errorf("get node:[%s] failed! error: %v", node.Name, err)
return false, nil
}
index := i % RackNum
n.Labels[RackLabel] = fmt.Sprintf("rack%d", index)
_, err = oa.kubeCli.CoreV1().Nodes().Update(n)
if err != nil {
glog.Errorf("label node:[%s] failed! error: %v", node.Name, err)
return false, nil
}
return true, nil
})

if err != nil {
glog.Errorf("label node:[%s] failed!", node.Name)
return err
return fmt.Errorf("label nodes failed, error: %v", err)
}
}
return nil
Expand Down