Skip to content

Commit

Permalink
updating reference to tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ina-stoyanova committed Oct 7, 2020
1 parent 3cbc1a6 commit 7e3b907
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions aws/ecs_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ func getAllEcsClustersOlderThan(awsSession *session.Session, region string, excl
var filteredEcsClusters []*string
for _, clusterArn := range clusterArns {

firstSeenTime, err := getClusterTag(awsSession, clusterArn, "first_seen")
firstSeenTime, err := getClusterTag(awsSession, clusterArn, firstSeenTagKey)
if err != nil {
logging.Logger.Errorf("Error getting the `first_seen` tag for ECS cluster with ARN %s", *clusterArn)
return nil, err
}

if firstSeenTime.IsZero() {
err := tagEcsCluster(awsSession, clusterArn, "first_seen", time.Now().UTC().String())
err := tagEcsCluster(awsSession, clusterArn, firstSeenTagKey, time.Now().UTC().String())
if err != nil {
logging.Logger.Errorf("Error tagigng the ECS cluster with ARN %s", *clusterArn)
return nil, err
Expand Down Expand Up @@ -97,7 +97,7 @@ func nukeEcsClusters(awsSession *session.Session, ecsClusterArns []*string) erro
}

numNuked := len(nukedEcsClusters)
logging.Logger.Infof("[OK] %d of %d ECS service(s) deleted in %s", numNuked, numNuking, *awsSession.Config.Region)
logging.Logger.Infof("[OK] %d of %d ECS cluster(s) deleted in %s", numNuked, numNuking, *awsSession.Config.Region)

return nil
}
Expand Down
16 changes: 7 additions & 9 deletions aws/ecs_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/require"
)

const tagKey = "first_seen"
const region = "eu-west-1"

// Test we can create a cluster, tag it, and then find the tag
Expand All @@ -28,10 +27,10 @@ func TestCanTagEcsClusters(t *testing.T) {

tagValue := time.Now().UTC().Format(time.RFC3339)

tagEcsCluster(awsSession, cluster.ClusterArn, tagKey, tagValue)
tagEcsCluster(awsSession, cluster.ClusterArn, firstSeenTagKey, tagValue)
require.NoError(t, err)

returnedTag, err := getClusterTag(awsSession, cluster.ClusterArn, tagKey)
returnedTag, err := getClusterTag(awsSession, cluster.ClusterArn, firstSeenTagKey)
require.NoError(t, err)

assert.Equal(t, returnedTag.Format(time.RFC3339), tagValue)
Expand All @@ -41,7 +40,6 @@ func TestCanTagEcsClusters(t *testing.T) {
func TestCanListAllEcsClustersOlderThan24hours(t *testing.T) {
t.Parallel()

region := "eu-west-1"
awsSession, err := session.NewSession(&awsgo.Config{
Region: awsgo.String(region),
})
Expand All @@ -56,8 +54,8 @@ func TestCanListAllEcsClustersOlderThan24hours(t *testing.T) {
var olderClusterTagValue = now.Add(time.Hour * time.Duration(-48)).Format(time.RFC3339)
var youngerClusterTagValue = now.Add(time.Hour * time.Duration(-23)).Format(time.RFC3339)

tagEcsCluster(awsSession, cluster1.ClusterArn, tagKey, olderClusterTagValue)
tagEcsCluster(awsSession, cluster2.ClusterArn, tagKey, youngerClusterTagValue)
tagEcsCluster(awsSession, cluster1.ClusterArn, firstSeenTagKey, olderClusterTagValue)
tagEcsCluster(awsSession, cluster2.ClusterArn, firstSeenTagKey, youngerClusterTagValue)
require.NoError(t, err)

last24Hours := now.Add(time.Hour * time.Duration(-24))
Expand Down Expand Up @@ -88,9 +86,9 @@ func TestCanNukeAllEcsClustersOlderThan24Hours(t *testing.T) {
var youngClusterTagValue = now.Format(time.RFC3339)
var oldClusterTagValue2 = now.Add(time.Hour * time.Duration(-27)).Format(time.RFC3339)

tagEcsCluster(awsSession, cluster1.ClusterArn, tagKey, oldClusterTagValue1)
tagEcsCluster(awsSession, cluster2.ClusterArn, tagKey, youngClusterTagValue)
tagEcsCluster(awsSession, cluster3.ClusterArn, tagKey, oldClusterTagValue2)
tagEcsCluster(awsSession, cluster1.ClusterArn, firstSeenTagKey, oldClusterTagValue1)
tagEcsCluster(awsSession, cluster2.ClusterArn, firstSeenTagKey, youngClusterTagValue)
tagEcsCluster(awsSession, cluster3.ClusterArn, firstSeenTagKey, oldClusterTagValue2)
require.NoError(t, err)

last24Hours := now.Add(time.Hour * time.Duration(-24))
Expand Down

0 comments on commit 7e3b907

Please sign in to comment.