Search in sources :

Example 56 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project flink by apache.

the class FlinkKubeClientFactory method fromConfiguration.

/**
 * Create a Flink Kubernetes client with the given configuration.
 *
 * @param flinkConfig Flink configuration
 * @param useCase Flink Kubernetes client use case (e.g. client, resourcemanager,
 *     kubernetes-ha-services)
 * @return Return the Flink Kubernetes client with the specified configuration and dedicated IO
 *     executor.
 */
public FlinkKubeClient fromConfiguration(Configuration flinkConfig, String useCase) {
    final Config config;
    final String kubeContext = flinkConfig.getString(KubernetesConfigOptions.CONTEXT);
    if (kubeContext != null) {
        LOG.info("Configuring kubernetes client to use context {}.", kubeContext);
    }
    final String kubeConfigFile = flinkConfig.getString(KubernetesConfigOptions.KUBE_CONFIG_FILE);
    if (kubeConfigFile != null) {
        LOG.debug("Trying to load kubernetes config from file: {}.", kubeConfigFile);
        try {
            // If kubeContext is null, the default context in the kubeConfigFile will be used.
            // Note: the third parameter kubeconfigPath is optional and is set to null. It is
            // only used to rewrite
            // relative tls asset paths inside kubeconfig when a file is passed, and in the case
            // that the kubeconfig
            // references some assets via relative paths.
            config = Config.fromKubeconfig(kubeContext, FileUtils.readFileUtf8(new File(kubeConfigFile)), null);
        } catch (IOException e) {
            throw new KubernetesClientException("Load kubernetes config failed.", e);
        }
    } else {
        LOG.debug("Trying to load default kubernetes config.");
        config = Config.autoConfigure(kubeContext);
    }
    final String namespace = flinkConfig.getString(KubernetesConfigOptions.NAMESPACE);
    LOG.debug("Setting namespace of Kubernetes client to {}", namespace);
    config.setNamespace(namespace);
    final NamespacedKubernetesClient client = new DefaultKubernetesClient(config);
    final int poolSize = flinkConfig.get(KubernetesConfigOptions.KUBERNETES_CLIENT_IO_EXECUTOR_POOL_SIZE);
    return new Fabric8FlinkKubeClient(flinkConfig, client, createThreadPoolForAsyncIO(poolSize, useCase));
}
Also used : Config(io.fabric8.kubernetes.client.Config) NamespacedKubernetesClient(io.fabric8.kubernetes.client.NamespacedKubernetesClient) IOException(java.io.IOException) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) File(java.io.File) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 57 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project citrus-samples by christophd.

the class AbstractKubernetesIT method checkMinikubeEnvironment.

@BeforeSuite(alwaysRun = true)
public void checkMinikubeEnvironment() {
    try {
        Future<Boolean> future = Executors.newSingleThreadExecutor().submit(() -> {
            KubernetesClient kubernetesClient = new DefaultKubernetesClient();
            kubernetesClient.pods().list();
            return true;
        });
        future.get(5000, TimeUnit.MILLISECONDS);
        connected = true;
    } catch (Exception e) {
        log.warn("Skipping Kubernetes test execution as no proper Kubernetes environment is available on host system!", e);
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) BeforeSuite(org.testng.annotations.BeforeSuite)

Example 58 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project shinyproxy by openanalytics.

the class KubernetesBackend method initialize.

@Override
public void initialize() throws ShinyProxyException {
    super.initialize();
    ConfigBuilder configBuilder = new ConfigBuilder();
    String masterUrl = getProperty(PROPERTY_URL);
    if (masterUrl != null)
        configBuilder.withMasterUrl(masterUrl);
    String certPath = getProperty(PROPERTY_CERT_PATH);
    if (certPath != null && Files.isDirectory(Paths.get(certPath))) {
        Path certFilePath = Paths.get(certPath, "ca.pem");
        if (Files.exists(certFilePath))
            configBuilder.withCaCertFile(certFilePath.toString());
        certFilePath = Paths.get(certPath, "cert.pem");
        if (Files.exists(certFilePath))
            configBuilder.withClientCertFile(certFilePath.toString());
        certFilePath = Paths.get(certPath, "key.pem");
        if (Files.exists(certFilePath))
            configBuilder.withClientKeyFile(certFilePath.toString());
    }
    kubeClient = new DefaultKubernetesClient(configBuilder.build());
}
Also used : Path(java.nio.file.Path) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 59 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by fabric8io.

the class WatchPodsExample method main.

public static void main(String... args) throws Exception {
    KubernetesClient client = new DefaultKubernetesClient();
    client.pods().watch(new io.fabric8.kubernetes.client.Watcher<Pod>() {

        @Override
        public void eventReceived(Action action, Pod pod) {
            System.out.println(action + ": " + pod);
        }

        @Override
        public void onClose(KubernetesClientException e) {
            System.out.println("Closed: " + e);
        }
    });
    client.close();
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Pod(io.fabric8.kubernetes.api.model.Pod) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 60 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by fabric8io.

the class ViewPipeline method main.

public static void main(String[] args) {
    if (args.length == 0) {
        System.err.println("Usage: ViewPipeline jobName [branchName] [gitUrl]");
        return;
    }
    String jobName = args[0];
    String branchName = "master";
    String gitUrl = null;
    if (args.length > 1) {
        branchName = args[1];
    }
    if (args.length > 2) {
        gitUrl = args[2];
    }
    try {
        JobEnvironment environment = new JobEnvironment();
        environment.setJobName(jobName);
        environment.setBranchName(branchName);
        environment.setGitUrl(gitUrl);
        KubernetesClient kubernetesClient = new DefaultKubernetesClient();
        String namespace = kubernetesClient.getNamespace();
        if (Strings.isNullOrBlank(namespace)) {
            namespace = KubernetesHelper.defaultNamespace();
        }
        Pipeline pipeline = Pipelines.getPipeline(kubernetesClient, namespace, environment);
        System.out.println("Found pipeline for job: " + pipeline.getJobName() + " of kind: " + pipeline.getKind());
    } catch (IntrospectionException e) {
        System.out.println("Failed with: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) IntrospectionException(java.beans.IntrospectionException) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Aggregations

DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)79 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)55 HashMap (java.util.HashMap)13 Config (io.fabric8.kubernetes.client.Config)11 ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)7 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)7 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)6 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)6 TaskAction (org.gradle.api.tasks.TaskAction)6 Pod (io.fabric8.kubernetes.api.model.Pod)5 IOException (java.io.IOException)5 Map (java.util.Map)5 Test (org.junit.Test)5 KubernetesModelGenerator (com.github.isdream.chameleon.container.kubernetes.KubernetesModelGenerator)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 File (java.io.File)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 Service (io.fabric8.kubernetes.api.model.Service)3 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)3 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)3