vm.Instance to use generic data field for extra info
The Instance
struct currently looks like this:
type Instance struct {
Name string
IPAddress string
// For machine authentication
Username string
Password string
PrivateSSHKey []byte
GCP gcp.Instance
}
Where we have an explicit gcp.Instance
field, and the vm
package needs to import a autoscaler/gcp/config
(alised to gcp
).
To solve this leaky abstraction, I propose we instead use:
type Instance struct {
Name string
IPAddress string
// For machine authentication
Username string
Password string
PrivateSSHKey []byte
// Data is underlying provider-specific instance data
Data interface{}
}
The only place Data
will be used is in a provider implementation, which is fully aware of what type will be stored within this field, and can easily vmInst.Data.(config.Instance)
to cast to the type it knows should be present.
Our use of interface{}
should correctly be rare, but I think this is a specific instance where we should allow it. It reminds me of similar situations you'll find in the Go runtime, such as with FileInfo
(https://golang.org/pkg/io/fs/#FileInfo) and being able to fetch the underlying data regarding a dir entry with Sys() interface{}
.