Skip to content

Commit

Permalink
feat(backend): 支持容器数据库集群纳管 #3334
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 5233
  • Loading branch information
zhangzhw8 committed Apr 7, 2024
1 parent 6f7bca1 commit fa21312
Show file tree
Hide file tree
Showing 969 changed files with 2,099 additions and 1,145 deletions.
11 changes: 10 additions & 1 deletion dbm-services/mysql/db-priv/service/add_priv.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (m *PrivTaskPara) AddPriv(jsonPara string) error {
AddErrorOnly(&errMsg, errors.New(failInfo+sep+err.Error()))
return
}
if m.ClusterType == tendbha || m.ClusterType == tendbsingle {
if m.ClusterType == tendbha || m.ClusterType == tendbsingle || m.ClusterType == MySQLOnK8S {
// 当"cluster_type": "tendbha", "bind_to": "proxy" tendbha的主域名, "bind_to": "storage" tendbha的备域名
if instance.ClusterType == tendbha && instance.BindTo == machineTypeProxy {
tendbhaMasterDomain = true
Expand All @@ -121,6 +121,15 @@ func (m *PrivTaskPara) AddPriv(jsonPara string) error {
errMsgInner = append(errMsgInner, err.Error())
}
}
if instance.ClusterType == MySQLOnK8S {
// TODO 这里要记录集群的访问端口,因为容器化集群可能没有存储实例,
address = fmt.Sprintf("%s:%d", instance.ImmuteDomain, 3306)
err = ImportBackendPrivilege(account, accountRule, address, proxyIPs, m.SourceIPs,
instance.ClusterType, tendbhaMasterDomain, instance.BkCloudId, false)
if err != nil {
errMsgInner = append(errMsgInner, err.Error())
}
}
if len(errMsgInner) > 0 {
AddErrorOnly(&errMsg, errors.New(failInfo+sep+strings.Join(errMsgInner, sep)))
return
Expand Down
6 changes: 3 additions & 3 deletions dbm-services/mysql/db-priv/service/add_priv_base_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
func GetAccountRuleInfo(bkBizId int64, clusterType string, user, dbname string) (TbAccounts, TbAccountRules, error) {
var account TbAccounts
var accountRule TbAccountRules
if clusterType == tendbha || clusterType == tendbsingle {
if clusterType == tendbha || clusterType == tendbsingle || clusterType == MySQLOnK8S {
clusterType = mysql
}
if clusterType == sqlserverHA || clusterType == sqlserverSingle {
Expand Down Expand Up @@ -185,7 +185,7 @@ func GenerateBackendSQL(account TbAccounts, rule TbAccountRules, ips []string, m
CreateUserVersion8 = fmt.Sprintf(`CREATE USER IF NOT EXISTS '%s'@'%s' %s;`,
account.User, ip, fmt.Sprintf("IDENTIFIED WITH %s AS '%s'", pswResp.PwdType, pswResp.Psw))
}
if (clusterType == tendbha || clusterType == tendbsingle) && MySQLVersionParse(mysqlVersion, "") >=
if (clusterType == tendbha || clusterType == tendbsingle || clusterType == MySQLOnK8S) && MySQLVersionParse(mysqlVersion, "") >=
MySQLVersionParse("8.0.0", "") {
sqlTemp = append(sqlTemp, CreateUserVersion8)
identifiedByPassword = ""
Expand Down Expand Up @@ -295,7 +295,7 @@ func GetPassword(user string, multiPsw MultiPsw, mysqlVersion, ip string, addres
var tipsForProxyIP string

if (MySQLVersionParse(mysqlVersion, "") > MySQLVersionParse("5.7.5", "")) &&
(clusterType == tendbha || clusterType == tendbsingle) {
(clusterType == tendbha || clusterType == tendbsingle || clusterType == MySQLOnK8S) {
passwdColName = "authentication_string"
}

Expand Down
2 changes: 1 addition & 1 deletion dbm-services/mysql/db-priv/service/admin_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func (m *ModifyAdminUserPasswordPara) ModifyAdminPasswordForMysql(
notOK := InstanceList{instanceList.Role, []IpPort{}}
role := instanceList.Role
if *cluster.ClusterType == tendbcluster && role == machineTypeSpider {
base = append(base, flushPriv, setBinlogOff, setDdlByCtlOFF)
base = append(base, flushPriv, setBinlogOff)
} else if *cluster.ClusterType == tendbcluster && role == tdbctl {
base = append(base, flushPriv, setBinlogOff, setTcAdminOFF)
} else {
Expand Down
1 change: 1 addition & 0 deletions dbm-services/mysql/db-priv/service/db_meta_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const mysql string = "mysql" // 包含tendbha和tendbsingle
const tendbha string = "tendbha"
const tendbsingle string = "tendbsingle"
const tendbcluster string = "tendbcluster"
const MySQLOnK8S string = "MySQLOnK8S"
const machineTypeBackend string = "backend"
const machineTypeSingle string = "single"
const machineTypeRemote string = "remote"
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/bk_web/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from django.conf import settings
from django.http import Http404, JsonResponse
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from rest_framework import exceptions, status

from backend.exceptions import AppBaseException, ErrorCode
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/bk_web/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from backend.bk_web.constants import LEN_NORMAL

Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from django.conf import settings
from django.core.cache import cache
from django.utils import translation
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from urllib3.exceptions import ConnectTimeoutError

from backend import env
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/bk.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import logging
from typing import Dict, Optional

from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from requests import PreparedRequest
from requests.auth import AuthBase

Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/bklog/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import BKLOG_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/bkmonitorv3/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import BKMONITORV3_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/bknodeman/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import BKNODEMAN_APIGW_DOMAIN
Expand Down
4 changes: 2 additions & 2 deletions dbm-ui/backend/components/cc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import CC_APIGW_DOMAIN
Expand All @@ -24,7 +24,7 @@ class ErrorCode:
HOST_NOT_BELONG_MODULE = 1110056
CUSTOM_FIELD_ALREADY_EXISTS = 1101107

def __init__(self):
def __init__(self, *args, **kwargs):
self.list_hosts_without_biz = self.generate_data_api(
method="POST",
url="list_hosts_without_biz/",
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/celery_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import CELERY_SERVICE_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/cmsi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from blue_krill.data_types.enum import EnumField, StructuredEnum

Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/db_name_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import NAMESERVICE_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/db_remote_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from backend import env

Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/dbconfig/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import DBCONFIG_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/dbresource/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
See the License for the specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import DBRESOURCE_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/dns/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import DNS_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/gcs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
See the License for the specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import GCS_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/gse/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
See the License for the specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import GSE_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/hadb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
See the License for the specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import HADB_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/itsm/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import ITSM_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/job/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import JOB_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/mysql_backup/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import BACKUP_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/mysql_partition/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import PARTITION_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/mysql_priv_manager/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import MYSQL_PRIV_MANAGER_APIGW_DOMAIN
Expand Down
12 changes: 5 additions & 7 deletions dbm-ui/backend/components/proxy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

from django.utils.translation import gettext as _

from backend import env
from backend.components.base import DataAPI
from backend.components.exception import DataAPIException
from backend.db_proxy.models import DBCloudProxy
from backend.db_services.ipchooser.constants import DEFAULT_CLOUD


class ProxyAPI(DataAPI):
Expand All @@ -23,19 +23,17 @@ class ProxyAPI(DataAPI):
"""

def build_actual_url(self, param):
url = super().build_actual_url(param)

# 如果配置了DOMAIN_SKIP_PROXY,表示跳过proxy代理
if env.DOMAIN_SKIP_PROXY:
return url

try:
bk_cloud_id = param["bk_cloud_id"]
except KeyError:
raise DataAPIException(_("ProxyApi 必须传入 bk_cloud_id 参数"))

url = super().build_actual_url(param)
# 只取最新的nginx作为转发服务
proxy = DBCloudProxy.objects.filter(bk_cloud_id=bk_cloud_id).last()
# 直连区域未部署代理时,直接返回原地址(用于一般容器化环境或本地开发)
if not proxy and bk_cloud_id == DEFAULT_CLOUD:
return url
host = "https://" if self.ssl else "http://"
external_address = f"{host}{proxy.external_address}"
return url.replace(self.base.rstrip("/"), external_address)
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/scr/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
See the License for the specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import SCR_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/sops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""


from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import SOPS_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/sql_import/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import MYSQL_SIMULATION_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/usermanage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ..base import BaseApi
from ..domains import USER_MANAGE_APIGW_DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/components/utils/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""
from typing import Any, Dict, List, Union

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from backend.components.exception import DataAPIException

Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/configuration/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from django.apps import AppConfig
from django.db.models.signals import post_migrate
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

logger = logging.getLogger("root")

Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/configuration/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from blue_krill.data_types.enum import EnumField, StructuredEnum

Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/configuration/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from backend.exceptions import AppBaseException, ErrorCode

Expand Down
Loading

0 comments on commit fa21312

Please sign in to comment.