Skip to content

Commit

Permalink
Merge pull request #317 from stelligent/issue-316
Browse files Browse the repository at this point in the history
fix #316 - Namespace not honored when terminating environments
  • Loading branch information
cplee committed Aug 17, 2018
2 parents af8954f + 23003d1 commit 2c3b479
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 29 deletions.
2 changes: 1 addition & 1 deletion common/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type StackUpserter interface {

// StackLister for listing stacks
type StackLister interface {
ListStacks(stackType StackType) ([]*Stack, error)
ListStacks(stackType StackType, namespace string) ([]*Stack, error)
}

// StackGetter for getting stacks
Expand Down
5 changes: 3 additions & 2 deletions provider/aws/cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func buildStack(stackDetails *cloudformation.Stack) *common.Stack {
}

// ListStacks will find mu stacks
func (cfnMgr *cloudformationStackManager) ListStacks(stackType common.StackType) ([]*common.Stack, error) {
func (cfnMgr *cloudformationStackManager) ListStacks(stackType common.StackType, namespace string) ([]*common.Stack, error) {
cfnAPI := cfnMgr.cfnAPI

params := &cloudformation.DescribeStacksInput{}
Expand All @@ -415,8 +415,9 @@ func (cfnMgr *cloudformationStackManager) ListStacks(stackType common.StackType)
}

stack := buildStack(stackDetails)
stackNamespace := strings.Split(stack.Name, "-")[0]

if stack.Tags["type"] == string(stackType) {
if stack.Tags["type"] == string(stackType) && stackNamespace == namespace {
stacks = append(stacks, stack)
}
}
Expand Down
9 changes: 5 additions & 4 deletions provider/aws/cloudformation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package aws

import (
"errors"
"io"
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go/service/cloudformation/cloudformationiface"
"github.com/stelligent/mu/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"io"
"testing"
"time"
)

type mockedExtensionsManager struct {
Expand Down Expand Up @@ -233,7 +234,7 @@ func TestCloudformationStackManager_ListStacks(t *testing.T) {
stackManager := cloudformationStackManager{
cfnAPI: cfn,
}
stacks, err := stackManager.ListStacks(common.StackTypeEnv)
stacks, err := stackManager.ListStacks(common.StackTypeEnv, "mu")

assert.Nil(err)
assert.NotNil(stacks)
Expand Down
9 changes: 5 additions & 4 deletions workflows/database_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package workflows

import (
"fmt"
"github.com/stelligent/mu/common"
"io"

"github.com/stelligent/mu/common"
)

// NewDatabaseLister create a new workflow for listing databases
Expand All @@ -12,14 +13,14 @@ func NewDatabaseLister(ctx *common.Context, writer io.Writer) Executor {
workflow := new(databaseWorkflow)

return newPipelineExecutor(
workflow.databaseLister(ctx.StackManager, writer),
workflow.databaseLister(ctx.Config.Namespace, ctx.StackManager, writer),
)
}

func (workflow *databaseWorkflow) databaseLister(stackLister common.StackLister, writer io.Writer) Executor {
func (workflow *databaseWorkflow) databaseLister(namespace string, stackLister common.StackLister, writer io.Writer) Executor {

return func() error {
stacks, err := stackLister.ListStacks(common.StackTypeDatabase)
stacks, err := stackLister.ListStacks(common.StackTypeDatabase, namespace)
if err != nil {
return err
}
Expand Down
9 changes: 5 additions & 4 deletions workflows/environment_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package workflows

import (
"fmt"
"github.com/stelligent/mu/common"
"io"

"github.com/stelligent/mu/common"
)

// NewEnvironmentLister create a new workflow for listing environments
Expand All @@ -12,14 +13,14 @@ func NewEnvironmentLister(ctx *common.Context, writer io.Writer) Executor {
workflow := new(environmentWorkflow)

return newPipelineExecutor(
workflow.environmentLister(ctx.StackManager, writer),
workflow.environmentLister(ctx.Config.Namespace, ctx.StackManager, writer),
)
}

func (workflow *environmentWorkflow) environmentLister(stackLister common.StackLister, writer io.Writer) Executor {
func (workflow *environmentWorkflow) environmentLister(namespace string, stackLister common.StackLister, writer io.Writer) Executor {

return func() error {
stacks, err := stackLister.ListStacks(common.StackTypeEnv)
stacks, err := stackLister.ListStacks(common.StackTypeEnv, namespace)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions workflows/environment_terminate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ func NewEnvironmentTerminator(ctx *common.Context, environmentName string) Execu
workflow := new(environmentWorkflow)

return newPipelineExecutor(
workflow.environmentServiceTerminator(environmentName, ctx.StackManager, ctx.StackManager, ctx.StackManager, ctx.RolesetManager),
workflow.environmentDbTerminator(environmentName, ctx.StackManager, ctx.StackManager, ctx.StackManager),
workflow.environmentServiceTerminator(ctx.Config.Namespace, environmentName, ctx.StackManager, ctx.StackManager, ctx.StackManager, ctx.RolesetManager),
workflow.environmentDbTerminator(ctx.Config.Namespace, environmentName, ctx.StackManager, ctx.StackManager, ctx.StackManager),
workflow.environmentEcsTerminator(ctx.Config.Namespace, environmentName, ctx.StackManager, ctx.StackManager),
workflow.environmentRolesetTerminator(ctx.RolesetManager, environmentName),
workflow.environmentElbTerminator(ctx.Config.Namespace, environmentName, ctx.StackManager, ctx.StackManager),
workflow.environmentVpcTerminator(ctx.Config.Namespace, environmentName, ctx.StackManager, ctx.StackManager),
)
}

func (workflow *environmentWorkflow) environmentServiceTerminator(environmentName string, stackLister common.StackLister, stackDeleter common.StackDeleter, stackWaiter common.StackWaiter, rolesetDeleter common.RolesetDeleter) Executor {
func (workflow *environmentWorkflow) environmentServiceTerminator(namespace string, environmentName string, stackLister common.StackLister, stackDeleter common.StackDeleter, stackWaiter common.StackWaiter, rolesetDeleter common.RolesetDeleter) Executor {
return func() error {
log.Noticef("Terminating Services for environment '%s' ...", environmentName)
stacks, err := stackLister.ListStacks(common.StackTypeService)
stacks, err := stackLister.ListStacks(common.StackTypeService, namespace)
if err != nil {
return err
}
Expand All @@ -51,10 +51,10 @@ func (workflow *environmentWorkflow) environmentServiceTerminator(environmentNam
return nil
}
}
func (workflow *environmentWorkflow) environmentDbTerminator(environmentName string, stackLister common.StackLister, stackDeleter common.StackDeleter, stackWaiter common.StackWaiter) Executor {
func (workflow *environmentWorkflow) environmentDbTerminator(namespace string, environmentName string, stackLister common.StackLister, stackDeleter common.StackDeleter, stackWaiter common.StackWaiter) Executor {
return func() error {
log.Noticef("Terminating Databases for environment '%s' ...", environmentName)
stacks, err := stackLister.ListStacks(common.StackTypeDatabase)
stacks, err := stackLister.ListStacks(common.StackTypeDatabase, namespace)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions workflows/environment_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package workflows
import (
"encoding/json"
"fmt"
"io"

"github.com/olekukonko/tablewriter"
"github.com/stelligent/mu/common"
"io"
)

// NewEnvironmentViewer create a new workflow for showing an environment
Expand Down Expand Up @@ -127,7 +128,7 @@ func (workflow *environmentWorkflow) environmentViewerCli(namespace string, envi

fmt.Fprint(writer, NewLine)
fmt.Fprintf(writer, HeadNewlineHeader, Bold(ServicesHeader))
stacks, err := stackLister.ListStacks(common.StackTypeService)
stacks, err := stackLister.ListStacks(common.StackTypeService, namespace)
if err != nil {
return err
}
Expand Down
9 changes: 5 additions & 4 deletions workflows/pipeline_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package workflows

import (
"fmt"
"github.com/stelligent/mu/common"
"io"

"github.com/stelligent/mu/common"
)

// NewPipelineLister create a new workflow for listing environments
Expand All @@ -12,14 +13,14 @@ func NewPipelineLister(ctx *common.Context, writer io.Writer) Executor {
workflow := new(pipelineWorkflow)

return newPipelineExecutor(
workflow.pipelineLister(ctx.StackManager, writer),
workflow.pipelineLister(ctx.Config.Namespace, ctx.StackManager, writer),
)
}

func (workflow *pipelineWorkflow) pipelineLister(stackLister common.StackLister, writer io.Writer) Executor {
func (workflow *pipelineWorkflow) pipelineLister(namespace string, stackLister common.StackLister, writer io.Writer) Executor {

return func() error {
stacks, err := stackLister.ListStacks(common.StackTypePipeline)
stacks, err := stackLister.ListStacks(common.StackTypePipeline, namespace)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions workflows/service_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package workflows

import (
"fmt"
"io"

"github.com/olekukonko/tablewriter"
"github.com/stelligent/mu/common"
"io"
)

// NewServiceViewer create a new workflow for showing an environment
Expand All @@ -21,7 +22,7 @@ func NewServiceViewer(ctx *common.Context, serviceName string, viewTasks bool, w
func (workflow *serviceWorkflow) serviceViewer(namespace string, stackLister common.StackLister, stackGetter common.StackGetter, pipelineStateLister common.PipelineStateLister, taskManager common.TaskManager, config common.Config, viewTasks bool, writer io.Writer) Executor {

return func() error {
stacks, err := stackLister.ListStacks(common.StackTypeService)
stacks, err := stackLister.ListStacks(common.StackTypeService, namespace)
if err != nil {
return err
}
Expand Down

0 comments on commit 2c3b479

Please sign in to comment.