
package io.quarkus.kubernetes.deployment;

import static io.quarkus.kubernetes.deployment.Constants.DEPLOY;

import java.util.function.BooleanSupplier;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;

import io.fabric8.kubernetes.api.model.RootPaths;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.quarkus.kubernetes.client.runtime.KubernetesClientUtils;

public class KubernetesDeploy implements BooleanSupplier {

    private final Logger LOGGER = Logger.getLogger(KubernetesDeploy.class);
    private static boolean serverFound = false;

    @Override
    public boolean getAsBoolean() {
        Config config = ConfigProvider.getConfig();
        if (!config.getOptionalValue(DEPLOY, Boolean.class).orElse(false)) {
            return false;
        }

        // No need to perform the check multiple times.
        if (serverFound) {
            return true;
        }
        try (final KubernetesClient client = KubernetesClientUtils.createClient()) {
            //Let's check id we can connect.
            RootPaths paths = client.rootPaths();
            LOGGER.info("Found kubernetes server.");
            serverFound = true;
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}

@@ -143,24 +143,69 @@
 nSupplier;%0A%0A
+import javax.net.ssl.SSLHandshakeException;%0A%0A
 import org.e
@@ -239,16 +239,16 @@
 Config;%0A
-
 import o
@@ -683,16 +683,66 @@
 = false;
+%0A    private static boolean alreadyWarned = false;
 %0A%0A    @O
@@ -1351,32 +1351,32 @@
    return true;%0A
-
         %7D catch 
@@ -1387,24 +1387,951 @@
 eption e) %7B%0A
+            if (!alreadyWarned) %7B%0A                if (e.getCause() instanceof SSLHandshakeException) %7B%0A                    String message = %22Although a Kubernetes deployment was requested, it will however not take place because the API Server certificates are not trusted. The certificates can be configured using the relevant configuration propertiers under the 'quarkus.kubernetes-client' config root, or %5C%22quarkus.kubernetes-client.trust-certs=true%5C%22 can be set to explicitly trust the certificates (not recommended)%22;%0A                    LOGGER.warn(message);%0A                %7D else %7B%0A                    LOGGER.error(%0A                            %22Although a Kubernetes deployment was requested, it will however not take place because there was an error during communication with the API Server: %22%0A                                    + e.getMessage());%0A                %7D%0A                alreadyWarned = true;%0A            %7D%0A
             

Add log message when a kubernetes deployment cannot be performed