fabric8io / fabric8

fabric8 is an open source microservices platform based on Docker, Kubernetes and Jenkins
http://fabric8.io/
1.76k stars 504 forks source link

ServiceList and ReplicationControllerList creation don't work #4981

Open sanjana-bhat opened 9 years ago

sanjana-bhat commented 9 years ago

I try to create services from a json file. But the output of the following is always empty and no services are created client.inNamespace(namespace).lists().load(inputStream).create() Output: BaseKubernetesList(apiVersion=v1, items=[], kind=List, metadata=null, additionalProperties={})

Below json works when used with kubectl

{
  "apiVersion": "v1",
  "kind": "ServiceList",
  "items": [
    {
      "kind": "Service",
      "apiVersion": "v1",
      "metadata": {
        "name": "nimbus-zk"
      },
      "spec": {
        "ports": [
          {
            "name": "client",
            "port": 2181,
            "targetPort": 2181,
            "protocol": "TCP"
          },
          {
            "name": "ui",
            "port": 9999,
            "targetPort": 9999,
            "protocol": "TCP"
          },
          {
            "name": "thrift",
            "port": 6627,
            "targetPort": 6627,
            "protocol": "TCP"
          },
          {
            "name": "webservice",
            "port": 4080,
            "targetPort": 4080,
            "protocol": "TCP"
          }
        ],
        "selector": {
          "cluster": "nimbus-zk-container"
        }
      }
    },
    {
      "kind": "Service",
      "apiVersion": "v1",
      "metadata": {
        "name": "supervisor"
      },
      "spec": {
        "ports": [
          {
            "name": "logs",
            "port": 4081,
            "targetPort": 4081,
            "protocol": "TCP"
          }
        ],
        "selector": {
          "name": "supervisor-container"
        }
      }
    }
  ]
}

Any help here is really appreciated. Thanks!

sanjana-bhat commented 9 years ago

KubernetesList list = client.inNamespace(namespace).lists().load(is).get(); client.inNamespace(namespace).lists().create(list);

This worked. Closing the issue

jimmidyson commented 9 years ago

Thanks for the report. The original code you posted should work still reopening.

sanjana-bhat commented 9 years ago

https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/KubernetesListOperationsImpl.java#L69

The original code had empty items and hence it didn't work. Should you have a check that if there is no parameter passed then use the class member item?

jimmidyson commented 9 years ago

Perfect! Would you be able to send in a PR for that?

sanjana-bhat commented 9 years ago

Sure, will do!

jimmidyson commented 9 years ago

Awesome! Thank you!

sanjana-bhat commented 9 years ago

@jimmidyson, can you please guide me on how I can test this change locally before I submit the PR? Is there a contributor guide?

jimmidyson commented 9 years ago

@sanjana-bhat Sorry we don't have a contributor guide right now - we'll try to get one created soon.

First I'd recommend adding an example to the kubernetes-example project & running that to test it out. We reference these examples for new users, demos, etc. Your example should compile & run so you can use it to test your code changes.

If you can, adding a test to https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/mock/KubernetesListTest.java would be awesome too.

Some time we will have proper integration tests, but so much other stuff to do that's taken priority right now unfortunately.

davsclaus commented 9 years ago

@sanjana-bhat did you get a chance to work on a PR?

sanjana-bhat commented 9 years ago

@davsclaus I have worked on the PR https://github.com/fabric8io/kubernetes-client/pull/229 but I'm not sure on how to test it locally. Can you please help me with that?