File tree Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 1+ package clbbinding
2+
3+ import (
4+ "slices"
5+
6+ networkingv1alpha1 "github.com/imroc/tke-extend-network-controller/api/v1alpha1"
7+ )
8+
9+ func SortPortBindings (bindings []networkingv1alpha1.PortBindingStatus ) {
10+ slices .SortFunc (bindings , func (a , b networkingv1alpha1.PortBindingStatus ) int {
11+ // 端口池
12+ if a .Pool > b .Pool {
13+ return 1
14+ } else if a .Pool < b .Pool {
15+ return - 1
16+ }
17+
18+ // lbId 排序
19+ if a .LoadbalancerId > b .LoadbalancerId {
20+ return 1
21+ } else if a .LoadbalancerId < b .LoadbalancerId {
22+ return - 1
23+ }
24+
25+ // 端口
26+ if a .LoadbalancerPort > b .LoadbalancerPort {
27+ return 1
28+ } else if a .LoadbalancerPort < b .LoadbalancerPort {
29+ return - 1
30+ }
31+
32+ // 端口
33+ if a .Port > b .Port {
34+ return 1
35+ } else if a .Port < b .Port {
36+ return - 1
37+ }
38+
39+ // 协议
40+ if a .Protocol > b .Protocol {
41+ return 1
42+ } else if a .Protocol < b .Protocol {
43+ return - 1
44+ }
45+
46+ // 监听器
47+ if a .ListenerId > b .ListenerId {
48+ return 1
49+ } else if a .ListenerId < b .ListenerId {
50+ return - 1
51+ }
52+
53+ // 证书
54+ if a .CertId != nil && b .CertId != nil {
55+ if * a .CertId > * b .CertId {
56+ return 1
57+ } else if * a .CertId < * b .CertId {
58+ return - 1
59+ }
60+ }
61+
62+ // endPort
63+ if a .LoadbalancerEndPort != nil && b .LoadbalancerEndPort != nil {
64+ if * a .LoadbalancerEndPort > * b .LoadbalancerEndPort {
65+ return 1
66+ } else if * a .LoadbalancerEndPort < * b .LoadbalancerEndPort {
67+ return - 1
68+ }
69+ }
70+
71+ // region
72+ if a .Region > b .Region {
73+ return 1
74+ } else if a .Region < b .Region {
75+ return - 1
76+ }
77+ return 0
78+ })
79+ }
Original file line number Diff line number Diff line change @@ -630,6 +630,7 @@ LOOP_PORT:
630630 statuses = append (statuses , port )
631631 }
632632 }
633+ clbbinding .SortPortBindings (statuses )
633634 status .PortBindings = statuses
634635 }
635636
You can’t perform that action at this time.
0 commit comments