diff --git a/CHANGELOG.md b/CHANGELOG.md index c56abe8fa64..68bcef43298 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Fix #5866: Addressed cycle in crd generation with Java 19+ and ZonedDateTime #### Improvements +* Fix #5605: proxy configs support proxy URLs without a scheme * Fix #5878: (java-generator) Add implements Editable for extraAnnotations * Fix #5878: (java-generator) Update documentation to include dependencies * Fix #5867: (crd-generator) Imply schemaFrom via JsonFormat shape (SchemaFrom takes precedence) diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java index c613acc590a..3022a748fce 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java @@ -86,7 +86,14 @@ static URI getProxyUri(URL master, Config config) throws URISyntaxException { proxy = config.getHttpProxy(); } if (proxy != null) { - URI proxyUrl = new URI(proxy); + final String completedProxy; + if (proxy.contains("://")) { + completedProxy = proxy; + } else { + // No protocol specified, default to cluster requirements + completedProxy = master.getProtocol() + "://" + proxy; + } + final URI proxyUrl = new URI(completedProxy); if (proxyUrl.getPort() < 0) { throw new IllegalArgumentException("Failure in creating proxy URL. Proxy port is required!"); } diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java index f623728c03a..25cfcaed57e 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java @@ -65,12 +65,12 @@ class HttpClientUtilsTest { @Test - void toProxyTypeTestUnknown() throws MalformedURLException { + void toProxyTypeTestUnknown() { assertThrows(MalformedURLException.class, () -> HttpClientUtils.toProxyType("unknown")); } @Test - void toProxyTypeTestNull() throws MalformedURLException { + void toProxyTypeTestNull() { assertThrows(MalformedURLException.class, () -> HttpClientUtils.toProxyType(null)); } @@ -160,7 +160,7 @@ void setUp() { @ParameterizedTest(name = "{index}: Master hostname ''{0}'' matched by No Proxy ''{1}'' ") @MethodSource("masterHostnameDoesMatchNoProxyInput") void masterHostnameDoesMatchNoProxy(String masterHostname, String[] noProxy) - throws MalformedURLException, URISyntaxException { + throws MalformedURLException { assertTrue(HttpClientUtils.isHostMatchedByNoProxy(masterHostname, noProxy)); } @@ -236,6 +236,19 @@ void withNoHttpProxyProvidedReturnsNull() throws MalformedURLException, URISynta // Then assertThat(url).isNull(); } + + @Test + void whenIncompleteHttpProxyUrlProvided_shouldInferProtocol() throws MalformedURLException, URISyntaxException { + // Given + Config config = configBuilder.withHttpProxy("example.com:8080").build(); + // When + URI url = HttpClientUtils.getProxyUri(new URL("http://localhost"), config); + // Then + assertThat(url) + .hasScheme("http") + .hasHost("example.com") + .hasPort(8080); + } } @Nested