Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b8f642a
pkg/infrastructure: generic stages interface
patrickdillon Sep 26, 2023
02e683e
pkg/infrastructure/providers: use terraform providers
patrickdillon Sep 26, 2023
343ab78
pkg/terraform: encapsulate & implement infra/stages
patrickdillon Sep 26, 2023
258c247
Replace terraform with infrastructure interface
patrickdillon Sep 27, 2023
3a14f6b
Add Alternate Infrastructure Build Tag
patrickdillon Sep 27, 2023
6322365
switch platform to point to terraform implementations
patrickdillon Sep 27, 2023
7298bbd
Vendor: Alt Infra AWS
patrickdillon Sep 27, 2023
ffa2c20
Handle nil values from infrastructure/stages
patrickdillon Sep 27, 2023
2668827
PoC: Alternate AWS Infrastructure provider
patrickdillon Sep 27, 2023
92d7c33
pkg/infra/aws: add iam resources creation
r4f4 Oct 6, 2023
acd0a79
pkg/infra/aws/vpc: add cross_zone attr for LBs
r4f4 Oct 6, 2023
ed855f5
pkg/infra/aws/vpc: fix missing return
r4f4 Oct 6, 2023
b87f8cf
WIP: temporarily ignore state file errors
r4f4 Oct 6, 2023
d7769a2
pkg/infra/aws: tag hosted zone
r4f4 Oct 8, 2023
5a14a35
pkg/infra/aws: bootstrap destroy
r4f4 Oct 9, 2023
3a5c849
pkg/infra/aws: tag ignition s3 bucket and object
r4f4 Oct 9, 2023
f1cb6a9
pkg/infra/aws: use a struct to make createEC2Instance arguments more …
r4f4 Oct 10, 2023
c0f1db2
pkg/asset/cluster: fix missing return
r4f4 Oct 11, 2023
b2dd8d7
pkg/infra/aws: fine-tune security groups and rules
r4f4 Oct 11, 2023
ba7c05a
pkg/infra/aws: use configured v4 CIDRs
r4f4 Oct 11, 2023
c4c2c5c
pkg/infra/aws: use custom user tags
r4f4 Oct 11, 2023
0f004cc
pkg/infra/aws: abuse of structured logging
r4f4 Oct 11, 2023
fd97aca
hack/build: skip terraform with altinfra tag
patrickdillon Oct 5, 2023
e6dfc35
pkg/infra/aws: enable volume encryption
r4f4 Oct 12, 2023
97cc7b9
pkg/infra/aws: allow BYO vpc
r4f4 Oct 12, 2023
56f16ce
pkg/infra/aws: allow additional security groups
r4f4 Oct 13, 2023
73b1bdc
pkg/infra/aws: isolate aws SDK calls as much as possible
r4f4 Oct 15, 2023
054d9ac
vendor: aws elbv2 interface
r4f4 Oct 15, 2023
6f64572
pkg/infra/aws: use elbv2 interface
r4f4 Oct 15, 2023
fe1f6fd
fixup! pkg/infra/aws: isolate aws SDK calls as much as possible
r4f4 Oct 15, 2023
9d6e722
Fix BYO VPC functionality
r4f4 Oct 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmd/openshift-install/gather.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
serialgather "github.com/openshift/installer/pkg/gather"
"github.com/openshift/installer/pkg/gather/service"
"github.com/openshift/installer/pkg/gather/ssh"
platformstages "github.com/openshift/installer/pkg/terraform/stages/platform"
"github.com/openshift/installer/pkg/infrastructure/platform"

_ "github.com/openshift/installer/pkg/gather/aws"
_ "github.com/openshift/installer/pkg/gather/azure"
Expand Down Expand Up @@ -118,7 +118,13 @@ func runGatherBootstrapCmd(directory string) (string, error) {
return "", errors.Wrapf(err, "failed to fetch %s", config.Name())
}

