io.kubernetes.client.ApiException Java Examples

The following examples show how to use io.kubernetes.client.ApiException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: K8sSubmitter.java    From submarine with Apache License 2.0 6 votes vote down vote up
@Override
public ExperimentLog getExperimentLog(ExperimentSpec spec, String id) {
  ExperimentLog experimentLog = new ExperimentLog();
  experimentLog.setExperimentId(id);
  try {
    final V1PodList podList = coreApi.listNamespacedPod(
        spec.getMeta().getNamespace(),
        "false", null, null,
        getJobLabelSelector(spec), null, null,
        null, null);

    for (V1Pod pod : podList.getItems()) {
      String podName = pod.getMetadata().getName();
      String namespace = pod.getMetadata().getNamespace();
      String podLog = coreApi.readNamespacedPodLog(
          podName, namespace, null, Boolean.FALSE,
          Integer.MAX_VALUE, null, Boolean.FALSE,
          Integer.MAX_VALUE, null, Boolean.FALSE);

      experimentLog.addPodLog(podName, podLog);
    }
  } catch (final ApiException e) {
    LOG.error("Error when listing pod for experiment:" + spec.getMeta().getName(), e.getMessage());
  }
  return experimentLog;
}
 
Example #2
Source File: KubernetesSecretsTokenAuthProviderTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testCacheAuthData() throws ApiException {
    CoreV1Api coreV1Api = mock(CoreV1Api.class);
    doReturn(new V1Secret()).when(coreV1Api).createNamespacedSecret(anyString(), any(), anyString());
    KubernetesSecretsTokenAuthProvider kubernetesSecretsTokenAuthProvider = new KubernetesSecretsTokenAuthProvider();
    kubernetesSecretsTokenAuthProvider.initialize(coreV1Api,  null, (fd) -> "default");
    Function.FunctionDetails funcDetails = Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-ns").setName("test-func").build();
    Optional<FunctionAuthData> functionAuthData = kubernetesSecretsTokenAuthProvider.cacheAuthData(funcDetails, new AuthenticationDataSource() {
                @Override
                public boolean hasDataFromCommand() {
                    return true;
                }

                @Override
                public String getCommandData() {
                    return "test-token";
                }
            });

    Assert.assertTrue(functionAuthData.isPresent());
    Assert.assertTrue(StringUtils.isNotBlank(new String(functionAuthData.get().getData())));
}
 
Example #3
Source File: KubernetesSpyResource.java    From HolandaCatalinaFw with Apache License 2.0 6 votes vote down vote up
private V1ConfigMap createConfigMap(Map<String,Object> configMapDefinition) {
    V1ConfigMap configMap;

    try {
        configMap = new V1ConfigMapBuilder().
                withApiVersion(Fields.ConfigMap.API_VERSION).
                withKind((String) configMapDefinition.get(Fields.KIND)).
                withMetadata(new V1ObjectMetaBuilder().
                        withName((String) configMapDefinition.get(Fields.ConfigMap.NAME)).
                        withNamespace(SystemProperties.get(SystemProperties.Cloud.Orchestrator.Kubernetes.NAMESPACE)).
                        build()).
                withData((Map<String, String>) configMapDefinition.get(Fields.ConfigMap.DATA)).
                build();

        api.createNamespacedConfigMap(
                SystemProperties.get(SystemProperties.Cloud.Orchestrator.Kubernetes.NAMESPACE),
                configMap, null, null, null);
    } catch (ApiException ex){
        throw new HCJFRuntimeException("Unable to create config map", ex);
    }

    return configMap;
}
 
Example #4
Source File: KubernetesClient.java    From cubeai with Apache License 2.0 6 votes vote down vote up
public boolean createService(String name) {
    try {
        Map<String, String> label = new HashMap<>(8);
        label.put("ucumos", name);
        V1Service serviceYaml = new V1ServiceBuilder()
            .withApiVersion("v1")
            .withKind("Service")
            .withNewMetadata()
            .withNamespace(nameSpace)
            .withName("service-" + name)
            .endMetadata()
            .withNewSpec()
            .withType("NodePort")
            .withSelector(label)
            .addNewPort()
            .withPort(3330)
            .withTargetPort(new IntOrString(3330))
            .endPort()
            .endSpec()
            .build();
        coreApi.createNamespacedService(nameSpace, serviceYaml, null, null, null);
        return true;
    } catch (ApiException e) {
        return false;
    }
}
 
