Skip to content

Commit

Permalink
chore: add support for sweepers (#4379)
Browse files Browse the repository at this point in the history
  • Loading branch information
remyleone authored Dec 26, 2024
1 parent 0686b22 commit 0781019
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,11 @@ jobs:
env:
SLACK_WEBHOOK_NIGHTLY: ${{ secrets.SLACK_WEBHOOK_NIGHTLY }}
FAILED_PRODUCT: ${{ matrix.products }}
- name: Run Sweepers
run: go run -v ./cmd/scw-sweepers
env:
SCW_DEBUG: 1
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
SCW_DEFAULT_PROJECT_ID: ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
194 changes: 194 additions & 0 deletions cmd/scw-sweeper/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
package main

import (
"log"
"os"

accountSweeper "github.com/scaleway/scaleway-sdk-go/api/account/v3/sweepers"
applesiliconSweeper "github.com/scaleway/scaleway-sdk-go/api/applesilicon/v1alpha1/sweepers"
baremetalSweeper "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1/sweepers"
blockSweeper "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1/sweepers"
cockpitSweeper "github.com/scaleway/scaleway-sdk-go/api/cockpit/v1/sweepers"
containerSweeper "github.com/scaleway/scaleway-sdk-go/api/container/v1beta1/sweepers"
flexibleipSweeper "github.com/scaleway/scaleway-sdk-go/api/flexibleip/v1alpha1/sweepers"
functionSweeper "github.com/scaleway/scaleway-sdk-go/api/function/v1beta1/sweepers"
inferenceSweeper "github.com/scaleway/scaleway-sdk-go/api/inference/v1beta1/sweepers"
instanceSweeper "github.com/scaleway/scaleway-sdk-go/api/instance/v1/sweepers"
iotSweeper "github.com/scaleway/scaleway-sdk-go/api/iot/v1/sweepers"
ipamSweeper "github.com/scaleway/scaleway-sdk-go/api/ipam/v1/sweepers"
jobsSweeper "github.com/scaleway/scaleway-sdk-go/api/jobs/v1alpha1/sweepers"
k8sSweeper "github.com/scaleway/scaleway-sdk-go/api/k8s/v1/sweepers"
lbSweeper "github.com/scaleway/scaleway-sdk-go/api/lb/v1/sweepers"
mnqSweeper "github.com/scaleway/scaleway-sdk-go/api/mnq/v1beta1/sweepers"
mongodbSweeper "github.com/scaleway/scaleway-sdk-go/api/mongodb/v1alpha1/sweepers"
rdbSweeper "github.com/scaleway/scaleway-sdk-go/api/rdb/v1/sweepers"
redisSweeper "github.com/scaleway/scaleway-sdk-go/api/redis/v1/sweepers"
registrySweeper "github.com/scaleway/scaleway-sdk-go/api/registry/v1/sweepers"
secretSweeper "github.com/scaleway/scaleway-sdk-go/api/secret/v1beta1/sweepers"
sdbSweeper "github.com/scaleway/scaleway-sdk-go/api/serverless_sqldb/v1alpha1/sweepers"
vpcSweeper "github.com/scaleway/scaleway-sdk-go/api/vpc/v2/sweepers"
vpcgwSweeper "github.com/scaleway/scaleway-sdk-go/api/vpcgw/v1/sweepers"
webhostingSweeper "github.com/scaleway/scaleway-sdk-go/api/webhosting/v1alpha1/sweepers"
"github.com/scaleway/scaleway-sdk-go/scw"
)

func main() {
exitCode := mainNoExit()
os.Exit(exitCode)
}

func mainNoExit() int {
config, err := scw.LoadConfig()
if err != nil {
// handle error
log.Fatal(err)
}
activeProfile, err := config.GetActiveProfile()
if err != nil {
// handle error
log.Fatal(err)
}

envProfile := scw.LoadEnvProfile()
profile := scw.MergeProfiles(activeProfile, envProfile)

client, err := scw.NewClient(
scw.WithProfile(profile),
scw.WithUserAgent("scw-sweeper"),
scw.WithEnv(),
)
if err != nil {
log.Fatalf("Cannot create Scaleway client: %s", err)
}

err = accountSweeper.SweepAll(client)
if err != nil {
return -1
}

err = applesiliconSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = baremetalSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = cockpitSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = containerSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = flexibleipSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = functionSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = inferenceSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = instanceSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

// Instance servers need to be swept before volumes and snapshots can be swept
// because volumes and snapshots are attached to servers.
err = blockSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = iotSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = ipamSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = jobsSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = k8sSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = lbSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = mongodbSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = mnqSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = rdbSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = redisSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = registrySweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = secretSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = sdbSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = vpcSweeper.SweepAllLocalities(client)
if err != nil {
return -1
}

err = vpcgwSweeper.SweepAllLocalities(client)
if err != nil {
log.Fatalf("Error sweeping vpcgw: %s", err)
return -1
}

err = webhostingSweeper.SweepAllLocalities(client)
if err != nil {
log.Fatalf("Error sweeping webhosting: %s", err)
return -1
}

return 0
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/mattn/go-isatty v0.0.20
github.com/moby/buildkit v0.13.2
github.com/opencontainers/go-digest v1.0.0
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20241219084541-35c11c799f4c
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20241224153503-37a05773a198
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20241219084541-35c11c799f4c h1:WMtLyaN8cHQFLmCS8bqnDRs+UOLxai1fyNb2BbQ+hC4=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20241219084541-35c11c799f4c/go.mod h1:kzh+BSAvpoyHHdHBCDhmSWtBc1NbLMZ2lWHqnBoxFks=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20241224153503-37a05773a198 h1:ym2tXsg7ZCAnZlKmB07jMApvvi5TE66lXWH6xRZTsFE=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20241224153503-37a05773a198/go.mod h1:kzh+BSAvpoyHHdHBCDhmSWtBc1NbLMZ2lWHqnBoxFks=
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM=
github.com/secure-systems-lab/go-securesystemslib v0.8.0 h1:mr5An6X45Kb2nddcFlbmfHkLguCE9laoZCUzEEpIZXA=
Expand Down

0 comments on commit 0781019

Please sign in to comment.