Skip to content
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ module: ## Run go mod tidy->verify against go modules.
$(GO) mod tidy -compat=1.21
$(GO) mod verify

TEST_PACKAGES ?= ./engines/... ./httpserver/... ./operations/... ./dcs/...
TEST_PACKAGES ?= ./engines/... ./httpserver/... ./operations/...

OUTPUT_COVERAGE=-coverprofile cover.out
.PHONY: test
Expand Down
30 changes: 4 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dbctl is a service that provides command execution channels, originally found in
dbctl itself provides two running modes: daemon mode and temporary task mode. You can choose the appropriate mode based on your business scenario.

## Daemon Mode
In this mode, dbctl runs as a daemon process and provides API services. This can be treated as one form of implementing the engines plugin. KubeBlocks does not impose restrictions on the form of engines plugins; they can run as sidecars, container daemons, or other forms. Currently, dbctl uses the localhost address to communicate with the database processes by default. Therefore, in this mode, it is recommended to deploy dbctl using the sidecar method, with the deployment template as follows:
In this mode, dbctl runs as a daemon process and provides API services. This can be treated as one form of implementing the engine plugin. KubeBlocks does not impose restrictions on the form of engines plugins; they can run as sidecars, container daemons, or other forms. Currently, dbctl uses the localhost address to communicate with the database processes by default. Therefore, in this mode, it is recommended to deploy dbctl using the sidecar method, with the deployment template as follows:
```
apiVersion: v1
kind: Pod
Expand All @@ -14,7 +14,7 @@ spec:
image: apecloud-registry.cn-zhangjiakou.cr.aliyuncs.com/apecloud/apecloud-mysql-server:8.0.30
...
- name: dbctl
image: apecloud-registry.cn-zhangjiakou.cr.aliyuncs.com/apecloud/dbctl:0.1.2
image: apecloud-registry.cn-zhangjiakou.cr.aliyuncs.com/apecloud/dbctl:0.2.0
command:
- dbctl
- mysql
Expand All @@ -25,16 +25,6 @@ spec:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: KB_POD_UID
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.uid
- name: KB_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: KB_SERVICE_USER
valueFrom:
secretKeyRef:
Expand All @@ -45,18 +35,6 @@ spec:
secretKeyRef:
key: password
name: cluster-mysql-account-root
- name: KB_CLUSTER_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.labels['app.kubernetes.io/instance']
- name: KB_COMP_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.labels['apps.kubeblocks.io/component-name']
- name: KB_ENGINE_TYPE
value: mysql
```