Example #5
Source File: KubernetesEnvImpl.java    From kruize with Apache License 2.0 6 votes vote down vote up
private boolean checkMonitoringAgentRunning() throws IOException, ApiException
{
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    CoreV1Api api = new CoreV1Api();

    V1ServiceList serviceList = api.listServiceForAllNamespaces(
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null
    );

    for (V1Service service : serviceList.getItems()) {
        String serviceName = service.getMetadata().getName();
        if (serviceName.toUpperCase().contains(DeploymentInfo.getMonitoringAgent()))
            return true;
    }

    return false;
}
 
Example #6
Source File: K8sSubmitter.java    From submarine with Apache License 2.0 6 votes vote down vote up
@Override
public ExperimentLog getExperimentLogName(ExperimentSpec spec, String id) {
  ExperimentLog experimentLog = new ExperimentLog();
  experimentLog.setExperimentId(id);
  try {
    final V1PodList podList = coreApi.listNamespacedPod(
        spec.getMeta().getNamespace(),
        "false", null, null,
        getJobLabelSelector(spec), null, null,
        null, null);
    for (V1Pod pod: podList.getItems()) {
      String podName = pod.getMetadata().getName();
      experimentLog.addPodLog(podName, null);
    }
  } catch (final ApiException e) {
    LOG.error("Error when listing pod for experiment:" + spec.getMeta().getName(), e.getMessage());
  }
  return experimentLog;
}
 
Example #7
Source File: ExperimentRestApiIT.java    From submarine with Apache License 2.0 6 votes vote down vote up
private void verifyDeleteJobApiResult(Experiment createdExperiment, Experiment deletedExperiment) {
  Assert.assertEquals(createdExperiment.getName(), deletedExperiment.getName());
  Assert.assertEquals(Experiment.Status.STATUS_DELETED.getValue(), deletedExperiment.getStatus());

  // verify the result by K8s api
  KfOperator operator = kfOperatorMap.get(createdExperiment.getSpec().getMeta().getFramework()
      .toLowerCase());
  JsonObject rootObject = null;
  try {
    rootObject = getJobByK8sApi(operator.getGroup(), operator.getVersion(),
        operator.getNamespace(), operator.getPlural(), createdExperiment.getName());
  } catch (ApiException e) {
    Assert.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), e.getCode());
  } finally {
    Assert.assertNull(rootObject);
  }
}
 
Example #8
Source File: KubernetesS3BackupRestoreTest.java    From cassandra-backup with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void setup() throws ApiException {

    final List<Module> modules = new ArrayList<Module>() {{
        add(new KubernetesApiModule());
        add(new S3Module());
        add(new ExecutorsModule());
    }};

    final Injector injector = Guice.createInjector(modules);
    injector.injectMembers(this);

    init();
}
 
Example #9
Source File: KubernetesSpyResource.java    From HolandaCatalinaFw with Apache License 2.0 5 votes vote down vote up
private V1Job createJob(Map<String,Object> jobDefinition) {
    V1Job job;
    try {
        job = new V1JobBuilder().
            withApiVersion(Fields.Job.API_VERSION).
            withKind((String) jobDefinition.get(Fields.KIND)).
            withMetadata(new V1ObjectMetaBuilder().
                withName((String) jobDefinition.get(Fields.Job.NAME)).
                withNamespace(SystemProperties.get(SystemProperties.Cloud.Orchestrator.Kubernetes.NAMESPACE)).build()).
            withSpec(new V1JobSpecBuilder().
                withTemplate(new V1PodTemplateSpecBuilder().
                    withMetadata(new V1ObjectMetaBuilder().
                        withName((String) jobDefinition.get(Fields.Job.NAME)).
                        withNamespace(SystemProperties.get(SystemProperties.Cloud.Orchestrator.Kubernetes.NAMESPACE)).build()
                    ).
                    withSpec(new V1PodSpecBuilder().
                        withVolumes(getVolumes((Collection<Map<String, Object>>) jobDefinition.get(Fields.Job.VOLUMES))).
                        withRestartPolicy((String) jobDefinition.get(Fields.Job.RESTART_POLICY)).
                        withContainers(getContainers((Collection<Map<String, Object>>) jobDefinition.get(Fields.Job.CONTAINERS))).build()
                    ).build()
                ).build()
            ).build();

        Integer replicas = (Integer) jobDefinition.get(Fields.Job.REPLICAS);
        for (int i = 0; i < replicas; i++) {
            batchApi.createNamespacedJob(
                    SystemProperties.get(SystemProperties.Cloud.Orchestrator.Kubernetes.NAMESPACE),
                    job, null, null, null);
        }
    } catch (ApiException ex) {
        throw new HCJFRuntimeException("Unable to create job, '%s'", ex, ex.getResponseBody());
    }
    return job;
}
 
