use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.
the class KubectlGet method execute.
@Override
public List<ApiType> execute() throws KubectlException {
refreshDiscovery();
GenericKubernetesApi<ApiType, ? extends KubernetesListObject> api = apiTypeListClass == null ? getGenericApi(apiTypeClass) : getGenericApi(apiTypeClass, apiTypeListClass);
try {
if (isNamespaced()) {
return (List<ApiType>) api.list(namespace, listOptions).throwsApiException().getObject().getItems();
} else {
return (List<ApiType>) api.list(listOptions).throwsApiException().getObject().getItems();
}
} catch (ApiException e) {
throw new KubectlException(e);
}
}
use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.
the class KubectlPortForward method executeInternal.
private void executeInternal() throws ApiException, KubectlException, IOException, InterruptedException {
PortForward pf = new PortForward(apiClient);
PortForward.PortForwardResult result = pf.forward(namespace, name, targetPorts);
if (result == null) {
throw new KubectlException("PortForward failed!");
}
// TODO: Convert this to NIO to reduce the number of threads?
List<Thread> threads = new ArrayList<>();
for (int i = 0; i < localPorts.size(); i++) {
int targetPort = targetPorts.get(i);
threads.add(portForward(new ServerSocket(localPorts.get(i)), result.getInputStream(targetPort), result.getOutboundStream(targetPort)));
}
for (Thread t : threads) {
t.join();
}
}
use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.
the class KubectlGetTest method testGetDefaultNamespaceOnePodForbiddenShouldThrowException.
@Test
public void testGetDefaultNamespaceOnePodForbiddenShouldThrowException() {
wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces/default/pods/foo1")).willReturn(aResponse().withStatus(403).withBody(apiClient.getJSON().serialize(new V1Status().code(403)))));
try {
V1Pod getPod = Kubectl.get(V1Pod.class).apiClient(apiClient).skipDiscovery().namespace(// no namespace specified
"default").name("foo1").execute();
} catch (KubectlException e) {
assertTrue(e.getCause() instanceof ApiException);
return;
} finally {
wireMockRule.verify(1, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods/foo1")));
}
fail();
}
use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.
the class KubectlCreate method execute.
@Override
public ApiType execute() throws KubectlException {
refreshDiscovery();
GenericKubernetesApi<ApiType, KubernetesListObject> api = getGenericApi();
if (ModelMapper.isNamespaced(this.targetObj.getClass())) {
String targetNamespace = namespace != null ? namespace : Strings.isNullOrEmpty(targetObj.getMetadata().getNamespace()) ? Namespaces.NAMESPACE_DEFAULT : targetObj.getMetadata().getNamespace();
try {
return api.create(targetNamespace, targetObj, new CreateOptions()).throwsApiException().getObject();
} catch (ApiException e) {
throw new KubectlException(e);
}
} else {
try {
return api.create(targetObj, new CreateOptions()).throwsApiException().getObject();
} catch (ApiException e) {
throw new KubectlException(e);
}
}
}
use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.
the class KubectlLog method execute.
@Override
public InputStream execute() throws KubectlException {
validate();
PodLogs logs = new PodLogs(apiClient);
String ns = (this.namespace == null ? "default" : this.namespace);
try {
return logs.streamNamespacedPodLog(ns, this.name, this.container);
} catch (ApiException | IOException ex) {
throw new KubectlException(ex);
}
}
Aggregations