kubernetes-client/java

How to set the host entries in ingress using SDK

irfanjs opened this issue · 7 comments

Using below code , we are able to fetch the list of hosts in the given ingress for all namespace . However, we need to overwrite/append the list of hosts entries using SDK
the list of hosts which needs to be added/appended , is getting from some external API .

           ```
       ArrayList<String> listOfTenants = new ArrayList<String>();
	ApiClient client = Config.defaultClient();
	 Configuration.setDefaultApiClient(client);
	 NetworkingV1Api netapi = new NetworkingV1Api();
	 V1IngressList list1 = netapi.listIngressForAllNamespaces(null, null, null, null, null, null, null, null,
	 null, null);
	 for (V1Ingress item : list1.getItems()) {
	 List<String> hosts = item.getSpec().getRules().stream().map(V1IngressRule::getHost).toList();
	 
	 for (int i = 0; i < hosts.size(); i++) {
	 listOfTenants.add(hosts.get(i));
	 }
	 } 
	 System.out.println(listOfTenants);

I see that , there is `setHost `method in `V1IngressRule ` bit not getting how to use it syntactically . 
can someone please help with example on how to use it ? Is there any another method for modify the host entries ? 
please suggest 

You can't update a list of Ingress objects. You have to update each Ingress one by one using replaceNamespacedIngress(...)

It may be easier for you to use the Kubectl.replace method here:

https://github.com/kubernetes-client/java/blob/master/extended/src/main/java/io/kubernetes/client/extended/kubectl/Kubectl.java#L54

@brendandburns
Thanks.

do we have any example on how to pass the body ? it is required parameter and no idea how to pass this ?
Any example please ?

@brendandburns
I saw the examples . Now , in order to replace the existing ingress object, do I need to export the existing object into YAML file and then use the YAML client (io.kubernetes.client.util.Yaml) to replace then entries in that YAML file ? and then give that YAML file to replaceNamespacedIngress ?

My doubt is , how I will export the existing object into YAML structure using java client and then use the modified YAML file as body for replaceNamespacedIngress method ?

Can you please elaborate ?

@brendandburns
Can you please suggest ? Thanks in advance.

@brendandburns :
can you please suggest

You don't need to export anything, you just use the updated V1Ingress object as the body to use for replace.

I'm going to close this issue because I don't think there is a problem with the client here. If you find issues with the client please file new issues or use the /reopen command.