This is an automated email from the ASF dual-hosted git repository.
leizhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-seata-k8s.git
The following commit(s) were added to refs/heads/master by this push:
new 3775b03 optimize: wait to start until hostname allocated (#13)
3775b03 is described below
commit 3775b0372770546bb9db930797e6831c85a7c4a4
Author: Xiangkun Yin <[email protected]>
AuthorDate: Thu Jan 25 17:46:52 2024 +0800
optimize: wait to start until hostname allocated (#13)
---
controllers/stateful_set.go | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/controllers/stateful_set.go b/controllers/stateful_set.go
index 0c1b340..686a86a 100644
--- a/controllers/stateful_set.go
+++ b/controllers/stateful_set.go
@@ -63,6 +63,22 @@ func initStatefulSet(s *seatav1alpha1.SeataServer)
*appsv1.StatefulSet {
return statefulSet
}
+const PythonScript = `
+import time
+import socket
+
+print('Waiting $SEATA_IP to be resolved...')
+while True:
+ try:
+ ip = socket.gethostbyname('$SEATA_IP')
+ print('Resolve $SEATA_IP to', ip)
+ except:
+ print('Cannot resolve $SEATA_IP, wait 2 seconds', flush=True)
+ time.sleep(2)
+ continue
+ exit(0)
+`
+
func updateStatefulSet(ctx context.Context, statefulSet *appsv1.StatefulSet, s
*seatav1alpha1.SeataServer) {
logger := log.FromContext(ctx)
var envs []apiv1.EnvVar
@@ -85,10 +101,9 @@ func updateStatefulSet(ctx context.Context, statefulSet
*appsv1.StatefulSet, s *
},
Args: []string{
"-c",
- fmt.Sprintf(
- "export SEATA_IP=$(HOST_NAME).%s; /bin/bash
/seata-server-entrypoint.sh;",
- s.Spec.ServiceName,
- ),
+ fmt.Sprintf("export SEATA_IP=$(HOST_NAME).%s;",
s.Spec.ServiceName) +
+ fmt.Sprintf("python3 -c \"\n%s\n\";",
PythonScript) +
+ "/bin/bash /seata-server-entrypoint.sh;",
},
Ports: []apiv1.ContainerPort{
{Name: "service-port", ContainerPort:
s.Spec.Ports.ServicePort},
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]