Skip to content

Commit 615be88

Browse files
committed
fix result annotation key use hostPort and remove unused role permission
Signed-off-by: roc <[email protected]>
1 parent c3a9273 commit 615be88

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

charts/tke-extend-network-controller/templates/role.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ rules:
9797
resources:
9898
- nodes
9999
verbs:
100-
- create
101-
- delete
102100
- get
103101
- list
104102
- patch
@@ -123,8 +121,6 @@ rules:
123121
resources:
124122
- pods
125123
verbs:
126-
- create
127-
- delete
128124
- get
129125
- list
130126
- patch

config/rbac/role.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ rules:
2626
resources:
2727
- nodes
2828
verbs:
29-
- create
30-
- delete
3129
- get
3230
- list
3331
- patch
@@ -52,8 +50,6 @@ rules:
5250
resources:
5351
- pods
5452
verbs:
55-
- create
56-
- delete
5753
- get
5854
- list
5955
- patch

internal/controller/clbbinding.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -528,23 +528,31 @@ func (r *CLBBindingReconciler[T]) ensureBackendStatusAnnotation(ctx context.Cont
528528
return errors.WithStack(err)
529529
}
530530

531-
if err := patchResult(ctx, r.Client, backend.GetObject(), string(val)); err != nil {
531+
if err := patchResult(ctx, r.Client, backend.GetObject(), string(val), false); err != nil {
532532
return errors.WithStack(err)
533533
}
534534
return nil
535535
}
536536

537-
func patchResult(ctx context.Context, c client.Client, obj client.Object, result string) error {
537+
func patchResult(ctx context.Context, c client.Client, obj client.Object, result string, hostPort bool) error {
538538
annotations := obj.GetAnnotations()
539539
if annotations == nil {
540540
annotations = map[string]string{}
541541
}
542+
var resultKey, statusKey string
543+
if hostPort {
544+
resultKey = constant.CLBHostPortMappingResultKey
545+
statusKey = constant.CLBHostPortMappingStatuslKey
546+
} else {
547+
resultKey = constant.CLBPortMappingResultKey
548+
statusKey = constant.CLBPortMappingStatuslKey
549+
}
542550
if annotations[constant.CLBPortMappingResultKey] != string(result) {
543551
patchMap := map[string]any{
544552
"metadata": map[string]any{
545553
"annotations": map[string]string{
546-
constant.CLBPortMappingResultKey: string(result),
547-
constant.CLBPortMappingStatuslKey: "Ready",
554+
resultKey: string(result),
555+
statusKey: "Ready",
548556
},
549557
},
550558
}
@@ -571,11 +579,11 @@ func patchResult(ctx context.Context, c client.Client, obj client.Object, result
571579
}
572580
// 存在对应的 gameserver,patch result 注解
573581
gsAnnotations := gs.GetAnnotations()
574-
if gsAnnotations == nil || gsAnnotations[constant.CLBPortMappingResultKey] != string(result) {
582+
if gsAnnotations == nil || gsAnnotations[resultKey] != string(result) {
575583
patchMap := map[string]any{
576584
"metadata": map[string]any{
577585
"annotations": map[string]string{
578-
constant.CLBPortMappingResultKey: string(result),
586+
resultKey: string(result),
579587
},
580588
},
581589
}

internal/controller/node_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type NodeReconciler struct {
3838
CLBBindingReconciler[*clbbinding.CLBNodeBinding]
3939
}
4040

41-
// +kubebuilder:rbac:groups=core,resources=nodes,verbs=get;list;watch;create;update;patch;delete
41+
// +kubebuilder:rbac:groups=core,resources=nodes,verbs=get;list;watch;update;patch
4242
// +kubebuilder:rbac:groups=core,resources=nodes/status,verbs=get;update;patch
4343
// +kubebuilder:rbac:groups=core,resources=nodes/finalizers,verbs=update
4444
// +kubebuilder:rbac:groups=core,resources=events,verbs=create;patch

internal/controller/pod_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type PodReconciler struct {
5151
CLBBindingReconciler[*clbbinding.CLBPodBinding]
5252
}
5353

54-
// +kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch;create;update;patch;delete
54+
// +kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch;update;patch
5555
// +kubebuilder:rbac:groups=core,resources=pods/status,verbs=get;update;patch
5656
// +kubebuilder:rbac:groups=core,resources=pods/finalizers,verbs=update
5757
// +kubebuilder:rbac:groups=core,resources=events,verbs=create;patch
@@ -189,7 +189,7 @@ func (r *PodReconciler) syncCLBHostPortMapping(ctx context.Context, pod *corev1.
189189
if err != nil {
190190
return result, errors.WithStack(err)
191191
}
192-
if err := patchResult(ctx, r.Client, pod, string(val)); err != nil {
192+
if err := patchResult(ctx, r.Client, pod, string(val), true); err != nil {
193193
return result, errors.WithStack(err)
194194
}
195195
return

0 commit comments

Comments
 (0)