platform/machine: only run DeleteKey if one has been added
Currently on AWS the `DeleteKey` API methods will be executed regardless
of if a key has been added. This will cause the platform level Flight
`Destroy` method to fail before entering the BaseFlight's `Destroy`.
@@ -34,6 +34,7 @@ var (
type flight struct {
*platform.BaseFlight
api *aws.API
+ keyAdded bool
}
// NewFlight creates an instance of a Flight suitable for spawning
@@ -67,6 +68,7 @@ func NewFlight(opts *aws.Options) (platform.Flight, error) {
af.Destroy()
return nil, err
}
+ af.keyAdded = true
return af, nil
}
@@ -90,9 +92,11 @@ func (af *flight) NewCluster(rconf *platform.RuntimeConfig) (platform.Cluster, e
}
func (af *flight) Destroy() {
+ if af.keyAdded {
if err := af.api.DeleteKey(af.Name()); err != nil {
plog.Errorf("Error deleting key %v: %v", af.Name(), err)
}
+ }
af.BaseFlight.Destroy()
}