for _, stage := range platformstages.StagesForPlatform(config.Config.Platform.Name()) {
stages, cleanup, err := platform.ProviderForPlatform(config.Config.Platform.Name(), directory)
if err != nil {
return "", errors.Wrapf(err, "failed to initialize provider to gather bootstrap")
}
defer cleanup()

for _, stage := range stages {
stageBootstrap, stagePort, stageMasters, err := stage.ExtractHostAddresses(directory, config.Config)
if err != nil {
logrus.Warnf("Failed to extract host addresses: %s", err.Error())
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/coreos/ignition/v2 v2.14.0
github.com/coreos/stream-metadata-go v0.1.8
github.com/daixiang0/gci v0.9.0
github.com/davecgh/go-spew v1.1.1
github.com/diskfs/go-diskfs v1.4.0
github.com/form3tech-oss/jwt-go v3.2.3+incompatible
github.com/go-openapi/errors v0.20.3
Expand Down Expand Up @@ -105,6 +106,7 @@ require (
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.90.1
k8s.io/utils v0.0.0-20230209194617-a36077c30491
sigs.k8s.io/controller-runtime v0.14.5
sigs.k8s.io/controller-tools v0.10.0
sigs.k8s.io/yaml v1.3.0
)
Expand All @@ -131,9 +133,9 @@ require (
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/coreos/vcontext v0.0.0-20211021162308-f1dbbca7bef4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand Down Expand Up @@ -225,7 +227,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/gorm v1.24.5 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
sigs.k8s.io/controller-runtime v0.14.5 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi
github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84=
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww=
github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4=
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
github.com/fatih/color v1.6.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
Expand Down Expand Up @@ -761,6 +762,7 @@ github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7P
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas=
Expand Down Expand Up @@ -1583,6 +1585,7 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
gomodules.xyz/jsonpatch/v2 v2.2.0 h1:4pT439QV83L+G9FkcCriY6EkpcK6r6bK+A5FBUMI7qY=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
Expand Down Expand Up @@ -1779,6 +1782,7 @@ k8s.io/code-generator v0.23.3/go.mod h1:S0Q1JVA+kSzTI1oUvbKAxZY/DYbA/ZUb4Uknog12
k8s.io/component-base v0.18.2/go.mod h1:kqLlMuhJNHQ9lz8Z7V5bxUUtjFZnrypArGl58gmDfUM=
k8s.io/component-base v0.19.0/go.mod h1:dKsY8BxkA+9dZIAh2aWJLL/UdASFDNtGYTCItL4LM7Y=
k8s.io/component-base v0.20.6/go.mod h1:6f1MPBAeI+mvuts3sIdtpjljHWBQ2cIy38oBIWMYnrM=
k8s.io/component-base v0.26.1 h1:4ahudpeQXHZL5kko+iDHqLj/FSGAEUnSVO0EBbgDd+4=
k8s.io/cri-api v0.20.6/go.mod h1:ew44AjNXwyn1s0U4xCKGodU7J1HzBeZ1MpGrpa5r8Yc=
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/gengo v0.0.0-20200114144118-36b2048a9120/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
Expand Down
12 changes: 8 additions & 4 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ fi

export CGO_ENABLED=0
MODE="${MODE:-release}"
# build terraform binaries before setting environment variables since it messes up make
make -C terraform all

# Copy terraform parts to embedded mirror.
copy_terraform_to_mirror
if ! (echo "${TAGS}" | grep -q 'altinfra')
then
# build terraform binaries before setting environment variables since it messes up make
make -C terraform all

# Copy terraform parts to embedded mirror.
copy_terraform_to_mirror
fi

GIT_COMMIT="${SOURCE_GIT_COMMIT:-$(git rev-parse --verify 'HEAD^{commit}')}"
GIT_TAG="${BUILD_VERSION:-$(git describe --always --abbrev=40 --dirty)}"
Expand Down
94 changes: 20 additions & 74 deletions pkg/asset/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ package cluster

import (
"context"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/hashicorp/terraform-exec/tfexec"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

Expand All @@ -18,9 +15,7 @@ import (
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/password"
"github.com/openshift/installer/pkg/asset/quota"
"github.com/openshift/installer/pkg/metrics/timer"
"github.com/openshift/installer/pkg/terraform"
platformstages "github.com/openshift/installer/pkg/terraform/stages/platform"
infrastructure "github.com/openshift/installer/pkg/infrastructure/platform"
typesaws "github.com/openshift/installer/pkg/types/aws"
typesazure "github.com/openshift/installer/pkg/types/azure"
typesopenstack "github.com/openshift/installer/pkg/types/openstack"
Expand Down Expand Up @@ -92,20 +87,13 @@ func (c *Cluster) Generate(parents asset.Parents) (err error) {
platform = typesazure.StackTerraformName
}

stages := platformstages.StagesForPlatform(platform)

terraformDir := filepath.Join(InstallDir, "terraform")
if err := os.Mkdir(terraformDir, 0777); err != nil {
return errors.Wrap(err, "could not create the terraform directory")
}

terraformDirPath, err := filepath.Abs(terraformDir)
stages, cleanup, err := infrastructure.ProviderForPlatform(platform, InstallDir)
if err != nil {
return errors.Wrap(err, "cannot get absolute path of terraform directory")
return errors.Wrap(err, "initializing cluster infrastructure provider ")
}
if cleanup != nil {
defer cleanup()
}

defer os.RemoveAll(terraformDir)
terraform.UnpackTerraform(terraformDirPath, stages)

logrus.Infof("Creating infrastructure resources...")
switch platform {
Expand All @@ -128,13 +116,22 @@ func (c *Cluster) Generate(parents asset.Parents) (err error) {
tfvarsFiles = append(tfvarsFiles, file)
}

// initialize to prevent nil pointer dereference
// TODO: similar as below, find more generic alternative to tfstate
c.FileList = []*asset.File{}

for _, stage := range stages {
outputs, err := c.applyStage(platform, stage, terraformDirPath, tfvarsFiles)
outputs, stateFile, err := stage.Provision(tfvarsFiles, c.FileList) //TODO: make sure c.FileList ends up being used
if err != nil {
return errors.Wrapf(err, "failure applying terraform for %q stage", stage.Name())
return errors.Wrapf(err, "provisioning infrastructure in stage %s", stage.Name())
}
if outputs != nil {
tfvarsFiles = append(tfvarsFiles, outputs)
c.FileList = append(c.FileList, outputs)
}
if stateFile != nil {
c.FileList = append(c.FileList, stateFile)
}
tfvarsFiles = append(tfvarsFiles, outputs)
c.FileList = append(c.FileList, outputs)
}

return nil
Expand All @@ -148,6 +145,7 @@ func (c *Cluster) Files() []*asset.File {
// Load returns error if the tfstate file is already on-disk, because we want to
// prevent user from accidentally re-launching the cluster.
func (c *Cluster) Load(f asset.FileFetcher) (found bool, err error) {
// TODO: make this less opinionated/coupled to terraform
matches, err := filepath.Glob("terraform(.*)?.tfstate")
if err != nil {
return true, err
Expand All @@ -158,55 +156,3 @@ func (c *Cluster) Load(f asset.FileFetcher) (found bool, err error) {

return false, nil
}

func (c *Cluster) applyStage(platform string, stage terraform.Stage, terraformDir string, tfvarsFiles []*asset.File) (*asset.File, error) {
// Copy the terraform.tfvars to a temp directory which will contain the terraform plan.
tmpDir, err := os.MkdirTemp("", fmt.Sprintf("openshift-install-%s-", stage.Name()))
if err != nil {
return nil, errors.Wrap(err, "failed to create temp dir for terraform execution")
}
defer os.RemoveAll(tmpDir)

var extraOpts []tfexec.ApplyOption
for _, file := range tfvarsFiles {
if err := os.WriteFile(filepath.Join(tmpDir, file.Filename), file.Data, 0o600); err != nil {
return nil, err
}
extraOpts = append(extraOpts, tfexec.VarFile(filepath.Join(tmpDir, file.Filename)))
}

return c.applyTerraform(tmpDir, platform, stage, terraformDir, extraOpts...)
}

func (c *Cluster) applyTerraform(tmpDir string, platform string, stage terraform.Stage, terraformDir string, opts ...tfexec.ApplyOption) (*asset.File, error) {
timer.StartTimer(stage.Name())
defer timer.StopTimer(stage.Name())

applyErr := terraform.Apply(tmpDir, platform, stage, terraformDir, opts...)

// Write the state file to the install directory even if the apply failed.
if data, err := os.ReadFile(filepath.Join(tmpDir, terraform.StateFilename)); err == nil {
c.FileList = append(c.FileList, &asset.File{
Filename: stage.StateFilename(),
Data: data,
})
} else if !os.IsNotExist(err) {
logrus.Errorf("Failed to read tfstate: %v", err)
return nil, errors.Wrap(err, "failed to read tfstate")
}

if applyErr != nil {
return nil, errors.Wrap(applyErr, asset.ClusterCreationError)
}

outputs, err := terraform.Outputs(tmpDir, terraformDir)
if err != nil {
return nil, errors.Wrapf(err, "could not get outputs from stage %q", stage.Name())
}

outputsFile := &asset.File{
Filename: stage.OutputsFilename(),
Data: outputs,
}
return outputsFile, nil
}
42 changes: 22 additions & 20 deletions pkg/destroy/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ func (o *ClusterUninstaller) RunWithContext(ctx context.Context) ([]string, erro
}

iamClient := iam.New(awsSession)
iamRoleSearch := &iamRoleSearch{
client: iamClient,
filters: o.Filters,
logger: o.Logger,
iamRoleSearch := &IamRoleSearch{
Client: iamClient,
Filters: o.Filters,
Logger: o.Logger,
}
iamUserSearch := &iamUserSearch{
client: iamClient,
Expand All @@ -180,7 +180,7 @@ func (o *ClusterUninstaller) RunWithContext(ctx context.Context) ([]string, erro
}
}

tracker := new(errorTracker)
tracker := new(ErrorTracker)

// Terminate EC2 instances. The instances need to be terminated first so that we can ensure that there is nothing
// running on the cluster creating new resources while we are attempting to delete resources, which could leak
Expand All @@ -190,7 +190,7 @@ func (o *ClusterUninstaller) RunWithContext(ctx context.Context) ([]string, erro
err = wait.PollImmediateUntil(
time.Second*10,
func() (done bool, err error) {
instancesRunning, instancesNotTerminated, err := findEC2Instances(ctx, ec2Client, deleted, o.Filters, o.Logger)
instancesRunning, instancesNotTerminated, err := FindEC2Instances(ctx, ec2Client, deleted, o.Filters, o.Logger)
if err != nil {
o.Logger.WithError(err).Info("error while finding EC2 instances to delete")
if err := ctx.Err(); err != nil {
Expand All @@ -205,7 +205,7 @@ func (o *ClusterUninstaller) RunWithContext(ctx context.Context) ([]string, erro
instancesToDelete = instancesNotTerminated
lastTerminateTime = time.Now()
}
newlyDeleted, err := o.deleteResources(ctx, awsSession, instancesToDelete, tracker)
newlyDeleted, err := DeleteResources(ctx, awsSession, instancesToDelete, tracker, o.Logger)
// Delete from the resources-to-delete set so that the current state of the resources to delete can be
// returned if the context is completed.
resourcesToDelete = resourcesToDelete.Difference(newlyDeleted)
Expand All @@ -227,7 +227,7 @@ func (o *ClusterUninstaller) RunWithContext(ctx context.Context) ([]string, erro
err = wait.PollImmediateUntil(
time.Second*10,
func() (done bool, err error) {
newlyDeleted, loopError := o.deleteResources(ctx, awsSession, resourcesToDelete.UnsortedList(), tracker)
newlyDeleted, loopError := DeleteResources(ctx, awsSession, resourcesToDelete.UnsortedList(), tracker, o.Logger)
// Delete from the resources-to-delete set so that the current state of the resources to delete can be
// returned if the context is completed.
resourcesToDelete = resourcesToDelete.Difference(newlyDeleted)
Expand Down Expand Up @@ -273,7 +273,7 @@ func (o *ClusterUninstaller) findResourcesToDelete(
ctx context.Context,
tagClients []*resourcegroupstaggingapi.ResourceGroupsTaggingAPI,
iamClient *iam.IAM,
iamRoleSearch *iamRoleSearch,
iamRoleSearch *IamRoleSearch,
iamUserSearch *iamUserSearch,
deleted sets.String,
) (sets.String, []*resourcegroupstaggingapi.ResourceGroupsTaggingAPI, error) {
Expand All @@ -283,7 +283,7 @@ func (o *ClusterUninstaller) findResourcesToDelete(

// Find resources by tag
for _, tagClient := range tagClients {
resourcesInTagClient, err := o.findResourcesByTag(ctx, tagClient, deleted)
resourcesInTagClient, err := FindResourcesByTag(ctx, tagClient, deleted, o.Filters, o.Logger)
if err != nil {
errs = append(errs, err)
}
Expand All @@ -298,7 +298,7 @@ func (o *ClusterUninstaller) findResourcesToDelete(
}

// Find IAM roles
iamRoleResources, err := findIAMRoles(ctx, iamRoleSearch, deleted, o.Logger)
iamRoleResources, err := FindIAMRoles(ctx, iamRoleSearch, deleted, o.Logger)
if err != nil {
errs = append(errs, err)
}
Expand All @@ -318,14 +318,16 @@ func (o *ClusterUninstaller) findResourcesToDelete(
//
// tagClients - clients of the tagging API to use to search for resources.
// deleted - the resources that have already been deleted. Any resources specified in this set will be ignored.
func (o *ClusterUninstaller) findResourcesByTag(
func FindResourcesByTag(
ctx context.Context,
tagClient *resourcegroupstaggingapi.ResourceGroupsTaggingAPI,
deleted sets.String,
filters []Filter,
logger logrus.FieldLogger,
) (sets.String, error) {
resources := sets.NewString()
for _, filter := range o.Filters {
o.Logger.Debugf("search for matching resources by tag in %s matching %#+v", *tagClient.Config.Region, filter)
for _, filter := range filters {
logger.Debugf("search for matching resources by tag in %s matching %#+v", *tagClient.Config.Region, filter)
tagFilters := make([]*resourcegroupstaggingapi.TagFilter, 0, len(filter))
for key, value := range filter {
tagFilters = append(tagFilters, &resourcegroupstaggingapi.TagFilter{
Expand All @@ -348,7 +350,7 @@ func (o *ClusterUninstaller) findResourcesByTag(
)
if err != nil {
err = errors.Wrap(err, "get tagged resources")
o.Logger.Info(err)
logger.Info(err)
return resources, err
}
}
Expand All @@ -360,17 +362,17 @@ func (o *ClusterUninstaller) findResourcesByTag(
// resources - the resources to be deleted.
//
// The first return is the ARNs of the resources that were successfully deleted
func (o *ClusterUninstaller) deleteResources(ctx context.Context, awsSession *session.Session, resources []string, tracker *errorTracker) (sets.String, error) {
func DeleteResources(ctx context.Context, awsSession *session.Session, resources []string, tracker *ErrorTracker, logger logrus.FieldLogger) (sets.String, error) {
deleted := sets.NewString()
for _, arnString := range resources {
logger := o.Logger.WithField("arn", arnString)
l := logger.WithField("arn", arnString)
parsedARN, err := arn.Parse(arnString)
if err != nil {
logger.WithError(err).Debug("could not parse ARN")
l.WithError(err).Debug("could not parse ARN")
continue
}
if err := deleteARN(ctx, awsSession, parsedARN, o.Logger); err != nil {
tracker.suppressWarning(arnString, err, logger)
if err := deleteARN(ctx, awsSession, parsedARN, logger); err != nil {
tracker.suppressWarning(arnString, err, l)
if err := ctx.Err(); err != nil {
return deleted, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/destroy/aws/ec2helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// stage and the second list is the list of resources that are not terminated.
//
// deleted - the resources that have already been deleted. Any resources specified in this set will be ignored.
func findEC2Instances(ctx context.Context, ec2Client *ec2.EC2, deleted sets.String, filters []Filter, logger logrus.FieldLogger) ([]string, []string, error) {
func FindEC2Instances(ctx context.Context, ec2Client *ec2.EC2, deleted sets.String, filters []Filter, logger logrus.FieldLogger) ([]string, []string, error) {
if ec2Client.Config.Region == nil {
return nil, nil, errors.New("EC2 client does not have region configured")
}
Expand Down
Loading