Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove tcp and http ports for tiflash >= 7.1.0 #5075

Merged
merged 6 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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