Skip to content

Commit 36a6b60

Browse files
authored
feat: apigw-manager support stages (TencentBlueKing#174)
1 parent 31eef02 commit 36a6b60

8 files changed

Lines changed: 186 additions & 198 deletions

File tree

sdks/apigw-manager/README.md

Lines changed: 77 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,63 @@ definition.yaml 中可以使用 Django 模版语法引用和渲染变量,内
7474

7575
推荐在一个文件中统一进行定义,用命名空间区分不同配置间的定义,definition.yaml 样例:
7676

77+
目前有两种配置文件版本:spec_version=1/2,主要区别就是stage相关的配置方式上有一些不一样。
78+
新接入系统请使用 spec_version=2, 旧有系统如果需要配置多个stage/配置多个backend, 建议也升级到spec_version=2并变更相关yaml配置。
79+
区别如下:
80+
spec_version: 1
7781
```yaml
78-
# definition.yaml 配置文件版本号,必填,固定值 1
82+
# definition.yaml 配置文件版本号,必填,固定值 1/2
83+
# 1:key为stage; 只支持单个 stage, 并且 proxy_http只能配置一个后端服务
7984
spec_version: 1
85+
stage:
86+
name: "prod"
87+
description: "描述"
88+
description_en: "English description"
89+
proxy_http:
90+
timeout: "65"
91+
upstreams:
92+
loadbalance: "roundrobin"
93+
hosts:
94+
- host: "http://httpbin.org"
95+
weight: 100
96+
```
97+
98+
spec_version: 2
99+
```yaml
100+
# definition.yaml 配置文件版本号,必填,固定值 1/2
101+
# 2:key为stages; 支持多个stages,并且每个stage可以配置多个backend后端服务
102+
spec_version: 2
103+
stages:
104+
- name: "prod"
105+
description: "描述"
106+
description_en: "English description"
107+
vars:
108+
status_500: "500"
109+
backends:
110+
- name: "default"
111+
config:
112+
timeout: 60
113+
loadbalance: "roundrobin"
114+
hosts:
115+
- host: "http://httpbin.org"
116+
weight: 100
117+
118+
- name: "backend1"
119+
config:
120+
timeout: 60
121+
loadbalance: "roundrobin"
122+
hosts:
123+
- host: "http://httpbin.org"
124+
weight: 100
125+
```
126+
> 📢 注意:如果之前接入过的,建议将 sepc_version改成 2,并将原先 `stage:{}`改成 `stages: []`
127+
128+
129+
整体的样例:
130+
131+
```yaml
132+
# definition.yaml 配置文件版本号,必填,固定值 1/2
133+
spec_version: 2 # 如果之前接入过的,建议将 sepc_version改成 2,并将原先 stage:改成 stages: []
80134
81135
# 定义发布内容,用于命令 `create_version_and_release_apigw`
82136
release:
@@ -97,52 +151,35 @@ apigateway:
97151
is_public: true
98152
# 标记网关为官方网关,网关名需以 `bk-` 开头,可选;非官方网关,可去除此配置
99153
api_type: 1
100-
# 应用请求网关时,是否允许从请求参数 (querystring, body) 中获取蓝鲸认证信息,默认值为 true;
101-
# 如果为 false,则只能从请求头 X-Bkapi-Authorization 获取蓝鲸认证信息;
102-
# 新接入的网关,可以设置为 false,已接入的网关,待推动所有调用者将认证信息放到请求头后,可设置为 false
103-
allow_auth_from_params: false
104-
# 网关请求后端时,是否删除请求参数 (querystring, body) 中的蓝鲸认证敏感信息,比如 bk_token,为 true 表示允许删除;
105-
# 待请求网关的所有调用者,将认证参数放到请求头 X-Bkapi-Authorization 时,可将此值设置为 false
106-
allow_delete_sensitive_params: false
107154
# 网关维护人员,仅维护人员有管理网关的权限
108155
maintainers:
109156
- "admin"
110157

111158
# 定义环境信息,用于命令 `sync_apigw_stage`
112-
stage:
113-
name: "prod"
114-
description: "描述"
115-
# 环境的英文名,蓝鲸官方网关需提供,以支持国际化
116-
description_en: "English description"
117-
# 环境变量;如未使用,可去除此配置
118-
# vars:
119-
# key: "value"
120-
# 代理配置
121-
# proxy_http 与 backends 二选一, 推荐使用 backends 方式配置
122-
# 网关版本 <= 1.13.3, 只支持一个后端服务, 默认是 default
123-
# proxy_http:
124-
# timeout: 60
125-
# # 负载均衡类型 + Hosts
126-
# upstreams:
127-
# loadbalance: "roundrobin"
128-
# hosts:
129-
# # 网关调用后端服务的默认域名或IP,不包含Path,比如:http://api.example.com
130-
# - host: ""
131-
# weight: 100
132-
133-
# 网关版本 1.13.3之后引入 backends 配置方式,支持多后端服务
134-
# 注意: 资源中引用的 backend 一定要配置, 否则会导入失败,不配置则会选择 default 后端服务
135-
# 如果 backends 没有配置 default 且 resource 未指定 backend 则会导致版本发布校验失败
136-
backends:
159+
stages:
160+
- name: "prod"
161+
description: "描述"
162+
# 环境的英文名,蓝鲸官方网关需提供,以支持国际化
163+
description_en: "English description"
164+
# 环境变量;如未使用,可去除此配置
165+
# vars:
166+
# key: "value"
167+
# 代理配置
168+
# proxy_http 与 backends 二选一, 推荐使用 backends 方式配置
169+
# 网关版本 <= 1.13.3, 只支持一个后端服务, 默认是 default
170+
# 网关版本 1.13.3之后引入 backends 配置方式,支持多后端服务
171+
# 注意: 资源中引用的 backend 一定要配置, 否则会导入失败,不配置则会选 择 default 后端服务
172+
# 如果 backends 没有配置 default 且 resource 未指定 backend 则会导致版本发布校验失败
173+
backends:
137174
- name: "default"
138175
config:
139-
timeout: 60
140-
loadbalance: "roundrobin"
141-
hosts:
142-
# 网关调用后端服务的默认域名或IP,不包含Path,比如:http://api.example.com
143-
- host: ""
144-
weight: 100
145-
176+
timeout: 60
177+
loadbalance: "roundrobin"
178+
hosts:
179+
# 网关调用后端服务的默认域名或IP,不包含Path,比如: http://api.example.com
180+
- host: ""
181+
weight: 100
182+
146183
- name: "service1"
147184
config:
148185
timeout: 60
@@ -175,22 +212,6 @@ stage:
175212
# allow_credential: false
176213

177214

178-
# 支持定义多个stage,如果定义多个,则同步脚本需要添加对应的同步命令,并指明:namespace(默认:stage) eg:stage2
179-
# 同步脚本 sync-apigateway.sh 需要新增以下命令:
180-
# python manage.py sync_apigw_stage --gateway-name=${gateway_name} --file="${definition_file}" --namespace="stage2"
181-
182-
#stage2:
183-
# name: "test"
184-
# description: "这是一个测试"
185-
# description_en: "This is a test"
186-
# proxy_http:
187-
# timeout: 60
188-
# upstreams:
189-
# loadbalance: "roundrobin"
190-
# hosts:
191-
# - host: "https://httpbin.org"
192-
# weight: 100
193-
194215

195216
# 主动授权,网关主动给应用,添加访问网关所有资源或者具体某个资源的权限;
196217
# 用于命令 `grant_apigw_permissions`

sdks/apigw-manager/README.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ definition.yaml 中可以使用 Django 模版语法引用和渲染变量,内
116116
is_public: true
117117
# 标记网关为官方网关,网关名需以 `bk-` 开头,可选;非官方网关,可去除此配置
118118
api_type: 1
119-
# 应用请求网关时,是否允许从请求参数 (querystring, body) 中获取蓝鲸认证信息,默认值为 true;
120-
# 如果为 false,则只能从请求头 X-Bkapi-Authorization 获取蓝鲸认证信息;
121-
# 新接入的网关,可以设置为 false,已接入的网关,待推动所有调用者将认证信息放到请求头后,可设置为 false
122-
allow_auth_from_params: false
123-
# 网关请求后端时,是否删除请求参数 (querystring, body) 中的蓝鲸认证敏感信息,比如 bk_token,为 true 表示允许删除;
124-
# 待请求网关的所有调用者,将认证参数放到请求头 X-Bkapi-Authorization 时,可将此值设置为 false
125-
allow_delete_sensitive_params: false
126119
# 网关维护人员,仅维护人员有管理网关的权限
127120
maintainers:
128121
- "admin"

sdks/apigw-manager/examples/chart/use-configmap/files/support-files/definition.yaml

Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
spec_version: 1
1+
spec_version: 2
22

33
release:
44
# 发布版本号
@@ -13,56 +13,41 @@ apigateway:
1313
maintainers:
1414
- "admin"
1515

16-
stage:
17-
name: "prod"
18-
description: "这是一个测试"
19-
description_en: "This is a test"
20-
proxy_http:
21-
timeout: 60
22-
upstreams:
23-
loadbalance: "roundrobin"
24-
hosts:
25-
- host: "https://httpbin.org"
26-
weight: 100
27-
# 环境插件配置
28-
# plugin_configs:
29-
# - type: bk-rate-limit
30-
# yaml: |-
31-
# rates:
32-
# __default:
33-
# - period: 1
34-
# tokens: 100
35-
# - type: bk-header-rewrite
36-
# yaml: |-
37-
# set:
38-
# - key: test
39-
# value: '2'
40-
# remove: []
41-
# - type: bk-cors
42-
# yaml: |-
43-
# allow_origins: '*'
44-
# allow_methods: '*'
45-
# allow_headers: '*'
46-
# expose_headers: '*'
47-
# max_age: 86400
48-
# allow_credential: false
49-
50-
51-
# 支持定义多个stage,如果定义多个,则同步脚本需要添加对应的同步命令,并指明:namespace(默认:stage) eg:stage2
52-
# 同步脚本 sync-apigateway.sh 需要新增以下命令:
53-
# call_definition_command_or_exit sync_apigw_stage "${definition_file}" --gateway-name=${gateway_name} --namespace="stage2"
54-
55-
#stage2:
56-
# name: "test"
57-
# description: "这是一个测试"
58-
# description_en: "This is a test"
59-
# proxy_http:
60-
# timeout: 60
61-
# upstreams:
62-
# loadbalance: "roundrobin"
63-
# hosts:
64-
# - host: "https://httpbin.org"
65-
# weight: 100
16+
stages:
17+
- name: "prod"
18+
description: "这是一个测试"
19+
description_en: "This is a test"
20+
backends:
21+
- name: "default"
22+
config:
23+
timeout: 60
24+
loadbalance: "roundrobin"
25+
hosts:
26+
# 网关调用后端服务的默认域名或IP,不包含Path,比如:http://api.example.com
27+
- host: "https://httpbin.org"
28+
weight: 100
29+
# 环境插件配置
30+
# plugin_configs:
31+
# - type: bk-rate-limit
32+
# yaml: |-
33+
# rates:
34+
# __default:
35+
# - period: 1
36+
# tokens: 100
37+
# - type: bk-header-rewrite
38+
# yaml: |-
39+
# set:
40+
# - key: test
41+
# value: '2'
42+
# remove: []
43+
# - type: bk-cors
44+
# yaml: |-
45+
# allow_origins: '*'
46+
# allow_methods: '*'
47+
# allow_headers: '*'
48+
# expose_headers: '*'
49+
# max_age: 86400
50+
# allow_credential: false
6651

6752

6853

sdks/apigw-manager/examples/chart/use-custom-docker-image/my-apigw-manager/support-files/definition.yaml

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
spec_version: 1
1+
spec_version: 2
22

33
release:
44
# 发布版本号
@@ -13,55 +13,42 @@ apigateway:
1313
maintainers:
1414
- "admin"
1515

16-
stage:
17-
name: "prod"
18-
description: "这是一个测试"
19-
description_en: "This is a test"
20-
proxy_http:
21-
timeout: 60
22-
upstreams:
23-
loadbalance: "roundrobin"
24-
hosts:
25-
- host: "https://httpbin.org"
26-
weight: 100
27-
# 环境插件配置
28-
# plugin_configs:
29-
# - type: bk-rate-limit
30-
# yaml: |-
31-
# rates:
32-
# __default:
33-
# - period: 1
34-
# tokens: 100
35-
# - type: bk-header-rewrite
36-
# yaml: |-
37-
# set:
38-
# - key: test
39-
# value: '2'
40-
# remove: []
41-
# - type: bk-cors
42-
# yaml: |-
43-
# allow_origins: '*'
44-
# allow_methods: '*'
45-
# allow_headers: '*'
46-
# expose_headers: '*'
47-
# max_age: 86400
48-
# allow_credential: false
49-
50-
# 支持定义多个stage,如果定义多个,则同步脚本需要添加对应的同步命令,并指明:namespace(默认:stage) eg:stage2
51-
# 同步脚本 sync-apigateway.sh 需要新增以下命令:
52-
# call_definition_command_or_exit sync_apigw_stage "${definition_file}" --gateway-name=${gateway_name} --namespace="stage2"
16+
stages:
17+
- name: "prod"
18+
description: "这是一个测试"
19+
description_en: "This is a test"
20+
backends:
21+
- name: "default"
22+
config:
23+
timeout: 60
24+
loadbalance: "roundrobin"
25+
hosts:
26+
# 网关调用后端服务的默认域名或IP,不包含Path,比如:http://api.example.com
27+
- host: "https://httpbin.org"
28+
weight: 100
5329

54-
#stage2:
55-
# name: "test"
56-
# description: "这是一个测试"
57-
# description_en: "This is a test"
58-
# proxy_http:
59-
# timeout: 60
60-
# upstreams:
61-
# loadbalance: "roundrobin"
62-
# hosts:
63-
# - host: "https://httpbin.org"
64-
# weight: 100
30+
# 环境插件配置
31+
# plugin_configs:
32+
# - type: bk-rate-limit
33+
# yaml: |-
34+
# rates:
35+
# __default:
36+
# - period: 1
37+
# tokens: 100
38+
# - type: bk-header-rewrite
39+
# yaml: |-
40+
# set:
41+
# - key: test
42+
# value: '2'
43+
# remove: []
44+
# - type: bk-cors
45+
# yaml: |-
46+
# allow_origins: '*'
47+
# allow_methods: '*'
48+
# allow_headers: '*'
49+
# expose_headers: '*'
50+
# max_age: 86400
51+
# allow_credential: false
6552

6653
# 资源文档
6754
# 资源文档的目录格式样例如下,en 为英文文档,zh 为中文文档:

0 commit comments

Comments
 (0)