Skip to content

Commit ffbfcc7

Browse files
CLOUDP-352101: Azure Tagging (#2875)
Move tags to more generic dir add tags to azure resource creators Co-authored-by: Igor Karpukhin <karpukhinigor@gmail.com>
1 parent d98c6f7 commit ffbfcc7

File tree

8 files changed

+59
-34
lines changed

8 files changed

+59
-34
lines changed

test/helper/cloud/aws/vpc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/aws/aws-sdk-go-v2/service/ec2"
2424
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
2525

26-
awshelper "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/api/aws"
26+
taghelper "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper"
2727
)
2828

2929
func CreateVPC(ctx context.Context, name, cidr, region string) (string, error) {
@@ -43,9 +43,9 @@ func CreateVPC(ctx context.Context, name, cidr, region string) (string, error) {
4343
ResourceType: types.ResourceTypeVpc,
4444
Tags: []types.Tag{
4545
{Key: aws.String("Name"), Value: aws.String(name)},
46-
{Key: aws.String(awshelper.OwnerEmailTag), Value: aws.String(awshelper.AKOEmail)},
47-
{Key: aws.String(awshelper.CostCenterTag), Value: aws.String(awshelper.AKOCostCenter)},
48-
{Key: aws.String(awshelper.EnvironmentTag), Value: aws.String(awshelper.AKOEnvTest)},
46+
{Key: aws.String(taghelper.OwnerEmailTag), Value: aws.String(taghelper.AKOEmail)},
47+
{Key: aws.String(taghelper.CostCenterTag), Value: aws.String(taghelper.AKOCostCenter)},
48+
{Key: aws.String(taghelper.EnvironmentTag), Value: aws.String(taghelper.AKOEnvTest)},
4949
},
5050
}},
5151
})

test/helper/cloud/azure/vpc.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2"
2323

2424
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/pointer"
25+
taghelper "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper"
2526
)
2627

2728
func CreateVPC(ctx context.Context, vpcName, cidr, region string) (string, error) {
@@ -45,7 +46,10 @@ func CreateVPC(ctx context.Context, vpcName, cidr, region string) (string, error
4546
},
4647
},
4748
Tags: map[string]*string{
48-
"Name": pointer.MakePtr(vpcName),
49+
"Name": pointer.MakePtr(vpcName),
50+
taghelper.OwnerEmailTag: pointer.MakePtr(taghelper.AKOEmail),
51+
taghelper.CostCenterTag: pointer.MakePtr(taghelper.AKOCostCenter),
52+
taghelper.EnvironmentTag: pointer.MakePtr(taghelper.AKOEnvTest),
4953
},
5054
},
5155
nil,

test/helper/e2e/actions/cloud/aws.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
. "github.com/onsi/gomega"
3636

3737
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/pointer"
38-
awshelper "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/api/aws"
38+
taghelper "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper"
3939
)
4040

4141
type AwsAction struct {
@@ -91,10 +91,10 @@ func (a *AwsAction) CreateKMS(ctx context.Context, alias, region, atlasAccountAr
9191
Origin: kmstypes.OriginTypeAwsKms,
9292
Policy: aws.String(policyString),
9393
Tags: []kmstypes.Tag{
94-
{TagKey: aws.String(awshelper.OwnerTag), TagValue: aws.String(awshelper.AKOTeam)},
95-
{TagKey: aws.String(awshelper.OwnerEmailTag), TagValue: aws.String(awshelper.AKOEmail)},
96-
{TagKey: aws.String(awshelper.CostCenterTag), TagValue: aws.String(awshelper.AKOCostCenter)},
97-
{TagKey: aws.String(awshelper.EnvironmentTag), TagValue: aws.String(awshelper.AKOEnvTest)},
94+
{TagKey: aws.String(taghelper.OwnerTag), TagValue: aws.String(taghelper.AKOTeam)},
95+
{TagKey: aws.String(taghelper.OwnerEmailTag), TagValue: aws.String(taghelper.AKOEmail)},
96+
{TagKey: aws.String(taghelper.CostCenterTag), TagValue: aws.String(taghelper.AKOCostCenter)},
97+
{TagKey: aws.String(taghelper.EnvironmentTag), TagValue: aws.String(taghelper.AKOEnvTest)},
9898
},
9999
})
100100

