Skip to content

Commit c343a75

Browse files
committed
add feilds to CLBNodeBinding
Signed-off-by: roc <[email protected]>
1 parent 8ce97fd commit c343a75

File tree

6 files changed

+215
-35
lines changed

6 files changed

+215
-35
lines changed

api/v1alpha1/clbnodebinding_types.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,21 @@ import (
2525

2626
// CLBNodeBindingSpec defines the desired state of CLBNodeBinding.
2727
type CLBNodeBindingSpec struct {
28-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29-
// Important: Run "make" to regenerate code after modifying this file
30-
31-
// Foo is an example field of CLBNodeBinding. Edit clbnodebinding_types.go to remove/update
32-
Foo string `json:"foo,omitempty"`
28+
// 网络隔离
29+
// +optional
30+
Disabled *bool `json:"disabled,omitempty"`
31+
// 需要绑定的端口配置列表
32+
Ports []PortEntry `json:"ports"`
3333
}
3434

3535
// CLBNodeBindingStatus defines the observed state of CLBNodeBinding.
3636
type CLBNodeBindingStatus struct {
37-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38-
// Important: Run "make" to regenerate code after modifying this file
37+
// 绑定状态
38+
State CLBBindingState `json:"state"`
39+
// 状态信息
40+
Message string `json:"message,omitempty"`
41+
// 端口绑定详情
42+
PortBindings []PortBindingStatus `json:"portBindings,omitempty"`
3943
}
4044

4145
// +kubebuilder:object:root=true

api/v1alpha1/clbpodbinding_types.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,23 @@ type PortEntry struct {
4646
UseSamePortAcrossPools *bool `json:"useSamePortAcrossPools,omitempty"`
4747
}
4848

49-
type CLBPodBindingState string
49+
type CLBBindingState string
5050

5151
const (
52-
CLBPodBindingStatePending CLBPodBindingState = "Pending"
53-
CLBPodBindingStateBound CLBPodBindingState = "Bound"
54-
CLBPodBindingStateWaitForPod CLBPodBindingState = "WaitForPod"
55-
CLBPodBindingStateWaitForLB CLBPodBindingState = "WaitForLB"
56-
CLBPodBindingStateDisabled CLBPodBindingState = "Disabled"
57-
CLBPodBindingStateFailed CLBPodBindingState = "Failed"
58-
CLBPodBindingStateDeleting CLBPodBindingState = "Deleting"
52+
CLBBindingStatePending CLBBindingState = "Pending"
53+
CLBBindingStateBound CLBBindingState = "Bound"
54+
CLBBindingStateWaitForPod CLBBindingState = "WaitForPod"
55+
CLBBindingStateWaitForNode CLBBindingState = "WaitForNode"
56+
CLBBindingStateWaitForLB CLBBindingState = "WaitForLB"
57+
CLBBindingStateDisabled CLBBindingState = "Disabled"
58+
CLBBindingStateFailed CLBBindingState = "Failed"
59+
CLBBindingStateDeleting CLBBindingState = "Deleting"
5960
)
6061

6162
// CLBPodBindingStatus defines the observed state of CLBPodBinding.
6263
type CLBPodBindingStatus struct {
6364
// 绑定状态
64-
State CLBPodBindingState `json:"state"`
65+
State CLBBindingState `json:"state"`
6566
// 状态信息
6667
Message string `json:"message,omitempty"`
6768
// 端口绑定详情

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 21 additions & 2 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_clbnodebindings.yaml

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,91 @@ spec:
4141
spec:
4242
description: CLBNodeBindingSpec defines the desired state of CLBNodeBinding.
4343
properties:
44-
foo:
45-
description: Foo is an example field of CLBNodeBinding. Edit clbnodebinding_types.go
46-
to remove/update
47-
type: string
44+
disabled:
45+
description: 网络隔离
46+
type: boolean
47+
ports:
48+
description: 需要绑定的端口配置列表
49+
items:
50+
description: PortEntry 定义单个端口的绑定配置
51+
properties:
52+
pools:
53+
description: 使用的端口池列表
54+
items:
55+
type: string
56+
type: array
57+
port:
58+
description: 应用监听的端口号
59+
type: integer
60+
protocol:
61+
description: 端口使用的协议
62+
enum:
63+
- TCP
64+
- UDP
65+
- TCPUDP
66+
type: string
67+
useSamePortAcrossPools:
68+
description: 是否跨端口池分配相同端口号
69+
type: boolean
70+
required:
71+
- pools
72+
- port
73+
- protocol
74+
type: object
75+
type: array
76+
required:
77+
- ports
4878
type: object
4979
status:
5080
description: CLBNodeBindingStatus defines the observed state of CLBNodeBinding.
81+
properties:
82+
message:
83+
description: 状态信息
84+
type: string
85+
portBindings:
86+
description: 端口绑定详情
87+
items:
88+
description: PortBindingStatus 描述单个端口的实际绑定情况
89+
properties:
90+
listenerId:
91+
description: 监听器ID
92+
type: string
93+
loadbalancerEndPort:
94+
description: 负载均衡器端口段结束端口(当使用端口段时)
95+
type: integer
96+
loadbalancerId:
97+
description: 负载均衡器ID
98+
type: string
99+
loadbalancerPort:
100+
description: 负载均衡器端口
101+
type: integer
102+
pool:
103+
description: 使用的端口池
104+
type: string
105+
port:
106+
description: 应用端口
107+
type: integer
108+
protocol:
109+
description: 协议类型
110+
type: string
111+
region:
112+
description: 地域信息
113+
type: string
114+
required:
115+
- listenerId
116+
- loadbalancerId
117+
- loadbalancerPort
118+
- pool
119+
- port
120+
- protocol
121+
- region
122+
type: object
123+
type: array
124+
state:
125+
description: 绑定状态
126+
type: string
127+
required:
128+
- state
51129
type: object
52130
type: object
53131
served: true

config/crd/bases/networking.cloud.tencent.com_clbnodebindings.yaml

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,91 @@ spec:
4141
spec:
4242
description: CLBNodeBindingSpec defines the desired state of CLBNodeBinding.
4343
properties:
44-
foo:
45-
description: Foo is an example field of CLBNodeBinding. Edit clbnodebinding_types.go
46-
to remove/update
47-
type: string
44+
disabled:
45+
description: 网络隔离
46+
type: boolean
47+
ports:
48+
description: 需要绑定的端口配置列表
49+
items:
50+
description: PortEntry 定义单个端口的绑定配置
51+
properties:
52+
pools:
53+
description: 使用的端口池列表
54+
items:
55+
type: string
56+
type: array
57+
port:
58+
description: 应用监听的端口号
59+
type: integer
60+
protocol:
61+
description: 端口使用的协议
62+
enum:
63+
- TCP
64+
- UDP
65+
- TCPUDP
66+
type: string
67+
useSamePortAcrossPools:
68+
description: 是否跨端口池分配相同端口号
69+
type: boolean
70+
required:
71+
- pools
72+
- port
73+
- protocol
74+
type: object
75+
type: array
76+
required:
77+
- ports
4878
type: object
4979
status:
5080
description: CLBNodeBindingStatus defines the observed state of CLBNodeBinding.
81+
properties:
82+
message:
83+
description: 状态信息
84+
type: string
85+
portBindings:
86+
description: 端口绑定详情
87+
items:
88+
description: PortBindingStatus 描述单个端口的实际绑定情况
89+
properties:
90+
listenerId:
91+
description: 监听器ID
92+
type: string
93+
loadbalancerEndPort:
94+
description: 负载均衡器端口段结束端口(当使用端口段时)
95+
type: integer
96+
loadbalancerId:
97+
description: 负载均衡器ID
98+
type: string
99+
loadbalancerPort:
100+
description: 负载均衡器端口
101+
type: integer
102+
pool:
103+
description: 使用的端口池
104+
type: string
105+
port:
106+
description: 应用端口
107+
type: integer
108+
protocol:
109+
description: 协议类型
110+
type: string
111+
region:
112+
description: 地域信息
113+
type: string
114+
required:
115+
- listenerId
116+
- loadbalancerId
117+
- loadbalancerPort
118+
- pool
119+
- port
120+
- protocol
121+
- region
122+
type: object
123+
type: array
124+
state:
125+
description: 绑定状态
126+
type: string
127+
required:
128+
- state
51129
type: object
52130
type: object
53131
served: true

internal/controller/clbpodbinding_controller.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type portKey struct {
7676
func (r *CLBPodBindingReconciler) sync(ctx context.Context, pb *networkingv1alpha1.CLBPodBinding) (result ctrl.Result, err error) {
7777
// 确保 State 不为空
7878
if pb.Status.State == "" {
79-
pb.Status.State = networkingv1alpha1.CLBPodBindingStatePending
79+
pb.Status.State = networkingv1alpha1.CLBBindingStatePending
8080
if err = r.Status().Update(ctx, pb); err != nil {
8181
return result, errors.WithStack(err)
8282
}
@@ -85,15 +85,15 @@ func (r *CLBPodBindingReconciler) sync(ctx context.Context, pb *networkingv1alph
8585
if err := r.ensureCLBPodBinding(ctx, pb); err != nil {
8686
// 如果是等待端口池扩容 CLB,确保状态为 WaitForLB,并重新入队,以便在 CLB 扩容完成后能自动分配端口并绑定 Pod
8787
if errors.Is(err, portpool.ErrWaitLBScale) {
88-
if err := r.ensureState(ctx, pb, networkingv1alpha1.CLBPodBindingStateWaitForLB); err != nil {
88+
if err := r.ensureState(ctx, pb, networkingv1alpha1.CLBBindingStateWaitForLB); err != nil {
8989
return result, errors.WithStack(err)
9090
}
9191
result.RequeueAfter = 3 * time.Second
9292
return result, nil
9393
}
9494
// 其它非资源冲突的错误,将错误记录到状态中方便排障
9595
if !apierrors.IsConflict(err) {
96-
pb.Status.State = networkingv1alpha1.CLBPodBindingStateFailed
96+
pb.Status.State = networkingv1alpha1.CLBBindingStateFailed
9797
pb.Status.Message = err.Error()
9898
if err := r.Status().Update(ctx, pb); err != nil {
9999
return result, errors.WithStack(err)
@@ -141,8 +141,8 @@ func (r *CLBPodBindingReconciler) ensureListeners(ctx context.Context, pb *netwo
141141
func (r *CLBPodBindingReconciler) ensurePodBindings(ctx context.Context, pb *networkingv1alpha1.CLBPodBinding) error {
142142
log.FromContext(ctx).V(10).Info("ensurePodBindings")
143143
ensureWaitForPod := func(msg string) error {
144-
if pb.Status.State != networkingv1alpha1.CLBPodBindingStateWaitForPod {
145-
pb.Status.State = networkingv1alpha1.CLBPodBindingStateWaitForPod
144+
if pb.Status.State != networkingv1alpha1.CLBBindingStateWaitForPod {
145+
pb.Status.State = networkingv1alpha1.CLBBindingStateWaitForPod
146146
pb.Status.Message = msg
147147
if err := r.Status().Update(ctx, pb); err != nil {
148148
return errors.WithStack(err)
@@ -190,8 +190,8 @@ func (r *CLBPodBindingReconciler) ensurePodBindings(ctx context.Context, pb *net
190190
}
191191
}
192192
// 所有端口都已绑定,更新状态并将绑定信息写入 pod 注解
193-
if pb.Status.State != networkingv1alpha1.CLBPodBindingStateBound {
194-
pb.Status.State = networkingv1alpha1.CLBPodBindingStateBound
193+
if pb.Status.State != networkingv1alpha1.CLBBindingStateBound {
194+
pb.Status.State = networkingv1alpha1.CLBBindingStateBound
195195
pb.Status.Message = ""
196196
if err := r.Status().Update(ctx, pb); err != nil {
197197
return errors.WithStack(err)
@@ -471,7 +471,7 @@ func portFromPortBindingStatus(status *networkingv1alpha1.PortBindingStatus) por
471471
return port
472472
}
473473

474-
func (r *CLBPodBindingReconciler) ensureState(ctx context.Context, pb *networkingv1alpha1.CLBPodBinding, state networkingv1alpha1.CLBPodBindingState) error {
474+
func (r *CLBPodBindingReconciler) ensureState(ctx context.Context, pb *networkingv1alpha1.CLBPodBinding, state networkingv1alpha1.CLBBindingState) error {
475475
if pb.Status.State == state {
476476
return nil
477477
}
@@ -486,7 +486,7 @@ func (r *CLBPodBindingReconciler) ensureState(ctx context.Context, pb *networkin
486486
func (r *CLBPodBindingReconciler) cleanup(ctx context.Context, pb *networkingv1alpha1.CLBPodBinding) (result ctrl.Result, err error) {
487487
log := log.FromContext(ctx)
488488
log.Info("cleanup CLBPodBinding")
489-
if err = r.ensureState(ctx, pb, networkingv1alpha1.CLBPodBindingStateDeleting); err != nil {
489+
if err = r.ensureState(ctx, pb, networkingv1alpha1.CLBBindingStateDeleting); err != nil {
490490
return result, errors.WithStack(err)
491491
}
492492
for _, binding := range pb.Status.PortBindings {

0 commit comments

Comments
 (0)