| 1 |
/* |
| 2 |
Copyright 2019 The Kubernetes Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package egressselector |
| 18 |
|
| 19 |
import ( |
| 20 |
"fmt" |
| 21 |
"os" |
| 22 |
"reflect" |
| 23 |
"strings" |
| 24 |
"testing" |
| 25 |
|
| 26 |
utiltesting "k8s.io/client-go/util/testing" |
| 27 |
|
| 28 |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 29 |
"k8s.io/apiserver/pkg/apis/apiserver" |
| 30 |
) |
| 31 |
|
| 32 |
func strptr(s string) *string { |
| 33 |
return &s |
| 34 |
} |
| 35 |
|
| 36 |
func TestReadEgressSelectorConfiguration(t *testing.T) { |
| 37 |
testcases := []struct { |
| 38 |
name string |
| 39 |
contents string |
| 40 |
createFile bool |
| 41 |
expectedResult *apiserver.EgressSelectorConfiguration |
| 42 |
expectedError *string |
| 43 |
}{ |
| 44 |
{ |
| 45 |
name: "empty", |
| 46 |
createFile: true, |
| 47 |
contents: ``, |
| 48 |
expectedResult: nil, |
| 49 |
expectedError: strptr("invalid service configuration object \"\""), |
| 50 |
}, |
| 51 |
{ |
| 52 |
name: "absent", |
| 53 |
createFile: false, |
| 54 |
contents: ``, |
| 55 |
expectedResult: nil, |
| 56 |
expectedError: strptr("errors.errorString{s:\"unable to read egress selector configuration"), |
| 57 |
}, |
| 58 |
{ |
| 59 |
name: "unknown field causes error", |
| 60 |
createFile: false, |
| 61 |
contents: ` |
| 62 |
apiVersion: apiserver.k8s.io/v1beta1 |
| 63 |
kind: EgressSelectorConfiguration |
| 64 |
egressSelections: |
| 65 |
- name: "etcd" |
| 66 |
connection: |
| 67 |
proxyProtocol: "Direct" |
| 68 |
foo: |
| 69 |
bar: "baz" |
| 70 |
`, |
| 71 |
expectedResult: nil, |
| 72 |
expectedError: strptr("runtime.strictDecodingError"), |
| 73 |
}, |
| 74 |
{ |
| 75 |
name: "duplicate field causes error", |
| 76 |
createFile: false, |
| 77 |
contents: ` |
| 78 |
apiVersion: apiserver.k8s.io/v1beta1 |
| 79 |
kind: EgressSelectorConfiguration |
| 80 |
egressSelections: |
| 81 |
- name: "etcd" |
| 82 |
connection: |
| 83 |
proxyProtocol: "Direct" |
| 84 |
connection: |
| 85 |
proxyProtocol: "Indirect" |
| 86 |
`, |
| 87 |
expectedResult: nil, |
| 88 |
expectedError: strptr("runtime.strictDecodingError"), |
| 89 |
}, |
| 90 |
{ |
| 91 |
name: "v1beta1", |
| 92 |
createFile: true, |
| 93 |
contents: ` |
| 94 |
apiVersion: apiserver.k8s.io/v1beta1 |
| 95 |
kind: EgressSelectorConfiguration |
| 96 |
egressSelections: |
| 97 |
- name: "cluster" |
| 98 |
connection: |
| 99 |
proxyProtocol: "HTTPConnect" |
| 100 |
transport: |
| 101 |
tcp: |
| 102 |
url: "https://127.0.0.1:8131" |
| 103 |
tlsConfig: |
| 104 |
caBundle: "/etc/srv/kubernetes/pki/konnectivity-server/ca.crt" |
| 105 |
clientKey: "/etc/srv/kubernetes/pki/konnectivity-server/client.key" |
| 106 |
clientCert: "/etc/srv/kubernetes/pki/konnectivity-server/client.crt" |
| 107 |
- name: "controlplane" |
| 108 |
connection: |
| 109 |
proxyProtocol: "HTTPConnect" |
| 110 |
transport: |
| 111 |
tcp: |
| 112 |
url: "https://127.0.0.1:8132" |
| 113 |
tlsConfig: |
| 114 |
caBundle: "/etc/srv/kubernetes/pki/konnectivity-server-master/ca.crt" |
| 115 |
clientKey: "/etc/srv/kubernetes/pki/konnectivity-server-master/client.key" |
| 116 |
clientCert: "/etc/srv/kubernetes/pki/konnectivity-server-master/client.crt" |
| 117 |
- name: "etcd" |
| 118 |
connection: |
| 119 |
proxyProtocol: "Direct" |
| 120 |
`, |
| 121 |
expectedResult: &apiserver.EgressSelectorConfiguration{ |
| 122 |
TypeMeta: metav1.TypeMeta{ |
| 123 |
Kind: "", |
| 124 |
APIVersion: "", |
| 125 |
}, |
| 126 |
EgressSelections: []apiserver.EgressSelection{ |
| 127 |
{ |
| 128 |
Name: "cluster", |
| 129 |
Connection: apiserver.Connection{ |
| 130 |
ProxyProtocol: "HTTPConnect", |
| 131 |
Transport: &apiserver.Transport{ |
| 132 |
TCP: &apiserver.TCPTransport{ |
| 133 |
URL: "https://127.0.0.1:8131", |
| 134 |
|
| 135 |
TLSConfig: &apiserver.TLSConfig{ |
| 136 |
CABundle: "/etc/srv/kubernetes/pki/konnectivity-server/ca.crt", |
| 137 |
ClientKey: "/etc/srv/kubernetes/pki/konnectivity-server/client.key", |
| 138 |
ClientCert: "/etc/srv/kubernetes/pki/konnectivity-server/client.crt", |
| 139 |
}, |
| 140 |
}, |
| 141 |
}, |
| 142 |
}, |
| 143 |
}, |
| 144 |
{ |
| 145 |
Name: "controlplane", |
| 146 |
Connection: apiserver.Connection{ |
| 147 |
ProxyProtocol: "HTTPConnect", |
| 148 |
Transport: &apiserver.Transport{ |
| 149 |
TCP: &apiserver.TCPTransport{ |
| 150 |
URL: "https://127.0.0.1:8132", |
| 151 |
TLSConfig: &apiserver.TLSConfig{ |
| 152 |
CABundle: "/etc/srv/kubernetes/pki/konnectivity-server-master/ca.crt", |
| 153 |
ClientKey: "/etc/srv/kubernetes/pki/konnectivity-server-master/client.key", |
| 154 |
ClientCert: "/etc/srv/kubernetes/pki/konnectivity-server-master/client.crt", |
| 155 |
}, |
| 156 |
}, |
| 157 |
}, |
| 158 |
}, |
| 159 |
}, |
| 160 |
{ |
| 161 |
Name: "etcd", |
| 162 |
Connection: apiserver.Connection{ |
| 163 |
ProxyProtocol: "Direct", |
| 164 |
}, |
| 165 |
}, |
| 166 |
}, |
| 167 |
}, |
| 168 |
expectedError: nil, |
| 169 |
}, |
| 170 |
{ |
| 171 |
name: "v1beta1 using deprecated 'master' type", |
| 172 |
createFile: true, |
| 173 |
contents: ` |
| 174 |
apiVersion: apiserver.k8s.io/v1beta1 |
| 175 |
kind: EgressSelectorConfiguration |
| 176 |
egressSelections: |
| 177 |
- name: "cluster" |
| 178 |
connection: |
| 179 |
proxyProtocol: "HTTPConnect" |
| 180 |
transport: |
| 181 |
tcp: |
| 182 |
url: "https://127.0.0.1:8131" |
| 183 |
tlsConfig: |
| 184 |
caBundle: "/etc/srv/kubernetes/pki/konnectivity-server/ca.crt" |
| 185 |
clientKey: "/etc/srv/kubernetes/pki/konnectivity-server/client.key" |
| 186 |
clientCert: "/etc/srv/kubernetes/pki/konnectivity-server/client.crt" |
| 187 |
- name: "master" |
| 188 |
connection: |
| 189 |
proxyProtocol: "HTTPConnect" |
| 190 |
transport: |
| 191 |
tcp: |
| 192 |
url: "https://127.0.0.1:8132" |
| 193 |
tlsConfig: |
| 194 |
caBundle: "/etc/srv/kubernetes/pki/konnectivity-server-master/ca.crt" |
| 195 |
clientKey: "/etc/srv/kubernetes/pki/konnectivity-server-master/client.key" |
| 196 |
clientCert: "/etc/srv/kubernetes/pki/konnectivity-server-master/client.crt" |
| 197 |
- name: "etcd" |
| 198 |
connection: |
| 199 |
proxyProtocol: "Direct" |
| 200 |
`, |
| 201 |
expectedResult: &apiserver.EgressSelectorConfiguration{ |
| 202 |
TypeMeta: metav1.TypeMeta{ |
| 203 |
Kind: "", |
| 204 |
APIVersion: "", |
| 205 |
}, |
| 206 |
EgressSelections: []apiserver.EgressSelection{ |
| 207 |
{ |
| 208 |
Name: "cluster", |
| 209 |
Connection: apiserver.Connection{ |
| 210 |
ProxyProtocol: "HTTPConnect", |
| 211 |
Transport: &apiserver.Transport{ |
| 212 |
TCP: &apiserver.TCPTransport{ |
| 213 |
URL: "https://127.0.0.1:8131", |
| 214 |
|
| 215 |
TLSConfig: &apiserver.TLSConfig{ |
| 216 |
CABundle: "/etc/srv/kubernetes/pki/konnectivity-server/ca.crt", |
| 217 |
ClientKey: "/etc/srv/kubernetes/pki/konnectivity-server/client.key", |
| 218 |
ClientCert: "/etc/srv/kubernetes/pki/konnectivity-server/client.crt", |
| 219 |
}, |
| 220 |
}, |
| 221 |
}, |
| 222 |
}, |
| 223 |
}, |
| 224 |
{ |
| 225 |
Name: "controlplane", |
| 226 |
Connection: apiserver.Connection{ |
| 227 |
ProxyProtocol: "HTTPConnect", |
| 228 |
Transport: &apiserver.Transport{ |
| 229 |
TCP: &apiserver.TCPTransport{ |
| 230 |
URL: "https://127.0.0.1:8132", |
| 231 |
TLSConfig: &apiserver.TLSConfig{ |
| 232 |
CABundle: "/etc/srv/kubernetes/pki/konnectivity-server-master/ca.crt", |
| 233 |
ClientKey: "/etc/srv/kubernetes/pki/konnectivity-server-master/client.key", |
| 234 |
ClientCert: "/etc/srv/kubernetes/pki/konnectivity-server-master/client.crt", |
| 235 |
}, |
| 236 |
}, |
| 237 |
}, |
| 238 |
}, |
| 239 |
}, |
| 240 |
{ |
| 241 |
Name: "etcd", |
| 242 |
Connection: apiserver.Connection{ |
| 243 |
ProxyProtocol: "Direct", |
| 244 |
}, |
| 245 |
}, |
| 246 |
}, |
| 247 |
}, |
| 248 |
expectedError: nil, |
| 249 |
}, |
| 250 |
{ |
| 251 |
name: "wrong_type", |
| 252 |
createFile: true, |
| 253 |
contents: ` |
| 254 |
apiVersion: apps/v1 |
| 255 |
kind: DaemonSet |
| 256 |
metadata: |
| 257 |
labels: |
| 258 |
addonmanager.kubernetes.io/mode: Reconcile |
| 259 |
k8s-app: konnectivity-agent |
| 260 |
namespace: kube-system |
| 261 |
name: proxy-agent |
| 262 |
spec: |
| 263 |
selector: |
| 264 |
matchLabels: |
| 265 |
k8s-app: konnectivity-agent |
| 266 |
updateStrategy: |
| 267 |
type: RollingUpdate |
| 268 |
template: |
| 269 |
metadata: |
| 270 |
labels: |
| 271 |
k8s-app: proxy-agent |
| 272 |
spec: |
| 273 |
priorityClassName: system-cluster-critical |
| 274 |
# Necessary to reboot node |
| 275 |
hostPID: true |
| 276 |
volumes: |
| 277 |
- name: pki |
| 278 |
hostPath: |
| 279 |
path: /etc/srv/kubernetes/pki/konnectivity-agent |
| 280 |
containers: |
| 281 |
- image: registry.k8s.io/proxy-agent:v0.0.3 |
| 282 |
name: proxy-agent |
| 283 |
command: ["/proxy-agent"] |
| 284 |
args: ["--caCert=/etc/srv/kubernetes/pki/proxy-agent/ca.crt", "--agentCert=/etc/srv/kubernetes/pki/proxy-agent/client.crt", "--agentKey=/etc/srv/kubernetes/pki/proxy-agent/client.key", "--proxyServerHost=127.0.0.1", "--proxyServerPort=8132"] |
| 285 |
securityContext: |
| 286 |
capabilities: |
| 287 |
add: ["SYS_BOOT"] |
| 288 |
env: |
| 289 |
- name: wrong-type |
| 290 |
valueFrom: |
| 291 |
fieldRef: |
| 292 |
fieldPath: metadata.name |
| 293 |
- name: kube-system |
| 294 |
valueFrom: |
| 295 |
fieldRef: |
| 296 |
fieldPath: metadata.namespace |
| 297 |
resources: |
| 298 |
limits: |
| 299 |
cpu: 50m |
| 300 |
memory: 30Mi |
| 301 |
volumeMounts: |
| 302 |
- name: pki |
| 303 |
mountPath: /etc/srv/kubernetes/pki/konnectivity-agent |
| 304 |
`, |
| 305 |
expectedResult: nil, |
| 306 |
expectedError: strptr("invalid service configuration object \"DaemonSet\""), |
| 307 |
}, |
| 308 |
} |
| 309 |
|
| 310 |
for _, tc := range testcases { |
| 311 |
t.Run(tc.name, func(t *testing.T) { |
| 312 |
proxyConfig := fmt.Sprintf("test-egress-selector-config-%s", tc.name) |
| 313 |
if tc.createFile { |
| 314 |
f, err := os.CreateTemp("", proxyConfig) |
| 315 |
if err != nil { |
| 316 |
t.Fatal(err) |
| 317 |
} |
| 318 |
defer utiltesting.CloseAndRemove(t, f) |
| 319 |
if err := os.WriteFile(f.Name(), []byte(tc.contents), os.FileMode(0755)); err != nil { |
| 320 |
t.Fatal(err) |
| 321 |
} |
| 322 |
proxyConfig = f.Name() |
| 323 |
} |
| 324 |
config, err := ReadEgressSelectorConfiguration(proxyConfig) |
| 325 |
if err == nil && tc.expectedError != nil { |
| 326 |
t.Errorf("calling ReadEgressSelectorConfiguration expected error: %s, did not get it", *tc.expectedError) |
| 327 |
} |
| 328 |
if err != nil && tc.expectedError == nil { |
| 329 |
t.Errorf("unexpected error calling ReadEgressSelectorConfiguration got: %#v", err) |
| 330 |
} |
| 331 |
if err != nil && tc.expectedError != nil && strings.Contains(err.Error(), *tc.expectedError) { |
| 332 |
t.Errorf("calling ReadEgressSelectorConfiguration expected error: %s, got %#v", *tc.expectedError, err) |
| 333 |
} |
| 334 |
if !reflect.DeepEqual(config, tc.expectedResult) { |
| 335 |
t.Errorf("problem with configuration returned from ReadEgressSelectorConfiguration expected: %#v, got: %#v", tc.expectedResult, config) |
| 336 |
} |
| 337 |
}) |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
func TestValidateEgressSelectorConfiguration(t *testing.T) { |
| 342 |
testcases := []struct { |
| 343 |
name string |
| 344 |
expectError bool |
| 345 |
contents *apiserver.EgressSelectorConfiguration |
| 346 |
}{ |
| 347 |
{ |
| 348 |
name: "direct-valid", |
| 349 |
expectError: false, |
| 350 |
contents: &apiserver.EgressSelectorConfiguration{ |
| 351 |
TypeMeta: metav1.TypeMeta{ |
| 352 |
Kind: "", |
| 353 |
APIVersion: "", |
| 354 |
}, |
| 355 |
EgressSelections: []apiserver.EgressSelection{ |
| 356 |
{ |
| 357 |
Name: "controlplane", |
| 358 |
Connection: apiserver.Connection{ |
| 359 |
ProxyProtocol: apiserver.ProtocolDirect, |
| 360 |
}, |
| 361 |
}, |
| 362 |
}, |
| 363 |
}, |
| 364 |
}, |
| 365 |
{ |
| 366 |
name: "direct-invalid-transport", |
| 367 |
expectError: true, |
| 368 |
contents: &apiserver.EgressSelectorConfiguration{ |
| 369 |
TypeMeta: metav1.TypeMeta{ |
| 370 |
Kind: "", |
| 371 |
APIVersion: "", |
| 372 |
}, |
| 373 |
EgressSelections: []apiserver.EgressSelection{ |
| 374 |
{ |
| 375 |
Name: "controlplane", |
| 376 |
Connection: apiserver.Connection{ |
| 377 |
ProxyProtocol: apiserver.ProtocolDirect, |
| 378 |
Transport: &apiserver.Transport{}, |
| 379 |
}, |
| 380 |
}, |
| 381 |
}, |
| 382 |
}, |
| 383 |
}, |
| 384 |
{ |
| 385 |
name: "httpconnect-no-https", |
| 386 |
expectError: false, |
| 387 |
contents: &apiserver.EgressSelectorConfiguration{ |
| 388 |
TypeMeta: metav1.TypeMeta{ |
| 389 |
Kind: "", |
| 390 |
APIVersion: "", |
| 391 |
}, |
| 392 |
EgressSelections: []apiserver.EgressSelection{ |
| 393 |
{ |
| 394 |
Name: "cluster", |
| 395 |
Connection: apiserver.Connection{ |
| 396 |
ProxyProtocol: apiserver.ProtocolHTTPConnect, |
| 397 |
Transport: &apiserver.Transport{ |
| 398 |
TCP: &apiserver.TCPTransport{ |
| 399 |
URL: "http://127.0.0.1:8131", |
| 400 |
}, |
| 401 |
}, |
| 402 |
}, |
| 403 |
}, |
| 404 |
}, |
| 405 |
}, |
| 406 |
}, |
| 407 |
{ |
| 408 |
name: "httpconnect-https-no-cert-error", |
| 409 |
expectError: true, |
| 410 |
contents: &apiserver.EgressSelectorConfiguration{ |
| 411 |
TypeMeta: metav1.TypeMeta{ |
| 412 |
Kind: "", |
| 413 |
APIVersion: "", |
| 414 |
}, |
| 415 |
EgressSelections: []apiserver.EgressSelection{ |
| 416 |
{ |
| 417 |
Name: "cluster", |
| 418 |
Connection: apiserver.Connection{ |
| 419 |
ProxyProtocol: apiserver.ProtocolHTTPConnect, |
| 420 |
Transport: &apiserver.Transport{ |
| 421 |
TCP: &apiserver.TCPTransport{ |
| 422 |
URL: "https://127.0.0.1:8131", |
| 423 |
}, |
| 424 |
}, |
| 425 |
}, |
| 426 |
}, |
| 427 |
}, |
| 428 |
}, |
| 429 |
}, |
| 430 |
{ |
| 431 |
name: "httpconnect-tcp-uds-both-set", |
| 432 |
expectError: true, |
| 433 |
contents: &apiserver.EgressSelectorConfiguration{ |
| 434 |
TypeMeta: metav1.TypeMeta{ |
| 435 |
Kind: "", |
| 436 |
APIVersion: "", |
| 437 |
}, |
| 438 |
EgressSelections: []apiserver.EgressSelection{ |
| 439 |
{ |
| 440 |
Name: "cluster", |
| 441 |
Connection: apiserver.Connection{ |
| 442 |
ProxyProtocol: apiserver.ProtocolHTTPConnect, |
| 443 |
Transport: &apiserver.Transport{ |
| 444 |
TCP: &apiserver.TCPTransport{ |
| 445 |
URL: "http://127.0.0.1:8131", |
| 446 |
}, |
| 447 |
UDS: &apiserver.UDSTransport{ |
| 448 |
UDSName: "/etc/srv/kubernetes/konnectivity/konnectivity-server.socket", |
| 449 |
}, |
| 450 |
}, |
| 451 |
}, |
| 452 |
}, |
| 453 |
}, |
| 454 |
}, |
| 455 |
}, |
| 456 |
{ |
| 457 |
name: "httpconnect-uds", |
| 458 |
expectError: false, |
| 459 |
contents: &apiserver.EgressSelectorConfiguration{ |
| 460 |
TypeMeta: metav1.TypeMeta{ |
| 461 |
Kind: "", |
| 462 |
APIVersion: "", |
| 463 |
}, |
| 464 |
EgressSelections: []apiserver.EgressSelection{ |
| 465 |
{ |
| 466 |
Name: "cluster", |
| 467 |
Connection: apiserver.Connection{ |
| 468 |
ProxyProtocol: apiserver.ProtocolHTTPConnect, |
| 469 |
Transport: &apiserver.Transport{ |
| 470 |
UDS: &apiserver.UDSTransport{ |
| 471 |
UDSName: "/etc/srv/kubernetes/konnectivity/konnectivity-server.socket", |
| 472 |
}, |
| 473 |
}, |
| 474 |
}, |
| 475 |
}, |
| 476 |
}, |
| 477 |
}, |
| 478 |
}, |
| 479 |
{ |
| 480 |
name: "grpc-https-invalid", |
| 481 |
expectError: true, |
| 482 |
contents: &apiserver.EgressSelectorConfiguration{ |
| 483 |
TypeMeta: metav1.TypeMeta{ |
| 484 |
Kind: "", |
| 485 |
APIVersion: "", |
| 486 |
}, |
| 487 |
EgressSelections: []apiserver.EgressSelection{ |
| 488 |
{ |
| 489 |
Name: "cluster", |
| 490 |
Connection: apiserver.Connection{ |
| 491 |
ProxyProtocol: apiserver.ProtocolGRPC, |
| 492 |
Transport: &apiserver.Transport{ |
| 493 |
TCP: &apiserver.TCPTransport{ |
| 494 |
URL: "http://127.0.0.1:8131", |
| 495 |
TLSConfig: &apiserver.TLSConfig{ |
| 496 |
CABundle: "", |
| 497 |
ClientKey: "", |
| 498 |
ClientCert: "", |
| 499 |
}, |
| 500 |
}, |
| 501 |
}, |
| 502 |
}, |
| 503 |
}, |
| 504 |
}, |
| 505 |
}, |
| 506 |
}, |
| 507 |
{ |
| 508 |
name: "grpc-uds", |
| 509 |
expectError: false, |
| 510 |
contents: &apiserver.EgressSelectorConfiguration{ |
| 511 |
TypeMeta: metav1.TypeMeta{ |
| 512 |
Kind: "", |
| 513 |
APIVersion: "", |
| 514 |
}, |
| 515 |
EgressSelections: []apiserver.EgressSelection{ |
| 516 |
{ |
| 517 |
Name: "cluster", |
| 518 |
Connection: apiserver.Connection{ |
| 519 |
ProxyProtocol: apiserver.ProtocolGRPC, |
| 520 |
Transport: &apiserver.Transport{ |
| 521 |
UDS: &apiserver.UDSTransport{ |
| 522 |
UDSName: "/etc/srv/kubernetes/konnectivity/konnectivity-server.socket", |
| 523 |
}, |
| 524 |
}, |
| 525 |
}, |
| 526 |
}, |
| 527 |
}, |
| 528 |
}, |
| 529 |
}, |
| 530 |
{ |
| 531 |
name: "invalid egress selection name", |
| 532 |
expectError: true, |
| 533 |
contents: &apiserver.EgressSelectorConfiguration{ |
| 534 |
TypeMeta: metav1.TypeMeta{ |
| 535 |
Kind: "", |
| 536 |
APIVersion: "", |
| 537 |
}, |
| 538 |
EgressSelections: []apiserver.EgressSelection{ |
| 539 |
{ |
| 540 |
Name: "invalid", |
| 541 |
Connection: apiserver.Connection{ |
| 542 |
ProxyProtocol: apiserver.ProtocolDirect, |
| 543 |
}, |
| 544 |
}, |
| 545 |
}, |
| 546 |
}, |
| 547 |
}, |
| 548 |
{ |
| 549 |
name: "duplicate egress selections configured", |
| 550 |
expectError: true, |
| 551 |
contents: &apiserver.EgressSelectorConfiguration{ |
| 552 |
TypeMeta: metav1.TypeMeta{ |
| 553 |
Kind: "", |
| 554 |
APIVersion: "", |
| 555 |
}, |
| 556 |
EgressSelections: []apiserver.EgressSelection{ |
| 557 |
{ |
| 558 |
Name: "controlplane", |
| 559 |
Connection: apiserver.Connection{ |
| 560 |
ProxyProtocol: apiserver.ProtocolDirect, |
| 561 |
}, |
| 562 |
}, |
| 563 |
{ |
| 564 |
Name: "controlplane", |
| 565 |
Connection: apiserver.Connection{ |
| 566 |
ProxyProtocol: apiserver.ProtocolDirect, |
| 567 |
}, |
| 568 |
}, |
| 569 |
}, |
| 570 |
}, |
| 571 |
}, |
| 572 |
} |
| 573 |
|
| 574 |
for _, tc := range testcases { |
| 575 |
t.Run(tc.name, func(t *testing.T) { |
| 576 |
errs := ValidateEgressSelectorConfiguration(tc.contents) |
| 577 |
if !tc.expectError && len(errs) != 0 { |
| 578 |
t.Errorf("Calling ValidateEgressSelectorConfiguration expected no error, got %v", errs) |
| 579 |
} else if tc.expectError && len(errs) == 0 { |
| 580 |
t.Errorf("Calling ValidateEgressSelectorConfiguration expected error, got no error") |
| 581 |
} |
| 582 |
}) |
| 583 |
} |
| 584 |
} |