@@ -406,10 +406,10 @@ func (a *AwsAction) createVPC(ctx context.Context, name, cidr, region string) (s
406406
ResourceType: ec2types.ResourceTypeVpc,
407407
Tags: []ec2types.Tag{
408408
{Key: aws.String("Name"), Value: aws.String(name)},
409-
{Key: aws.String(awshelper.OwnerTag), Value: aws.String(awshelper.AKOTeam)},
410-
{Key: aws.String(awshelper.OwnerEmailTag), Value: aws.String(awshelper.AKOEmail)},
411-
{Key: aws.String(awshelper.CostCenterTag), Value: aws.String(awshelper.AKOCostCenter)},
412-
{Key: aws.String(awshelper.EnvironmentTag), Value: aws.String(awshelper.AKOEnvTest)},
409+
{Key: aws.String(taghelper.OwnerTag), Value: aws.String(taghelper.AKOTeam)},
410+
{Key: aws.String(taghelper.OwnerEmailTag), Value: aws.String(taghelper.AKOEmail)},
411+
{Key: aws.String(taghelper.CostCenterTag), Value: aws.String(taghelper.AKOCostCenter)},
412+
{Key: aws.String(taghelper.EnvironmentTag), Value: aws.String(taghelper.AKOEnvTest)},
413413
},
414414
}},
415415
}
@@ -486,10 +486,10 @@ func (a *AwsAction) createSubnet(ctx context.Context, vpcID, name, cidr, region,
486486
ResourceType: ec2types.ResourceTypeSubnet,
487487
Tags: []ec2types.Tag{
488488
{Key: aws.String("Name"), Value: aws.String(name)},
489-
{Key: aws.String(awshelper.OwnerTag), Value: aws.String(awshelper.AKOTeam)},
490-
{Key: aws.String(awshelper.OwnerEmailTag), Value: aws.String(awshelper.AKOEmail)},
491-
{Key: aws.String(awshelper.CostCenterTag), Value: aws.String(awshelper.AKOCostCenter)},
492-
{Key: aws.String(awshelper.EnvironmentTag), Value: aws.String(awshelper.AKOEnvTest)},
489+
{Key: aws.String(taghelper.OwnerTag), Value: aws.String(taghelper.AKOTeam)},
490+
{Key: aws.String(taghelper.OwnerEmailTag), Value: aws.String(taghelper.AKOEmail)},
491+
{Key: aws.String(taghelper.CostCenterTag), Value: aws.String(taghelper.AKOCostCenter)},
492+
{Key: aws.String(taghelper.EnvironmentTag), Value: aws.String(taghelper.AKOEnvTest)},
493493
},
494494
}},
495495
VpcId: aws.String(vpcID),

test/helper/e2e/actions/cloud/azure.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/onsi/ginkgo/v2/dsl/core"
2727

2828
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/pointer"
29+
taghelper "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper"
2930
)
3031

3132
const (
@@ -141,6 +142,11 @@ func (a *AzureAction) CreatePrivateEndpoint(vpcName, subnetName, endpointName, s
141142
},
142143
},
143144
},
145+
Tags: map[string]*string{
146+
taghelper.OwnerEmailTag: pointer.MakePtr(taghelper.AKOEmail),
147+
taghelper.CostCenterTag: pointer.MakePtr(taghelper.AKOCostCenter),
148+
taghelper.EnvironmentTag: pointer.MakePtr(taghelper.AKOEnvTest),
149+
},
144150
},
145151
nil,
146152
)
@@ -246,7 +252,10 @@ func (a *AzureAction) createVpcWithSubnets(ctx context.Context, vpcName, cidr, r
246252
Subnets: subnetsSpec,
247253
},
248254
Tags: map[string]*string{
249-
"Name": pointer.MakePtr(vpcName),
255+
"Name": pointer.MakePtr(vpcName),
256+
taghelper.OwnerEmailTag: pointer.MakePtr(taghelper.AKOEmail),
257+
taghelper.CostCenterTag: pointer.MakePtr(taghelper.AKOCostCenter),
258+
taghelper.EnvironmentTag: pointer.MakePtr(taghelper.AKOEnvTest),
250259
},
251260
},
252261
nil,
@@ -421,6 +430,11 @@ func (a *AzureAction) CreateKeyVault(keyName string) (string, error) {
421430
Properties: &armkeyvault.KeyProperties{
422431
Kty: pointer.MakePtr(armkeyvault.JSONWebKeyTypeRSA),
423432
},
433+
Tags: map[string]*string{
434+
taghelper.OwnerEmailTag: pointer.MakePtr(taghelper.AKOEmail),
435+
taghelper.CostCenterTag: pointer.MakePtr(taghelper.AKOCostCenter),
436+
taghelper.EnvironmentTag: pointer.MakePtr(taghelper.AKOEnvTest),
437+
},
424438
}
425439

426440
r, err := a.keyVaultResourceFactory.NewKeysClient().CreateIfNotExist(ctx, a.resourceGroupName, AzureKeyVaultName, keyName, params, nil)

test/helper/e2e/actions/cloudaccess/aws_roles.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/aws/aws-sdk-go-v2/service/iam"
2626
"github.com/aws/aws-sdk-go-v2/service/iam/types"
2727

28-
awshelper "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/api/aws"
28+
taghelper "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper"
2929
)
3030

