Skip to content

Commit

Permalink
Remove tcp and http ports for tiflash >= 7.1.0 (#5075) (#5078)
Browse files Browse the repository at this point in the history
Co-authored-by: zanmato <[email protected]>
  • Loading branch information
ti-chi-bot and zanmato1984 committed Jun 20, 2023
1 parent 096228e commit a4c32ce
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 35 deletions.
15 changes: 11 additions & 4 deletions pkg/manager/member/tiflash_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -138,6 +140,7 @@ func getTiFlashConfigV2(tc *v1alpha1.TidbCluster) *v1alpha1.TiFlashConfigWraper
if tc.Spec.PreferIPv6 {
listenHost = listenHostForIPv6
}
version := tc.TiFlashVersion()

// common
{
Expand All @@ -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)
Expand Down Expand Up @@ -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")

Expand Down
64 changes: 33 additions & 31 deletions pkg/manager/member/tiflash_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}
})
}
})
Expand Down

0 comments on commit a4c32ce

Please sign in to comment.