Skip to content

Commit b1569fb

Browse files
authored
Added eks configs (#65)
* Added eks configs * Added eks configs * Added eks configs * Added eks configs * Added helm package * Added route53 cleanup method * Added route53 cleanup method * Added route53 cleanup method * Added route53 cleanup method
1 parent 0312739 commit b1569fb

File tree

3 files changed

+89
-11
lines changed

3 files changed

+89
-11
lines changed

pkg/aws/eks.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func NewEksClientE(t testing.TestingT, region string) (*eks.Client, error) {
9999
}
100100

101101

102-
func NewK8SClientset(cluster *types.Cluster) (*kubernetes.Clientset, error) {
102+
func NewK8SClientConfig(cluster *types.Cluster) (*rest.Config, error) {
103103
gen, err := token.NewGenerator(true, false)
104104
if err != nil {
105105
return nil, err
@@ -115,15 +115,24 @@ func NewK8SClientset(cluster *types.Cluster) (*kubernetes.Clientset, error) {
115115
if err != nil {
116116
return nil, err
117117
}
118-
clientset, err := kubernetes.NewForConfig(
119-
&rest.Config{
120-
Host: *cluster.Endpoint,
121-
BearerToken: tok.Token,
122-
TLSClientConfig: rest.TLSClientConfig{
123-
CAData: ca,
124-
},
118+
119+
return &rest.Config{
120+
Host: *cluster.Endpoint,
121+
BearerToken: tok.Token,
122+
TLSClientConfig: rest.TLSClientConfig{
123+
CAData: ca,
125124
},
126-
)
125+
}, nil
126+
}
127+
128+
129+
func NewK8SClientset(cluster *types.Cluster) (*kubernetes.Clientset, error) {
130+
config, err := NewK8SClientConfig(cluster)
131+
if err != nil {
132+
return nil, err
133+
}
134+
135+
clientset, err := kubernetes.NewForConfig(config)
127136
if err != nil {
128137
return nil, err
129138
}

pkg/aws/route53.go

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import (
77

88
"github.com/aws/aws-sdk-go-v2/service/route53"
99
"github.com/aws/aws-sdk-go-v2/service/route53/types"
10-
"github.com/gruntwork-io/terratest/modules/aws"
10+
awsTerratest "github.com/gruntwork-io/terratest/modules/aws"
11+
12+
"github.com/aws/aws-sdk-go-v2/aws"
1113
)
1214

1315

16+
1417
func GetDNSZoneByNameE(t *testing.T, ctx context.Context, hostName string, awsRegion string) (*types.HostedZone, error) {
1518
if hostName == "" {
1619
return nil, fmt.Errorf("hostName cannot be empty")
@@ -19,7 +22,7 @@ func GetDNSZoneByNameE(t *testing.T, ctx context.Context, hostName string, awsRe
1922
return nil, fmt.Errorf("awsRegion cannot be empty")
2023
}
2124

22-
client, err := aws.NewRoute53ClientE(t, awsRegion)
25+
client, err := awsTerratest.NewRoute53ClientE(t, awsRegion)
2326
if err != nil {
2427
return nil, err
2528
}
@@ -38,3 +41,55 @@ func GetDNSZoneByNameE(t *testing.T, ctx context.Context, hostName string, awsRe
3841
}
3942
return nil, fmt.Errorf("no exact match found for hosted zone %s", hostName)
4043
}
44+
45+
func CleanDNSZoneID(t *testing.T, ctx context.Context, zoneID string, awsRegion string) error {
46+
route53Client, err := awsTerratest.NewRoute53ClientE(t, awsRegion)
47+
if err != nil {
48+
return err
49+
}
50+
51+
o, err := route53Client.ListResourceRecordSets(ctx, &route53.ListResourceRecordSetsInput{
52+
HostedZoneId: &zoneID,
53+
MaxItems: aws.Int32(100),
54+
})
55+
if err != nil {
56+
return err
57+
}
58+
59+
var changes []types.Change
60+
61+
for _, record := range o.ResourceRecordSets {
62+
63+
if record.Type == types.RRTypeNs || record.Type == types.RRTypeSoa {
64+
continue
65+
}
66+
// Build a deletion change for each record
67+
changes = append(changes, types.Change{
68+
Action: types.ChangeActionDelete,
69+
ResourceRecordSet: &record,
70+
})
71+
}
72+
73+
if len(changes) == 0 {
74+
fmt.Println("No deletable records found.")
75+
return nil
76+
}
77+
78+
// Prepare the change batch
79+
changeBatch := &types.ChangeBatch{
80+
Changes: changes,
81+
}
82+
83+
// Call ChangeResourceRecordSets to delete the records
84+
changeInput := &route53.ChangeResourceRecordSetsInput{
85+
HostedZoneId: aws.String(zoneID),
86+
ChangeBatch: changeBatch,
87+
}
88+
89+
_, err = route53Client.ChangeResourceRecordSets(ctx, changeInput)
90+
if err != nil {
91+
return err
92+
}
93+
94+
return nil
95+
}

pkg/helm/metadata.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package helm
2+
3+
type Metadata struct {
4+
AppVersion string `json:"app_version"`
5+
Chart string `json:"chart"`
6+
FirstDeployed float64 `json:"first_deployed"`
7+
LastDeployed float64 `json:"last_deployed"`
8+
Name string `json:"name"`
9+
Namespace string `json:"namespace"`
10+
Notes string `json:"notes"`
11+
Revision int `json:"revision"`
12+
Values string `json:"values"`
13+
Version string `json:"version"`
14+
}

0 commit comments

Comments
 (0)