File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed
java/io/kubernetes/client/util Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ class ClientBuilderTest {
4848 Resources .getResource ("kubeconfig-https" ).getPath ();
4949 private static final String KUBECONFIG_HTTPS_X509_FILE_PATH =
5050 Resources .getResource ("kubeconfig-https-x509" ).getPath ();
51+ private static final String KUBECONFIG_TLS_SERVER_NAME_FILE_PATH =
52+ Resources .getResource ("kubeconfig-tls-server-name" ).getPath ();
5153 private static final String SSL_CA_CERT_PATH =
5254 new File (Resources .getResource ("ca-cert.pem" ).getPath ()).toString ();
5355 private static final String INVALID_SSL_CA_CERT_PATH =
@@ -321,4 +323,22 @@ void detectsServerNotSet() {
321323 ClientBuilder .kubeconfig (kubeConfigWithoutServer );
322324 }).hasMessage ("No server in kubeconfig" ).isInstanceOf (IllegalArgumentException .class );
323325 }
326+
327+ @ Test
328+ void tlsServerNameSetFromKubeConfig () throws IOException {
329+ ApiClient client =
330+ ClientBuilder .kubeconfig (
331+ KubeConfig .loadKubeConfig (new FileReader (KUBECONFIG_TLS_SERVER_NAME_FILE_PATH )))
332+ .build ();
333+ assertThat (client .getTlsServerName ()).isEqualTo ("my-cluster.example.com" );
334+ }
335+
336+ @ Test
337+ void tlsServerNameNotSetWhenNotInKubeConfig () throws IOException {
338+ ApiClient client =
339+ ClientBuilder .kubeconfig (
340+ KubeConfig .loadKubeConfig (new FileReader (KUBECONFIG_HTTPS_FILE_PATH )))
341+ .build ();
342+ assertThat (client .getTlsServerName ()).isNull ();
343+ }
324344}
Original file line number Diff line number Diff line change @@ -425,4 +425,35 @@ void execCredentialsCertificate() {
425425 assertThat (kc .getCredentials ()).containsEntry (KubeConfig .CRED_CLIENT_KEY_DATA_KEY , "key" );
426426 assertThat (kc .getCredentials ().get (KubeConfig .CRED_TOKEN_KEY )).isNull ();
427427 }
428+
429+ @ Test
430+ void tlsServerName () {
431+ String configWithTlsServerName =
432+ "apiVersion: v1\n "
433+ + "clusters:\n "
434+ + "- cluster:\n "
435+ + " server: https://192.168.1.1:6443\n "
436+ + " tls-server-name: my-cluster.example.com\n "
437+ + " certificate-authority-data: dGVzdAo=\n "
438+ + " name: test-cluster\n "
439+ + "users:\n "
440+ + "- user:\n "
441+ + " token: test-token\n "
442+ + " name: test-user\n "
443+ + "contexts:\n "
444+ + "- context:\n "
445+ + " cluster: test-cluster\n "
446+ + " user: test-user\n "
447+ + " name: test-context\n "
448+ + "current-context: test-context\n " ;
449+
450+ KubeConfig config = KubeConfig .loadKubeConfig (new StringReader (configWithTlsServerName ));
451+ assertThat ("my-cluster.example.com" ).isEqualTo (config .getTlsServerName ());
452+ }
453+
454+ @ Test
455+ void tlsServerNameNotPresent () {
456+ KubeConfig config = KubeConfig .loadKubeConfig (new StringReader (KUBECONFIG_TOKEN ));
457+ assertThat (config .getTlsServerName ()).isNull ();
458+ }
428459}
Original file line number Diff line number Diff line change 1+ apiVersion: v1
2+ clusters:
3+ - cluster:
4+ server: https://192.168.1.1:6443
5+ tls-server-name: my-cluster.example.com
6+ certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJkekNDQVIyZ0F3SUJBZ0lCQURBS0JnZ3Foa2pPUFFRREFqQWpNU0V3SHdZRFZRUUREQmhyTTNNdGMyVnkKZG1WeUxXTmhRREUzTXpNMU1qYzFPVGN3SGhjTk1qUXhNREkzTVRnek1ETTNXaGNOTXpReE1ESTFNVGd6TURNMwpXakFqTVNFd0h3WURWUVFEREJock0zTXRjMlZ5ZG1WeUxXTmhRREUzTXpNMU1qYzFPVGN3V1RBVEJnY3Foa2pPClBRSUJCZ2dxaGtqT1BRTUJCd05DQUFUMmY5dzdYZEJLRktDN2ptQUxYaDFlNVgyWjNYL0h5K2JYR0MxV1VoeHUKS3BZUUJ5Q0oxcU5RUjhQWHhOWEdvd3BJUFp0ekU0T2NQdjFRUlJyd0hvNkZvMEl3UURBT0JnTlZIUThCQWY4RQpCQU1DQXFRd0R3WURWUjBUQVFIL0JBVXdBd0VCL3pBZEJnTlZIUTRFRmdRVXdYam5rdWRSek55T1N2VmY2Mm1PCnFqc2FxREF3Q2dZSUtvWkl6ajBFQXdJRFNBQXdSUUlnRGRYelNuYTRnS2x6akJ2MllLVDJqM0VlSzY1WndPa2cKNGMxaG1nK29CVHdDSVFEdTBGR2NjRVE3OXE2U0pGTkF1bUhsd0JaY3lmeE5sOWhDb3hSRUdWVy93Zz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
7+ name: test-cluster
8+ users:
9+ - user:
10+ token: test-token
11+ name: test-user
12+ contexts:
13+ - context:
14+ cluster: test-cluster
15+ user: test-user
16+ name: test-context
17+ current-context: test-context
You can’t perform that action at this time.
0 commit comments