use of io.fabric8.kubernetes.client.dsl.internal.core.v1.PodOperationsImpl in project kubernetes-client by fabric8io.
the class BaseOperationTest method testSimpleFieldQueryParamConcatenation.
@Test
void testSimpleFieldQueryParamConcatenation() {
Map<String, String> fieldsMap = new HashMap<>();
fieldsMap.put("yesKey1", "yesValue1");
fieldsMap.put("yesKey2", "yesValue2");
PodOperationsImpl operation = new PodOperationsImpl(new PodOperationContext(), new OperationContext());
operation = (PodOperationsImpl) operation.withFields(fieldsMap).withField("yesKey2", "overrideValue2").withoutField("noKey1", "noValue1").withoutField("noKey2", "noValue2");
final String fieldQueryParam = operation.getFieldQueryParam();
// Use contains to not be depending on map key/value pair ordering
assertThat(fieldQueryParam, containsString("yesKey1=yesValue1"));
assertThat(fieldQueryParam, containsString("yesKey2=overrideValue2"));
assertThat(fieldQueryParam, containsString("noKey1!=noValue1"));
assertThat(fieldQueryParam, containsString("noKey2!=noValue2"));
}
use of io.fabric8.kubernetes.client.dsl.internal.core.v1.PodOperationsImpl in project kubernetes-client by fabric8io.
the class BaseOperationTest method testFilterContextModification.
@Test
void testFilterContextModification() {
PodOperationsImpl operation = new PodOperationsImpl(new PodOperationContext(), new OperationContext());
operation.withField("x", "y");
// should not modify the existing context
assertTrue(Utils.isNullOrEmpty(operation.getFieldQueryParam()));
}
use of io.fabric8.kubernetes.client.dsl.internal.core.v1.PodOperationsImpl in project kubernetes-client by fabric8io.
the class ServiceOperationsImpl method matchingPod.
private Pod matchingPod() {
Service item = requireFromServer();
Map<String, String> labels = item.getSpec().getSelector();
PodList list = new PodOperationsImpl(context).inNamespace(item.getMetadata().getNamespace()).withLabels(labels).list();
return list.getItems().stream().findFirst().orElseThrow(() -> new IllegalStateException("Could not find matching pod for service:" + item + "."));
}
use of io.fabric8.kubernetes.client.dsl.internal.core.v1.PodOperationsImpl in project syndesis by syndesisio.
the class KubernetesSupport method watchLog.
/*
* Feeds the controller of the given podName to the callback handler for processing.
*
* We do this instead of using the watchLog() feature of the k8s client lib because it really sucks due to:
* 1. You can't configure the timestamps option or the sinceTime option. Need to resume log downloads.
* 2. It seems to need extra threads..
* 3. It might be hiding some of the http failure conditions.
*
*/
protected void watchLog(String podName, Consumer<InputStream> handler, String sinceTime, Executor executor) throws IOException {
try {
PodOperationsImpl pod = (PodOperationsImpl) client.pods().withName(podName);
List<Container> containers = pod.get().getSpec().getContainers();
String containerFilter = getSpecificUserContainer(containers).map(n -> "&container=" + n).orElse("");
StringBuilder url = new StringBuilder().append(pod.getResourceUrl().toString()).append("/log?pretty=false&follow=true×tamps=true").append(containerFilter);
if (sinceTime != null) {
url.append("&sinceTime=").append(sinceTime);
}
String podLogUrl = url.toString();
Thread.currentThread().setName("Logs Controller [running], request: " + podLogUrl);
Request request = new Request.Builder().url(new URL(podLogUrl)).get().tag("log-watcher").build();
OkHttpClient clone = okHttpClient.newBuilder().readTimeout(readTimeout).build();
clone.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
LOG.info("Failure occurred getting controller for pod: {},", podName, e);
handler.accept(null);
}
@Override
public void onResponse(final Call call, final Response response) throws IOException {
executor.execute(() -> {
Thread.currentThread().setName("Logs Controller [running], streaming: " + podLogUrl);
try {
if (response.code() == 200) {
handler.accept(response.body().byteStream());
} else {
LOG.info("Failure occurred while processing controller for pod: {}, http status: {}, details: {}", podName, response.code(), response.body().string());
handler.accept(null);
}
} catch (SocketTimeoutException timeout) {
LOG.warn("Timed out reading the log stream");
LOG.debug("Timed out reading the log stream", timeout);
} catch (IOException e) {
LOG.error("Unexpected Error", e);
} finally {
Thread.currentThread().setName(ActivityTrackingController.IDLE_THREAD_NAME);
}
});
}
});
} catch (RuntimeException t) {
throw new IOException("Unexpected Error", t);
} finally {
Thread.currentThread().setName(ActivityTrackingController.IDLE_THREAD_NAME);
}
}
use of io.fabric8.kubernetes.client.dsl.internal.core.v1.PodOperationsImpl in project cloud-pipeline by epam.
the class PipelineExecutor method launchRootPod.
public void launchRootPod(String command, PipelineRun run, List<EnvVar> envVars, List<String> endpoints, String pipelineId, String nodeIdLabel, String secretName, String clusterId, boolean pullImage) {
try (KubernetesClient client = new DefaultKubernetesClient()) {
Map<String, String> labels = new HashMap<>();
labels.put("spawned_by", "pipeline-api");
labels.put("pipeline_id", pipelineId);
addWorkerLabel(clusterId, labels, run);
LOGGER.debug("Root pipeline task ID: {}", run.getPodId());
Map<String, String> nodeSelector = new HashMap<>();
if (preferenceManager.getPreference(SystemPreferences.CLUSTER_ENABLE_AUTOSCALING)) {
nodeSelector.put("runid", nodeIdLabel);
// id pod ip == pipeline id we have a root pod, otherwise we prefer to skip pod in autoscaler
if (run.getPodId().equals(pipelineId)) {
labels.put("type", "pipeline");
}
labels.put("runid", nodeIdLabel);
} else {
nodeSelector.put("skill", "luigi");
}
labels.putAll(getServiceLabels(endpoints));
OkHttpClient httpClient = HttpClientUtils.createHttpClient(client.getConfiguration());
ObjectMeta metadata = getObjectMeta(run, labels);
PodSpec spec = getPodSpec(run, envVars, secretName, nodeSelector, run.getDockerImage(), command, pullImage);
Pod pod = new Pod("v1", "Pod", metadata, spec, null);
Pod created = new PodOperationsImpl(httpClient, client.getConfiguration(), kubeNamespace).create(pod);
LOGGER.debug("Created POD: {}", created.toString());
}
}
Aggregations