-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'github-bk-bcs/master'
* github-bk-bcs/master: fix: 操作中的按钮需禁用 --bug=126386957 (#3309) feat:配置示例需求部分代码 --story=885066745 (#3256) feat: 模板文件部署annotation 注入版本和模板名,同时资源视图列表增加版本和模板名解析 (#3310)
- Loading branch information
Showing
49 changed files
with
2,718 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
bcs-services/bcs-bscp/ui/src/assets/exampleData/file-cmd.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# 业务 ID,从当前环境自动获取,无需修改 | ||
biz: {{ .Bk_Bscp_Variable_BkBizId }} | ||
|
||
# 服务订阅地址,从当前环境自动获取,无需修改 | ||
feed_addr: {{ .Bk_Bscp_Variable_FEED_ADDR }} | ||
|
||
# 客户端密钥,请填写与此服务配置关联过的实际客户端密钥 | ||
token: {{ .Bk_Bscp_Variable_ClientKey }} | ||
|
||
# 实例标签,实例标签通常用于按标签进行灰度发布,支持多个标签,请填写实际实例标签键值;如果不需要按标签灰度发布,可不填写此环境变量 | ||
labels: {{ .Bk_Bscp_Variable_Leabels }} | ||
# 临时目录,在拉取配置文件时,用于存储配置文件的目录,默认为:/data/bscp,可根据实际情况调整 | ||
temp_dir: {{ .Bk_Bscp_VariableTempDir }} |
76 changes: 76 additions & 0 deletions
76
bcs-services/bcs-bscp/ui/src/assets/exampleData/file-container.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# 在正式业务使用时,请根据实际情况将以下 manifest 中的 kind、metadata、selector、labels 以及 Nginx 示例容器替换为业务相应的信息 | ||
|
||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: demo_app | ||
namespace: default | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: demo_app | ||
template: | ||
metadata: | ||
labels: | ||
app: demo_app | ||
spec: | ||
initContainers: | ||
# BSCP Init 容器在 Pod 启动时负责首次下载配置文件至指定目录,以避免因缺少配置文件导致业务程序无法正常启动的问题 | ||
- name: bscp-init | ||
image: ccr.ccs.tencentyun.com/blueking/bscp-init:latest | ||
env: | ||
# 业务 ID,从当前环境自动获取,无需修改 | ||
- name: biz | ||
value: {{ .Bk_Bscp_Variable_BkBizId }} | ||
# 服务名称,从当前环境自动获取,无需修改 | ||
- name: app | ||
value: {{ .Bk_Bscp_Variable_ServiceName }} | ||
# 服务订阅地址,从当前环境自动获取,无需修改 | ||
- name: feed_addrs | ||
value: {{ .Bk_Bscp_Variable_FEED_ADDR }} | ||
# 客户端密钥,请将 value 赋值为与此服务配置关联过的实际客户端密钥 | ||
- name: token | ||
value: {{ .Bk_Bscp_Variable_ClientKey }} | ||
# 实例标签,实例标签通常用于按标签进行灰度发布,支持多个标签,如:'{"app": "nginx", "area": "shanghai"}',请填写实际实例标签 value;如果不需要按标签灰度发布,可不填写此环境变量 | ||
- name: labels | ||
value: {{ .Bk_Bscp_Variable_Leabels }} | ||
# 配置文件临时目录,文件将下发到 {temp_dir}/files 目录下 | ||
- name: temp_dir | ||
value: {{ .Bk_Bscp_VariableTempDir }} | ||
# 需要同时挂载文件临时目录到 Init 容器,sidecar 容器,业务容器 | ||
volumeMounts: | ||
- mountPath: {{ .Bk_Bscp_VariableTempDir }} | ||
name: bscp-temp-dir | ||
containers: | ||
# 以 Nginx 容器为例的业务容器,正式使用时需将其替换为实际业务程序容器 | ||
- name: Nginx | ||
image: nginx | ||
ports: | ||
- containerPort: 80 | ||
# 需要同时挂载文件临时目录到 Init 容器,sidecar 容器,业务容器 | ||
volumeMounts: | ||
- mountPath: {{ .Bk_Bscp_VariableTempDir }} | ||
name: bscp-temp-dir | ||
# BSCP Sidecar 容器负责监控配置文件版本变动,并将更新的配置文件下载到指定临时目录,业务可以通过后置脚本或其他流程实现新配置文件的生效 | ||
- name: bscp-sidecar | ||
image: ccr.ccs.tencentyun.com/blueking/bscp-sidecar:latest | ||
env: | ||
# bscp-sidecar 容器的环境变量配置和 bscp-init 容器完全一致,正式使用时填写 token 与 labels 环境变量实际值即可 | ||
- name: biz | ||
value: 2 | ||
- name: app | ||
value: demo_app | ||
- name: feed_addrs | ||
value: {{ .Bk_Bscp_Variable_FEED_ADDR }} | ||
- name: token | ||
value: {{ .Bk_Bscp_Variable_ClientKey }} | ||
- name: labels | ||
value: {{ .Bk_Bscp_Variable_Leabels }} | ||
- name: temp_dir | ||
value: {{ .Bk_Bscp_VariableTempDir }} | ||
volumeMounts: | ||
- mountPath: {{ .Bk_Bscp_VariableTempDir }} | ||
name: bscp-temp-dir | ||
volumes: | ||
- name: bscp-temp-dir | ||
emptyDir: '{}' |
72 changes: 72 additions & 0 deletions
72
bcs-services/bcs-bscp/ui/src/assets/exampleData/kv-c++-pull.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
### Pull | ||
|
||
```c++ | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
#include "client.h" | ||
int main(int argc, char** argv) | ||
{ | ||
// set client options. | ||
bscp::core::ClientOptions options; | ||
options.m_feedAddrs.push_back({{ .Bk_Bscp_Variable_FEED_ADDR }}); | ||
options.m_token = {{ .Bk_Bscp_Variable_ClientKey }}; | ||
options.m_bizID = {{ .Bk_Bscp_Variable_BkBizId }}; | ||
options.m_sideRid = "xx"; | ||
// labels. | ||
std::map<std::string, std::string> labels{{{ .Bk_Bscp_Variable_Leabels }}}; | ||
options.m_labels = labels; | ||
// instantiate client. | ||
bscp::Client client(options); | ||
// set log handle, if not set, no logs will be output. | ||
bscp::log::Log::SetLogHandler([](const bscp::log::LogLevel& level, const std::string& msg) { | ||
std::cout << msg << std::endl; | ||
return 0; | ||
}); | ||
// you must initialize before you use client. | ||
auto ret = client.Initialize(); | ||
if (ret) | ||
{ | ||
std::cout << "failed to initialize client" << std::endl; | ||
return ret; | ||
} | ||
bscp::core::AppOptions appOptions; | ||
std::string app = "{{ .Bk_Bscp_Variable_ServiceName }}"; | ||
std::vector<std::string> match; | ||
bscp::Release release; | ||
ret = client.PullKvs(app, match, appOptions, release); | ||
if (ret) | ||
{ | ||
std::cout << "call get error, err-code(" << ret << ")" << std::endl; | ||
return 0; | ||
} | ||
std::cout << "release ID: " << release.m_releaseID << std::endl; | ||
for (auto kv : release.m_kvItems) | ||
{ | ||
std::string value; | ||
ret = client.Get(app, kv.m_key, appOptions, value); | ||
if (ret) | ||
{ | ||
std::cout << "call get error, err-code(" << ret << ")" << std::endl; | ||
return ret; | ||
} | ||
std::cout << kv.m_key << "=" << value << std::endl; | ||
} | ||
std::cout << "call pull kvs success" << std::endl; | ||
return 0; | ||
} |
107 changes: 107 additions & 0 deletions
107
bcs-services/bcs-bscp/ui/src/assets/exampleData/kv-c++-watch.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
### Watch | ||
|
||
```c++ | ||
#include <ctime> | ||
#include <iostream> | ||
#include <string> | ||
#include <thread> | ||
#include <vector> | ||
#include <unistd.h> | ||
#include "client.h" | ||
int main(int argc, char** argv) | ||
{ | ||
// set client options. | ||
bscp::core::ClientOptions options; | ||
options.m_feedAddrs.push_back({{ .Bk_Bscp_Variable_FEED_ADDR }}); | ||
options.m_token = {{ .Bk_Bscp_Variable_ClientKey }}; | ||
options.m_bizID = {{ .Bk_Bscp_Variable_BkBizId }}; | ||
options.m_sideRid = "xx"; | ||
// labels. | ||
std::map<std::string, std::string> labels{{{ .Bk_Bscp_Variable_Leabels }}}; | ||
options.m_labels = labels; | ||
// instantiate client. | ||
bscp::Client client(options); | ||
// set log handle, if not set, no logs will be output. | ||
bscp::log::Log::SetLogHandler([](const bscp::log::LogLevel& level, const std::string& msg) { | ||
std::cout << msg << std::endl; | ||
return 0; | ||
}); | ||
// you must initialize before you use client. | ||
auto ret = client.Initialize(); | ||
if (ret) | ||
{ | ||
std::cout << "failed to initialize client" << std::endl; | ||
return ret; | ||
} | ||
bscp::core::AppOptions appOptions; | ||
std::string app = "{{ .Bk_Bscp_Variable_ServiceName }}"; | ||
// add watch. | ||
// set handle function for the watch receive release data. | ||
ret = client.AddWatcher( | ||
app, | ||
[&app, &appOptions, &client](const bscp::Release& release) { | ||
std::cout << "release ID: " << release.m_releaseID << std::endl; | ||
for (auto kv : release.m_kvItems) | ||
{ | ||
std::string value; | ||
auto ret = client.Get(app, kv.m_key, appOptions, value); | ||
if (ret) | ||
{ | ||
std::cout << "call get error, err-code(" << ret << ")" << std::endl; | ||
return ret; | ||
} | ||
std::cout << kv.m_key << "=" << value << std::endl; | ||
} | ||
return 0; | ||
}, | ||
appOptions); | ||
if (ret) | ||
{ | ||
std::cout << "failed to add watcher" << std::endl; | ||
} | ||
else | ||
{ | ||
std::cout << "add watcher success" << std::endl; | ||
} | ||
// watch. | ||
// call this to watch the bscp server, if bscp server publish new release, it will call the handle callback function | ||
// user setted to handle the received release data. | ||
ret = client.StartWatch(); | ||
if (ret) | ||
{ | ||
std::cout << "failed to start watch" << std::endl; | ||
} | ||
std::cout << "start watch success" << std::endl; | ||
// in here, user can exec their tasks. | ||
// feel free to call other client api in here, such as Client::Get(), Client::PullKvs(). | ||
std::cout << "exec other tasks" << std::endl; | ||
sleep(30); | ||
// when user does not need to watch, call stop watch to close the watch channel. | ||
ret = client.StopWatch(); | ||
if (ret) | ||
{ | ||
std::cout << "failed to stop watch" << std::endl; | ||
} | ||
else | ||
{ | ||
std::cout << "stop watch success" << std::endl; | ||
} | ||
return 0; | ||
} |
11 changes: 11 additions & 0 deletions
11
bcs-services/bcs-bscp/ui/src/assets/exampleData/kv-cmd.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# 业务 ID,从当前环境自动获取,无需修改 | ||
biz: {{ .Bk_Bscp_Variable_BkBizId }} | ||
|
||
# 服务订阅地址,从当前环境自动获取,无需修改 | ||
feed_addr: {{ .Bk_Bscp_Variable_FEED_ADDR }} | ||
|
||
# 客户端密钥,请填写与此服务配置关联过的实际客户端密钥 | ||
token: {{ .Bk_Bscp_Variable_ClientKey }} | ||
|
||
# 实例标签,实例标签通常用于按标签进行灰度发布,支持多个标签,请填写实际实例标签键值;如果不需要按标签灰度发布,可不填写此环境变量 | ||
labels: {{ .Bk_Bscp_Variable_Leabels }} |
58 changes: 58 additions & 0 deletions
58
bcs-services/bcs-bscp/ui/src/assets/exampleData/kv-go-pull.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
### Pull | ||
|
||
```golang | ||
// pull kv example for bscp sdk | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/TencentBlueKing/bscp-go/client" | ||
"github.com/TencentBlueKing/bscp-go/pkg/logger" | ||
) | ||
|
||
func main() { | ||
// 设置日志自定义 Handler | ||
// logger.SetHandler(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{})) | ||
|
||
// 在线服务, 可设置 metrics | ||
// metrics.RegisterMetrics() | ||
// http.Handle("/metrics", promhttp.Handler()) | ||
|
||
// 初始化配置信息 | ||
var feedAddr string = "{{ .Bk_Bscp_Variable_FEED_ADDR }}" | ||
var biz uint32 = {{ .Bk_Bscp_Variable_BkBizId }} | ||
var token string = {{ .Bk_Bscp_Variable_ClientKey }} | ||
var app string = "{{ .Bk_Bscp_Variable_ServiceName }}" | ||
|
||
labels := map[string]string{ | ||
{{ .Bk_Bscp_Variable_Leabels }} | ||
} | ||
|
||
bscp, err := client.New( | ||
client.WithFeedAddr(feedAddr), | ||
client.WithBizID(biz), | ||
client.WithToken(token), | ||
client.WithLabels(labels), | ||
) | ||
if err != nil { | ||
logger.Error("init client", logger.ErrAttr(err)) | ||
os.Exit(1) | ||
} | ||
|
||
opts := []client.AppOption{} | ||
|
||
release, err := bscp.PullKvs(app, []string{}, opts...) | ||
|
||
for _, kv := range release.KvItems { | ||
value, err := bscp.Get(app, kv.Key, opts...) | ||
if err != nil { | ||
logger.Error("get value", logger.ErrAttr(err)) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Printf("%s=%s\n", kv.Key, value) | ||
} | ||
} |
Oops, something went wrong.