Skip to content

Commit

Permalink
add EnableAdvertiseAddress switch
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxGit committed Mar 4, 2020
1 parent fce9b7f commit 086b832
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 28 deletions.
2 changes: 2 additions & 0 deletions charts/tidb-cluster/templates/scripts/_start_tidb.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ fi
# Use HOSTNAME if POD_NAME is unset for backward compatibility.
POD_NAME=${POD_NAME:-$HOSTNAME}
ARGS="--store=tikv \
{{- if .Values.tidb.enableAdvertiseAddress | default false }}
--advertise-address=${POD_NAME}.${HEADLESS_SERVICE_NAME}.${NAMESPACE}.svc \
{{- end }}
--host=0.0.0.0 \
--path=${CLUSTER_NAME}-pd:2379 \
--config=/etc/tidb/tidb.toml
Expand Down
4 changes: 4 additions & 0 deletions charts/tidb-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ tidb:
# annotations:
# cloud.google.com/load-balancer-type: Internal
separateSlowLog: true

# Add --advertise-address to TiDB's startup parameters
enableAdvertiseAddress: false

slowLogTailer:
image: busybox:1.26.2
resources:
Expand Down
4 changes: 4 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3782,6 +3782,10 @@ spec:
cluster-level updateStrategy if present Optional: Defaults to
cluster-level setting'
type: string
enableAdvertiseAddress:
description: 'Add --advertise-address to TiDB''s startup parameters
Optional: Defaults to false'
type: boolean
hostNetwork:
description: 'Whether Hostnetwork of the component is enabled. Override
the cluster-level setting if present Optional: Defaults to cluster-level
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/pingcap/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 15 additions & 7 deletions pkg/apis/pingcap/v1alpha1/tidbcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import (

const (
// defaultHelperImage is default image of helper
defaultHelperImage = "busybox:1.26.2"
defaultTimeZone = "UTC"
defaultEnableTLSCluster = false
defaultEnableTLSClient = false
defaultExposeStatus = true
defaultSeparateSlowLog = true
defaultEnablePVReclaim = false
defaultHelperImage = "busybox:1.26.2"
defaultTimeZone = "UTC"
defaultEnableTLSCluster = false
defaultEnableTLSClient = false
defaultExposeStatus = true
defaultSeparateSlowLog = true
defaultEnablePVReclaim = false
defaultEnableTiDBAdvertiseAddress = false
)

var (
Expand Down Expand Up @@ -342,6 +343,13 @@ func (tidb *TiDBSpec) IsTLSClientEnabled() bool {
return tidb.TLSClient != nil && tidb.TLSClient.Enabled
}

func (tidb *TiDBSpec) IsAdvertiseAddressEnabled() bool {
if tidb.EnableAdvertiseAddress == nil {
return defaultEnableTiDBAdvertiseAddress
}
return *tidb.EnableAdvertiseAddress
}

func (tidb *TiDBSpec) IsUserGeneratedCertificate() bool {
return tidb.IsTLSClientEnabled() && tidb.TLSClient.SecretName != ""
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ type TiDBSpec struct {
// +optional
BinlogEnabled *bool `json:"binlogEnabled,omitempty"`

// Add --advertise-address to TiDB's startup parameters
// Optional: Defaults to false
// +optional
EnableAdvertiseAddress *bool `json:"enableAdvertiseAddress,omitempty"`

// MaxFailoverCount limit the max replicas could be added in failover, 0 means unlimited
// Optional: Defaults to 0
// +kubebuilder:validation:Minimum=0
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions pkg/manager/member/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ fi
# Use HOSTNAME if POD_NAME is unset for backward compatibility.
POD_NAME=${POD_NAME:-$HOSTNAME}
ARGS="--store=tikv \
{{- if .EnableAdvertiseAddress }}
--advertise-address=${POD_NAME}.${HEADLESS_SERVICE_NAME}.${NAMESPACE}.svc \
{{- end }}
--host=0.0.0.0 \
--path=${CLUSTER_NAME}-pd:2379 \
--config=/etc/tidb/tidb.toml
Expand All @@ -77,10 +79,11 @@ exec /tidb-server ${ARGS}
`))

type TidbStartScriptModel struct {
ClusterName string
EnablePlugin bool
PluginDirectory string
PluginList string
ClusterName string
EnableAdvertiseAddress bool
EnablePlugin bool
PluginDirectory string
PluginList string
}

func RenderTiDBStartScript(model *TidbStartScriptModel) (string, error) {
Expand Down
36 changes: 19 additions & 17 deletions pkg/manager/member/tidb_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,11 @@ func getTiDBConfigMap(tc *v1alpha1.TidbCluster) (*corev1.ConfigMap, error) {

plugins := tc.Spec.TiDB.Plugins
startScript, err := RenderTiDBStartScript(&TidbStartScriptModel{
ClusterName: tc.Name,
EnablePlugin: len(plugins) > 0,
PluginDirectory: "/plugins",
PluginList: strings.Join(plugins, ","),
ClusterName: tc.Name,
EnableAdvertiseAddress: tc.Spec.TiDB.IsAdvertiseAddressEnabled(),
EnablePlugin: len(plugins) > 0,
PluginDirectory: "/plugins",
PluginList: strings.Join(plugins, ","),
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -721,14 +722,6 @@ func getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbCluster, cm *corev1.ConfigMap)
},
},
},
{
Name: "POD_NAME",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.name",
},
},
},
{
Name: "CLUSTER_NAME",
Value: tc.GetName(),
Expand All @@ -755,6 +748,20 @@ func getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbCluster, cm *corev1.ConfigMap)
if tc.IsTLSClusterEnabled() {
scheme = corev1.URISchemeHTTPS
}

podSpec := baseTiDBSpec.BuildPodSpec()
if baseTiDBSpec.HostNetwork() {
podSpec.DNSPolicy = corev1.DNSClusterFirstWithHostNet
envs = append(envs, corev1.EnvVar{
Name: "POD_NAME",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.name",
},
},
})
}

containers = append(containers, corev1.Container{
Name: v1alpha1.TiDBMemberType.String(),
Image: tc.TiDBImage(),
Expand Down Expand Up @@ -787,16 +794,11 @@ func getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbCluster, cm *corev1.ConfigMap)
},
})

podSpec := baseTiDBSpec.BuildPodSpec()
podSpec.Containers = containers
podSpec.Volumes = vols
podSpec.SecurityContext = podSecurityContext
podSpec.InitContainers = initContainers

if baseTiDBSpec.HostNetwork() {
podSpec.DNSPolicy = corev1.DNSClusterFirstWithHostNet
}

tidbLabel := label.New().Instance(instanceName).TiDB()
podAnnotations := CombineAnnotations(controller.AnnProm(10080), baseTiDBSpec.Annotations())
stsAnnotations := getStsAnnotations(tc, label.TiDBLabelVal)
Expand Down

0 comments on commit 086b832

Please sign in to comment.