ionos-cloud/ionosctl

Only using last network in "ionosctl k8s nodepool lan add"

Programie opened this issue · 2 comments

Description

I try to add multiple routes to a private LAN to be added to a Kubernetes node pool.

But instead of adding each network to the private LAN, only the last one is added multiple times.

Expected behavior

Each route should be added to the private LAN.

How to Reproduce

Create a new Kubernetes Cluster and add a Node Pool to it.

Add the private LAN (replace variables with the correct values):

ionosctl k8s nodepool lan add --verbose --cluster-id $CLUSTER_ID --nodepool-id $NODEPOOL_ID --lan-id 1 --network $SUBNET1,$SUBNET2,$SUBNET3,$SUBNET4,$SUBNET5 --gateway-ip $GATEWAY1,$GATEWAY2,GATEWAY3,GATEWAY4,GATEWAY5

The command is executed successfully, the verbose output also shows the correct networks to be added:

Property Network set: [$SUBNET1 $SUBNET2 $SUBNET3 $SUBNET4 $SUBNET5]

But the response at the end of the command shows the following in RoutesNetwork which is wrong (the same subnet is listed multiple times):

$SUBNET5,$SUBNET5,$SUBNET5,$SUBNET5,$SUBNET5

References

This is related to #273 in which the ability to add multiple routes/networks to a single private LAN was implemented.

Hi, sorry for the inconvenience, this seems to be caused by https://github.com/ionos-cloud/ionosctl/blob/master/commands/cloudapi-v6/k8s_nodepool_lan.go#L355, specifically the address for the loop variable is reused in each loop iteration

I have no experience with Go (yet), but for me the code looks correct.

It is iterating over network and the net variable contains the network from the current iteration. But I could also be completely wrong.

Would be really helpful if that could be fixed soon. 👍

EDIT: I guess the issue is caused by the & in front of net and gatewayIp[i] as it is passing the value by-reference. So, removing the & should fix the issue?