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

feat: sqlchannel support switchover and failover #3767

Closed
wants to merge 76 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
6e44bf4
sqlchannle support DB tools image
xuriwuyun Jun 2, 2023
d9934fe
add sqlchannel command line tool
xuriwuyun Jun 2, 2023
864d6b1
add sqlchannel options
xuriwuyun Jun 8, 2023
14d5ab4
update sqlchannel ctr
xuriwuyun Jun 9, 2023
1894e76
update sqlchannel ctr
xuriwuyun Jun 9, 2023
1e9873d
update sqlchannel client
xuriwuyun Jun 9, 2023
afa3996
update sqlctl
xuriwuyun Jun 12, 2023
475cfaf
Merge branch 'main' into support/sqlchannel_manage_db
xuriwuyun Jun 12, 2023
f142c1c
update dockerfile for sqlctl
xuriwuyun Jun 13, 2023
8ff9e41
update probe image
xuriwuyun Jun 13, 2023
b0cde21
Merge branch 'main' into feature/sqlchannel_support_switchover
xuriwuyun Jun 15, 2023
8663ef4
add HA framework
xuriwuyun Jun 15, 2023
8ecb0b6
update
xuriwuyun Jun 15, 2023
eed6011
update
xuriwuyun Jun 15, 2023
5c773b5
sqlchannel add k8s component
xuriwuyun Jun 16, 2023
53eeb22
update kubernets store
xuriwuyun Jun 16, 2023
580e7d4
add dcs getcluster
xuriwuyun Jun 16, 2023
a65fea0
update
xuriwuyun Jun 19, 2023
5f3a1f9
update
xuriwuyun Jun 19, 2023
2bf182a
update
xuriwuyun Jun 19, 2023
187d1cd
update
xuriwuyun Jun 19, 2023
3831f11
update
xuriwuyun Jun 20, 2023
7df64f1
add mongodb db manager
xuriwuyun Jun 20, 2023
fd5f3f6
update
xuriwuyun Jun 21, 2023
ad8c736
add cluster initialize for mongodb
xuriwuyun Jun 21, 2023
3b5e462
fix
xuriwuyun Jun 25, 2023
efd67ab
fix
xuriwuyun Jun 25, 2023
eed4db8
fix
xuriwuyun Jun 25, 2023
6c1a12c
fix
xuriwuyun Jun 25, 2023
40f3f25
fix
xuriwuyun Jun 25, 2023
e629f60
fix
xuriwuyun Jun 25, 2023
40129de
fix
xuriwuyun Jun 25, 2023
d6da2df
fix
xuriwuyun Jun 25, 2023
99d0119
add log
xuriwuyun Jun 25, 2023
5ff2e50
add mongodb premote
xuriwuyun Jun 25, 2023
8716233
add log
xuriwuyun Jun 26, 2023
986894c
update
xuriwuyun Jun 26, 2023
f876e4b
add switchover
xuriwuyun Jun 26, 2023
950ffa1
update
xuriwuyun Jun 26, 2023
8a51d71
fix
xuriwuyun Jun 26, 2023
7ec6bea
update lock
xuriwuyun Jun 27, 2023
f7ca708
fix
xuriwuyun Jun 27, 2023
ff1e1cd
update switchover
xuriwuyun Jun 27, 2023
8a8864d
add mongodb is healthy
xuriwuyun Jun 28, 2023
90ed9f5
update ha
xuriwuyun Jun 28, 2023
a59d8ad
fix
xuriwuyun Jun 28, 2023
2a96c4a
fix
xuriwuyun Jun 28, 2023
d9c0928
fix
xuriwuyun Jun 28, 2023
697dd46
fix
xuriwuyun Jun 28, 2023
134bbb7
fix
xuriwuyun Jun 28, 2023
998d134
fix
xuriwuyun Jun 28, 2023
b4484ff
fix
xuriwuyun Jun 29, 2023
8153104
fix
xuriwuyun Jun 29, 2023
8f32277
ha support addmembertocluster and deletememberfromcluster
xuriwuyun Jun 30, 2023
255eeeb
ha add isclusterhealthy
xuriwuyun Jun 30, 2023
c6b60b6
update ha to check cluster healthy
xuriwuyun Jun 30, 2023
6b37fe7
add log
xuriwuyun Jun 30, 2023
42648ad
fix
xuriwuyun Jun 30, 2023
953286a
fix
xuriwuyun Jun 30, 2023
5f18905
fix
xuriwuyun Jun 30, 2023
a73a73e
add support for rbac
xuriwuyun Jul 3, 2023
ce3db1b
support postgresql patroni rbac
xuriwuyun Jul 3, 2023
3483f50
update kubeblocks rbac
xuriwuyun Jul 3, 2023
1aaeec3
Merge branch 'feature/manage_rbac' into feature/sqlchannel_support_sw…
xuriwuyun Jul 3, 2023
3b4a994
update
xuriwuyun Jul 3, 2023
83555a1
update kubeblocks rbac for rbac manage
xuriwuyun Jul 3, 2023
d3b9d3e
Merge branch 'feature/manage_rbac' into feature/sqlchannel_support_sw…
xuriwuyun Jul 3, 2023
1fc5851
update cv spec
xuriwuyun Jul 3, 2023
f6889b3
Merge branch 'main' into feature/sqlchannel_support_switchover
xuriwuyun Jul 3, 2023
bad7c6e
fix typo
xuriwuyun Jul 3, 2023
49d064c
fix rbac delete problem
xuriwuyun Jul 3, 2023
d3107cd
add unit tests
xuriwuyun Jul 4, 2023
5f566c7
remove rbac manage from kbcli and helm template
xuriwuyun Jul 4, 2023
943d38f
fix pg bug
xuriwuyun Jul 4, 2023
d0bcbba
remove duplicate code
xuriwuyun Jul 4, 2023
666a2ac
Merge branch 'feature/manage_rbac' into feature/sqlchannel_support_sw…
xuriwuyun Jul 4, 2023
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
134 changes: 134 additions & 0 deletions cmd/probe/cli/ctr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
Copyright (C) 2022-2023 ApeCloud Co., Ltd

