use of org.eclipse.jkube.kit.config.access.ClusterAccess in project jkube by eclipse.
the class AbstractJKubeMojo method init.
protected void init() throws DependencyResolutionRequiredException {
log = createLogger(null);
clusterAccess = new ClusterAccess(log, initClusterConfiguration());
javaProject = MavenUtil.convertMavenProjectToJKubeProject(project, session);
jkubeServiceHub = initJKubeServiceHubBuilder(javaProject).build();
resources = updateResourceConfigNamespace(namespace, resources);
}
use of org.eclipse.jkube.kit.config.access.ClusterAccess in project jkube by eclipse.
the class DockerImageWatcher method executeCommandInPod.
private String executeCommandInPod(String command, Collection<HasMetadata> resources) throws IOException, WatchException {
ClusterAccess clusterAccess = getContext().getJKubeServiceHub().getClusterAccess();
try {
final PodExecutor podExecutor = new PodExecutor(clusterAccess, WAIT_TIMEOUT);
podExecutor.executeCommandInPod(resources, command);
return podExecutor.getOutput();
} catch (InterruptedException exception) {
log.error("Execute command task interrupted");
Thread.currentThread().interrupt();
}
return null;
}
use of org.eclipse.jkube.kit.config.access.ClusterAccess in project jkube by eclipse.
the class DockerImageWatcher method copyFileToPod.
private void copyFileToPod(File fileToUpload, Collection<HasMetadata> resources) throws IOException, WatchException {
ClusterAccess clusterAccess = getContext().getJKubeServiceHub().getClusterAccess();
try (final PipedOutputStream pos = new PipedOutputStream();
final PipedInputStream pis = new PipedInputStream(pos)) {
final Runnable filePusher = uploadFilesRunnable(fileToUpload, pos, log);
final PodExecutor podExecutor = new PodExecutor(clusterAccess, pis, WAIT_TIMEOUT, filePusher);
podExecutor.executeCommandInPod(resources, "sh");
} catch (InterruptedException exception) {
log.error("Copy files task interrupted");
Thread.currentThread().interrupt();
}
}
use of org.eclipse.jkube.kit.config.access.ClusterAccess in project jkube by eclipse.
the class DockerImageWatcher method restartContainer.
protected void restartContainer(WatchService.ImageWatcher watcher, Collection<HasMetadata> resources) {
ImageConfiguration imageConfig = watcher.getImageConfiguration();
String imageName = imageConfig.getName();
ClusterAccess clusterAccess = getContext().getJKubeServiceHub().getClusterAccess();
try (KubernetesClient client = clusterAccess.createDefaultClient()) {
String namespace = clusterAccess.getNamespace();
String imagePrefix = getImagePrefix(imageName);
for (HasMetadata entity : resources) {
updateImageName(client, namespace, entity, imagePrefix, imageName);
}
} catch (KubernetesClientException e) {
KubernetesHelper.handleKubernetesClientException(e, this.log);
} catch (IllegalStateException e) {
throw e;
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
use of org.eclipse.jkube.kit.config.access.ClusterAccess in project jkube by eclipse.
the class OpenshiftBuildService method initClient.
private void initClient() {
ClusterAccess clusterAccess = jKubeServiceHub.getClusterAccess();
if (clusterAccess == null) {
clusterAccess = new ClusterAccess(log, ClusterConfiguration.from(System.getProperties(), jKubeServiceHub.getConfiguration().getProject().getProperties()).build());
}
KubernetesClient k8sClient = clusterAccess.createDefaultClient();
if (!isOpenShift(k8sClient)) {
throw new IllegalStateException("OpenShift platform has been specified but OpenShift has not been detected!");
}
client = (OpenShiftClient) k8sClient;
if (buildServiceConfig.getResourceConfig() != null && buildServiceConfig.getResourceConfig().getNamespace() != null) {
applicableOpenShiftNamespace = buildServiceConfig.getResourceConfig().getNamespace();
} else {
applicableOpenShiftNamespace = clusterAccess.getNamespace();
}
}
Aggregations