11package org .csanchez .jenkins .plugins .kubernetes ;
22
33
4+ import hudson .Util ;
45import io .fabric8 .kubernetes .client .KubernetesClientBuilder ;
56import java .util .Base64 ;
67import java .util .Collections ;
@@ -76,7 +77,7 @@ public KubernetesFactoryAdapter(String serviceAddress, String namespace, @CheckF
7677 @ CheckForNull String credentialsId , boolean skipTlsVerify , int connectTimeout , int readTimeout , int maxRequestsPerHost , boolean useJenkinsProxy ) throws KubernetesAuthException {
7778 this .serviceAddress = serviceAddress ;
7879 this .namespace = namespace ;
79- this .caCertData = caCertData ;
80+ this .caCertData = decodeBase64IfNeeded ( caCertData ) ;
8081 this .auth = AuthenticationTokens .convert (KubernetesAuth .class , resolveCredentials (credentialsId ));
8182 this .skipTlsVerify = skipTlsVerify ;
8283 this .connectTimeout = connectTimeout ;
@@ -85,6 +86,19 @@ public KubernetesFactoryAdapter(String serviceAddress, String namespace, @CheckF
8586 this .useJenkinsProxy = useJenkinsProxy ;
8687 }
8788
89+ private static String decodeBase64IfNeeded (String caCertData ) {
90+ if (Util .fixEmpty (caCertData ) != null ) {
91+ try {
92+ // Decode Base64 if needed
93+ byte [] decode = Base64 .getDecoder ().decode (caCertData .getBytes (UTF_8 ));
94+ return new String (decode , UTF_8 );
95+ } catch (IllegalArgumentException e ) {
96+ return caCertData ;
97+ }
98+ }
99+ return caCertData ;
100+ }
101+
88102 public KubernetesClient createClient () throws KubernetesAuthException {
89103
90104 ConfigBuilder builder ;
0 commit comments