Skip to content

Commit 77699dc

Browse files
committed
修复maxPod字段
* 同步 crd 到 chart * 可选字段使用指针,避免apply时发生不预期现象 * 更新文档
1 parent f47ad20 commit 77699dc

File tree

7 files changed

+37
-15
lines changed

7 files changed

+37
-15
lines changed

api/v1alpha1/dedicatedclbservice_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type DedicatedCLBServiceSpec struct {
3030
LbRegion string `json:"lbRegion,omitempty"`
3131
// CLB 所在 VPC ID,不填则使用 TKE 集群所在的 VPC 的 ID。
3232
// +optional
33-
VpcId string `json:"vpcId"`
33+
VpcId *string `json:"vpcId"`
3434
// CLB 端口范围的最小端口号。
3535
// +optional
3636
// +kubebuilder:default:value=500
@@ -41,7 +41,7 @@ type DedicatedCLBServiceSpec struct {
4141
MaxPort int64 `json:"maxPort,omitempty"`
4242
// 限制单个 CLB 的 Pod/监听器 的最大数量。
4343
// +optional
44-
MaxPod int64 `json:"maxPod,omitempty"`
44+
MaxPod *int64 `json:"maxPod,omitempty"`
4545
// Pod 的标签选择器,被选中的 Pod 会被绑定到 CLB 监听器下。
4646
Selector map[string]string `json:"selector"`
4747
// Pod 监听的端口。

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/tke-extend-network-controller/templates/networking.cloud.tencent.com_dedicatedclbservices.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,17 @@ spec:
6060
listenerExtensiveParameters:
6161
description: 创建监听器的参数,JSON 格式,详细参数请参考 CreateListener 接口:https://cloud.tencent.com/document/api/214/30693
6262
type: string
63+
maxPod:
64+
description: 限制单个 CLB 的 Pod/监听器 的最大数量。
65+
format: int64
66+
type: integer
6367
maxPort:
68+
default: 50000
6469
description: CLB 端口范围的最大端口号。
6570
format: int64
6671
type: integer
6772
minPort:
73+
default: 500
6874
description: CLB 端口范围的最小端口号。
6975
format: int64
7076
type: integer
@@ -97,8 +103,6 @@ spec:
97103
description: CLB 所在 VPC ID,不填则使用 TKE 集群所在的 VPC 的 ID。
98104
type: string
99105
required:
100-
- maxPort
101-
- minPort
102106
- ports
103107
- selector
104108
type: object
@@ -145,3 +149,4 @@ spec:
145149
storage: true
146150
subresources:
147151
status: {}
152+

docs/api.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ _Appears in:_
2727
| Field | Description | Default | Validation |
2828
| --- | --- | --- | --- |
2929
| `lbId` _string_ | CLB 实例的 ID。 | | |
30-
| `maxPort` _integer_ | CLB 当前已被分配的端口。 | | |
30+
| `currentPort` _integer_ | CLB 当前已被分配的端口。 | | |
3131
| `autoCreate` _boolean_ | 是否是自动创建的 CLB。如果是,删除 DedicatedCLBService 时,CLB 也会被清理。 | | |
3232

3333

@@ -163,8 +163,9 @@ _Appears in:_
163163
| --- | --- | --- | --- |
164164
| `lbRegion` _string_ | CLB 所在地域,不填则使用 TKE 集群所在的地域。 | | |
165165
| `vpcId` _string_ | CLB 所在 VPC ID,不填则使用 TKE 集群所在的 VPC 的 ID。 | | |
166-
| `minPort` _integer_ | CLB 端口范围的最小端口号。 | | |
167-
| `maxPort` _integer_ | CLB 端口范围的最大端口号。 | | |
166+
| `minPort` _integer_ | CLB 端口范围的最小端口号。 | 500 | |
167+
| `maxPort` _integer_ | CLB 端口范围的最大端口号。 | 50000 | |
168+
| `maxPod` _integer_ | 限制单个 CLB 的 Pod/监听器 的最大数量。 | | |
168169
| `selector` _object (keys:string, values:string)_ | Pod 的标签选择器,被选中的 Pod 会被绑定到 CLB 监听器下。 | | |
169170
| `ports` _[DedicatedCLBServicePort](#dedicatedclbserviceport) array_ | Pod 监听的端口。 | | |
170171
| `listenerExtensiveParameters` _string_ | 创建监听器的参数,JSON 格式,详细参数请参考 CreateListener 接口:https://cloud.tencent.com/document/api/214/30693 | | |

docs/clb-mapping.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
1. `selector` 选中目标应用 Pod 的 labels。
99
2. `existedLbIds` 传入用于为 Pod 分配公网映射的 CLB 实例 ID 列表,可动态追加。
1010
3. `minPort``maxPort` 为 CLB 自动创建监听器的端口范围,每个端口只绑定一个 Pod。
11-
4. `ports` Pod 监听的端口列表,通常一个房间进程只监听一个端口。其中 `addressPodAnnotation` 用于 CLB 绑定 Pod 后,自动将其 CLB 外部映射地址自动注入到指定的 pod annotation 中,可结合 Kubernetes 的 Downward API 将外部地址挂载进容器内,以便让应用能够感知到自身的公网地址
12-
11+
4. `maxPod` 用于限制最大 Pod/监听器 数量
12+
5. `ports` 为 Pod 监听的端口列表,通常一个房间进程只监听一个端口。其中 `addressPodAnnotation` 用于 CLB 绑定 Pod 后,自动将其 CLB 外部映射地址自动注入到指定的 pod annotation 中,可结合 Kubernetes 的 Downward API 将外部地址挂载进容器内,以便让应用能够感知到自身的公网地址。
1313

1414
```yaml
1515
apiVersion: networking.cloud.tencent.com/v1alpha1
@@ -19,8 +19,9 @@ metadata:
1919
name: gameserver
2020
spec:
2121
lbRegion: ap-chengdu # 可选,CLB 所在地域,默认为集群所在地域
22-
minPort: 501 # 在 CLB 自动创建监听器,每个 Pod 占用一个端口,端口号范围在 501-600
23-
maxPort: 600
22+
minPort: 500 # 可选,在 CLB 自动创建监听器,每个 Pod 占用一个端口,默认端口号范围在 500-50000
23+
maxPort: 50000
24+
maxPod: 50 # 可选,限制最大 Pod/监听器 数量。
2425
selector:
2526
app: gameserver
2627
ports:

docs/crd.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ metadata:
1515
name: gameserver
1616
spec:
1717
lbRegion: ap-chengdu # 可选,CLB 所在地域,默认为集群所在地域
18-
minPort: 501 # 在 CLB 自动创建监听器,每个 Pod 占用一个端口,端口号范围在 501-600
19-
maxPort: 600
18+
minPort: 500 # 可选,在 CLB 自动创建监听器,每个 Pod 占用一个端口,默认端口号范围在 500-50000
19+
maxPort: 50000
20+
maxPod: 50 # 可选,限制最大 Pod/监听器 数量。
2021
listenerExtensiveParameters: | # 可选,指定创建监听器时的参数(JSON 格式),完整参考 CreateListener 接口: https://cloud.tencent.com/document/api/214/30693 (由于是一个监听器只挂一个 Pod,通常不需要自定义监听器配置,因为健康检查、调度算法这些配置,对于只有一个 RS 的监听器没有意义)
2122
{
2223
"DeregisterTargetRst": true

internal/controller/dedicatedclbservice_controller.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,11 @@ func (r *DedicatedCLBServiceReconciler) sync(ctx context.Context, ds *networking
233233
}
234234

235235
func (r *DedicatedCLBServiceReconciler) allocateNewCLB(ctx context.Context, ds *networkingv1alpha1.DedicatedCLBService, num int) error {
236-
ids, err := clb.Create(ctx, ds.Spec.LbRegion, ds.Spec.VpcId, ds.Spec.LbAutoCreate.ExtensiveParameters, num)
236+
var vpcId string
237+
if ds.Spec.VpcId != nil {
238+
vpcId = *ds.Spec.VpcId
239+
}
240+
ids, err := clb.Create(ctx, ds.Spec.LbRegion, vpcId, ds.Spec.LbAutoCreate.ExtensiveParameters, num)
237241
if err != nil {
238242
return err
239243
}
@@ -366,7 +370,7 @@ func (r *DedicatedCLBServiceReconciler) allocateListener(ctx context.Context, ds
366370
return true
367371
}
368372
allocatedPorts := (lb.CurrentPort - ds.Spec.MinPort + 1)
369-
return allocatedPorts >= listenerQuota || (ds.Spec.MaxPod > 0 && allocatedPorts >= ds.Spec.MaxPod)
373+
return allocatedPorts >= listenerQuota || (ds.Spec.MaxPod != nil && allocatedPorts >= *ds.Spec.MaxPod)
370374
}
371375
if havePort() { // 该lb已分配完所有端口,尝试下一个lb
372376
ds.Status.AllocatableLb = ds.Status.AllocatableLb[1:]

0 commit comments

Comments
 (0)