3131
type AssumeRolePolicyDocument struct {
@@ -113,10 +113,10 @@ func CreateAWSIAMRole(ctx context.Context, roleName string) (string, error) {
113113
AssumeRolePolicyDocument: &policy,
114114
}
115115
roleInput.Tags = []types.Tag{
116-
{Key: aws.String(awshelper.OwnerTag), Value: aws.String(awshelper.AKOTeam)},
117-
{Key: aws.String(awshelper.OwnerEmailTag), Value: aws.String(awshelper.AKOEmail)},
118-
{Key: aws.String(awshelper.CostCenterTag), Value: aws.String(awshelper.AKOCostCenter)},
119-
{Key: aws.String(awshelper.EnvironmentTag), Value: aws.String(awshelper.AKOEnvTest)},
116+
{Key: aws.String(taghelper.OwnerTag), Value: aws.String(taghelper.AKOTeam)},
117+
{Key: aws.String(taghelper.OwnerEmailTag), Value: aws.String(taghelper.AKOEmail)},
118+
{Key: aws.String(taghelper.CostCenterTag), Value: aws.String(taghelper.AKOCostCenter)},
119+
{Key: aws.String(taghelper.EnvironmentTag), Value: aws.String(taghelper.AKOEnvTest)},
120120
}
121121
role, err := IAMClient.CreateRole(ctx, &roleInput)
122122
if err != nil {

test/helper/e2e/api/aws/aws_resources_generator.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"github.com/aws/aws-sdk-go-v2/service/s3"
2727
s3types "github.com/aws/aws-sdk-go-v2/service/s3/types"
2828
"github.com/onsi/ginkgo/v2"
29+
30+
taghelper "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper"
2931
)
3032

3133
type AwsResourcesGenerator struct {
@@ -108,10 +110,10 @@ func (g *AwsResourcesGenerator) CreatePolicy(ctx context.Context, name string, p
108110
PolicyDocument: policy(),
109111
PolicyName: aws.String(name),
110112
Tags: []iamtypes.Tag{
111-
{Key: aws.String(OwnerTag), Value: aws.String(AKOTeam)},
112-
{Key: aws.String(OwnerEmailTag), Value: aws.String(AKOEmail)},
113-
{Key: aws.String(CostCenterTag), Value: aws.String(AKOCostCenter)},
114-
{Key: aws.String(EnvironmentTag), Value: aws.String(AKOEnvTest)},
113+
{Key: aws.String(taghelper.OwnerTag), Value: aws.String(taghelper.AKOTeam)},
114+
{Key: aws.String(taghelper.OwnerEmailTag), Value: aws.String(taghelper.AKOEmail)},
115+
{Key: aws.String(taghelper.CostCenterTag), Value: aws.String(taghelper.AKOCostCenter)},
116+
{Key: aws.String(taghelper.EnvironmentTag), Value: aws.String(taghelper.AKOEnvTest)},
115117
},
116118
}
117119

@@ -194,10 +196,10 @@ func (g *AwsResourcesGenerator) CreateBucket(ctx context.Context, name string) e
194196

195197
tagSet := &s3types.Tagging{
196198
TagSet: []s3types.Tag{
197-
{Key: aws.String(OwnerTag), Value: aws.String(AKOTeam)},
198-
{Key: aws.String(OwnerEmailTag), Value: aws.String(AKOEmail)},
199-
{Key: aws.String(CostCenterTag), Value: aws.String(AKOCostCenter)},
200-
{Key: aws.String(EnvironmentTag), Value: aws.String(AKOEnvTest)},
199+
{Key: aws.String(taghelper.OwnerTag), Value: aws.String(taghelper.AKOTeam)},
200+
{Key: aws.String(taghelper.OwnerEmailTag), Value: aws.String(taghelper.AKOEmail)},
201+
{Key: aws.String(taghelper.CostCenterTag), Value: aws.String(taghelper.AKOCostCenter)},
202+
{Key: aws.String(taghelper.EnvironmentTag), Value: aws.String(taghelper.AKOEnvTest)},
201203
},
202204
}
203205

test/helper/e2e/api/azure/azure.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"github.com/Azure/go-autorest/autorest/azure/auth"
2727
"github.com/Azure/go-autorest/autorest/to"
2828

29+
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/pointer"
30+
taghelper "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper"
2931
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/config"
3032
)
3133

@@ -63,8 +65,11 @@ func SessionAzure(subscriptionID string, tagNameValue string) (sessionAzure, err
6365
SubscriptionID: subscriptionID,
6466
Authorizer: authorizer,
6567
Tags: map[string]*string{
66-
"name": to.StringPtr(tagNameValue),
67-
config.TagForTestKey: to.StringPtr(config.TagForTestValue),
68+
"name": to.StringPtr(tagNameValue),
69+
config.TagForTestKey: to.StringPtr(config.TagForTestValue),
70+
taghelper.OwnerEmailTag: pointer.MakePtr(taghelper.AKOEmail),
71+
taghelper.CostCenterTag: pointer.MakePtr(taghelper.AKOCostCenter),
72+
taghelper.EnvironmentTag: pointer.MakePtr(taghelper.AKOEnvTest),
6873
},
6974
}, nil
7075
}
File renamed without changes.

0 commit comments

Comments
 (0)