Skip to content

Commit

Permalink
sidecar: Remove the old role tag setting method. radondb#330
Browse files Browse the repository at this point in the history
  • Loading branch information
runkecheng committed Dec 27, 2021
1 parent e7d8f16 commit a5d6d9f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 36 deletions.
40 changes: 19 additions & 21 deletions sidecar/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,6 @@ func (cfg *Config) buildXenonConf() []byte {
"admit-defeat-hearbeat-count": %d,
"heartbeat-timeout": %d,
"meta-datadir": "/var/lib/xenon/",
"leader-start-command": "/scripts/leader-start.sh",
"leader-stop-command": "/scripts/leader-stop.sh",
"semi-sync-degrade": true,
"purge-binlog-disabled": true,
"super-idle": false
Expand Down Expand Up @@ -408,25 +406,25 @@ func (cfg *Config) buildClientConfig() (*ini.File, error) {
return conf, nil
}

// buildLeaderStart build the leader-start.sh.
func (cfg *Config) buildLeaderStart() []byte {
str := fmt.Sprintf(`#!/usr/bin/env bash
curl -X PATCH -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" -H "Content-Type: application/json-patch+json" \
--cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/%s/pods/$HOSTNAME \
-d '[{"op": "replace", "path": "/metadata/labels/role", "value": "leader"}]'
`, cfg.NameSpace)
return utils.StringToBytes(str)
}

// buildLeaderStop build the leader-stop.sh.
func (cfg *Config) buildLeaderStop() []byte {
str := fmt.Sprintf(`#!/usr/bin/env bash
curl -X PATCH -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" -H "Content-Type: application/json-patch+json" \
--cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/%s/pods/$HOSTNAME \
-d '[{"op": "replace", "path": "/metadata/labels/role", "value": "follower"}]'
`, cfg.NameSpace)
return utils.StringToBytes(str)
}
// // buildLeaderStart build the leader-start.sh.
// func (cfg *Config) buildLeaderStart() []byte {
// str := fmt.Sprintf(`#!/usr/bin/env bash
// curl -X PATCH -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" -H "Content-Type: application/json-patch+json" \
// --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/%s/pods/$HOSTNAME \
// -d '[{"op": "replace", "path": "/metadata/labels/role", "value": "leader"}]'
// `, cfg.NameSpace)
// return utils.StringToBytes(str)
// }

// // buildLeaderStop build the leader-stop.sh.
// func (cfg *Config) buildLeaderStop() []byte {
// str := fmt.Sprintf(`#!/usr/bin/env bash
// curl -X PATCH -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" -H "Content-Type: application/json-patch+json" \
// --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/%s/pods/$HOSTNAME \
// -d '[{"op": "replace", "path": "/metadata/labels/role", "value": "follower"}]'
// `, cfg.NameSpace)
// return utils.StringToBytes(str)
// }

/* The function is equivalent to the following shell script template:
#!/bin/sh
Expand Down
26 changes: 13 additions & 13 deletions sidecar/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,19 @@ func runInitCommand(cfg *Config) error {
return fmt.Errorf("failed to save extra.cnf: %s", err)
}

// build leader-start.sh.
bashLeaderStart := cfg.buildLeaderStart()
leaderStartPath := path.Join(scriptsPath, "leader-start.sh")
if err = ioutil.WriteFile(leaderStartPath, bashLeaderStart, os.FileMode(0755)); err != nil {
return fmt.Errorf("failed to write leader-start.sh: %s", err)
}

// build leader-stop.sh.
bashLeaderStop := cfg.buildLeaderStop()
leaderStopPath := path.Join(scriptsPath, "leader-stop.sh")
if err = ioutil.WriteFile(leaderStopPath, bashLeaderStop, os.FileMode(0755)); err != nil {
return fmt.Errorf("failed to write leader-stop.sh: %s", err)
}
// // build leader-start.sh.
// bashLeaderStart := cfg.buildLeaderStart()
// leaderStartPath := path.Join(scriptsPath, "leader-start.sh")
// if err = ioutil.WriteFile(leaderStartPath, bashLeaderStart, os.FileMode(0755)); err != nil {
// return fmt.Errorf("failed to write leader-start.sh: %s", err)
// }

// // build leader-stop.sh.
// bashLeaderStop := cfg.buildLeaderStop()
// leaderStopPath := path.Join(scriptsPath, "leader-stop.sh")
// if err = ioutil.WriteFile(leaderStopPath, bashLeaderStop, os.FileMode(0755)); err != nil {
// return fmt.Errorf("failed to write leader-stop.sh: %s", err)
// }

// for install tokudb.
if cfg.InitTokuDB {
Expand Down
4 changes: 2 additions & 2 deletions sidecar/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ var (
// dataPath is the mysql data path.
dataPath = utils.DataVolumeMountPath

// scriptsPath is the scripts path used for xenon.
scriptsPath = utils.ScriptsVolumeMountPath
// // scriptsPath is the scripts path used for xenon.
// scriptsPath = utils.ScriptsVolumeMountPath

// sysPath is the linux kernel path used for install tokudb.
sysPath = utils.SysVolumeMountPath
Expand Down

0 comments on commit a5d6d9f

Please sign in to comment.