File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
main/java/io/kubernetes/client/util
test/java/io/kubernetes/client/util Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -277,6 +277,9 @@ public static ClientBuilder kubeconfig(KubeConfig config) throws IOException {
277
277
final ClientBuilder builder = new ClientBuilder ();
278
278
279
279
String server = config .getServer ();
280
+ if (server == null ) {
281
+ throw new IllegalArgumentException ("No server in kubeconfig" );
282
+ }
280
283
if (!server .contains ("://" )) {
281
284
if (server .contains (":443" )) {
282
285
server = "https://" + server ;
Original file line number Diff line number Diff line change 18
18
import static org .hamcrest .MatcherAssert .assertThat ;
19
19
import static org .hamcrest .core .Is .is ;
20
20
import static org .junit .Assert .assertEquals ;
21
+ import static org .junit .Assert .assertThrows ;
21
22
import static org .mockito .Mockito .mock ;
22
23
import static org .mockito .Mockito .verify ;
23
24
31
32
import java .io .IOException ;
32
33
import java .nio .file .Files ;
33
34
import java .nio .file .Paths ;
35
+
34
36
import org .junit .Test ;
35
37
36
38
/** Tests for the ConfigBuilder helper class */
@@ -299,4 +301,13 @@ public void testSettingPassphraseForKubeConfigShouldWork() throws IOException {
299
301
((ClientCertificateAuthentication ) receivingAuthn .getDelegateAuthentication ())
300
302
.getPassphrase ());
301
303
}
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
+ }
302
313
}
You can’t perform that action at this time.
0 commit comments