Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOUDP-188104: Deployment Resource Tagging #1041

Merged
merged 68 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
5ae5085
Resource tagging feature for deployment added without limitations and…
cveticm Jul 10, 2023
cdf940b
Adding support for tagging Serverless instance and applying key-value…
cveticm Jul 17, 2023
02e5f05
Adding updating for serverless and minor changes to comments
cveticm Jul 18, 2023
173db4d
Adding resource tagging for deployment tests and removing tags from e…
cveticm Jul 18, 2023
50fc804
cleaning comments
cveticm Jul 18, 2023
c7f1296
Update atlasdeployment_controller.go
cveticm Jul 18, 2023
a632a79
fix for test
cveticm Jul 24, 2023
89caf44
Resolving merge conflict by taking local solution
cveticm Jul 24, 2023
6bf8b41
Fix
cveticm Jul 24, 2023
d47a04e
Test issue
cveticm Jul 25, 2023
61122f7
Partial test fixes
cveticm Jul 26, 2023
81a49f6
Test fixes
cveticm Jul 26, 2023
eb513dc
Test fixes
cveticm Jul 27, 2023
d5416e6
Test fixes
cveticm Jul 27, 2023
0e87a28
Fix tests to work with new serverless tag type
cveticm Jul 27, 2023
95655f1
Fix tests to work with new serverless tag type
cveticm Jul 27, 2023
84b9819
Fix
cveticm Jul 27, 2023
2bf27bb
Updating dependencies
cveticm Jul 28, 2023
74eb6cd
Changing variable name due to dependency change
cveticm Jul 28, 2023
bdf2804
Merge branch 'CLOUDP-188104/deployment-resource-tagging' of https://g…
cveticm Jul 28, 2023
1f5a3d4
Merge branch 'main' into CLOUDP-188104/deployment-resource-tagging
cveticm Jul 28, 2023
13afe65
Fix
cveticm Jul 28, 2023
a8d854c
Testing for fix
cveticm Jul 28, 2023
5c8ee25
Testing for fix
cveticm Jul 28, 2023
eccabb9
Testing for fix
cveticm Jul 28, 2023
9dd3fa8
Testing for fix
cveticm Jul 28, 2023
a841ff6
Testing for fix
cveticm Jul 28, 2023
5918e97
Testing for fix
cveticm Jul 28, 2023
bab073d
Testing for fixes
cveticm Jul 30, 2023
d89ffb4
Testing for fixes
cveticm Jul 30, 2023
281cd4f
Testing fixes
cveticm Jul 31, 2023
dae759d
Testing fixes
cveticm Jul 31, 2023
e3bc2f3
Testing fixes
cveticm Jul 31, 2023
8d64bab
Testing fixes
cveticm Jul 31, 2023
e6c5c6d
Testing fixes
cveticm Jul 31, 2023
ae29cb5
Testing fixes
cveticm Jul 31, 2023
98cd3a3
Testing fixes
cveticm Jul 31, 2023
4ccb7f5
Testing fixes
cveticm Jul 31, 2023
052eb95
Testing fixes
igor-karpukhin Jul 31, 2023
54a35f0
Testing fixes
igor-karpukhin Jul 31, 2023
d2fd07d
Testing for fixes
cveticm Jul 31, 2023
3bd7041
Testing for fixes
cveticm Jul 31, 2023
3be95ac
Testing for fixes
cveticm Jul 31, 2023
f361a0b
Testing for fixes
cveticm Jul 31, 2023
eab0d74
Fix
cveticm Jul 31, 2023
ea8088a
Fix
cveticm Jul 31, 2023
0755ab1
Fix
cveticm Jul 31, 2023
72155fc
Fix
cveticm Jul 31, 2023
7fd9a19
Fix
cveticm Jul 31, 2023
1444e58
Fixes from review
cveticm Aug 2, 2023
09f1af6
Improved tag testing and isEqual edited and renamed to isTagsEqual
cveticm Aug 4, 2023
490cdfa
Fix
cveticm Aug 4, 2023
edf4e23
Merge branch 'main' into CLOUDP-188104/deployment-resource-tagging
cveticm Aug 8, 2023
22a452e
Removing comment
cveticm Aug 8, 2023
a0b34f5
Fix
cveticm Aug 8, 2023
c8b4266
Merge branch 'CLOUDP-188104/deployment-resource-tagging' of https://g…
cveticm Aug 10, 2023
ffe7705
CLOUDP-153003: Encryption at Rest Tests for GCP & Azure (#1035)
roothorp Aug 9, 2023
00050f2
Fixed missing CRD changes for EaR secret refs (#1076)
igor-karpukhin Aug 9, 2023
32cb2b7
Manually bump Atlas client to version 0.32 (#1077)
josvazg Aug 9, 2023
05aa2d3
Release 1.8.1 (#1078)
github-actions[bot] Aug 9, 2023
0ca9968
Merge branch 'main' into CLOUDP-188104/deployment-resource-tagging
cveticm Aug 10, 2023
382ed43
Fix renamed fields of CPA client (#1079)
helderjs Aug 10, 2023
f58fe9e
Fix Auditing comparison to avoid reconcile in every loop (#1081)
helderjs Aug 11, 2023
96a9914
Merge fix
cveticm Aug 11, 2023
57e14f0
Fix on uniqueKey
cveticm Aug 11, 2023
a6f0793
Fix
cveticm Aug 14, 2023
c73a8bd
Merge branch 'main' into CLOUDP-188104/deployment-resource-tagging
cveticm Aug 23, 2023
4420410
Fix lint error
cveticm Aug 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions config/crd/bases/atlas.mongodb.com_atlasdeployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,28 @@ spec:
type: array
rootCertType:
type: string
tags:
description: Key-value pairs for resource tagging.
items:
description: TagSpec holds a key-value pair for resource tagging
on this deployment.
properties:
key:
maxLength: 255
minLength: 1
pattern: ^[a-zA-Z0-9][a-zA-Z0-9 @_.+`;`-]*$
type: string
value:
maxLength: 255
minLength: 1
pattern: ^[a-zA-Z0-9][a-zA-Z0-9@_.+`;`-]*$
type: string
required:
- key
- value
type: object
maxItems: 50
type: array
versionReleaseSystem:
type: string
type: object
Expand Down Expand Up @@ -574,6 +596,28 @@ spec:
type: string
type: object
type: array
tags:
description: Key-value pairs for resource tagging.
items:
description: TagSpec holds a key-value pair for resource tagging
on this deployment.
properties:
key:
maxLength: 255
minLength: 1
pattern: ^[a-zA-Z0-9][a-zA-Z0-9 @_.+`;`-]*$
type: string
value:
maxLength: 255
minLength: 1
pattern: ^[a-zA-Z0-9][a-zA-Z0-9@_.+`;`-]*$
type: string
required:
- key
- value
type: object
maxItems: 50
type: array
required:
- name
- providerSettings
Expand Down Expand Up @@ -747,6 +791,28 @@ spec:
required:
- providerName
type: object
tags:
description: Key-value pairs for resource tagging.
items:
description: TagSpec holds a key-value pair for resource tagging
on this deployment.
properties:
key:
maxLength: 255
minLength: 1
pattern: ^[a-zA-Z0-9][a-zA-Z0-9 @_.+`;`-]*$
type: string
value:
maxLength: 255
minLength: 1
pattern: ^[a-zA-Z0-9][a-zA-Z0-9@_.+`;`-]*$
type: string
required:
- key
- value
type: object
maxItems: 50
type: array
required:
- name
- providerSettings
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/pborman/uuid v1.2.1
github.com/sethvargo/go-password v0.2.0
github.com/stretchr/testify v1.8.4
go.mongodb.org/atlas v0.31.0
go.mongodb.org/atlas v0.32.0
cveticm marked this conversation as resolved.
Show resolved Hide resolved
go.mongodb.org/mongo-driver v1.12.0
go.uber.org/zap v1.24.0
golang.org/x/sync v0.3.0
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU=
github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
Expand Down Expand Up @@ -393,8 +394,8 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.mongodb.org/atlas v0.31.0 h1:NgLqsNYm6wDYeDUO90etw1sl8T1U2DUKu36eUdnrFSI=
go.mongodb.org/atlas v0.31.0/go.mod h1:L4BKwVx/OeEhOVjCSdgo90KJm4469iv7ZLzQms/EPTg=
go.mongodb.org/atlas v0.32.0 h1:6uHwus8Bz+h1Ax75Pf3qo3kWCwnaUYav+SxSMU2RGiQ=
go.mongodb.org/atlas v0.32.0/go.mod h1:L4BKwVx/OeEhOVjCSdgo90KJm4469iv7ZLzQms/EPTg=
go.mongodb.org/mongo-driver v1.12.0 h1:aPx33jmn/rQuJXPQLZQ8NtfPQG8CaqgLThFtqRb0PiE=
go.mongodb.org/mongo-driver v1.12.0/go.mod h1:AZkxhPnFJUoH7kZlFkVKucV20K387miPfm7oimrSmK0=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
Expand Down
47 changes: 39 additions & 8 deletions pkg/api/v1/atlasdeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ type DeploymentSpec struct {
// +kubebuilder:validation:Pattern:=^[a-zA-Z0-9][a-zA-Z0-9-]*$
Name string `json:"name"`

// Key-value pairs for resource tagging.
// +kubebuilder:validation:MaxItems=50
// +optional
Tags []*TagSpec `json:"tags,omitempty"`

// Positive integer that specifies the number of shards to deploy for a sharded deployment.
// The parameter is required if replicationSpecs are configured
// +kubebuilder:validation:Minimum=1
Expand Down Expand Up @@ -163,12 +168,16 @@ type AdvancedDeploymentSpec struct {
// After Atlas creates the deployment, you can't change its name.
// Can only contain ASCII letters, numbers, and hyphens.
// +kubebuilder:validation:Pattern:=^[a-zA-Z0-9][a-zA-Z0-9-]*$
Name string `json:"name,omitempty"`
Paused *bool `json:"paused,omitempty"`
PitEnabled *bool `json:"pitEnabled,omitempty"`
ReplicationSpecs []*AdvancedReplicationSpec `json:"replicationSpecs,omitempty"`
RootCertType string `json:"rootCertType,omitempty"`
VersionReleaseSystem string `json:"versionReleaseSystem,omitempty"`
Name string `json:"name,omitempty"`
Paused *bool `json:"paused,omitempty"`
PitEnabled *bool `json:"pitEnabled,omitempty"`
ReplicationSpecs []*AdvancedReplicationSpec `json:"replicationSpecs,omitempty"`
RootCertType string `json:"rootCertType,omitempty"`
// Key-value pairs for resource tagging.
// +kubebuilder:validation:MaxItems=50
// +optional
Tags []*TagSpec `json:"tags,omitempty"`
VersionReleaseSystem string `json:"versionReleaseSystem,omitempty"`
// +optional
CustomZoneMapping []CustomZoneMapping `json:"customZoneMapping,omitempty"`
// +optional
Expand Down Expand Up @@ -205,9 +214,19 @@ type ServerlessSpec struct {
// +kubebuilder:validation:Pattern:=^[a-zA-Z0-9][a-zA-Z0-9-]*$
Name string `json:"name"`
// Configuration for the provisioned hosts on which MongoDB runs. The available options are specific to the cloud service provider.
ProviderSettings *ProviderSettingsSpec `json:"providerSettings"`

ProviderSettings *ProviderSettingsSpec `json:"providerSettings"`
PrivateEndpoints []ServerlessPrivateEndpoint `json:"privateEndpoints,omitempty"`
// Key-value pairs for resource tagging.
// +kubebuilder:validation:MaxItems=50
// +optional
Tags []*TagSpec `json:"tags,omitempty"`
}

// ServerlessToAtlas converts the ServerlessSpec to native Atlas client Cluster format.
func (s *ServerlessSpec) ServerlessToAtlas() (*mongodbatlas.Cluster, error) {
result := &mongodbatlas.Cluster{}
err := compat.JSONCopy(result, s)
return result, err
josvazg marked this conversation as resolved.
Show resolved Hide resolved
}

// BiConnector specifies BI Connector for Atlas configuration on this deployment.
Expand All @@ -216,6 +235,18 @@ type BiConnector struct {
ReadPreference string `json:"readPreference,omitempty"`
}

// TagSpec holds a key-value pair for resource tagging on this deployment.
type TagSpec struct {
// +kubebuilder:validation:MaxLength:=255
// +kubebuilder:validation:MinLength:=1
// +kubebuilder:validation:Pattern:=^[a-zA-Z0-9][a-zA-Z0-9 @_.+`;`-]*$
Key string `json:"key"`
// +kubebuilder:validation:MaxLength:=255
// +kubebuilder:validation:MinLength:=1
// +kubebuilder:validation:Pattern:=^[a-zA-Z0-9][a-zA-Z0-9@_.+`;`-]*$
Value string `json:"value"`
}

// ConnectionStrings configuration for applications use to connect to this deployment.
type ConnectionStrings struct {
Standard string `json:"standard,omitempty"`
Expand Down
1 change: 0 additions & 1 deletion pkg/api/v1/atlasdeployment_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func init() {
excludedClusterFieldsTheirs["createDate"] = true
excludedClusterFieldsTheirs["versionReleaseSystem"] = true
excludedClusterFieldsTheirs["serverlessBackupOptions"] = true
excludedClusterFieldsTheirs["tags"] = true
}

func TestCompatibility(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1/status/cloud_provider_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *CloudProviderAccessRole) FailedToAuthorise(errorMessage string) {
c.ErrorMessage = errorMessage
}

func (c *CloudProviderAccessRole) Update(role mongodbatlas.AWSIAMRole, isEmptyArn bool) {
func (c *CloudProviderAccessRole) Update(role mongodbatlas.CloudProviderAccessRole, isEmptyArn bool) {
c.RoleID = role.RoleID
c.AtlasAssumedRoleExternalID = role.AtlasAssumedRoleExternalID
c.AtlasAWSAccountArn = role.AtlasAWSAccountARN
Expand Down
48 changes: 48 additions & 0 deletions pkg/api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion pkg/controller/atlasdeployment/atlasdeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ func (r *AtlasDeploymentReconciler) Reconcile(context context.Context, req ctrl.
deployment.Spec.DeploymentSpec = nil
}

if err := uniqueKey(&deployment.Spec); err != nil {
log.Errorw("failed to validate tags", "error", err)
result := workflow.Terminate(workflow.Internal, err.Error())
ctx.SetConditionFromResult(status.DeploymentReadyType, result)
return result.ReconcileResult(), nil
}

handleDeployment := r.selectDeploymentHandler(deployment)
if result, _ := handleDeployment(ctx, project, deployment, req); !result.IsOk() {
ctx.SetConditionFromResult(status.DeploymentReadyType, result)
Expand All @@ -205,7 +212,6 @@ func (r *AtlasDeploymentReconciler) Reconcile(context context.Context, req ctrl.
return result.ReconcileResult(), nil
}
}

return workflow.OK().ReconcileResult(), nil
}

Expand Down Expand Up @@ -478,3 +484,24 @@ func (r *AtlasDeploymentReconciler) removeDeletionFinalizer(context context.Cont
}

type deploymentHandlerFunc func(ctx *workflow.Context, project *mdbv1.AtlasProject, deployment *mdbv1.AtlasDeployment, req reconcile.Request) (workflow.Result, error)

// Parse through tags and verfiy that all keys are unique. Return error on duplicate key.
josvazg marked this conversation as resolved.
Show resolved Hide resolved
func uniqueKey(deploymentSpec *mdbv1.AtlasDeploymentSpec) error {
store := make(map[string]string)
var arrTags []*mdbv1.TagSpec

if deploymentSpec.AdvancedDeploymentSpec != nil {
arrTags = deploymentSpec.AdvancedDeploymentSpec.Tags
} else {
arrTags = deploymentSpec.ServerlessSpec.Tags
}
for _, currTag := range arrTags {
if store[currTag.Key] == "" {
store[currTag.Key] = currTag.Value
} else {
err := errors.New("duplicate keys found in tags, this is forbidden")
return err
}
}
return nil
}
49 changes: 49 additions & 0 deletions pkg/controller/atlasdeployment/atlasdeployment_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package atlasdeployment

import (
"testing"

"github.com/stretchr/testify/assert"

mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1"
)

func TestUniqueKey(t *testing.T) {
//var deploymentSpec *mdbv1.AtlasDeploymentSpec
cveticm marked this conversation as resolved.
Show resolved Hide resolved
t.Run("Test duplicates in Advanced Deployment", func(t *testing.T) {
deploymentSpec := &mdbv1.AtlasDeploymentSpec{
AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{
Tags: []*mdbv1.TagSpec{{Key: "foo", Value: "true"}, {Key: "foo", Value: "false"}},
},
}
err := uniqueKey(deploymentSpec)
assert.Error(t, err)
})
t.Run("Test no duplicates in Advanced Deployment", func(t *testing.T) {
deploymentSpec := &mdbv1.AtlasDeploymentSpec{
AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{
Tags: []*mdbv1.TagSpec{{Key: "foo", Value: "true"}, {Key: "bar", Value: "false"}, {Key: "foobar", Value: "false"}},
},
}
err := uniqueKey(deploymentSpec)
assert.NoError(t, err)
})
t.Run("Test duplicates in Serverless Instance", func(t *testing.T) {
deploymentSpec := &mdbv1.AtlasDeploymentSpec{
ServerlessSpec: &mdbv1.ServerlessSpec{
Tags: []*mdbv1.TagSpec{{Key: "foo", Value: "true"}, {Key: "bar", Value: "false"}, {Key: "foo", Value: "false"}},
},
}
err := uniqueKey(deploymentSpec)
assert.Error(t, err)
})
t.Run("Test no duplicates in Serverless Instance", func(t *testing.T) {
deploymentSpec := &mdbv1.AtlasDeploymentSpec{
ServerlessSpec: &mdbv1.ServerlessSpec{
Tags: []*mdbv1.TagSpec{{Key: "foo", Value: "true"}, {Key: "bar", Value: "false"}},
},
}
err := uniqueKey(deploymentSpec)
assert.NoError(t, err)
})
}
1 change: 1 addition & 0 deletions pkg/controller/atlasdeployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func ConvertLegacyDeployment(deploymentSpec *mdbv1.AtlasDeploymentSpec) error {
Labels: legacy.Labels,
MongoDBMajorVersion: legacy.MongoDBMajorVersion,
Name: legacy.Name,
Tags: legacy.Tags,
Paused: legacy.Paused,
PitEnabled: legacy.PitEnabled,
ReplicationSpecs: replicationSpecs,
Expand Down
Loading
Loading