io.fabric8.kubernetes.api.model.NamespaceList Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.NamespaceList. 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: NamespaceTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testListWithLables() {
  server.expect().withPath("/api/v1/namespaces?labelSelector=" + Utils.toUrlEncoded("key1=value1,key2=value2,key3=value3")).andReturn(200, new NamespaceListBuilder().build()).always();
  server.expect().withPath("/api/v1/namespaces?labelSelector=" + Utils.toUrlEncoded("key1=value1,key2=value2")).andReturn(200, new NamespaceListBuilder().addNewItem().and()
    .addNewItem().and()
    .addNewItem().and()
    .build()).once();

  KubernetesClient client = server.getClient();

  NamespaceList namespaceList = client.namespaces()
    .withLabel("key1", "value1")
    .withLabel("key2", "value2")
    .list();
  assertEquals(3, namespaceList.getItems().size());

  namespaceList = client.namespaces()
    .withLabel("key1", "value1")
    .withLabel("key2", "value2")
    .withLabel("key3", "value3")
    .list();
  assertEquals(0, namespaceList.getItems().size());
}
 
Example #2
Source File: ApplyStepExecution.java    From kubernetes-pipeline-plugin with Apache License 2.0 5 votes vote down vote up
private void createEnvironment(String environment, Controller controller) {
    boolean found = false;
    OpenShiftClient oClient = openShiftClient();
    if (isOpenShift() && oClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.PROJECT)) {
        ProjectList ps = oClient.projects().list();
        for(Project p : ps.getItems()){
            listener.getLogger().println("Found namespace " +p.getMetadata().getName());
            if (environment.equalsIgnoreCase(p.getMetadata().getName())){
                found = true;
                listener.getLogger().println("Found existing environment " + environment);
                break;
            }
        }
    } else {
        NamespaceList ns = getKubernetes().namespaces().list();
        for(Namespace n : ns.getItems()){
            listener.getLogger().println("Found namespace " +n.getMetadata().getName());
            if (environment.equalsIgnoreCase(n.getMetadata().getName())){
                found = true;
                listener.getLogger().println("Found existing environment " + environment);
                break;
            }
        }

    }
    if (!found){
        listener.getLogger().println("Creating environment " + environment);
        controller.applyNamespace(environment);
    }
}
 
Example #3
Source File: KubernetesNamespaceFactoryTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private void prepareListedNamespaces(List<Namespace> namespaces) throws Exception {
  @SuppressWarnings("unchecked")
  NamespaceList namespaceList = mock(NamespaceList.class);
  when(namespaceOperation.list()).thenReturn(namespaceList);

  when(namespaceList.getItems()).thenReturn(namespaces);
}
 
Example #4
Source File: NamespaceTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testList() {
  server.expect().withPath("/api/v1/namespaces").andReturn(200, new NamespaceListBuilder()
    .addNewItem().and()
    .addNewItem().and()
    .build()).once();

  KubernetesClient client = server.getClient();
  NamespaceList namespaceList = client.namespaces().list();
  assertNotNull(namespaceList);
  assertEquals(2, namespaceList.getItems().size());
}
 
Example #5
Source File: AutoAdaptableKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public NonNamespaceOperation<Namespace, NamespaceList, DoneableNamespace, Resource<Namespace, DoneableNamespace>> namespaces() {
  return delegate.namespaces();
}
 
Example #6
Source File: DefaultKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public NonNamespaceOperation<Namespace, NamespaceList, DoneableNamespace, Resource<Namespace, DoneableNamespace>> namespaces() {
  return new NamespaceOperationsImpl(httpClient, getConfiguration());
}
 
Example #7
Source File: ManagedKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public NonNamespaceOperation<Namespace, NamespaceList, DoneableNamespace, Resource<Namespace, DoneableNamespace>> namespaces() {
  return delegate.namespaces();
}
 
Example #8
Source File: KubernetesClient.java    From kubernetes-client with Apache License 2.0 2 votes vote down vote up
/**
 * API entrypoint for namespace related operations in Kubernetes. Namespace (core/v1)
 *
 * @return NonNamespaceOperation object for Namespace related operations
 */
NonNamespaceOperation< Namespace, NamespaceList, DoneableNamespace, Resource<Namespace, DoneableNamespace>> namespaces();