Skip to content

Commit

Permalink
added eks fargate profile resource (#469)
Browse files Browse the repository at this point in the history
* added eks fargate profile resource
  • Loading branch information
jami committed Feb 10, 2020
1 parent ae134bc commit 38b4ff9
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions resources/eks-fargate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package resources

import (
"fmt"

"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 EKSFargateProfile struct {
svc *eks.EKS
cluster *string
name *string
}

func init() {
register("EKSFargateProfiles", ListEKSFargateProfiles)
}

func ListEKSFargateProfiles(sess *session.Session) ([]Resource, error) {
svc := eks.New(sess)
clusterNames := []*string{}
resources := []Resource{}

clusterInputParams := &eks.ListClustersInput{
MaxResults: aws.Int64(100),
}

// fetch all cluster names
for {
resp, err := svc.ListClusters(clusterInputParams)
if err != nil {
return nil, err
}

for _, cluster := range resp.Clusters {
clusterNames = append(clusterNames, cluster)
}

if resp.NextToken == nil {
break
}

clusterInputParams.NextToken = resp.NextToken
}

fargateInputParams := &eks.ListFargateProfilesInput{
MaxResults: aws.Int64(100),
}

// fetch the associated eks fargate profiles
for _, clusterName := range clusterNames {
fargateInputParams.ClusterName = clusterName

for {
resp, err := svc.ListFargateProfiles(fargateInputParams)
if err != nil {
return nil, err
}

for _, name := range resp.FargateProfileNames {
resources = append(resources, &EKSFargateProfile{
svc: svc,
name: name,
cluster: clusterName,
})
}

if resp.NextToken == nil {
fargateInputParams.NextToken = nil
break
}

fargateInputParams.NextToken = resp.NextToken
}

}

return resources, nil
}

func (fp *EKSFargateProfile) Remove() error {
_, err := fp.svc.DeleteFargateProfile(&eks.DeleteFargateProfileInput{
ClusterName: fp.cluster,
FargateProfileName: fp.name,
})
return err
}

func (fp *EKSFargateProfile) Properties() types.Properties {
return types.NewProperties().
Set("Cluster", *fp.cluster).
Set("Profile", *fp.name)
}

func (fp *EKSFargateProfile) String() string {
return fmt.Sprintf("%s:%s", *fp.cluster, *fp.name)
}

0 comments on commit 38b4ff9

Please sign in to comment.