use of io.kubernetes.client.openapi.apis.CoreV1Api in project pravega by pravega.
the class K8sClient method deployPod.
/**
* Deploy a pod. This ignores exception when the pod has already been deployed.
* @param namespace Namespace.
* @param pod Pod details.
* @return Future which is completed once the deployemnt has been triggered.
*/
@SneakyThrows(ApiException.class)
public CompletableFuture<V1Pod> deployPod(final String namespace, final V1Pod pod) {
CoreV1Api api = new CoreV1Api();
K8AsyncCallback<V1Pod> callback = new K8AsyncCallback<>("createPod-" + pod.getMetadata().getName());
api.createNamespacedPodAsync(namespace, pod, PRETTY_PRINT, DRY_RUN, FIELD_MANAGER, callback);
return exceptionallyExpecting(callback.getFuture(), isConflict, null);
}
use of io.kubernetes.client.openapi.apis.CoreV1Api in project java by kubernetes-client.
the class YamlExample method main.
public static void main(String[] args) throws IOException, ApiException, ClassNotFoundException {
V1Pod pod = new V1PodBuilder().withNewMetadata().withName("apod").endMetadata().withNewSpec().addNewContainer().withName("www").withImage("nginx").withNewResources().withLimits(new HashMap<>()).endResources().endContainer().endSpec().build();
System.out.println(Yaml.dump(pod));
V1Service svc = new V1ServiceBuilder().withNewMetadata().withName("aservice").endMetadata().withNewSpec().withSessionAffinity(V1ServiceSpec.SessionAffinityEnum.CLIENTIP).withType(V1ServiceSpec.TypeEnum.NODEPORT).addNewPort().withProtocol(V1ServicePort.ProtocolEnum.TCP).withName("client").withPort(8008).withNodePort(8080).withTargetPort(new IntOrString(8080)).endPort().endSpec().build();
System.out.println(Yaml.dump(svc));
// Read yaml configuration file, and deploy it
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
// See issue #474. Not needed at most cases, but it is needed if you are using war
// packging or running this on JUnit.
Yaml.addModelMap("v1", "Service", V1Service.class);
// Example yaml file can be found in $REPO_DIR/test-svc.yaml
File file = new File("test-svc.yaml");
V1Service yamlSvc = (V1Service) Yaml.load(file);
// Deployment and StatefulSet is defined in apps/v1, so you should use AppsV1Api instead of
// CoreV1API
CoreV1Api api = new CoreV1Api();
V1Service createResult = api.createNamespacedService("default", yamlSvc, null, null, null, null);
System.out.println(createResult);
V1Service deleteResult = api.deleteNamespacedService(yamlSvc.getMetadata().getName(), "default", null, null, null, null, null, new V1DeleteOptions());
System.out.println(deleteResult);
}
use of io.kubernetes.client.openapi.apis.CoreV1Api in project java by kubernetes-client.
the class LeaderElectorTest method deleteConfigMapLockResource.
private void deleteConfigMapLockResource() throws Exception {
try {
CoreV1Api coreV1Api = new CoreV1Api(apiClient);
coreV1Api.deleteNamespacedConfigMap(LOCK_RESOURCE_NAME, NAMESPACE, null, null, null, null, null, null);
} catch (ApiException ex) {
if (ex.getCode() != HttpURLConnection.HTTP_NOT_FOUND) {
throw ex;
}
}
}
use of io.kubernetes.client.openapi.apis.CoreV1Api in project java by kubernetes-client.
the class LeaderElectorTest method deleteEndpointsLockResource.
private void deleteEndpointsLockResource() throws Exception {
try {
CoreV1Api coreV1Api = new CoreV1Api(apiClient);
coreV1Api.deleteNamespacedEndpoints(LOCK_RESOURCE_NAME, NAMESPACE, null, null, null, null, null, null);
} catch (ApiException ex) {
if (ex.getCode() != HttpURLConnection.HTTP_NOT_FOUND) {
throw ex;
}
}
}
use of io.kubernetes.client.openapi.apis.CoreV1Api in project java by kubernetes-client.
the class InformerExample method main.
public static void main(String[] args) throws Exception {
CoreV1Api coreV1Api = new CoreV1Api();
ApiClient apiClient = coreV1Api.getApiClient();
OkHttpClient httpClient = apiClient.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build();
apiClient.setHttpClient(httpClient);
SharedInformerFactory factory = new SharedInformerFactory(apiClient);
// Node informer
SharedIndexInformer<V1Node> nodeInformer = factory.sharedIndexInformerFor(// the informer-factory.
(CallGeneratorParams params) -> {
return coreV1Api.listNodeCall(null, null, null, null, null, null, params.resourceVersion, null, params.timeoutSeconds, params.watch, null);
}, V1Node.class, V1NodeList.class);
nodeInformer.addEventHandler(new ResourceEventHandler<V1Node>() {
@Override
public void onAdd(V1Node node) {
System.out.printf("%s node added!\n", node.getMetadata().getName());
}
@Override
public void onUpdate(V1Node oldNode, V1Node newNode) {
System.out.printf("%s => %s node updated!\n", oldNode.getMetadata().getName(), newNode.getMetadata().getName());
}
@Override
public void onDelete(V1Node node, boolean deletedFinalStateUnknown) {
System.out.printf("%s node deleted!\n", node.getMetadata().getName());
}
});
factory.startAllRegisteredInformers();
V1Node nodeToCreate = new V1Node();
V1ObjectMeta metadata = new V1ObjectMeta();
metadata.setName("noxu");
nodeToCreate.setMetadata(metadata);
V1Node createdNode = coreV1Api.createNode(nodeToCreate, null, null, null, null);
Thread.sleep(3000);
Lister<V1Node> nodeLister = new Lister<V1Node>(nodeInformer.getIndexer());
V1Node node = nodeLister.get("noxu");
System.out.printf("noxu created! %s\n", node.getMetadata().getCreationTimestamp());
factory.stopAllRegisteredInformers();
Thread.sleep(3000);
System.out.println("informer stopped..");
}
Aggregations