Example #10
Source File: KubernetesOperation.java    From k8s-Azure-Container-Service-AKS--on-Azure with MIT License 5 votes vote down vote up
/**
 * Scale up/down the number of pod in Deployment
 *
 * @param deploymentName
 * @param numberOfReplicas
 * @throws ApiException
 */
public void scaleDeployment(String deploymentName, int numberOfReplicas) throws ApiException {
    ExtensionsV1beta1Api extensionV1Api = new ExtensionsV1beta1Api();
    extensionV1Api.setApiClient(corev1Api.getApiClient());
    ExtensionsV1beta1DeploymentList listNamespacedDeployment = extensionV1Api.listNamespacedDeployment(
            DEFAULT_NAME_SPACE, //namespace - object name and auth scope, such as for teams and projects (required)
            null, //pretty - If 'true', then the output is pretty printed. (optional)
            null, //_continue - The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server the server will respond with a 410 ResourceExpired error indicating the client must restart their list without the continue field. This field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications. (optional)
            null, //fieldSelector - A selector to restrict the list of returned objects by their fields. Defaults to everything. (optional) 
            Boolean.FALSE, //includeUninitialized - If true, partially initialized resources are included in the response. (optional)
            null, //labelSelector - A selector to restrict the list of returned objects by their labels. Defaults to everything. (optional)
            null, //limit - limit is a maximum number of responses to return for a list call. If more items exist, the server will set the `continue` field on the list metadata to a value that can be used with the same initial query to retrieve the next set of results. Setting a limit may return fewer than the requested amount of items (up to zero items) in the event all requested objects are filtered out and clients should only use the presence of the continue field to determine whether more results are available. Servers may choose not to support the limit argument and will return all of the available results. If limit is specified and the continue field is empty, clients may assume that no more results are available. This field is not supported if watch is true. The server guarantees that the objects returned when using continue will be identical to issuing a single list call without a limit - that is, no objects created, modified, or deleted after the first request is issued will be included in any subsequent continued requests. This is sometimes referred to as a consistent snapshot, and ensures that a client that is using limit to receive smaller chunks of a very large result can ensure they see all possible objects. If objects are updated during a chunked list the version of the object that was present at the time the first list result was calculated is returned. (optional)
            null, //resourceVersion - When specified with a watch call, shows changes that occur after that particular version of a resource. Defaults to changes from the beginning of history. When specified for list: - if unset, then the result is returned from remote storage based on quorum-read flag; - if it's 0, then we simply return what we currently have in cache, no guarantee; - if set to non zero, then the result is at least as fresh as given rv. (optional)
            null, //timeoutSeconds - Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity. (optional)
            Boolean.FALSE); //watch - Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion. (optional)

    List<ExtensionsV1beta1Deployment> extensionsV1beta1DeploymentItems = listNamespacedDeployment.getItems();
    Optional<ExtensionsV1beta1Deployment> findedDeployment = extensionsV1beta1DeploymentItems.stream()
            .filter((ExtensionsV1beta1Deployment deployment) -> deployment.getMetadata().getName().equals(deploymentName))
            .findFirst();
    findedDeployment.ifPresent((ExtensionsV1beta1Deployment deploy) -> {
        try {
            ExtensionsV1beta1DeploymentSpec newSpec = deploy.getSpec().replicas(numberOfReplicas);
            ExtensionsV1beta1Deployment newDeploy = deploy.spec(newSpec);
            extensionV1Api.replaceNamespacedDeployment(deploymentName, DEFAULT_NAME_SPACE, newDeploy, null);
        } catch (ApiException ex) {
            LOGGER.log(Level.SEVERE, null, ex);
        }
    });
}
 
Example #11
Source File: KubernetesOperation.java    From k8s-Azure-Container-Service-AKS--on-Azure with MIT License 5 votes vote down vote up
/**
 * List pod in specific namespace with label
 *
 * @param namespace
 * @param label
 * @return
 * @throws ApiException
 */
