Using Fabric8's Openshift Client, is there a way I can tell if a Project Name is available, as a regular user?

12/13/2017

In the recent versions of OpenShift when you delete a project, the project will be taken off of the project list, but for whatever reason - the namespace will be unavailable until after some time. I imagine it is still cleaning up and/or shutting down resources in the background.

Before, I was using client.projects.list() to get access to the projects, to verify that the new project I wish to create did not already exist. But now a project may not be in this list, but it's name may still be unavailable (if it were recently deleted), thus throwing an error when I submit a new project request for creation (i.e. stating "This name is already in use").

How can I easily verify, as a regular user, if a project name is available for use?

-- dagda88
fabric8
kubernetes
openshift
openshift-client-tools
openshift-origin

1 Answer

12/17/2017

OpenShiftClient can watch the state of the project.

Project project  = new ProjectBuilder().withNewMetadata().addToLabels("key", "label").endMetadata().build();
client.resource(project).watch(new Watcher<Project>() {
@Override
public void eventReceived(Action action, Project resource) {
    // logic goes here     
}

@Override
public void onClose(KubernetesClientException cause) {
}
});
-- Hrishikesh
Source: StackOverflow