2828
2929import org .jboss .logging .Logger ;
3030
31- import io .dekorate .utils .Clients ;
3231import io .dekorate .utils .Packaging ;
3332import io .dekorate .utils .Serialization ;
3433import io .fabric8 .kubernetes .api .model .HasMetadata ;
3534import io .fabric8 .kubernetes .api .model .KubernetesList ;
3635import io .fabric8 .kubernetes .api .model .Secret ;
3736import io .fabric8 .kubernetes .client .Config ;
3837import io .fabric8 .kubernetes .client .KubernetesClient ;
38+ import io .fabric8 .kubernetes .client .KubernetesClientBuilder ;
3939import io .fabric8 .kubernetes .client .KubernetesClientException ;
4040import io .fabric8 .kubernetes .client .dsl .LogWatch ;
41+ import io .fabric8 .kubernetes .client .http .HttpClient ;
4142import io .fabric8 .openshift .api .model .Build ;
4243import io .fabric8 .openshift .api .model .BuildConfig ;
4344import io .fabric8 .openshift .api .model .ImageStream ;
@@ -231,7 +232,7 @@ public void openshiftRequirementsNative(OpenshiftConfig openshiftConfig,
231232 public void openshiftBuildFromJar (OpenshiftConfig openshiftConfig ,
232233 S2iConfig s2iConfig ,
233234 ContainerImageConfig containerImageConfig ,
234- KubernetesClientBuildItem kubernetesClientSupplier ,
235+ KubernetesClientBuildItem kubernetesClientBuilder ,
235236 ContainerImageInfoBuildItem containerImage ,
236237 ArchiveRootBuildItem archiveRoot , OutputTargetBuildItem out , PackageConfig packageConfig ,
237238 List <GeneratedFileSystemResourceBuildItem > generatedResources ,
@@ -263,7 +264,7 @@ public void openshiftBuildFromJar(OpenshiftConfig openshiftConfig,
263264 return ;
264265 }
265266
266- try (KubernetesClient kubernetesClient = kubernetesClientSupplier . getClient (). get ()) {
267+ try (KubernetesClient kubernetesClient = kubernetesClientBuilder . buildClient ()) {
267268 String namespace = Optional .ofNullable (kubernetesClient .getNamespace ()).orElse ("default" );
268269 LOG .info ("Starting (in-cluster) container image build for jar using: " + config .buildStrategy + " on server: "
269270 + kubernetesClient .getMasterUrl () + " in namespace:" + namespace + "." );
@@ -272,14 +273,16 @@ public void openshiftBuildFromJar(OpenshiftConfig openshiftConfig,
272273 //For s2i kind of builds where jars are expected directly in the '/' we have to use null.
273274 String outputDirName = out .getOutputDirectory ().getFileName ().toString ();
274275 String contextRoot = getContextRoot (outputDirName , packageConfig .isFastJar (), config .buildStrategy );
276+ KubernetesClientBuilder clientBuilder = newClientBuilderWithoutHttp2 (kubernetesClient .getConfiguration (),
277+ kubernetesClientBuilder .getHttpClientFactory ());
275278 if (packageConfig .isFastJar ()) {
276- createContainerImage (kubernetesClient , openshiftYml .get (), config , contextRoot , jar .getPath ().getParent (),
279+ createContainerImage (clientBuilder , openshiftYml .get (), config , contextRoot , jar .getPath ().getParent (),
277280 jar .getPath ().getParent ());
278281 } else if (jar .getLibraryDir () != null ) { //When using uber-jar the libraryDir is going to be null, potentially causing NPE.
279- createContainerImage (kubernetesClient , openshiftYml .get (), config , contextRoot , jar .getPath ().getParent (),
282+ createContainerImage (clientBuilder , openshiftYml .get (), config , contextRoot , jar .getPath ().getParent (),
280283 jar .getPath (), jar .getLibraryDir ());
281284 } else {
282- createContainerImage (kubernetesClient , openshiftYml .get (), config , contextRoot , jar .getPath ().getParent (),
285+ createContainerImage (clientBuilder , openshiftYml .get (), config , contextRoot , jar .getPath ().getParent (),
283286 jar .getPath ());
284287 }
285288 artifactResultProducer .produce (new ArtifactResultBuildItem (null , "jar-container" , Collections .emptyMap ()));
@@ -300,7 +303,7 @@ private String getContextRoot(String outputDirName, boolean isFastJar, BuildStra
300303 @ BuildStep (onlyIf = { IsNormalNotRemoteDev .class , OpenshiftBuild .class , NativeBuild .class })
301304 public void openshiftBuildFromNative (OpenshiftConfig openshiftConfig , S2iConfig s2iConfig ,
302305 ContainerImageConfig containerImageConfig ,
303- KubernetesClientBuildItem kubernetesClientSupplier ,
306+ KubernetesClientBuildItem kubernetesClientBuilder ,
304307 ContainerImageInfoBuildItem containerImage ,
305308 ArchiveRootBuildItem archiveRoot , OutputTargetBuildItem out , PackageConfig packageConfig ,
306309 List <GeneratedFileSystemResourceBuildItem > generatedResources ,
@@ -321,7 +324,7 @@ public void openshiftBuildFromNative(OpenshiftConfig openshiftConfig, S2iConfig
321324 return ;
322325 }
323326
324- try (KubernetesClient kubernetesClient = kubernetesClientSupplier . getClient (). get ()) {
327+ try (KubernetesClient kubernetesClient = kubernetesClientBuilder . buildClient ()) {
325328 String namespace = Optional .ofNullable (kubernetesClient .getNamespace ()).orElse ("default" );
326329
327330 LOG .info ("Starting (in-cluster) container image build for jar using: " + config .buildStrategy + " on server: "
@@ -340,14 +343,16 @@ public void openshiftBuildFromNative(OpenshiftConfig openshiftConfig, S2iConfig
340343 //For docker kind of builds where we use instructions like: `COPY target/*.jar /deployments` it using '/target' is a requirement.
341344 //For s2i kind of builds where jars are expected directly in the '/' we have to use null.
342345 String contextRoot = config .buildStrategy == BuildStrategy .DOCKER ? "target" : null ;
343- createContainerImage (kubernetesClient , openshiftYml .get (), config , contextRoot , out .getOutputDirectory (),
344- nativeImage .getPath ());
346+ createContainerImage (
347+ newClientBuilderWithoutHttp2 (kubernetesClient .getConfiguration (),
348+ kubernetesClientBuilder .getHttpClientFactory ()),
349+ openshiftYml .get (), config , contextRoot , out .getOutputDirectory (), nativeImage .getPath ());
345350 artifactResultProducer .produce (new ArtifactResultBuildItem (null , "native-container" , Collections .emptyMap ()));
346351 containerImageBuilder .produce (new ContainerImageBuilderBuildItem (OPENSHIFT ));
347352 }
348353 }
349354
350- public static void createContainerImage (KubernetesClient kubernetesClient ,
355+ public static void createContainerImage (KubernetesClientBuilder kubernetesClientBuilder ,
351356 GeneratedFileSystemResourceBuildItem openshiftManifests ,
352357 OpenshiftConfig openshiftConfig ,
353358 String base ,
@@ -364,10 +369,7 @@ public static void createContainerImage(KubernetesClient kubernetesClient,
364369 throw new RuntimeException ("Error creating the openshift binary build archive." , e );
365370 }
366371
367- Config config = kubernetesClient .getConfiguration ();
368- //Let's disable http2 as it causes issues with duplicate build triggers.
369- config .setHttp2Disable (true );
370- try (KubernetesClient client = Clients .fromConfig (config )) {
372+ try (KubernetesClient client = kubernetesClientBuilder .build ()) {
371373 OpenShiftClient openShiftClient = toOpenshiftClient (client );
372374 KubernetesList kubernetesList = Serialization
373375 .unmarshalAsList (new ByteArrayInputStream (openshiftManifests .getData ()));
@@ -533,6 +535,14 @@ private static void display(Reader logReader, Logger.Level level) throws IOExcep
533535 }
534536 }
535537
538+ private static KubernetesClientBuilder newClientBuilderWithoutHttp2 (Config configuration ,
539+ HttpClient .Factory httpClientFactory ) {
540+ //Let's disable http2 as it causes issues with duplicate build triggers.
541+ configuration .setHttp2Disable (true );
542+
543+ return new KubernetesClientBuilder ().withConfig (configuration ).withHttpClientFactory (httpClientFactory );
544+ }
545+
536546 // visible for test
537547 static String concatUnixPaths (String ... elements ) {
538548 StringBuilder result = new StringBuilder ();
0 commit comments