public List<String> getNamespacedPod(String namespace, String label) throws ApiException {
    List<String> listPods = corev1Api.listNamespacedPod(namespace, //namespace - object name and auth scope, such as for teams and projects (required)
            null, //pretty - If 'true', then the output is pretty printed. (optional)
            null, //_continue - The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server the server will respond with a 410 ResourceExpired error indicating the client must restart their list without the continue field. This field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications. (optional)
            null, //fieldSelector - A selector to restrict the list of returned objects by their fields. Defaults to everything. (optional)
            Boolean.FALSE, //includeUninitialized - If true, partially initialized resources are included in the response. (optional)
            label, //labelSelector - A selector to restrict the list of returned objects by their labels. Defaults to everything. (optional)
            Integer.SIZE, //limit - limit is a maximum number of responses to return for a list call. If more items exist, the server will set the `continue` field on the list metadata to a value that can be used with the same initial query to retrieve the next set of results. Setting a limit may return fewer than the requested amount of items (up to zero items) in the event all requested objects are filtered out and clients should only use the presence of the continue field to determine whether more results are available. Servers may choose not to support the limit argument and will return all of the available results. If limit is specified and the continue field is empty, clients may assume that no more results are available. This field is not supported if watch is true. The server guarantees that the objects returned when using continue will be identical to issuing a single list call without a limit - that is, no objects created, modified, or deleted after the first request is issued will be included in any subsequent continued requests. This is sometimes referred to as a consistent snapshot, and ensures that a client that is using limit to receive smaller chunks of a very large result can ensure they see all possible objects. If objects are updated during a chunked list the version of the object that was present at the time the first list result was calculated is returned. (optional)
            null, //resourceVersion - When specified with a watch call, shows changes that occur after that particular version of a resource. Defaults to changes from the beginning of history. When specified for list: - if unset, then the result is returned from remote storage based on quorum-read flag; - if it's 0, then we simply return what we currently have in cache, no guarantee; - if set to non zero, then the result is at least as fresh as given rv. (optional)
            Integer.BYTES, //timeoutSeconds  - Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity. (optional)
            Boolean.FALSE).getItems().stream().map(v1pod -> v1pod.getMetadata().getName()).collect(Collectors.toList());//watch           - Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion. (optional)
    return listPods;
}
 
Example #12
Source File: KubernetesOperation.java    From k8s-Azure-Container-Service-AKS--on-Azure with MIT License 5 votes vote down vote up
/**
 * List all pod names in all namespaces in k8s cluster
 *
 * @return
 * @throws ApiException
 */
public List<String> getPods() throws ApiException {
    V1PodList v1podList = corev1Api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null);
    List<String> podList = v1podList.getItems()
                                        .stream()
                                        .map(v1Pod -> v1Pod.getMetadata().getName())
                                        .collect(Collectors.toList());
    return podList;
}
 
Example #13
Source File: KubernetesOperation.java    From k8s-Azure-Container-Service-AKS--on-Azure with MIT License 5 votes vote down vote up
public void executeCommand() throws ApiException {

        //ScaleUp/ScaleDown the Deployment pod
        System.out.println("----- Scale Deployment Start -----");
        scaleDeployment("account-service", 5);
        System.out.println("----- Scale Deployment End -----");

        //List all of the namaspaces and pods
        List<String> nameSpaces = getAllNameSapces();
        nameSpaces.stream().forEach(namespace -> {
            try {
                System.out.println("----- " + namespace + " -----");
                getNamespacedPod(namespace).stream().forEach(System.out::println);
            } catch (ApiException ex) {
                LOGGER.log(Level.SEVERE, null, ex);
            }
        });

        //Print all of the Services
        System.out.println("----- Print list all Services Start -----");
        List<String> services = getServices();
        services.stream().forEach(System.out::println);
        System.out.println("----- Print list all Services End -----");

        //Print log of specific pod
        System.out.println("----- Print Log of Specific Pod Start -----");
        printLog(DEFAULT_NAME_SPACE, "account-service-cbd44cc8-tq5hb");
        System.out.println("----- Print Log of Specific Pod End -----");
    }
 
Example #14
Source File: KubernetesOperation.java    From k8s-Azure-Container-Service-AKS--on-Azure with MIT License 5 votes vote down vote up
/**
 * Main method
 *
 * @param args
 */
