funktionio / funktion

a CLI tool for working with funktion
https://funktion.fabric8.io/
Apache License 2.0
297 stars 25 forks source link

function edit always edits the last connector #21

Closed iocanel closed 7 years ago

iocanel commented 7 years ago

I am following the Getting Started Guide to the point where I edit the twitter connector.

Then I derive from the script by trying to edit another connector:

funktion edit connector http4

and I get the twitter's properties instead. If I delete twitter and try again I get:

The connector `http4` has no properties to configure!%  
jstrachan commented 7 years ago

Ah I've seen this issue before! Its always confused me too; rather than loading a Map of the ConfigMap resources, then looking up the one you want by name, I found just only setting a pointer to the one that matches the name fixes it.

e.g. like this loop https://github.com/funktionio/funktion/blob/master/cmd/logs.go#L99-L104

still no idea why loading a map of all values then looking up the map seems to always find the last one mind you!

iocanel commented 7 years ago

@jstrachan: I am a complete noob at golang and I haven't touched c in ages, but I think that the problem is that you are storing the address of the resource (which is the iterator), like shown below:

p.configMaps[resource.Name] = &resource

The address, doesn't change, what changes is the value stored in the address. So all items within the map point to the same memory address.

This https://github.com/funktionio/funktion/blob/master/cmd/logs.go#L99-L104 also suffers from a similar problem, but break saves the day.

I'll send a PR shortly.

jimmidyson commented 7 years ago

@iocanel You got it! 50 points to you! http://www.g-var.com/posts/blog/go/50-shades-of-go/#iteration-variables-and-closures-in-for-statements