File tree Expand file tree Collapse file tree
main/java/io/kubernetes/client/util
test/java/io/kubernetes/client/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -277,6 +277,9 @@ public static ClientBuilder kubeconfig(KubeConfig config) throws IOException {
277277 final ClientBuilder builder = new ClientBuilder ();
278278
279279 String server = config .getServer ();
280+ if (server == null ) {
281+ throw new IllegalArgumentException ("No server in kubeconfig" );
282+ }
280283 if (!server .contains ("://" )) {
281284 if (server .contains (":443" )) {
282285 server = "https://" + server ;
Original file line number Diff line number Diff line change 1818import static org .hamcrest .MatcherAssert .assertThat ;
1919import static org .hamcrest .core .Is .is ;
2020import static org .junit .Assert .assertEquals ;
21+ import static org .junit .Assert .assertThrows ;
2122import static org .mockito .Mockito .mock ;
2223import static org .mockito .Mockito .verify ;
2324
3132import java .io .IOException ;
3233import java .nio .file .Files ;
3334import java .nio .file .Paths ;
35+
3436import org .junit .Test ;
3537
3638/** Tests for the ConfigBuilder helper class */
@@ -299,4 +301,13 @@ public void testSettingPassphraseForKubeConfigShouldWork() throws IOException {
299301 ((ClientCertificateAuthentication ) receivingAuthn .getDelegateAuthentication ())
300302 .getPassphrase ());
301303 }
304+
305+ @ Test
306+ public void testDetectsServerNotSet () {
307+ assertThrows ("No server in kubeconfig" , IllegalArgumentException .class , () -> {
308+ KubeConfig kubeConfigWithoutServer = mock (KubeConfig .class );
309+
310+ ClientBuilder .kubeconfig (kubeConfigWithoutServer );
311+ });
312+ }
302313}
You can’t perform that action at this time.
0 commit comments