Skip to content

Commit

Permalink
Add tag outputs for the EFSFileSystem, EKSCluster, EKSNodegroup and E…
Browse files Browse the repository at this point in the history
…SDomain resources (rebuy-de#727)

* add property for EKSCluster tags

* add property for ESDomain tags

* fix property for ESDomain tags

* add property for EFS tags

* add property for Nodegroup tags

* fix property for Nodegroup tags

* fix merge conflict for eks-nodegroups

Co-authored-by: y509319 <y509319>
  • Loading branch information
y509319 authored and mrkenkeller committed Feb 26, 2022
1 parent a9db7f2 commit 7802ee7
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 10 deletions.
27 changes: 21 additions & 6 deletions resources/efs-filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package resources
import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/efs"
"github.com/rebuy-de/aws-nuke/pkg/types"
)

type EFSFileSystem struct {
svc *efs.EFS
id string
name string
svc *efs.EFS
id string
name string
tagList []*efs.Tag
}

func init() {
Expand All @@ -25,10 +27,15 @@ func ListEFSFileSystems(sess *session.Session) ([]Resource, error) {

resources := make([]Resource, 0)
for _, fs := range resp.FileSystems {
lto, err := svc.ListTagsForResource(&efs.ListTagsForResourceInput{ResourceId: fs.FileSystemId})
if err != nil {
return nil, err
}
resources = append(resources, &EFSFileSystem{
svc: svc,
id: *fs.FileSystemId,
name: *fs.CreationToken,
svc: svc,
id: *fs.FileSystemId,
name: *fs.CreationToken,
tagList: lto.Tags,
})

}
Expand All @@ -44,6 +51,14 @@ func (e *EFSFileSystem) Remove() error {
return err
}

func (e *EFSFileSystem) Properties() types.Properties {
properties := types.NewProperties()
for _, t := range e.tagList {
properties.SetTag(t.Key, t.Value)
}
return properties
}

func (e *EFSFileSystem) String() string {
return e.name
}
26 changes: 22 additions & 4 deletions resources/eks-clusters.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package resources

import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/eks"
"github.com/rebuy-de/aws-nuke/pkg/types"
)

type EKSCluster struct {
svc *eks.EKS
name *string
svc *eks.EKS
name *string
cluster *eks.Cluster
}

func init() {
Expand All @@ -30,9 +34,14 @@ func ListEKSClusters(sess *session.Session) ([]Resource, error) {
}

for _, cluster := range resp.Clusters {
dcResp, err := svc.DescribeCluster(&eks.DescribeClusterInput{Name: cluster})
if err != nil {
return nil, err
}
resources = append(resources, &EKSCluster{
svc: svc,
name: cluster,
svc: svc,
name: cluster,
cluster: dcResp.Cluster,
})
}
if resp.NextToken == nil {
Expand All @@ -53,6 +62,15 @@ func (f *EKSCluster) Remove() error {
return err
}

func (f *EKSCluster) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("CreatedAt", f.cluster.CreatedAt.Format(time.RFC3339))
for key, value := range f.cluster.Tags {
properties.SetTag(&key, value)
}
return properties
}

func (f *EKSCluster) String() string {
return *f.name
}
3 changes: 3 additions & 0 deletions resources/eks-nodegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ func (ng *EKSNodegroup) Properties() types.Properties {
if ng.nodegroup.CreatedAt != nil {
properties.Set("CreatedAt", ng.nodegroup.CreatedAt.Format(time.RFC3339))
}
for k, v := range ng.nodegroup.Tags {
properties.SetTag(&k, v)
}
return properties
}

Expand Down
20 changes: 20 additions & 0 deletions resources/elasticsearchservice-domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package resources
import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/elasticsearchservice"
"github.com/rebuy-de/aws-nuke/pkg/types"
)

type ESDomain struct {
svc *elasticsearchservice.ElasticsearchService
domainName *string
tagList []*elasticsearchservice.Tag
}

func init() {
Expand All @@ -25,9 +27,19 @@ func ListESDomains(sess *session.Session) ([]Resource, error) {

resources := make([]Resource, 0)
for _, domain := range resp.DomainNames {
dedo, err := svc.DescribeElasticsearchDomain(
&elasticsearchservice.DescribeElasticsearchDomainInput{DomainName: domain.DomainName})
if err != nil {
return nil, err
}
lto, err := svc.ListTags(&elasticsearchservice.ListTagsInput{ARN: dedo.DomainStatus.ARN})
if err != nil {
return nil, err
}
resources = append(resources, &ESDomain{
svc: svc,
domainName: domain.DomainName,
tagList: lto.TagList,
})
}

Expand All @@ -43,6 +55,14 @@ func (f *ESDomain) Remove() error {
return err
}

func (f *ESDomain) Properties() types.Properties {
properties := types.NewProperties()
for _, t := range f.tagList {
properties.SetTag(t.Key, t.Value)
}
return properties
}

func (f *ESDomain) String() string {
return *f.domainName
}

0 comments on commit 7802ee7

Please sign in to comment.