[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Openshift rest client


sorry for the delay.
You cannot list all pods. So you need to list on a namespace:
List<IPod> pods = client.list(ResourceKind.POD, namespace);
for(Pod pod : pods) {
  pod.getLabels().get("service_owner") gives you the SERVICE_OWNER label and so on for your specific labels

Please use the mailing list dev lists openshift redhat com to contact OpenShift devs from now


On Wed, Feb 27, 2019 at 4:31 AM Tony Herstell <tony herstell gmail com> wrote:

Hi Jeff,


I am trying to use the openshift-rest-client and am stuck.

Please advise where i should ask this question if you don't want to answer.

No one is on freenode... 


The use case:

I need to list all the pods, for the complete openshift service, and get back some label info as well as a lot of other info like time the pod was created…. Cpu... Mem... is burstable...


oc get pods --show-labels --loglevel=8 --label-columns=service_owner,cost_centre,project_code

               This in the logs does this:

  GET https://cloud.nz.thenational.com:8443/api/v1/namespaces/mylend-extract-app/pods?limit=500

               NAME                          READY     STATUS      RESTARTS   AGE       SERVICE_OWNER         COST_CENTRE   PROJECT_CODE   LABELS

    dev-xxxxx-23-tl426               1/1       Running     0          49m               xxxx-Bob_SMith                   12345           PR11111                cost_centre=xxxxx,deployment=dev-xxxx-extract-23,deploymentconfig=dev-xxxx-extract,project_code=123456,promoted-on=2019-02-20T15.43.03Z,sdlc_phase=dev,security_context=Protect,service_class=gold,service_owner=xxxx-Bob_Smith


But how is this possible with openshift-rest-client?


This Rest Call gives me what I want… but the return is JSON.




    "kind": "PodList",

    "apiVersion": "v1",

    "metadata": {

        "selfLink": "/api/v1/pods",

        "resourceVersion": "229294082"


    "items": [


            "metadata": {

                "name": "httpd-ex-2-pxphv",

                "generateName": "httpd-ex-2-",

                "namespace": "1-leng",

                "selfLink": "/api/v1/namespaces/1-leng/pods/httpd-ex-2-pxphv",

                "uid": "7882e0b2-2041-11e9-a2d1-001a4a408f4f",

                "resourceVersion": "200150030",

                "creationTimestamp": "2019-01-25T01:35:17Z",

                "labels": {

                    "app": "httpd-ex",

                    "deployment": "httpd-ex-2",

                    "deploymentconfig": "httpd-ex"



This, being JSON, in itself is a pain as I can’t find the “model” anywhere to create the java beans from (so can use JAXRS/B to map the data to it)…

The best I can do, here, is take an example and slap it into http://www.jsonschema2pojo.org/ and then hack it… but this will not have all the “model” unless I am lucky enough to have an example that has all the parts…


I would rather use the openshift-client-api as:

  • Obviously it’s the preferred method
  • Its more future proofed as we can update the openshift rest client for simplicity… as it will map to the newer version
  • Its going to be “simple”




      public void getPods() {

             IClient client = new ClientBuilder("https://cloud-dev.xx.xxx.com:8443")




             logger.info("============== Openshift Connection Established ==============");

             logger.info("Openshift Verion :" + client.getOpenShiftAPIVersion());

             logger.info("Openshift Server Ready Status :" + client.getServerReadyStatus());


// List the pods in the all namespaces

             List<IPod> pods = client.list(ResourceKind.POD);  // ?? AllNamespaces (perhaps I need to get ALL projects and then look at pods in them?)


                    // What I want to do with a POD

                    IPod aPod = pods.get(1);

                    String name = aPod.getName();

                    String creationTime = aPod.getCreationTimeStamp(); // This is the timestamp when the pod started

                    Map<String, String> labels = aPod.getLabels(); // These are the labels for the Pod .. find the ones we want

                    aPod.getNamespace().getRequester(); // Use this if the person responsible has not set a label

                    // aPod.get?? I want: Requested Number of CPUs, Requested MEM and if the pod is burstable.                    



I tried to get the projects but stumbled there too…


I could not find much documentation.


I downloaded the source and looked in there but there was not much to go on.


I looked at the test case in the source but there was not much to go on.


I am fairly new to Openshift (used a lot but now am peeking into the guts).


Please can you advise how I go about this…


Tony Herstell (on mobile)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]