use of io.fabric8.kubernetes.client.Config in project camel by apache.
the class KubernetesEndpoint method createKubernetesClient.
private KubernetesClient createKubernetesClient() {
LOG.debug("Create Kubernetes client with the following Configuration: " + configuration.toString());
ConfigBuilder builder = new ConfigBuilder();
builder.withMasterUrl(configuration.getMasterUrl());
if ((ObjectHelper.isNotEmpty(configuration.getUsername()) && ObjectHelper.isNotEmpty(configuration.getPassword())) && ObjectHelper.isEmpty(configuration.getOauthToken())) {
builder.withUsername(configuration.getUsername());
builder.withPassword(configuration.getPassword());
}
if (ObjectHelper.isNotEmpty(configuration.getOauthToken())) {
builder.withOauthToken(configuration.getOauthToken());
}
if (ObjectHelper.isNotEmpty(configuration.getCaCertData())) {
builder.withCaCertData(configuration.getCaCertData());
}
if (ObjectHelper.isNotEmpty(configuration.getCaCertFile())) {
builder.withCaCertFile(configuration.getCaCertFile());
}
if (ObjectHelper.isNotEmpty(configuration.getClientCertData())) {
builder.withClientCertData(configuration.getClientCertData());
}
if (ObjectHelper.isNotEmpty(configuration.getClientCertFile())) {
builder.withClientCertFile(configuration.getClientCertFile());
}
if (ObjectHelper.isNotEmpty(configuration.getApiVersion())) {
builder.withApiVersion(configuration.getApiVersion());
}
if (ObjectHelper.isNotEmpty(configuration.getClientKeyAlgo())) {
builder.withClientKeyAlgo(configuration.getClientKeyAlgo());
}
if (ObjectHelper.isNotEmpty(configuration.getClientKeyData())) {
builder.withClientKeyData(configuration.getClientKeyData());
}
if (ObjectHelper.isNotEmpty(configuration.getClientKeyFile())) {
builder.withClientKeyFile(configuration.getClientKeyFile());
}
if (ObjectHelper.isNotEmpty(configuration.getClientKeyPassphrase())) {
builder.withClientKeyPassphrase(configuration.getClientKeyPassphrase());
}
if (ObjectHelper.isNotEmpty(configuration.getTrustCerts())) {
builder.withTrustCerts(configuration.getTrustCerts());
}
Config conf = builder.build();
return new DefaultKubernetesClient(conf);
}
use of io.fabric8.kubernetes.client.Config in project camel by apache.
the class KubernetesBuildConfigsProducer method doGetBuildConfig.
protected void doGetBuildConfig(Exchange exchange, String operation) throws Exception {
BuildConfig buildConfig = null;
String buildConfigName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILD_CONFIG_NAME, String.class);
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
if (ObjectHelper.isEmpty(buildConfigName)) {
LOG.error("Get a specific Build Config require specify a Build Config name");
throw new IllegalArgumentException("Get a specific Build Config require specify a Build Config name");
}
if (ObjectHelper.isEmpty(namespaceName)) {
LOG.error("Get a specific Build Config require specify a namespace name");
throw new IllegalArgumentException("Get a specific Build Config require specify a namespace name");
}
buildConfig = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs().inNamespace(namespaceName).withName(buildConfigName).get();
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(buildConfig);
}
use of io.fabric8.kubernetes.client.Config in project che by eclipse.
the class OpenShiftConnector method createContainerInfo.
/**
* Collects the relevant information from a Service, an ImageInfo, and a Pod into
* a docker ContainerInfo JSON object. The returned object is what would be returned
* by executing {@code docker inspect <container>}, with fields filled as available.
* @param svc
* @param imageInfo
* @param pod
* @param containerId
* @return
*/
private ContainerInfo createContainerInfo(Service svc, ImageInfo imageInfo, Pod pod, String containerId) {
// In Che on OpenShift, we only have one container per pod.
Container container = pod.getSpec().getContainers().get(0);
ContainerConfig imageContainerConfig = imageInfo.getContainerConfig();
// HostConfig
HostConfig hostConfig = new HostConfig();
hostConfig.setBinds(new String[0]);
hostConfig.setMemory(imageInfo.getConfig().getMemory());
// Env vars
List<String> imageEnv = Arrays.asList(imageContainerConfig.getEnv());
List<String> containerEnv = container.getEnv().stream().map(e -> String.format("%s=%s", e.getName(), e.getValue())).collect(Collectors.toList());
String[] env = Stream.concat(imageEnv.stream(), containerEnv.stream()).toArray(String[]::new);
// Exposed Ports
Map<String, List<PortBinding>> ports = getCheServicePorts(svc);
Map<String, Map<String, String>> exposedPorts = new HashMap<>();
for (String key : ports.keySet()) {
exposedPorts.put(key, Collections.emptyMap());
}
// Labels
Map<String, String> annotations = KubernetesLabelConverter.namesToLabels(svc.getMetadata().getAnnotations());
Map<String, String> containerLabels = imageInfo.getConfig().getLabels();
Map<String, String> labels = Stream.concat(annotations.entrySet().stream(), containerLabels.entrySet().stream()).filter(e -> e.getKey().startsWith(KubernetesLabelConverter.getCheServerLabelPrefix())).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
// ContainerConfig
ContainerConfig config = imageContainerConfig;
config.setHostname(svc.getMetadata().getName());
config.setEnv(env);
config.setExposedPorts(exposedPorts);
config.setLabels(labels);
config.setImage(container.getImage());
// NetworkSettings
NetworkSettings networkSettings = new NetworkSettings();
networkSettings.setIpAddress(svc.getSpec().getClusterIP());
networkSettings.setGateway(svc.getSpec().getClusterIP());
networkSettings.setPorts(ports);
// Make final ContainerInfo
ContainerInfo info = new ContainerInfo();
info.setId(containerId);
info.setConfig(config);
info.setNetworkSettings(networkSettings);
info.setHostConfig(hostConfig);
info.setImage(imageInfo.getConfig().getImage());
return info;
}
Aggregations