elotl / kip

Virtual-kubelet provider running pods in cloud instances
Apache License 2.0
223 stars 14 forks source link

Handle broken metadata response in google cloud #99

Closed justnoise closed 4 years ago

justnoise commented 4 years ago

For some reason, when you curl the gce metadata service for the zone, from alpine, an extra slash gets added to the response:

exec -it curler -- /bin/ash
# curl "http://metadata.google.internal/computeMetadata/v1/instance/zone" -H "Metadata-Flavor: Google"
projects/832569367454/zones/us-west1-a/

This does not happen in other distros (debian and ubuntu were tested)

kk exec -it curler -- curl "http://metadata.google.internal/computeMetadata/v1/instance/zone" -H "Metadata-Flavor: Google"
projects/832569367454/zones/us-west1-a

The library we use assumes the response doesn't end with a slash and it'll break if it does end in a slash. This PR gets the zone from the metadata ourselves and handle both cases.

ldx commented 4 years ago

Does this only happen when you use curl, or in kip too? I think the default curl in alpine is just a busybox alias, you need to add curl explicitly via apk to get the "real" one.

justnoise commented 4 years ago

I noticed this happening inside kip first. It would return emptystring for the zone which would mess up autodetecting its environment. I then investigated on alpine by apk adding curl and testing it out. (busybox doesn't come with its own curl but it does implement wget) The really strange thing is that the problem doesn't show up when you exec virtual-kubelet -- curl <metadata URL> whithout the interactive shell...

Overall, I'm not sure what the heck is causing the problem but we can easily work around it.