Skip to content

Commit

Permalink
cmd/osbuild-service-maintenance: clean up secure instances
Browse files Browse the repository at this point in the history
Now and then there are leftover secure instances, probably when worker
instances get terminated during builds, this is possible in ASGs. 2
hours as a cutoff should be enough, since the build times out after 60
minutes, and fetching the output archive after 30 minutes, so that
leaves 30 minutes for booting and connection.
  • Loading branch information
croissanne committed Oct 23, 2024
1 parent 1c7a276 commit 04a5ca6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmd/osbuild-service-maintenance/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -82,5 +83,22 @@ func AWSCleanup(maxConcurrentRequests int, dryRun bool, accessKeyID, accessKey s
wg.Wait()
}

// Terminate leftover secure instances
reservations, err := a.DescribeInstancesByTag("parent", "i-*")
if err != nil {
return fmt.Errorf("Unable to describe instances by tag %w", err)
}
var instanceIDs []string
for _, res := range reservations {
for _, i := range res.Instances {
if i.LaunchTime.Before(time.Now().Add(-time.Hour * 2)) {
instanceIDs = append(instanceIDs, *i.InstanceId)
}
}
}
err = a.TerminateInstances(instanceIDs)
if err != nil {
return fmt.Errorf("Unable to terminate secure instances: %w", err)
}
return nil
}

0 comments on commit 04a5ca6

Please sign in to comment.