Skip to content

Commit

Permalink
feat: 配置示例新增 配置文件筛选功能--story=119697737 (#3544)
Browse files Browse the repository at this point in the history
* feat: 配置示例新增 配置文件筛选功能--story=119697737

* feat: 配置示例新增配置文件筛选功能done--story=119697737
  • Loading branch information
q15971095971 committed Sep 29, 2024
1 parent 8935dfa commit 9d411e7
Show file tree
Hide file tree
Showing 13 changed files with 451 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ labels: {{ .Bk_Bscp_Variable_Leabels }}

# 临时目录,在拉取配置文件时,用于存储配置文件的目录,默认为:/data/bscp,可根据实际情况调整
temp_dir: {{ .Bk_Bscp_VariableTempDir }}

{{ .Bk_Bscp_Variable_Rules }}
EOF
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ spec:
- name: temp_dir
value: {{ .Bk_Bscp_Variable_TempDir }}
{{ .Bk_Bscp_Variable_p2p_part1 }}
{{ .Bk_Bscp_Variable_Rules }}
# 需要同时挂载文件临时目录到 Init 容器,sidecar 容器,业务容器
volumeMounts:
- mountPath: {{ .Bk_Bscp_Variable_TempDir }}
Expand Down
11 changes: 10 additions & 1 deletion bcs-services/bcs-bscp/ui/src/i18n/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ export default {
复制命令: 'Command Copy',
'仅支持字母,数字,\'-\',\'_\',\'.\' 及 \'/\' 且需以字母数字开头和结尾': 'Only supports letters, numbers, \'-\', \'_\', \'.\' and \'/\' characters, and must start and end with a letter or number',
'需以字母、数字开头和结尾,可包含 \'-\',\'_\',\'.\' 和字母数字及负数': 'Must start and end with a letter or number, can include \'-\', \'_\', \'.\', and alphanumeric characters, as well as negative numbers',
服务标签: 'service label',
服务标签: 'Service label',
'启用 P2P 网络加速': 'Enable P2P network acceleration',
查看说明: 'View instructions',
'启用 P2P 网络加速主要适用于业务但配置文件较大及大量节点拉取配置的场景,以实现更优的文件传输速度。': 'Enabling P2P network acceleration is primarily suitable for scenarios where business configuration files are large and many nodes are pulling configurations, to achieve better file transfer speeds',
Expand All @@ -867,6 +867,15 @@ export default {
'请输入BCS 集群 ID,替换下方示例代码后,再尝试复制示例': 'Please enter the BCS cluster ID, replace the example code below, and then try copying the example',
'BCS集群ID须符合以下格式:BCS-K8S-xxxxx,其中xxxxx为5位数字': 'The BCS cluster ID must follow the format: BCS-K8S-xxxxx, where xxxxx is a five-digit numbe',
一键复制: 'Copy',
启用配置文件筛选: 'Enable configuration file filtering',
'当客户端无需拉取配置服务中的全量配置文件时,可以启用此功能,指定相应的通配符,可仅拉取客户端所需的文件': 'When the client does not need to pull the full configuration files from the configuration service, this feature can be enabled. By specifying the appropriate wildcard, the client can pull only the required files',
已设置的筛选规则: '{count} filtering rules have been set',
规则设置: 'Rule configuration',
配置文件筛选规则: 'Configuration file filter rules',
配置文件筛选: 'Configuration file filter',
'全局配置文件筛选:': 'Global Configuration File Filter:',
'(全局配置文件筛选与服务配置文件筛选一样,不同的是全局配置文件筛选可供多个服务共用)': '(The filtering of the global configuration file is the same as that of the service configuration file; the difference is that the global configuration file can be shared among multiple services)',
配置筛选规则: 'Configuration filtering rules',

// 公共组件
页面不存在: 'Page does not exist',
Expand Down
9 changes: 9 additions & 0 deletions bcs-services/bcs-bscp/ui/src/i18n/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,15 @@ export default {
'请输入BCS 集群 ID,替换下方示例代码后,再尝试复制示例': '请输入BCS 集群 ID,替换下方示例代码后,再尝试复制示例',
'BCS集群ID须符合以下格式:BCS-K8S-xxxxx,其中xxxxx为5位数字': 'BCS集群ID须符合以下格式:BCS-K8S-xxxxx,其中xxxxx为5位数字',
一键复制: '一键复制',
启用配置文件筛选: '启用配置文件筛选',
'当客户端无需拉取配置服务中的全量配置文件时,可以启用此功能,指定相应的通配符,可仅拉取客户端所需的文件': '当客户端无需拉取配置服务中的全量配置文件时,可以启用此功能,指定相应的通配符,可仅拉取客户端所需的文件',
已设置的筛选规则: '已设置 {count} 个筛选规则',
规则设置: '规则设置',
配置文件筛选规则: '配置文件筛选规则',
配置文件筛选: '配置文件筛选',
'全局配置文件筛选:': '全局配置文件筛选:',
'(全局配置文件筛选与服务配置文件筛选一样,不同的是全局配置文件筛选可供多个服务共用)': '全局配置文件筛选与服务配置文件筛选一样,不同的是全局配置文件筛选可供多个服务共用',
配置筛选规则: '配置筛选规则',

// 公共组件
页面不存在: '页面不存在',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
<template>
<div class="associate-config">
<!-- 标签 -->
<div class="associate-config-wrap">
<span class="label-span">{{ $t('启用配置文件筛选') }}</span>
<info
class="icon-info"
v-bk-tooltips="{
content: $t(
'当客户端无需拉取配置服务中的全量配置文件时,可以启用此功能,指定相应的通配符,可仅拉取客户端所需的文件',
),
placement: 'top',
}" />
<bk-switcher class="label-switch" :value="configSwitch" size="small" theme="primary" @change="handleSwitcher" />
</div>
<div class="associate-config-content" v-if="configSwitch">
<div class="associate-info-wrap">
<div class="associate-info-count">{{ $t('已设置的筛选规则', { count: ruleList.length }) }}</div>
<bk-button class="associate-info-btn" theme="primary" size="small" text @click="openRuleConfig">
<cog-shape class="btn-icon" />{{ $t('规则设置') }}
</bk-button>
</div>
<associate-side-bar
:show="sideBarShow"
:id="-1"
:perm-check-loading="permCheckLoading"
:has-manage-perm="hasManagePerm"
:example-rules="rules"
:is-example-mode="true"
@send-example-rules="updateRule"
@close="handleClose" />
</div>
</div>
</template>
<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { Info, CogShape } from 'bkui-vue/lib/icon';
import associateSideBar from '../../../credentials/associate-config-items/index.vue';
import { permissionCheck } from '../../../../../api/index';
import { ICredentialRule, IRuleUpdateParams } from '../../../../../../types/credential';
const emits = defineEmits(['updateRules']);
const route = useRoute();
const spaceId = ref(Number(route.params.spaceId));
const configSwitch = ref(false);
const sideBarShow = ref(false);
const permCheckLoading = ref(false);
const hasManagePerm = ref(false);
const ruleList = ref<{ app: string; scope: string; id: number }[]>([]);
const rules = ref<ICredentialRule[]>([]);
onMounted(() => {
getPermData();
});
const getPermData = async () => {
permCheckLoading.value = true;
const res = await permissionCheck({
resources: [
{
biz_id: spaceId.value,
basic: {
type: 'credential',
action: 'manage',
},
},
],
});
hasManagePerm.value = res.is_allowed;
permCheckLoading.value = false;
};
// 获取筛选的规则
const updateRule = (data: IRuleUpdateParams) => {
const { add_scope, alter_scope, del_id } = data;
if (add_scope.length) {
add_scope.forEach((item) => {
ruleList.value.push({
app: item.app,
scope: item.scope,
id: Math.floor(Math.random() * 10000) + 1, // 配置示例没有规则id配置与返回
});
});
}
if (alter_scope.length) {
alter_scope.forEach((alter) => {
const scopeToUpdate = ruleList.value.find((item) => item.id === alter.id);
if (scopeToUpdate) {
scopeToUpdate.scope = alter.scope;
}
});
}
if (del_id.length) {
const filteredVal = ruleList.value.filter((item) => !del_id.includes(item.id));
ruleList.value = filteredVal;
}
sendRules();
sideBarShow.value = false;
};
const openRuleConfig = () => {
rules.value = ruleList.value.map((item) => {
return {
id: item.id,
spec: {
scope: item.scope,
app: item.app,
},
attachment: {
biz_id: spaceId.value,
credential_id: -1,
},
revision: {
creator: '',
reviser: '',
create_at: '',
update_at: '',
expired_at: '',
},
};
});
sideBarShow.value = true;
};
const handleClose = () => {
sideBarShow.value = false;
};
const handleSwitcher = (val: boolean) => {
configSwitch.value = val;
if (!val) {
ruleList.value = [];
sendRules();
}
};
const sendRules = () => {
const ruleString = ruleList.value.map((item) => item.scope);
emits('updateRules', ruleString);
};
</script>

<style scoped lang="scss">
.associate-config-wrap {
display: flex;
justify-content: flex-start;
align-items: center;
}
.label-span {
font-size: 12px;
line-height: 20px;
color: #63656e;
&.em {
cursor: pointer;
color: #3a84ff;
}
&.required {
padding-right: 10px;
position: relative;
&::after {
content: '*';
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
font-size: 12px;
color: #ea3636;
}
}
}
.label-switch {
margin: 0 16px 0 12px;
}
.associate-config-content {
margin-top: 24px;
}
.icon-info {
margin-left: 9px;
font-size: 14px;
color: #979ba5;
cursor: pointer;
}
.popover-wrap {
font-size: 14px;
}
.popover-block {
line-height: 22px;
color: #63656e;
&-gap {
margin-top: 20px;
}
}
.popover-btn {
display: block;
margin: 8px 0 0 auto;
}
.associate-info-wrap {
padding: 6px 12px;
display: inline-flex;
justify-content: flex-start;
align-items: center;
font-size: 12px;
line-height: 20px;
background-color: #f5f7fa;
}
.associate-info-count {
position: relative;
padding-right: 12px;
&::after {
content: '';
position: absolute;
right: 0;
top: 0;
width: 1px;
height: 100%;
background-color: #dcdee5;
}
}
.associate-info-btn {
margin-left: 12px;
.btn-icon {
margin-right: 4px;
font-size: 16px;
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<form-option
ref="fileOptionRef"
:directory-show="basicInfo!.serviceType.value === 'file'"
:associate-config-show="basicInfo!.serviceType.value === 'file'"
@update-option-data="getOptionData" />
<div class="preview-container">
<p class="headline">{{ $t('配置指引与示例预览') }}</p>
Expand Down Expand Up @@ -142,6 +143,7 @@
privacyCredential: '',
labelArr: [],
tempDir: '',
rules: [],
});
const cmdContent = computed(() => {
Expand Down Expand Up @@ -173,7 +175,19 @@
let updateString = replaceVal.value;
updateString = updateString.replace('{{ .Bk_Bscp_Variable_BkBizId }}', bkBizId.value);
updateString = updateString.replace('{{ .Bk_Bscp_Variable_ServiceName }}', basicInfo!.serviceName.value);
replaceVal.value = updateString.replaceAll('{{ .Bk_Bscp_Variable_FEED_ADDR }}', (window as any).GRPC_ADDR);
updateString = updateString.replaceAll('{{ .Bk_Bscp_Variable_FEED_ADDR }}', (window as any).GRPC_ADDR);
// 文件配置筛选规则动态增/删
if (optionData.value.rules?.length) {
const rulesPart = `
# 当客户端无需拉取配置服务中的全量配置文件时,指定相应的通配符,可仅拉取客户端所需的文件,支持多个通配符
config_matches
${optionData.value.rules.map((rule) => `- "${rule}"`).join('\n')}`;
updateString = updateString.replaceAll('{{ .Bk_Bscp_Variable_Rules }}', rulesPart.trim());
} else {
updateString = updateString.replaceAll('{{ .Bk_Bscp_Variable_Rules }}', '');
}
// 去除 动态插入的值为空的情况下产生的空白行
replaceVal.value = updateString.replaceAll(/\r\n\s+\r\n/g, '\n');
};
const updateVariables = () => {
variables.value = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<template>
<section class="example-wrap">
<form-option ref="fileOptionRef" :p2p-show="true" @update-option-data="getOptionData" />
<form-option
ref="fileOptionRef"
:p2p-show="true"
:associate-config-show="true"
@update-option-data="getOptionData" />
<div class="preview-container">
<span class="preview-label">{{ $t('示例预览') }}</span>
<bk-button theme="primary" class="copy-btn" @click="copyExample">{{ $t('复制示例') }}</bk-button>
Expand Down Expand Up @@ -41,6 +45,7 @@
tempDir: '',
clusterSwitch: false,
clusterInfo: '',
rules: [],
});
const bkBizId = ref(String(route.params.spaceId));
const replaceVal = ref('');
Expand Down Expand Up @@ -98,13 +103,24 @@
apiVersion: v1
fieldPath: metadata.uid`;
updateString = updateString.replaceAll('{{ .Bk_Bscp_Variable_p2p_part1 }}', p2pPart1.trim());
replaceVal.value = updateString.replaceAll('{{ .Bk_Bscp_Variable_p2p_part2 }}', p2pPart2.trim());
updateString = updateString.replaceAll('{{ .Bk_Bscp_Variable_p2p_part2 }}', p2pPart2.trim());
} else {
updateString = updateString.replaceAll('{{ .Bk_Bscp_Variable_p2p_part1 }}', '');
updateString = updateString.replaceAll('{{ .Bk_Bscp_Variable_p2p_part2 }}', '');
// 去除不含p2p相关内容后,遗留的空白行去除
replaceVal.value = updateString.replaceAll(/\r\n\s+\r\n/g, '\n');
}
// 文件配置筛选规则动态增/删
if (optionData.value.rules?.length) {
const rulesPart = `
# 当客户端无需拉取配置服务中的全量配置文件时,指定相应的通配符,可仅拉取客户端所需的文件,支持多个通配符
- name: config_matches
value: ${optionData.value.rules}`;
updateString = updateString.replaceAll('{{ .Bk_Bscp_Variable_Rules }}', rulesPart.trim());
} else {
updateString = updateString.replaceAll('{{ .Bk_Bscp_Variable_Rules }}', '');
}
// 去除 动态插入的值为空的情况下产生的空白行
replaceVal.value = updateString.replaceAll(/\r\n\s+\r\n/g, '\n');
};
// 高亮配置
const updateVariables = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
const kvConfig = computed(() => {
// @ts-ignore
// eslint-disable-next-line
const url = BSCP_CONFIG.python_sdk_dependency_doc;
const url = (typeof BSCP_CONFIG !== 'undefined' && BSCP_CONFIG.python_sdk_dependency_doc) || '';
switch (props.kvName) {
case 'python':
// get
Expand Down
Loading

0 comments on commit 9d411e7

Please sign in to comment.