@@ -657,29 +657,30 @@ func (d *Driver) Remove() error {
657
657
return errors .Wrap (err , "could not delete server" )
658
658
}
659
659
660
- err = d . removeEmptyServerPlacementGroup ( srv )
661
- if err != nil {
662
- log .Error (err ) // not a hard failure
660
+ // failure to remove a placement group is not a hard error
661
+ if softErr := d . removeEmptyServerPlacementGroup ( srv ); softErr != nil {
662
+ log .Error (softErr )
663
663
}
664
664
}
665
665
}
666
666
667
- // Failing to remove these is just a soft error
667
+ // failure to remove a key is not ha hard error
668
668
for i , id := range d .AdditionalKeyIDs {
669
669
log .Infof (" -> Destroying additional key #%d (%d)" , i , id )
670
- key , _ , err := d .getClient ().SSHKey .GetByID (context .Background (), id )
671
- if err != nil {
672
- log .Warnf (" -> -> could not retrieve key %v" , err )
670
+ key , _ , softErr := d .getClient ().SSHKey .GetByID (context .Background (), id )
671
+ if softErr != nil {
672
+ log .Warnf (" -> -> could not retrieve key %v" , softErr )
673
673
} else if key == nil {
674
674
log .Warnf (" -> -> %d no longer exists" , id )
675
675
}
676
676
677
- _ , err = d .getClient ().SSHKey .Delete (context .Background (), key )
678
- if err != nil {
679
- log .Warnf (" -> -> could not remove key: %v" , err )
677
+ _ , softErr = d .getClient ().SSHKey .Delete (context .Background (), key )
678
+ if softErr != nil {
679
+ log .Warnf (" -> -> could not remove key: %v" , softErr )
680
680
}
681
681
}
682
682
683
+ // failure to remove a server-specific key is a hard error
683
684
if ! d .IsExistingKey && d .KeyID != 0 {
684
685
key , err := d .getKey ()
685
686
if err != nil {
@@ -953,16 +954,16 @@ func (d *Driver) makePlacementGroup(name string, labels map[string]string) (*hcl
953
954
d .dangling = append (d .dangling , func () {
954
955
_ , err := d .getClient ().PlacementGroup .Delete (context .Background (), grp .PlacementGroup )
955
956
if err != nil {
956
- log .Error ( fmt . Errorf ("could not delete placement group: %w " , err ) )
957
+ log .Errorf ("could not delete placement group: %v " , err )
957
958
}
958
959
})
959
960
}
960
961
961
962
if err != nil {
962
- err = fmt .Errorf ("could not create placement group: %w" , err )
963
+ return nil , fmt .Errorf ("could not create placement group: %w" , err )
963
964
}
964
965
965
- return grp .PlacementGroup , err
966
+ return grp .PlacementGroup , nil
966
967
}
967
968
968
969
func (d * Driver ) getPlacementGroup () (* hcloud.PlacementGroup , error ) {
@@ -1006,9 +1007,9 @@ func (d *Driver) removeEmptyServerPlacementGroup(srv *hcloud.Server) error {
1006
1007
if auto , exists := pg .Labels [d .labelName (labelAutoCreated )]; exists && auto == "true" {
1007
1008
_ , err := d .getClient ().PlacementGroup .Delete (context .Background (), pg )
1008
1009
if err != nil {
1009
- err = fmt .Errorf ("could not remove placement group: %w" , err )
1010
+ return fmt .Errorf ("could not remove placement group: %w" , err )
1010
1011
}
1011
- return err
1012
+ return nil
1012
1013
} else {
1013
1014
log .Debugf ("group not auto-created, ignoring: %v" , pg )
1014
1015
return nil
0 commit comments