public static void main(String[] args) {
    try {
        KubernetesOperation operation = new KubernetesOperation();
        operation.executeCommand();
    } catch (ApiException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
    }
}
 
Example #15
Source File: S3BackupRestoreTest.java    From cassandra-backup with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void setup() throws ApiException, IOException {

    final List<Module> modules = new ArrayList<Module>() {{
        add(new KubernetesApiModule());
        add(new S3Module());
        add(new ExecutorsModule());
    }};

    final Injector injector = Guice.createInjector(modules);
    injector.injectMembers(this);

    init();
}
 
Example #16
Source File: KubernetesS3BackupRestoreTest.java    From cassandra-backup with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() throws ApiException {
    System.setProperty("kubernetes.client", "true");

    kubernetesService.createSecret(SIDECAR_SECRET_NAME, new HashMap<String, String>() {{
        put("awssecretaccesskey", System.getProperty("awssecretaccesskey"));
        put("awsaccesskeyid", System.getProperty("awsaccesskeyid"));
    }});
}
 
Example #17
Source File: KubernetesEnvImpl.java    From kruize with Apache License 2.0 5 votes vote down vote up
@Override
public void setupMonitoringAgent()
{
    try {

        if (DeploymentInfo.getMonitoringAgentEndpoint() == null
                || DeploymentInfo.getMonitoringAgentEndpoint().equals("")) {
            if (DeploymentInfo.getMonitoringAgentService() != null) {
                getMonitoringEndpointFromService();
            } else {
                throw new MonitoringAgentMissingException("ERROR: No service or endpoint specified");
            }
        }
        if (!checkMonitoringAgentSupported()) {
            throw new MonitoringAgentNotSupportedException();
        }
        if (!checkMonitoringAgentRunning()) {
            throw new MonitoringAgentMissingException(DeploymentInfo.getMonitoringAgent() + " not running");
        }
        setMonitoringLabels();
    } catch (MonitoringAgentNotSupportedException |
            MonitoringAgentMissingException |
            IOException |
            ApiException e) {
        e.printStackTrace();
        System.exit(1);
    }
}
 
Example #18
Source File: KubernetesGoogleStorageBackupRestoreTest.java    From cassandra-backup with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() throws ApiException, IOException {
    System.setProperty("kubernetes.client", "true");

    assertNotNull(kubernetesService);

    kubernetesService.createSecret(SIDECAR_SECRET_NAME, new HashMap<String, String>() {{
        put("gcp", new String(Files.readAllBytes(Paths.get(System.getProperty("google.application.credentials")))));
    }});
}
 
Example #19
Source File: KubernetesAzureBackupRestoreTest.java    From cassandra-backup with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() throws ApiException {
    System.setProperty("kubernetes.client", "true");

    assertNotNull(kubernetesService);

    kubernetesService.createSecret(SIDECAR_SECRET_NAME, new HashMap<String, String>() {{
        put("azurestorageaccount", System.getProperty("azurestorageaccount"));
        put("azurestoragekey", System.getProperty("azurestoragekey"));
    }});
}
 
Example #20
Source File: ExperimentRestApiIT.java    From submarine with Apache License 2.0 5 votes vote down vote up
private JsonObject getJobByK8sApi(String group, String version, String namespace, String plural,
    String name) throws ApiException {
  Object obj = k8sApi.getNamespacedCustomObject(group, version, namespace, plural, name);
  Gson gson = new JSON().getGson();
  JsonObject rootObject = gson.toJsonTree(obj).getAsJsonObject();
  Assert.assertNotNull("Parse the K8s API Server response failed.", rootObject);
  return rootObject;
}
 
Example #21
Source File: KubernetesEnvImpl.java    From kruize with Apache License 2.0 5 votes vote down vote up
private void getMonitoringEndpointFromService() throws IOException, ApiException
{
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    CoreV1Api api = new CoreV1Api();

    V1ServiceList serviceList = api.listServiceForAllNamespaces(
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null
    );

    for (V1Service service : serviceList.getItems()) {
        String serviceName = service.getMetadata().getName();
        if (serviceName.toUpperCase().equals(DeploymentInfo.getMonitoringAgentService())) {
            String clusterIP = service.getSpec().getClusterIP();
            int port = service.getSpec().getPorts().get(0).getPort();
            DeploymentInfo.setMonitoringAgentEndpoint("http://" + clusterIP + ":" + port);
        }
    }
}
 
