From 4b717f9a0ed341163f4891f3007f990f658262d3 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 11 一月 2024 20:12:14 +0800
Subject: [PATCH] 创建clusterIP service

---
 src/k8s/create.go |   63 ++++++++++++++-----------------
 1 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/src/k8s/create.go b/src/k8s/create.go
index 6388990..b08e0d9 100644
--- a/src/k8s/create.go
+++ b/src/k8s/create.go
@@ -48,6 +48,8 @@
 	ALHost         string                // 绠楁硶Host
 	Host           string                // 鏈嶅姟Host
 	NodeID         string                // Nsq鑺傜偣ID
+	HttpNodePort   int32                 // HTTP nodePort绔彛
+	RpcNodePort    int32                 // RPC nodePort绔彛
 }
 
 func create_test() {
@@ -298,7 +300,7 @@
 		return err
 	}
 
-	config.HttpPort, config.RpcPort, err = getTwoNodePort(config.Client)
+	config.HttpNodePort, config.RpcNodePort, err = getTwoNodePort(config.Client)
 	if err != nil {
 		return err
 	}
@@ -327,12 +329,13 @@
 		},
 		{
 			Name: "DB_HOST",
-			ValueFrom: &apiv1.EnvVarSource{
-				FieldRef: &apiv1.ObjectFieldSelector{
-					APIVersion: "v1",
-					FieldPath:  "status.hostIP",
-				},
-			},
+			//ValueFrom: &apiv1.EnvVarSource{
+			//	FieldRef: &apiv1.ObjectFieldSelector{
+			//		APIVersion: "v1",
+			//		FieldPath:  "status.hostIP",
+			//	},
+			//},
+			Value: config.DBHost,
 		},
 		{
 			Name: "HOST",
@@ -342,6 +345,18 @@
 					FieldPath:  "status.hostIP",
 				},
 			},
+		},
+		{
+			Name:  "AL_HOST",
+			Value: config.ALHost,
+		},
+		{
+			Name:  "GRPC_NODE_PORT",
+			Value: strconv.Itoa(int(config.RpcNodePort)),
+		},
+		{
+			Name:  "NODE_ID",
+			Value: config.NodeID,
 		},
 		{
 			Name:  "DB_NAME",
@@ -361,28 +376,6 @@
 		},
 	}
 
-	if config.ALHost != "" {
-		envs = append(envs, apiv1.EnvVar{
-			Name:  "AL_HOST",
-			Value: config.ALHost,
-		})
-	}
-
-	if config.NodeID != "" {
-		envs = append(envs, apiv1.EnvVar{
-			Name:  "NODE_ID",
-			Value: config.NodeID,
-		})
-	}
-
-	if len(pairs) > 0 {
-		for name, value := range pairs {
-			envs = append(envs, apiv1.EnvVar{
-				Name:  name,
-				Value: value,
-			})
-		}
-	}
 	for name, value := range pairs {
 		envs = append(envs, apiv1.EnvVar{
 			Name:  name,
@@ -468,16 +461,16 @@
 				{
 					Name:       "http",
 					Protocol:   apiv1.ProtocolTCP,
-					Port:       port,                      // 闆嗙兢鍐呴儴璁块棶绔彛
-					TargetPort: intstr.FromInt(int(port)), // 瀹瑰櫒瀵瑰绔彛
-					NodePort:   config.HttpPort,           // 澶栭儴璁块棶绔彛
+					Port:       config.HttpPort,                      // 闆嗙兢鍐呴儴璁块棶绔彛
+					TargetPort: intstr.FromInt(int(config.HttpPort)), // 瀹瑰櫒瀵瑰绔彛
+					NodePort:   config.HttpNodePort,                  // 澶栭儴璁块棶绔彛
 				},
 				{
 					Name:       "tcp",
 					Protocol:   apiv1.ProtocolTCP,
-					Port:       rpcPort,
-					TargetPort: intstr.FromInt(int(rpcPort)),
-					NodePort:   config.RpcPort,
+					Port:       config.RpcPort,
+					TargetPort: intstr.FromInt(int(config.RpcPort)),
+					NodePort:   config.RpcNodePort,
 				},
 			},
 			SessionAffinity: apiv1.ServiceAffinityClientIP,

--
Gitblit v1.8.0