use of io.kubernetes.client.extended.kubectl.exception.KubectlException in project java by kubernetes-client.
the class KubectlReplace method execute.
@Override
public ApiType execute() throws KubectlException {
verifyArguments();
refreshDiscovery();
if (isNamespaced(apiTypeClass)) {
try {
return getGenericApi().update(updateObject, options).throwsApiException().getObject();
} catch (ApiException e) {
throw new KubectlException(e);
}
} else {
try {
return getGenericApi().update(updateObject, options).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 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 KubectlApply method executeServerSideApply.
private ApiType executeServerSideApply() throws KubectlException {
refreshDiscovery();
GenericKubernetesApi<ApiType, KubernetesListObject> api = getGenericApi();
PatchOptions patchOptions = new PatchOptions();
patchOptions.setForce(this.forceConflict);
patchOptions.setFieldManager(this.fieldManager);
if (ModelMapper.isNamespaced(this.targetObj.getClass())) {
String targetNamespace = namespace != null ? namespace : Strings.isNullOrEmpty(targetObj.getMetadata().getNamespace()) ? Namespaces.NAMESPACE_DEFAULT : targetObj.getMetadata().getNamespace();
KubernetesApiResponse<KubernetesObject> response = null;
try {
return api.patch(targetNamespace, targetObj.getMetadata().getName(), V1Patch.PATCH_FORMAT_APPLY_YAML, new V1Patch(apiClient.getJSON().serialize(targetObj)), patchOptions).throwsApiException().getObject();
} catch (ApiException e) {
throw new KubectlException(e);
}
} else {
try {
return api.patch(targetObj.getMetadata().getName(), V1Patch.PATCH_FORMAT_APPLY_YAML, new V1Patch(apiClient.getJSON().serialize(targetObj)), patchOptions).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 KubectlExec method execute.
@Override
public Integer execute() throws KubectlException {
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(name).namespace(namespace));
Exec exec = new Exec(apiClient);
try {
Process proc = exec.exec(pod, command, container, stdin, tty);
copyAsync(proc.getInputStream(), System.out);
copyAsync(proc.getErrorStream(), System.err);
if (stdin) {
copyAsync(System.in, proc.getOutputStream());
}
return proc.waitFor();
} catch (InterruptedException | ApiException | IOException ex) {
throw new KubectlException(ex);
}
}
Aggregations