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));
}
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);
}
}
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());
}
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();
}
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();
}
}
Aggregations