Example #22
Source File: KubernetesClient.java    From cubeai with Apache License 2.0 5 votes vote down vote up
public boolean readNamespace() {
    try {
        coreApi.readNamespace(this.nameSpace, null, null, null);
        return true;
    } catch (ApiException e) {
        return false;
    }
}
 
Example #23
Source File: KubernetesClient.java    From cubeai with Apache License 2.0 5 votes vote down vote up
public boolean createNamespace() {
    try {
        if (!readNamespace()) {
            coreApi.createNamespace(new V1Namespace().metadata(new V1ObjectMeta().name(nameSpace)),
                null, null, null);
        }
        return true;
    } catch (ApiException e) {
        return false;
    }
}
 
Example #24
Source File: KubernetesClient.java    From cubeai with Apache License 2.0 5 votes vote down vote up
public boolean readNetworkPolicy() {
    try {
        networkingApi.readNamespacedNetworkPolicy(
                "networkpolicy-" + nameSpace, nameSpace, null, null, null);
        return true;
    } catch (ApiException e) {
        return false;
    }
}
 
Example #25
Source File: KubernetesClient.java    From cubeai with Apache License 2.0 5 votes vote down vote up
public boolean deleteNetworkPolicy() {
    try {
        networkingApi.deleteNamespacedNetworkPolicy("networkpolicy-" + nameSpace, nameSpace, null,
                new V1DeleteOptions(), null, null, null, null);
    } catch (ApiException e) {
        if(e.getCode() != 404) {
            return false;
        }
    }
    return true;
}
 
Example #26
Source File: KubernetesClient.java    From cubeai with Apache License 2.0 5 votes vote down vote up
public boolean createDeployment(String name, String imageUrl, String imageName) {
    try {
        Map<String, String> label = new HashMap<>(8);
        label.put("ucumos", name);
        V1Deployment deployYaml = new V1DeploymentBuilder()
            .withApiVersion("apps/v1")
            .withKind("Deployment")
            .withNewMetadata()
                .withNamespace(nameSpace)
                .withName("deployment-" + name)
            .endMetadata()
            .withNewSpec()
                .withReplicas(1)
                .withNewSelector()
                    .withMatchLabels(label)
                .endSelector()
                .withNewTemplate()
                    .withNewMetadata()
                        .withLabels(label)
                    .endMetadata()
                    .withNewSpec()
                        .addNewContainer()
                            .withName(imageName)
                            .withImage(imageUrl)
                            .addNewPort()
                                .withContainerPort(3330)
                            .endPort()
                            .withResources(buildResource())
                        .endContainer()
                    .endSpec()
                .endTemplate()
            .endSpec()
            .build();
        appsApi.createNamespacedDeployment(nameSpace, deployYaml, null, null, null);
        return true;
    } catch (ApiException e) {
        return false;
    }
}
 
Example #27
Source File: KubernetesClient.java    From cubeai with Apache License 2.0 5 votes vote down vote up
public boolean deleteDeployment(String name) {
    try {
        appsApi.deleteNamespacedDeployment("deployment-" + name, nameSpace, null, new V1DeleteOptions(),
            null, null, null, null);
    } catch (ApiException e) {
        if(e.getCode() != 404) {
            return false;
        }
    }
    return true;
}
 
Example #28
Source File: KubernetesClient.java    From cubeai with Apache License 2.0 5 votes vote down vote up
public boolean deleteService(String name) {
    try {
        coreApi.deleteNamespacedService("service-" + name, nameSpace, null, new V1DeleteOptions(),
            null, null, null, null);
    } catch (ApiException e) {
        if(e.getCode() != 404) {
            return false;
        }
    }
    return true;
}
 
Example #29
Source File: KubernetesS3BackupRestoreTest.java    From cassandra-backup with Apache License 2.0 4 votes vote down vote up
@Override
protected void destroy() throws ApiException {
    kubernetesService.deleteSecret("test-sidecar-secret");
    System.setProperty("kubernetes.client", "false");
}
 
Example #30
Source File: S3BackupRestoreTest.java    From cassandra-backup with Apache License 2.0 4 votes vote down vote up
@AfterMethod
public void teardown() throws ApiException {
    destroy();
}