Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
474e468
commit a504080
Showing
5 changed files
with
208 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package iam | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/kris-nova/logger" | ||
"github.com/weaveworks/eksctl/pkg/ctl/cmdutils" | ||
"github.com/weaveworks/eksctl/pkg/kubernetes" | ||
) | ||
|
||
func (m *Manager) Delete(serviceAccounts []string, plan, wait bool) error { | ||
tasks, err := m.stackManager.NewTasksToDeleteIAMServiceAccounts(serviceAccounts, kubernetes.NewCachedClientSet(m.clientSet), wait) | ||
if err != nil { | ||
return err | ||
} | ||
tasks.PlanMode = plan | ||
|
||
logger.Info(tasks.Describe()) | ||
if errs := tasks.DoAllSync(); len(errs) > 0 { | ||
logger.Info("%d error(s) occurred and IAM Role stacks haven't been deleted properly, you may wish to check CloudFormation console", len(errs)) | ||
for _, err := range errs { | ||
logger.Critical("%s\n", err.Error()) | ||
} | ||
return fmt.Errorf("failed to delete iamserviceaccount(s)") | ||
} | ||
|
||
cmdutils.LogPlanModeWarning(plan && len(serviceAccounts) > 0) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package iam_test | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/cloudformation" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/weaveworks/eksctl/pkg/cfn/manager" | ||
"github.com/weaveworks/eksctl/pkg/eks" | ||
|
||
"github.com/weaveworks/eksctl/pkg/actions/iam" | ||
"github.com/weaveworks/eksctl/pkg/actions/iam/fakes" | ||
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5" | ||
iamoidc "github.com/weaveworks/eksctl/pkg/iam/oidc" | ||
"github.com/weaveworks/eksctl/pkg/testutils/mockprovider" | ||
) | ||
|
||
var _ = Describe("Delete", func() { | ||
|
||
var ( | ||
iamManager *iam.Manager | ||
oidc *iamoidc.OpenIDConnectManager | ||
fakeStackManager *fakes.FakeStackManager | ||
mockProvider *mockprovider.MockProvider | ||
serviceAccount []*api.ClusterIAMServiceAccount | ||
) | ||
|
||
BeforeEach(func() { | ||
serviceAccount = []*api.ClusterIAMServiceAccount{ | ||
{ | ||
ClusterIAMMeta: api.ClusterIAMMeta{ | ||
Name: "test-sa", | ||
Namespace: "default", | ||
}, | ||
AttachPolicyARNs: []string{"arn-123"}, | ||
}, | ||
} | ||
var err error | ||
|
||
fakeStackManager = new(fakes.FakeStackManager) | ||
mockProvider = mockprovider.NewMockProvider() | ||
|
||
oidc, err = iamoidc.NewOpenIDConnectManager(nil, "456123987123", "https://oidc.eks.us-west-2.amazonaws.com/id/A39A2842863C47208955D753DE205E6E", "aws") | ||
Expect(err).ToNot(HaveOccurred()) | ||
oidc.ProviderARN = "arn:aws:iam::456123987123:oidc-provider/oidc.eks.us-west-2.amazonaws.com/id/A39A2842863C47208955D753DE205E6E" | ||
iamManager = iam.New("my-cluster", &eks.ClusterProvider{Provider: mockProvider}, fakeStackManager, oidc, nil) | ||
}) | ||
|
||
When("the IAMServiceAccount exists", func() { | ||
It("deletes it", func() { | ||
fakeStackManager.ListStacksMatchingReturns([]*cloudformation.Stack{ | ||
{ | ||
StackName: aws.String("eksctl-my-cluster-addon-iamserviceaccount-default-test-sa"), | ||
}, | ||
}, nil) | ||
|
||
err := iamManager.Delete(serviceAccount, false) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
Expect(fakeStackManager.ListStacksMatchingCallCount()).To(Equal(1)) | ||
Expect(fakeStackManager.ListStacksMatchingArgsForCall(0)).To(Equal("eksctl-.*-addon-iamserviceaccount")) | ||
Expect(fakeStackManager.UpdateStackCallCount()).To(Equal(1)) | ||
fakeStackManager.UpdateStackArgsForCall(0) | ||
stackName, changeSetName, description, templateData, _ := fakeStackManager.UpdateStackArgsForCall(0) | ||
Expect(stackName).To(Equal("eksctl-my-cluster-addon-iamserviceaccount-default-test-sa")) | ||
Expect(changeSetName).To(Equal("updating-policy")) | ||
Expect(description).To(Equal("updating policies for IAMServiceAccount default/test-sa")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(string(templateData.(manager.TemplateBody))).To(ContainSubstring("arn-123")) | ||
Expect(string(templateData.(manager.TemplateBody))).To(ContainSubstring(":sub\":\"system:serviceaccount:default:test-sa")) | ||
}) | ||
|
||
//When("in plan mode", func() { | ||
// It("does not trigger a delete", func() { | ||
// fakeStackManager.ListStacksMatchingReturns([]*cloudformation.Stack{ | ||
// { | ||
// StackName: aws.String("eksctl-my-cluster-addon-iamserviceaccount-default-test-sa"), | ||
// }, | ||
// }, nil) | ||
// | ||
// err := iamManager.UpdateIAMServiceAccounts(serviceAccount, true) | ||
// Expect(err).NotTo(HaveOccurred()) | ||
// | ||
// Expect(fakeStackManager.ListStacksMatchingCallCount()).To(Equal(1)) | ||
// Expect(fakeStackManager.ListStacksMatchingArgsForCall(0)).To(Equal("eksctl-.*-addon-iamserviceaccount")) | ||
// Expect(fakeStackManager.UpdateStackCallCount()).To(Equal(0)) | ||
// }) | ||
//}) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters