-
Notifications
You must be signed in to change notification settings - Fork 495
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
Fix service update which would changed the nodeport #2284
Changes from 9 commits
2ceba12
2c4f472
bdcb729
5244fd6
eb46821
09c0b4a
425006c
9b3b621
b627042
79ff420
9064254
0ba603f
4130cfa
a933c40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -528,6 +528,92 @@ var _ = ginkgo.Describe("[tidb-operator] TiDBCluster", func() { | |
}) | ||
|
||
framework.ExpectNoError(err) | ||
|
||
// Create TidbCluster with NodePort to check whether node port would change | ||
nodeTc := fixture.GetTidbCluster(ns, "nodeport", utilimage.TiDBV3Version) | ||
nodeTc.Spec.PD.Replicas = 1 | ||
nodeTc.Spec.TiKV.Replicas = 1 | ||
nodeTc.Spec.TiDB.Replicas = 1 | ||
nodeTc.Spec.TiDB.Service = &v1alpha1.TiDBServiceSpec{ | ||
ServiceSpec: v1alpha1.ServiceSpec{ | ||
Type: corev1.ServiceTypeNodePort, | ||
}, | ||
} | ||
err = genericCli.Create(context.TODO(), nodeTc) | ||
framework.ExpectNoError(err, "Expected TiDB cluster created") | ||
err = oa.WaitForTidbClusterReady(tc, 30*time.Minute, 15*time.Second) | ||
framework.ExpectNoError(err, "Expected TiDB cluster ready") | ||
|
||
var s *corev1.Service | ||
err = wait.Poll(5*time.Second, 5*time.Minute, func() (done bool, err error) { | ||
s, err = c.CoreV1().Services(ns).Get("nodeport-tidb", metav1.GetOptions{}) | ||
if err != nil { | ||
klog.Errorf(err.Error()) | ||
return false, nil | ||
} | ||
if s.Spec.Type != corev1.ServiceTypeNodePort { | ||
return false, fmt.Errorf("nodePort tidbcluster tidb service type isn't NodePort") | ||
} | ||
return true, nil | ||
}) | ||
framework.ExpectNoError(err) | ||
ports := s.Spec.Ports | ||
|
||
// check node port unchanged for 5mins | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update some attributes of the service and then check no change for nodeport? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
err = wait.Poll(5*time.Second, 5*time.Minute, func() (done bool, err error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1 minute IMO is enough because our reconciliation period is 30 seconds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
s, err := c.CoreV1().Services(ns).Get("nodeport-tidb", metav1.GetOptions{}) | ||
if err != nil { | ||
klog.Errorf(err.Error()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, you can return these errors in this wait function. this will make this function shorter and errors will be printed if the test fails because what you expect is |
||
return true, nil | ||
} | ||
if s.Spec.Type != corev1.ServiceTypeNodePort { | ||
klog.Error("nodePort tidbcluster tidb service type isn't NodePort") | ||
return true, nil | ||
} | ||
for _, dport := range s.Spec.Ports { | ||
for _, eport := range ports { | ||
if dport.Port == eport.Port && dport.NodePort != eport.NodePort { | ||
klog.Error("nodePort tidbcluster tidb service NodePort changed") | ||
return true, nil | ||
} | ||
} | ||
} | ||
return false, nil | ||
}) | ||
framework.ExpectError(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, you can return these errors in this wait function. this will make this function shorter and errors will be printed if the test fails because what you expect is |
||
klog.Info("nodePort tidbcluster tidb service NodePort haven't changed") | ||
|
||
tc, err = cli.PingcapV1alpha1().TidbClusters(ns).Get("nodeport", metav1.GetOptions{}) | ||
framework.ExpectNoError(err) | ||
tc.Spec.TiDB.Service.Annotations = map[string]string{ | ||
"foo": "bar", | ||
} | ||
_, err = cli.PingcapV1alpha1().TidbClusters(ns).Update(tc) | ||
framework.ExpectNoError(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use previous
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated. |
||
|
||
err = wait.Poll(5*time.Second, 5*time.Minute, func() (done bool, err error) { | ||
s, err = c.CoreV1().Services(ns).Get("nodeport-tidb", metav1.GetOptions{}) | ||
if err != nil { | ||
return false, nil | ||
} | ||
if s.Annotations == nil { | ||
return false, nil | ||
} | ||
v, ok := s.Annotations["foo"] | ||
if !ok || v != "bar" { | ||
return false, nil | ||
} | ||
for _, oport := range ports { | ||
for _, eport := range s.Spec.Ports { | ||
if oport.Port == eport.Port && oport.Protocol == eport.Protocol && oport.NodePort != eport.NodePort { | ||
return false, fmt.Errorf("node port has been changed") | ||
} | ||
} | ||
} | ||
return true, nil | ||
}) | ||
framework.ExpectNoError(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should wait for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated. |
||
klog.Info("nodePort tidbcluster tidb service NodePort haven't changed after update") | ||
}) | ||
|
||
updateStrategy := v1alpha1.ConfigUpdateStrategyInPlace | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to use
framework.Logf
which writes to ginkgo writer and the logs can be printed into ginkgo test report if failed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.