@@ -25,14 +25,16 @@ import (
25
25
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
26
v1listers "k8s.io/client-go/listers/core/v1"
27
27
"k8s.io/client-go/tools/cache"
28
+ k8sports "k8s.io/kubernetes/pkg/master/ports"
28
29
)
29
30
30
31
func TestGetNodeIngressRules (t * testing.T ) {
31
32
testCases := []struct {
32
33
name string
33
34
securityList * core.SecurityList
34
35
lbSubnets []* core.Subnet
35
- port int
36
+ actualPorts * portSpec
37
+ desiredPorts portSpec
36
38
services []* v1.Service
37
39
expected []core.IngressSecurityRule
38
40
}{
@@ -47,81 +49,108 @@ func TestGetNodeIngressRules(t *testing.T) {
47
49
{CidrBlock : common .String ("1" )},
48
50
{CidrBlock : common .String ("2" )},
49
51
},
50
- port : 80 ,
52
+ desiredPorts : portSpec {
53
+ BackendPort : 80 ,
54
+ HealthCheckerPort : k8sports .ProxyHealthzPort ,
55
+ },
51
56
services : []* v1.Service {},
52
57
expected : []core.IngressSecurityRule {
53
58
makeIngressSecurityRule ("existing" , 9000 ),
54
59
makeIngressSecurityRule ("1" , 80 ),
55
60
makeIngressSecurityRule ("2" , 80 ),
61
+ makeIngressSecurityRule ("1" , k8sports .ProxyHealthzPort ),
62
+ makeIngressSecurityRule ("2" , k8sports .ProxyHealthzPort ),
56
63
},
57
64
}, {
58
65
name : "no change" ,
59
66
securityList : & core.SecurityList {
60
67
IngressSecurityRules : []core.IngressSecurityRule {
61
68
makeIngressSecurityRule ("existing" , 9000 ),
62
69
makeIngressSecurityRule ("1" , 80 ),
70
+ makeIngressSecurityRule ("1" , k8sports .ProxyHealthzPort ),
63
71
makeIngressSecurityRule ("2" , 80 ),
72
+ makeIngressSecurityRule ("2" , k8sports .ProxyHealthzPort ),
64
73
},
65
74
},
66
75
lbSubnets : []* core.Subnet {
67
76
{CidrBlock : common .String ("1" )},
68
77
{CidrBlock : common .String ("2" )},
69
78
},
70
- port : 80 ,
79
+ desiredPorts : portSpec {
80
+ BackendPort : 80 ,
81
+ HealthCheckerPort : k8sports .ProxyHealthzPort ,
82
+ },
71
83
services : []* v1.Service {},
72
84
expected : []core.IngressSecurityRule {
73
85
makeIngressSecurityRule ("existing" , 9000 ),
74
86
makeIngressSecurityRule ("1" , 80 ),
87
+ makeIngressSecurityRule ("1" , k8sports .ProxyHealthzPort ),
75
88
makeIngressSecurityRule ("2" , 80 ),
89
+ makeIngressSecurityRule ("2" , k8sports .ProxyHealthzPort ),
76
90
},
77
91
}, {
78
92
name : "change lb subnet" ,
79
93
securityList : & core.SecurityList {
80
94
IngressSecurityRules : []core.IngressSecurityRule {
81
95
makeIngressSecurityRule ("existing" , 9000 ),
82
96
makeIngressSecurityRule ("1" , 80 ),
97
+ makeIngressSecurityRule ("1" , k8sports .ProxyHealthzPort ),
83
98
makeIngressSecurityRule ("2" , 80 ),
99
+ makeIngressSecurityRule ("2" , k8sports .ProxyHealthzPort ),
84
100
makeIngressSecurityRule ("existing" , 9001 ),
85
101
},
86
102
},
87
103
lbSubnets : []* core.Subnet {
88
104
{CidrBlock : common .String ("1" )},
89
105
{CidrBlock : common .String ("3" )},
90
106
},
91
- port : 80 ,
107
+ desiredPorts : portSpec {
108
+ BackendPort : 80 ,
109
+ HealthCheckerPort : k8sports .ProxyHealthzPort ,
110
+ },
92
111
services : []* v1.Service {},
93
112
expected : []core.IngressSecurityRule {
94
113
makeIngressSecurityRule ("existing" , 9000 ),
95
114
makeIngressSecurityRule ("1" , 80 ),
115
+ makeIngressSecurityRule ("1" , k8sports .ProxyHealthzPort ),
96
116
makeIngressSecurityRule ("existing" , 9001 ),
97
117
makeIngressSecurityRule ("3" , 80 ),
118
+ makeIngressSecurityRule ("3" , k8sports .ProxyHealthzPort ),
98
119
},
99
120
}, {
100
121
name : "remove lb subnets" ,
101
122
securityList : & core.SecurityList {
102
123
IngressSecurityRules : []core.IngressSecurityRule {
103
124
makeIngressSecurityRule ("existing" , 9000 ),
104
125
makeIngressSecurityRule ("1" , 80 ),
126
+ makeIngressSecurityRule ("1" , k8sports .ProxyHealthzPort ),
105
127
makeIngressSecurityRule ("2" , 80 ),
128
+ makeIngressSecurityRule ("2" , k8sports .ProxyHealthzPort ),
106
129
makeIngressSecurityRule ("existing" , 9001 ),
107
130
},
108
131
},
109
132
lbSubnets : []* core.Subnet {},
110
- port : 80 ,
111
- services : []* v1.Service {},
133
+ desiredPorts : portSpec {
134
+ BackendPort : 80 ,
135
+ HealthCheckerPort : k8sports .ProxyHealthzPort ,
136
+ },
137
+ services : []* v1.Service {},
112
138
expected : []core.IngressSecurityRule {
113
139
makeIngressSecurityRule ("existing" , 9000 ),
114
140
makeIngressSecurityRule ("existing" , 9001 ),
115
141
},
116
142
}, {
117
- name : "do not delete a port rule which is used by another services (default) health check" ,
143
+ name : "do not delete a rule which is used by another services (default) health check" ,
118
144
securityList : & core.SecurityList {
119
145
IngressSecurityRules : []core.IngressSecurityRule {
120
146
makeIngressSecurityRule ("0.0.0.0/0" , lbNodesHealthCheckPort ),
121
147
},
122
148
},
123
149
lbSubnets : []* core.Subnet {},
124
- port : lbNodesHealthCheckPort ,
150
+ desiredPorts : portSpec {
151
+ BackendPort : 80 ,
152
+ HealthCheckerPort : k8sports .ProxyHealthzPort ,
153
+ },
125
154
services : []* v1.Service {
126
155
{
127
156
ObjectMeta : metav1.ObjectMeta {Namespace : "namespace" , Name : "using-default-health-check-port" },
@@ -134,6 +163,37 @@ func TestGetNodeIngressRules(t *testing.T) {
134
163
expected : []core.IngressSecurityRule {
135
164
makeIngressSecurityRule ("0.0.0.0/0" , lbNodesHealthCheckPort ),
136
165
},
166
+ }, {
167
+ name : "update node port" ,
168
+ securityList : & core.SecurityList {
169
+ IngressSecurityRules : []core.IngressSecurityRule {
170
+ makeIngressSecurityRule ("existing" , 9000 ),
171
+ makeIngressSecurityRule ("1" , 8081 ),
172
+ makeIngressSecurityRule ("2" , 8081 ),
173
+ makeIngressSecurityRule ("1" , k8sports .ProxyHealthzPort ),
174
+ makeIngressSecurityRule ("2" , k8sports .ProxyHealthzPort ),
175
+ },
176
+ },
177
+ lbSubnets : []* core.Subnet {
178
+ {CidrBlock : common .String ("1" )},
179
+ {CidrBlock : common .String ("2" )},
180
+ },
181
+ actualPorts : & portSpec {
182
+ BackendPort : 8081 ,
183
+ HealthCheckerPort : k8sports .ProxyHealthzPort ,
184
+ },
185
+ desiredPorts : portSpec {
186
+ BackendPort : 80 ,
187
+ HealthCheckerPort : k8sports .ProxyHealthzPort ,
188
+ },
189
+ services : []* v1.Service {},
190
+ expected : []core.IngressSecurityRule {
191
+ makeIngressSecurityRule ("existing" , 9000 ),
192
+ makeIngressSecurityRule ("1" , k8sports .ProxyHealthzPort ),
193
+ makeIngressSecurityRule ("2" , k8sports .ProxyHealthzPort ),
194
+ makeIngressSecurityRule ("1" , 80 ),
195
+ makeIngressSecurityRule ("2" , 80 ),
196
+ },
137
197
},
138
198
}
139
199
@@ -146,7 +206,7 @@ func TestGetNodeIngressRules(t *testing.T) {
146
206
}
147
207
}
148
208
t .Run (tc .name , func (t * testing.T ) {
149
- rules := getNodeIngressRules (tc .securityList .IngressSecurityRules , tc .lbSubnets , tc .port , serviceLister )
209
+ rules := getNodeIngressRules (tc .securityList .IngressSecurityRules , tc .lbSubnets , tc .actualPorts , tc . desiredPorts , serviceLister )
150
210
if ! reflect .DeepEqual (rules , tc .expected ) {
151
211
t .Errorf ("expected rules\n %+v\n but got\n %+v" , tc .expected , rules )
152
212
}
0 commit comments