upcloud-go-api icon indicating copy to clipboard operation
upcloud-go-api copied to clipboard

Add support for instance metadata

Open thevilledev opened this issue 4 years ago • 2 comments

According to version history instance metadata support was added in version 1.3.3 (released Mar 30, 2020). If enabled, it allows instances to query information about themselves through a link-local API endpoint at http://169.254.169.254/metadata/v1.json.

This is of course a very useful feature. It would be nice to have proper library support for it, so that this data could be accessed in a native way (without manually parsing the JSON). Maybe add it as a separate package, like at upcloud-go-api/upcloud/metadata? This information should be retrievable without having to define a username/password combination, thus having a separate package might make sense.

Example use case: I have a Go service that I've built to run on UpCloud. It's running on multiple zones, however each instance of the service will only communicate with its peers in the same zone. The service needs to get this information seamlessly from the metadata service, rather than from its own configuration, for example like this:

import (
    "log"
    "github.com/UpCloudLtd/upcloud-go-api/upcloud/metadata"
)

func main() {
    m := metadata.New()
    log.Printf("I'm at '%s' and my instance ID is '%s'", m.Region, m.InstanceID)
}

thevilledev avatar Sep 23 '20 16:09 thevilledev

Hi,

Sorry, I misunderstood a bit when we talked about this that we should offer this through our API. Providing this by using the metadata API is certainly something we can provide. Our metadata service is internally written in Go, so we can easily port the same structs to use in our Golang library. We'll talk about this internally and get back to it, cheers! :)

ajmyyra avatar Oct 02 '20 07:10 ajmyyra

Very nice, thanks @ajmyyra!

thevilledev avatar Oct 02 '20 07:10 thevilledev

Thank you for the feature request, Ville from September 2020

This is now possible through https://github.com/UpCloudLtd/upcloud-go-instance-metadata

thevilledev avatar Jun 15 '23 11:06 thevilledev