Skip to content

Commit 84c2ef9

Browse files
committed
sort clb binding status
Signed-off-by: roc <[email protected]>
1 parent 67ce0d4 commit 84c2ef9

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

internal/clbbinding/sort.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
}

internal/controller/clbbinding.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)