Skip to content

Commit

Permalink
feat(eks-fargate-profile): tag support
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Sep 30, 2024
1 parent 2e3e61f commit 8b95ddd
Showing 2 changed files with 49 additions and 16 deletions.
45 changes: 29 additions & 16 deletions resources/eks-fargate.go → resources/eks-fargate-profile.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ package resources

import (
"context"
"github.com/sirupsen/logrus"
"time"

"fmt"

@@ -71,10 +73,21 @@ func (l *EKSFargateProfileLister) List(_ context.Context, o interface{}) ([]reso
}

for _, name := range resp.FargateProfileNames {
profResp, err := svc.DescribeFargateProfile(&eks.DescribeFargateProfileInput{
ClusterName: clusterName,
FargateProfileName: name,
})
if err != nil {
logrus.WithError(err).Error("unable to describe fargate profile")
continue
}

resources = append(resources, &EKSFargateProfile{
svc: svc,
name: name,
cluster: clusterName,
svc: svc,
Name: name,
Cluster: clusterName,
CreatedAt: profResp.FargateProfile.CreatedAt,
Tags: profResp.FargateProfile.Tags,
})
}

@@ -91,25 +104,25 @@ func (l *EKSFargateProfileLister) List(_ context.Context, o interface{}) ([]reso
}

type EKSFargateProfile struct {
svc *eks.EKS
cluster *string
name *string
svc *eks.EKS
Cluster *string
Name *string
CreatedAt *time.Time
Tags map[string]*string
}

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

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

func (fp *EKSFargateProfile) String() string {
return fmt.Sprintf("%s:%s", *fp.cluster, *fp.name)
func (r *EKSFargateProfile) String() string {
return fmt.Sprintf("%s:%s", *r.Cluster, *r.Name)
}
20 changes: 20 additions & 0 deletions resources/eks-fargate-profile_mock_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package resources

import (
"github.com/gotidy/ptr"
"github.com/stretchr/testify/assert"
"testing"
)

func TestEKSFargateProperties(t *testing.T) {
resource := &EKSFargateProfile{
Cluster: ptr.String("test-id"),
Name: ptr.String("test-name"),
}

properties := resource.Properties()

assert.Equal(t, "test-id", properties.Get("Cluster"))
assert.Equal(t, "test-name", properties.Get("Name"))
assert.Equal(t, "test-id:test-name", resource.String())
}

0 comments on commit 8b95ddd

Please sign in to comment.