From a4c32cef00c211a25c154962640550f50312b08c Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Tue, 20 Jun 2023 10:32:58 +0800 Subject: [PATCH] Remove tcp and http ports for tiflash >= 7.1.0 (#5075) (#5078) Co-authored-by: zanmato --- pkg/manager/member/tiflash_util.go | 15 ++++-- pkg/manager/member/tiflash_util_test.go | 64 +++++++++++++------------ 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/pkg/manager/member/tiflash_util.go b/pkg/manager/member/tiflash_util.go index 1c8065beeb..f954385289 100644 --- a/pkg/manager/member/tiflash_util.go +++ b/pkg/manager/member/tiflash_util.go @@ -37,6 +37,8 @@ const ( var ( // the first version that tiflash change default config tiflashEqualOrGreaterThanV540, _ = cmpver.NewConstraint(cmpver.GreaterOrEqual, "v5.4.0") + // the first version that tiflash discards http and tcp ports. + tiflashEqualOrGreaterThanV710, _ = cmpver.NewConstraint(cmpver.GreaterOrEqual, "v7.1.0") ) func buildTiFlashSidecarContainers(tc *v1alpha1.TidbCluster) ([]corev1.Container, error) { @@ -138,6 +140,7 @@ func getTiFlashConfigV2(tc *v1alpha1.TidbCluster) *v1alpha1.TiFlashConfigWraper if tc.Spec.PreferIPv6 { listenHost = listenHostForIPv6 } + version := tc.TiFlashVersion() // common { @@ -161,8 +164,10 @@ func getTiFlashConfigV2(tc *v1alpha1.TidbCluster) *v1alpha1.TiFlashConfigWraper common.SetIfNil("tmp_path", "/data0/tmp") // port - common.SetIfNil("tcp_port", int64(v1alpha1.DefaultTiFlashTcpPort)) - common.SetIfNil("http_port", int64(v1alpha1.DefaultTiFlashHttpPort)) + if ok, err := tiflashEqualOrGreaterThanV710.Check(version); err == nil && !ok { + common.SetIfNil("tcp_port", int64(v1alpha1.DefaultTiFlashTcpPort)) + common.SetIfNil("http_port", int64(v1alpha1.DefaultTiFlashHttpPort)) + } // flash tidbStatusAddr := fmt.Sprintf("%s.%s.svc:%d", controller.TiDBMemberName(name), ns, v1alpha1.DefaultTiDBStatusPort) @@ -224,8 +229,10 @@ func getTiFlashConfigV2(tc *v1alpha1.TidbCluster) *v1alpha1.TiFlashConfigWraper common.Set("security.ca_path", path.Join(tiflashCertPath, corev1.ServiceAccountRootCAKey)) common.Set("security.cert_path", path.Join(tiflashCertPath, corev1.TLSCertKey)) common.Set("security.key_path", path.Join(tiflashCertPath, corev1.TLSPrivateKeyKey)) - common.SetIfNil("tcp_port_secure", int64(v1alpha1.DefaultTiFlashTcpPort)) - common.SetIfNil("https_port", int64(v1alpha1.DefaultTiFlashHttpPort)) + if ok, err := tiflashEqualOrGreaterThanV710.Check(version); err == nil && !ok { + common.SetIfNil("tcp_port_secure", int64(v1alpha1.DefaultTiFlashTcpPort)) + common.SetIfNil("https_port", int64(v1alpha1.DefaultTiFlashHttpPort)) + } common.Del("http_port") common.Del("tcp_port") diff --git a/pkg/manager/member/tiflash_util_test.go b/pkg/manager/member/tiflash_util_test.go index 906ffb1358..cff1648c33 100644 --- a/pkg/manager/member/tiflash_util_test.go +++ b/pkg/manager/member/tiflash_util_test.go @@ -1511,8 +1511,6 @@ func TestTestGetTiFlashConfig(t *testing.T) { tc.Spec.TiFlash.Config = nil }, expectCommonCfg: ` - http_port = 8123 - tcp_port = 9000 tmp_path = "/data0/tmp" [flash] service_addr = "0.0.0.0:3930" @@ -1549,8 +1547,6 @@ func TestTestGetTiFlashConfig(t *testing.T) { tc.Spec.TLSCluster = &v1alpha1.TLSCluster{Enabled: true} }, expectCommonCfg: ` - https_port = 8123 - tcp_port_secure = 9000 tmp_path = "/data0/tmp" [flash] service_addr = "0.0.0.0:3930" @@ -1598,8 +1594,6 @@ func TestTestGetTiFlashConfig(t *testing.T) { tc.Spec.TLSCluster = &v1alpha1.TLSCluster{Enabled: true} }, expectCommonCfg: ` - https_port = 8123 - tcp_port_secure = 9000 tmp_path = "/data0/tmp" [flash] service_addr = "0.0.0.0:3930" @@ -1653,8 +1647,6 @@ func TestTestGetTiFlashConfig(t *testing.T) { }, expectCommonCfg: ` - http_port = 8123 - tcp_port = 9000 tmp_path = "/data0/tmp" [flash] service_addr = "0.0.0.0:3930" @@ -1693,8 +1685,6 @@ func TestTestGetTiFlashConfig(t *testing.T) { tc.Spec.Cluster = &v1alpha1.TidbClusterRef{Name: "cluster-1", Namespace: "default"} }, expectCommonCfg: ` - http_port = 8123 - tcp_port = 9000 tmp_path = "/data0/tmp" [flash] service_addr = "0.0.0.0:3930" @@ -1731,8 +1721,6 @@ func TestTestGetTiFlashConfig(t *testing.T) { tc.Spec.AcrossK8s = true }, expectCommonCfg: ` - http_port = 8123 - tcp_port = 9000 tmp_path = "/data0/tmp" [flash] service_addr = "0.0.0.0:3930" @@ -1772,8 +1760,6 @@ func TestTestGetTiFlashConfig(t *testing.T) { tc.Spec.AcrossK8s = true }, expectCommonCfg: ` - http_port = 8123 - tcp_port = 9000 tmp_path = "/data0/tmp" [flash] service_addr = "0.0.0.0:3930" @@ -1813,8 +1799,6 @@ func TestTestGetTiFlashConfig(t *testing.T) { tc.Spec.AcrossK8s = true }, expectCommonCfg: ` - http_port = 8123 - tcp_port = 9000 tmp_path = "/data0/tmp" [flash] service_addr = "0.0.0.0:3930" @@ -1854,29 +1838,47 @@ func TestTestGetTiFlashConfig(t *testing.T) { tc.Name = "test" tc.Namespace = "default" tc.Spec.TiFlash = &v1alpha1.TiFlashSpec{} + tc.Spec.TiFlash.BaseImage = "pingcap/tiflash" if testcase.setTC != nil { testcase.setTC(tc) } - cfg := getTiFlashConfigV2(tc) + for _, version := range []string{"v7.0.0", "v7.1.0"} { + tc.Spec.Version = version + + expectCommonCfg := testcase.expectCommonCfg + if ok, err := tiflashEqualOrGreaterThanV710.Check(version); err == nil && !ok { + if tc.Spec.TLSCluster != nil && tc.Spec.TLSCluster.Enabled { + expectCommonCfg = ` + https_port = 8123 + tcp_port_secure = 9000` + expectCommonCfg + } else { + expectCommonCfg = ` + http_port = 8123 + tcp_port = 9000` + expectCommonCfg + } + } - commonCfgData, err := cfg.Common.MarshalTOML() - g.Expect(err).Should(Succeed()) - proxyCfgData, err := cfg.Proxy.MarshalTOML() - g.Expect(err).Should(Succeed()) + cfg := getTiFlashConfigV2(tc) - outputCfg := v1alpha1.NewTiFlashConfig() - expectCfg := v1alpha1.NewTiFlashConfig() - outputCfg.Common.UnmarshalTOML(commonCfgData) - outputCfg.Proxy.UnmarshalTOML(proxyCfgData) - expectCfg.Common.UnmarshalTOML([]byte(testcase.expectCommonCfg)) - expectCfg.Proxy.UnmarshalTOML([]byte(testcase.expectProxyCfg)) + commonCfgData, err := cfg.Common.MarshalTOML() + g.Expect(err).Should(Succeed()) + proxyCfgData, err := cfg.Proxy.MarshalTOML() + g.Expect(err).Should(Succeed()) - diff := cmp.Diff(outputCfg.Common.Inner(), expectCfg.Common.Inner()) - g.Expect(diff).Should(BeEmpty()) - diff = cmp.Diff(outputCfg.Proxy.Inner(), expectCfg.Proxy.Inner()) - g.Expect(diff).Should(BeEmpty()) + outputCfg := v1alpha1.NewTiFlashConfig() + expectCfg := v1alpha1.NewTiFlashConfig() + outputCfg.Common.UnmarshalTOML(commonCfgData) + outputCfg.Proxy.UnmarshalTOML(proxyCfgData) + expectCfg.Common.UnmarshalTOML([]byte(expectCommonCfg)) + expectCfg.Proxy.UnmarshalTOML([]byte(testcase.expectProxyCfg)) + + diff := cmp.Diff(outputCfg.Common.Inner(), expectCfg.Common.Inner()) + g.Expect(diff).Should(BeEmpty()) + diff = cmp.Diff(outputCfg.Proxy.Inner(), expectCfg.Proxy.Inner()) + g.Expect(diff).Should(BeEmpty()) + } }) } })