Skip to content

Commit ec74bee

Browse files
authored
refactor: use pod ip instead of service name to make it consistent (#335)
1 parent e53b240 commit ec74bee

File tree

5 files changed

+19
-42
lines changed

5 files changed

+19
-42
lines changed

cmd/initializer/internal/config_generator.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@ type Options struct {
3535
RoleKind string
3636

3737
// For generating config of datanode or flownode.
38-
RPCPort int32
39-
ServiceName string
40-
41-
// Note: It's Deprecated and will be removed soon. For generating config of datanode.
42-
DatanodeRPCPort int32
43-
DatanodeServiceName string
38+
RPCPort int32
4439

4540
// DatanodeGroupID is the id of the datanode group when use `DatanodeGroups` in GreptimeDBCluster.
4641
DatanodeGroupID int32
@@ -117,22 +112,16 @@ func (c *ConfigGenerator) generateDatanodeConfig(initConfig []byte) ([]byte, err
117112
if len(podIP) == 0 {
118113
return nil, fmt.Errorf("empty pod ip")
119114
}
120-
datanodeCfg.RPCBindAddr = ptr.To(fmt.Sprintf("%s:%d", podIP, c.DatanodeRPCPort))
115+
datanodeCfg.RPCBindAddr = ptr.To(fmt.Sprintf("%s:%d", podIP, c.RPCPort))
121116

122117
podName := os.Getenv(deployer.EnvPodName)
123118
if len(podName) == 0 {
124119
return nil, fmt.Errorf("empty pod name")
125120
}
126121

127-
datanodeCfg.RPCServerAddr = ptr.To(fmt.Sprintf("%s.%s.%s:%d", podName,
128-
c.DatanodeServiceName, c.Namespace, c.DatanodeRPCPort))
122+
datanodeCfg.RPCServerAddr = ptr.To(fmt.Sprintf("%s:%d", podIP, c.RPCPort))
129123

130-
configData, err := dbconfig.Marshal(cfg, v1alpha1.ConfigMergeStrategyOperatorFirst)
131-
if err != nil {
132-
return nil, err
133-
}
134-
135-
return configData, nil
124+
return dbconfig.Marshal(cfg, v1alpha1.ConfigMergeStrategyOperatorFirst)
136125
}
137126

138127
func (c *ConfigGenerator) generateFlownodeConfig(initConfig []byte) ([]byte, error) {
@@ -167,8 +156,7 @@ func (c *ConfigGenerator) generateFlownodeConfig(initConfig []byte) ([]byte, err
167156
return nil, fmt.Errorf("empty pod name")
168157
}
169158

170-
flownodeCfg.RPCServerAddr = ptr.To(fmt.Sprintf("%s.%s.%s:%d", podName,
171-
c.ServiceName, c.Namespace, c.RPCPort))
159+
flownodeCfg.RPCServerAddr = ptr.To(fmt.Sprintf("%s:%d", podIP, c.RPCPort))
172160

173161
configData, err := dbconfig.Marshal(cfg, v1alpha1.ConfigMergeStrategyOperatorFirst)
174162
if err != nil {

cmd/initializer/internal/config_generator_test.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ func TestDatanodeConfigGenerator(t *testing.T) {
4646
defer file.Close()
4747

4848
opts := &Options{
49-
ConfigPath: file.Name(),
50-
InitConfigPath: "testdata/datanode-config.toml",
51-
Namespace: testClusterNamespace,
52-
RoleKind: string(v1alpha1.DatanodeRoleKind),
53-
DatanodeRPCPort: testRPCPort,
54-
DatanodeServiceName: testClusterService,
49+
ConfigPath: file.Name(),
50+
InitConfigPath: "testdata/datanode-config.toml",
51+
Namespace: testClusterNamespace,
52+
RoleKind: string(v1alpha1.DatanodeRoleKind),
53+
RPCPort: testRPCPort,
5554
}
5655

5756
t.Setenv(deployer.EnvPodIP, testPodIP)
@@ -93,7 +92,7 @@ func TestDatanodeConfigGenerator(t *testing.T) {
9392
if !ok {
9493
t.Fatalf("grpc server_addr is not string")
9594
}
96-
wantRPCServerAddr := fmt.Sprintf("%s.%s.%s:%d", testDatanodePodName, testClusterService, testClusterNamespace, testRPCPort)
95+
wantRPCServerAddr := fmt.Sprintf("%s:%d", testPodIP, testRPCPort)
9796
if !reflect.DeepEqual(wantRPCServerAddr, rpcServerAddr) {
9897
t.Fatalf("RPCServerAddr is not equal, want: '%s', got: '%s'", wantRPCServerAddr, rpcServerAddr)
9998
}
@@ -112,7 +111,6 @@ func TestFlownodeConfigGenerator(t *testing.T) {
112111
Namespace: testClusterNamespace,
113112
RoleKind: string(v1alpha1.FlownodeRoleKind),
114113
RPCPort: testRPCPort,
115-
ServiceName: testClusterService,
116114
}
117115

118116
t.Setenv(deployer.EnvPodIP, testPodIP)
@@ -154,7 +152,7 @@ func TestFlownodeConfigGenerator(t *testing.T) {
154152
if !ok {
155153
t.Fatalf("grpc server_addr is not string")
156154
}
157-
wantRPCServerAddr := fmt.Sprintf("%s.%s.%s:%d", testFlownodePodName, testClusterService, testClusterNamespace, testRPCPort)
155+
wantRPCServerAddr := fmt.Sprintf("%s:%d", testPodIP, testRPCPort)
158156
if !reflect.DeepEqual(wantRPCServerAddr, rpcServerAddr) {
159157
t.Fatalf("RPCServerAddr is not equal, want: '%s', got: '%s'", wantRPCServerAddr, rpcServerAddr)
160158
}
@@ -170,13 +168,12 @@ func TestDatanodeConfigGeneratorWithDatanodeGroupID(t *testing.T) {
170168
defer tmpConfigFile.Close()
171169

172170
opts := &Options{
173-
ConfigPath: tmpConfigFile.Name(),
174-
InitConfigPath: "testdata/datanode-config.toml",
175-
Namespace: testClusterNamespace,
176-
RoleKind: string(v1alpha1.DatanodeRoleKind),
177-
DatanodeRPCPort: testRPCPort,
178-
DatanodeServiceName: testClusterService,
179-
DatanodeGroupID: testDatanodeGroupID,
171+
ConfigPath: tmpConfigFile.Name(),
172+
InitConfigPath: "testdata/datanode-config.toml",
173+
Namespace: testClusterNamespace,
174+
RoleKind: string(v1alpha1.DatanodeRoleKind),
175+
RPCPort: testRPCPort,
176+
DatanodeGroupID: testDatanodeGroupID,
180177
}
181178

182179
t.Setenv(deployer.EnvPodIP, testPodIP)

cmd/initializer/main.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@ func main() {
2929

3030
pflag.StringVar(&opts.ConfigPath, "config-path", "/etc/greptimedb/config.toml", "the config path")
3131
pflag.StringVar(&opts.InitConfigPath, "init-config-path", "/etc/greptimedb/init-config.toml", "the init config path")
32-
pflag.StringVar(&opts.Namespace, "namespace", "", "the namespace of greptimedb cluster")
3332
pflag.StringVar(&opts.RoleKind, "component-kind", "", "the component kind")
3433

35-
pflag.StringVar(&opts.ServiceName, "service-name", "", "the name of service")
3634
pflag.Int32Var(&opts.RPCPort, "rpc-port", 4001, "the RPC port")
37-
pflag.StringVar(&opts.DatanodeServiceName, "datanode-service-name", "", "the name of datanode service")
38-
pflag.Int32Var(&opts.DatanodeRPCPort, "datanode-rpc-port", 4001, "the datanode RPC port")
3935
pflag.Int32Var(&opts.DatanodeGroupID, "datanode-group-id", -1, "the id of the datanode group")
4036
klog.InitFlags(nil)
4137
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)

controllers/greptimedbcluster/deployers/datanode.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,7 @@ func (b *datanodeBuilder) generateInitializer(spec *v1alpha1.DatanodeSpec, group
655655
Args: []string{
656656
"--config-path", path.Join(constant.GreptimeDBConfigDir, constant.GreptimeDBConfigFileName),
657657
"--init-config-path", path.Join(constant.GreptimeDBInitConfigDir, constant.GreptimeDBConfigFileName),
658-
"--datanode-rpc-port", fmt.Sprintf("%d", spec.RPCPort),
659-
"--datanode-service-name", common.ResourceName(b.Cluster.Name, b.RoleKind, spec.GetName()),
660-
"--namespace", b.Cluster.Namespace,
658+
"--rpc-port", fmt.Sprintf("%d", spec.RPCPort),
661659
"--component-kind", string(b.RoleKind),
662660
},
663661
VolumeMounts: []corev1.VolumeMount{

controllers/greptimedbcluster/deployers/flownode.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,6 @@ func (b *flownodeBuilder) generateInitializer() *corev1.Container {
297297
"--config-path", path.Join(constant.GreptimeDBConfigDir, constant.GreptimeDBConfigFileName),
298298
"--init-config-path", path.Join(constant.GreptimeDBInitConfigDir, constant.GreptimeDBConfigFileName),
299299
"--rpc-port", fmt.Sprintf("%d", b.Cluster.Spec.Flownode.RPCPort),
300-
"--service-name", common.ResourceName(b.Cluster.Name, b.RoleKind),
301-
"--namespace", b.Cluster.Namespace,
302300
"--component-kind", string(b.RoleKind),
303301
},
304302
VolumeMounts: []corev1.VolumeMount{

0 commit comments

Comments
 (0)