Fabric8 java library to edit existing resource

9/25/2018

I want to edit an ingress to have another path as follows

Existing Ingress :

apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: test-ingress
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      rules:
      - http:
          paths:
          - path: /testpath
            backend:
              serviceName: test
              servicePort: 80

Updated Ingress:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /testpath
        backend:
          serviceName: test
          servicePort: 80

     - path: /newPath
        backend:
          serviceName: newService
          servicePort: 80

I want to add a new backend to a new path for an existing ingress. I am using the fabric8 java library to achieve this as follows

kubernetesClient.extensions().ingresses().inNamespace(my-env)
        .withName(ingressName).edit().editOrNewSpec().editFirstRule().editHttp()
        .addNewPathLike(path).withNewBackendLike(ingressBackend);

This is replacing the existing path and backend.

apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: test-ingress
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      rules:
      - http:
          paths:
          - path: /newPath
            backend:
              serviceName: newService
              servicePort: 80

What am I missing?

-- user_mda
fabric8
java
kubernetes

1 Answer

9/26/2018

I believe you need to use addToPaths(path) instead. Something like this:

kubernetesClient.extensions().ingresses().inNamespace(my-env)
        .withName(ingressName).edit().editOrNewSpec().editFirstRule().editHttp()
        .addToPaths(path).withNewBackendLike(ingressBackend);

More info here

-- Rico
Source: StackOverflow