Skip to content

Commit

Permalink
mantle/platform: handle improperly created azure resource groups
Browse files Browse the repository at this point in the history
In some cases (especially when Azure infra is having trouble)
resource groups can get created without some necessary tags. Let's
handle the case when a group doesn't have a "createdAt" tag so we
clean that resource group up and don't panic/segfault.

Fixes #3057
  • Loading branch information
dustymabe committed Sep 1, 2022
1 parent 3991e6f commit 6b7a7ba
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions mantle/platform/api/azure/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,25 @@ func (a *API) GC(gracePeriod time.Duration) error {

for _, l := range *listGroups.Value {
if strings.HasPrefix(*l.Name, "kola-cluster") {
createdAt := *(*l.Tags)["createdAt"]
timeCreated, err := time.Parse(time.RFC3339, createdAt)
if err != nil {
return fmt.Errorf("error parsing time: %v", err)
terminate := false
if l.Tags == nil || (*l.Tags)["createdAt"] == nil {
// If the group name starts with kola-cluster and has
// no tags OR no createdAt then it failed to properly
// get created and we should clean it up.
// https://github.com/coreos/coreos-assembler/issues/3057
terminate = true
} else {
createdAt := *(*l.Tags)["createdAt"]
timeCreated, err := time.Parse(time.RFC3339, createdAt)
if err != nil {
return fmt.Errorf("error parsing time: %v", err)
}
if !timeCreated.After(durationAgo) {
// If the group is older than specified time then gc
terminate = true
}
}
if !timeCreated.After(durationAgo) {
if terminate {
if err = a.TerminateResourceGroup(*l.Name); err != nil {
return err
}
Expand Down

0 comments on commit 6b7a7ba

Please sign in to comment.