This file is part of KubeBlocks project

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package cli

import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/dapr/cli/pkg/api"
"github.com/dapr/cli/pkg/print"
"github.com/dapr/cli/pkg/standalone"
)

const cliVersionTemplateString = "CLI version: %s \nRuntime version: %s\n"

var RootCmd = &cobra.Command{
Use: "sqlctl",
Short: "SQL Channel CLI",
Long: `
_____ ____ __ ________ __
/ ___// __ \ / / / ____/ /_ ____ _____ ____ ___ / /
\__ \/ / / / / / / / / __ \/ __ \/ __ \/ __ \/ _ \/ /
___/ / /_/ / / /___ / /___/ / / / /_/ / / / / / / / __/ /
/____/\___\_\/_____/ \____/_/ /_/\__,_/_/ /_/_/ /_/\___/_/

===============================
SQL Channel client`,
Run: func(cmd *cobra.Command, _ []string) {
if versionFlag {
printVersion()
} else {
cmd.Help()
}
},
}

type sqlChannelVersion struct {
CliVersion string `json:"Cli version"`
RuntimeVersion string `json:"Runtime version"`
}

var (
cliVersion string
versionFlag bool
sqlChannelVer sqlChannelVersion
logAsJSON bool
sqlChannelRuntimePath string
)

// Execute adds all child commands to the root command.
func Execute(version, apiVersion string) {
cliVersion = version
api.RuntimeAPIVersion = apiVersion

sqlChannelVer = sqlChannelVersion{
CliVersion: version,
RuntimeVersion: strings.ReplaceAll(standalone.GetRuntimeVersion(), "\n", ""),
}

cobra.OnInitialize(initConfig)

setVersion()

if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
}

func setVersion() {
template := fmt.Sprintf(cliVersionTemplateString, sqlChannelVer.CliVersion, sqlChannelVer.RuntimeVersion)
RootCmd.SetVersionTemplate(template)
}

func printVersion() {
fmt.Printf(cliVersionTemplateString, sqlChannelVer.CliVersion, sqlChannelVer.RuntimeVersion)
}

func initConfig() {
if logAsJSON {
print.EnableJSONFormat()
}

// err intentionally ignored since sqlChanneld may not yet be installed.
runtimeVer := GetRuntimeVersion()

sqlChannelVer = sqlChannelVersion{
// Set in Execute() method in this file before initConfig() is called by cmd.Execute().
CliVersion: cliVersion,
RuntimeVersion: strings.ReplaceAll(runtimeVer, "\n", ""),
}

viper.SetEnvPrefix("sqlChannel")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()
}

func init() {
RootCmd.PersistentFlags().StringVarP(&sqlChannelRuntimePath, "kb-runtime-dir", "", "/kubeblocks/", "The directory of kubeblocks binaries")
}

// GetRuntimeVersion returns the version for the local sqlChannel runtime.
func GetRuntimeVersion() string {
sqlchannelCMD := filepath.Join(sqlChannelRuntimePath, "probe")

out, err := exec.Command(sqlchannelCMD, "--version").Output()
if err != nil {
return "n/a\n"
}
return string(out)
}
Loading
Loading