When using dbctl in daemon mode, action definitions can be implemented by calling the dbctl API:
Expand All @@ -67,7 +45,7 @@ When using dbctl in daemon mode, action definitions can be implemented by callin
command:
- /bin/bash
- -c
- curl -X GET -H 'Content-Type: application/json' 'http://127.0.0.1:3501/v1.0/getrole'
- curl -X GET -H 'Content-Type: application/json' 'http://127.0.0.1:5001/v1.0/getrole'
```

## Temporary Task
Expand All @@ -77,7 +55,7 @@ In this mode, dbctl completes the corresponding task and then exits immediately.
lifecycleActions:
roleProbe:
exec:
image: apecloud-registry.cn-zhangjiakou.cr.aliyuncs.com/apecloud/dbctl:0.1.2
image: apecloud-registry.cn-zhangjiakou.cr.aliyuncs.com/apecloud/dbctl:0.2.0
command:
- dbctl
- mysql
Expand Down
3 changes: 1 addition & 2 deletions cmd/dbctl/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2022-2024 ApeCloud Co., Ltd
Copyright (C) 2022-2025 ApeCloud Co., Ltd

This file is part of KubeBlocks project

Expand Down Expand Up @@ -34,7 +34,6 @@ func init() {
}

func main() {
// Set GOMAXPROCS
_, _ = maxprocs.Set()

ctl.Execute("", "")
Expand Down
6 changes: 0 additions & 6 deletions config/dbctl/components/binding_apecloud_postgresql.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions config/dbctl/components/binding_custom.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions config/dbctl/components/binding_etcd.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions config/dbctl/components/binding_kafka.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions config/dbctl/components/binding_mongodb.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions config/dbctl/components/binding_mysql.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions config/dbctl/components/binding_oceanbase.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions config/dbctl/components/binding_polarx.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions config/dbctl/components/binding_postgresql.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions config/dbctl/components/binding_redis.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions config/dbctl/components/middleware_probe.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions config/dbctl/config.yaml

This file was deleted.

37 changes: 0 additions & 37 deletions constant/const.go

This file was deleted.

90 changes: 5 additions & 85 deletions constant/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,27 @@ import (
"github.com/spf13/viper"
)

// Lorry
const (
KBEnvWorkloadType = "KB_WORKLOAD_TYPE"
KBEnvBuiltinHandler = "KB_BUILTIN_HANDLER"
KBEnvActionCommands = "KB_ACTION_COMMANDS"
KBEnvEngineType = "KB_ENGINE_TYPE"
KBEnvServiceUser = "KB_SERVICE_USER"
KBEnvServicePassword = "KB_SERVICE_PASSWORD"
// KBEnvServiceRoles defines the Roles configured in the cluster definition that are visible to users.
KBEnvServiceRoles = "KB_SERVICE_ROLES"

// KBEnvServicePort defines the port of the DB service
KBEnvServicePort = "KB_SERVICE_PORT"

// KBEnvTTL controls the lease expiration time in DCS. If the leader fails to renew its lease within the TTL duration, it will lose the leader role, allowing other replicas to take over.
KBEnvTTL = "KB_TTL"

// KBEnvMaxLag defines maximum replication lag permitted when performing a switchover.
KBEnvMaxLag = "KB_MAX_LAG"

// KBEnvEnableHA Whether to enable high availability, true by default.
KBEnvEnableHA = "KB_ENABLE_HA"

// KBEnvRsmRoleUpdateMechanism defines the method to send events: DirectAPIServerEventUpdate(through lorry service), ReadinessProbeEventUpdate(through kubelet service)
KBEnvRsmRoleUpdateMechanism = "KB_RSM_ROLE_UPDATE_MECHANISM"
KBEnvRoleProbeTimeout = "KB_RSM_ROLE_PROBE_TIMEOUT"
KBEnvRoleProbePeriod = "KB_RSM_ROLE_PROBE_PERIOD"
)

// new envs for KB 1.0
const (
EnvNamespace = "MY_NAMESPACE"
EnvPodName = "MY_POD_NAME"
EnvPodIP = "MY_POD_IP"
EnvPodUID = "MY_POD_UID"
EnvClusterName = "MY_CLUSTER_NAME"
EnvComponentName = "MY_COMP_NAME"
EnvClusterCompName = "MY_CLUSTER_COMP_NAME"
)

// old envs for KB 0.9
const (
KBEnvNamespace = "KB_NAMESPACE"
KBEnvClusterName = "KB_CLUSTER_NAME"
KBEnvClusterCompName = "KB_CLUSTER_COMP_NAME"
KBEnvCompName = "KB_COMP_NAME"
KBEnvPodName = "KB_POD_NAME"
KBEnvPodUID = "KB_POD_UID"
KBEnvPodIP = "KB_POD_IP"
KBEnvPodFQDN = "KB_POD_FQDN"
KBEnvNodeName = "KB_NODENAME"
)

func GetPodName() string {
Expand All @@ -91,61 +61,6 @@ func GetPodName() string {
}
}

func GetPodIP() string {
switch {
case viper.IsSet(KBEnvPodIP):
return viper.GetString(KBEnvPodIP)
case viper.IsSet(EnvPodIP):
return viper.GetString(EnvPodIP)
default:
return ""
}
}

func GetPodUID() string {
switch {
case viper.IsSet(KBEnvPodUID):
return viper.GetString(KBEnvPodUID)
case viper.IsSet(EnvPodUID):
return viper.GetString(EnvPodUID)
default:
return ""
}
}

func GetNamespace() string {
switch {
case viper.IsSet(KBEnvNamespace):
return viper.GetString(KBEnvNamespace)
case viper.IsSet(EnvNamespace):
return viper.GetString(EnvNamespace)
default:
return ""
}
}

func GetClusterName() string {
switch {
case viper.IsSet(KBEnvClusterName):
return viper.GetString(KBEnvClusterName)
case viper.IsSet(EnvClusterName):
return viper.GetString(EnvClusterName)
default:
return ""
}
}

func GetComponentName() string {
switch {
case viper.IsSet(KBEnvCompName):
return viper.GetString(KBEnvCompName)
case viper.IsSet(EnvComponentName):
return viper.GetString(EnvComponentName)
default:
return ""
}
}

func GetClusterCompName() string {
switch {
case viper.IsSet(KBEnvClusterCompName):
Expand All @@ -156,3 +71,8 @@ func GetClusterCompName() string {
return ""
}
}

const (
ConfigKeyUserName = "username"
ConfigKeyPassword = "password"
)
Loading