Skip to content

Commit a8b6093

Browse files
authored
CLOUDP-149150: Add global deployment features (#813)
1 parent 31df5cf commit a8b6093

20 files changed

+1130
-2
lines changed

.github/workflows/test-e2e.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ jobs:
137137
"deployment-ns",
138138
"deployment-wide",
139139
"encryption-at-rest",
140+
"global-deployment",
140141
"helm-ns",
141142
"helm-update",
142143
"helm-wide",

config/crd/bases/atlas.mongodb.com_atlasdeployments.yaml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ spec:
6060
type: object
6161
clusterType:
6262
type: string
63+
customZoneMapping:
64+
items:
65+
properties:
66+
location:
67+
type: string
68+
zone:
69+
type: string
70+
required:
71+
- location
72+
- zone
73+
type: object
74+
type: array
6375
diskSizeGB:
6476
type: integer
6577
encryptionAtRestProvider:
@@ -79,6 +91,30 @@ spec:
7991
- value
8092
type: object
8193
type: array
94+
managedNamespaces:
95+
items:
96+
description: ManagedNamespace represents the information about
97+
managed namespace configuration.
98+
properties:
99+
collection:
100+
type: string
101+
customShardKey:
102+
type: string
103+
db:
104+
type: string
105+
isCustomShardKeyHashed:
106+
type: boolean
107+
isShardKeyUnique:
108+
type: boolean
109+
numInitialChunks:
110+
type: integer
111+
presplitHashedZones:
112+
type: boolean
113+
required:
114+
- collection
115+
- db
116+
type: object
117+
type: array
82118
mongoDBMajorVersion:
83119
type: string
84120
mongoDBVersion:
@@ -279,6 +315,18 @@ spec:
279315
- SHARDED
280316
- GEOSHARDED
281317
type: string
318+
customZoneMapping:
319+
items:
320+
properties:
321+
location:
322+
type: string
323+
zone:
324+
type: string
325+
required:
326+
- location
327+
- zone
328+
type: object
329+
type: array
282330
diskSizeGB:
283331
description: Capacity, in gigabytes, of the host's root volume.
284332
Increase this number to add capacity, up to a maximum possible
@@ -314,6 +362,30 @@ spec:
314362
- value
315363
type: object
316364
type: array
365+
managedNamespaces:
366+
items:
367+
description: ManagedNamespace represents the information about
368+
managed namespace configuration.
369+
properties:
370+
collection:
371+
type: string
372+
customShardKey:
373+
type: string
374+
db:
375+
type: string
376+
isCustomShardKeyHashed:
377+
type: boolean
378+
isShardKeyUnique:
379+
type: boolean
380+
numInitialChunks:
381+
type: integer
382+
presplitHashedZones:
383+
type: boolean
384+
required:
385+
- collection
386+
- db
387+
type: object
388+
type: array
317389
mongoDBMajorVersion:
318390
description: Version of the deployment to deploy.
319391
type: string
@@ -789,6 +861,43 @@ spec:
789861
cluster.
790862
type: string
791863
type: object
864+
customZoneMapping:
865+
properties:
866+
customZoneMapping:
867+
additionalProperties:
868+
type: string
869+
type: object
870+
zoneMappingErrMessage:
871+
type: string
872+
zoneMappingState:
873+
type: string
874+
type: object
875+
managedNamespaces:
876+
items:
877+
properties:
878+
collection:
879+
type: string
880+
customShardKey:
881+
type: string
882+
db:
883+
type: string
884+
errMessage:
885+
type: string
886+
isCustomShardKeyHashed:
887+
type: boolean
888+
isShardKeyUnique:
889+
type: boolean
890+
numInitialChunks:
891+
type: integer
892+
presplitHashedZones:
893+
type: boolean
894+
status:
895+
type: string
896+
required:
897+
- collection
898+
- db
899+
type: object
900+
type: array
792901
mongoDBVersion:
793902
description: MongoDBVersion is the version of MongoDB the cluster
794903
runs, in <major version>.<minor version> format.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/pborman/uuid v1.2.1
2121
github.com/sethvargo/go-password v0.2.0
2222
github.com/stretchr/testify v1.8.1
23-
go.mongodb.org/atlas v0.18.0
23+
go.mongodb.org/atlas v0.20.1-0.20230105135126-32300174f475
2424
go.mongodb.org/mongo-driver v1.11.0
2525
go.uber.org/zap v1.23.0
2626
golang.org/x/sync v0.1.0
@@ -80,7 +80,7 @@ require (
8080
github.com/modern-go/reflect2 v1.0.2 // indirect
8181
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
8282
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
83-
github.com/openlyinc/pointy v1.1.2 // indirect
83+
github.com/openlyinc/pointy v1.2.0 // indirect
8484
github.com/pkg/errors v0.9.1 // indirect
8585
github.com/pmezard/go-difflib v1.0.0 // indirect
8686
github.com/prometheus/client_golang v1.12.2 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ github.com/onsi/gomega v1.24.1 h1:KORJXNNTzJXzu4ScJWssJfJMnJ+2QJqhoQSRwNlze9E=
299299
github.com/onsi/gomega v1.24.1/go.mod h1:3AOiACssS3/MajrniINInwbfOOtfZvplPzuRSmvt1jM=
300300
github.com/openlyinc/pointy v1.1.2 h1:LywVV2BWC5Sp5v7FoP4bUD+2Yn5k0VNeRbU5vq9jUMY=
301301
github.com/openlyinc/pointy v1.1.2/go.mod h1:w2Sytx+0FVuMKn37xpXIAyBNhFNBIJGR/v2m7ik1WtM=
302+
github.com/openlyinc/pointy v1.2.0 h1:vbb/WoPbshyTH8j3/XYu3enlZfv+NHxAD15qTm1zbk0=
303+
github.com/openlyinc/pointy v1.2.0/go.mod h1:JodZOTJoBNaAQHeU0F/SwA4PL0lg4pKF7fYFpX291P0=
302304
github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw=
303305
github.com/pborman/uuid v1.2.1/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
304306
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -371,6 +373,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
371373
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
372374
go.mongodb.org/atlas v0.18.0 h1:hDEBykn31FlW0KKMt3xsGyqOrx+jkxB9jCO4GLhH6M0=
373375
go.mongodb.org/atlas v0.18.0/go.mod h1:GUuW7/ZrHzCO0o47aiqhokN0N6i0GM3yraRyHIBTykU=
376+
go.mongodb.org/atlas v0.20.1-0.20230105135126-32300174f475 h1:fbTbroM+NA113Wv3YvXmYUVx/+dkJcGLrX4gtvKBiZw=
377+
go.mongodb.org/atlas v0.20.1-0.20230105135126-32300174f475/go.mod h1:XTjsxWgoOSwaZrQUvhTEuwjymxnF0r12RPibZuW1Uts=
374378
go.mongodb.org/mongo-driver v1.11.0 h1:FZKhBSTydeuffHj9CBjXlR8vQLee1cQyTWYPA6/tqiE=
375379
go.mongodb.org/mongo-driver v1.11.0/go.mod h1:s7p5vEtfbeR1gYi6pnj3c3/urpbLv2T5Sfd6Rp2HBB8=
376380
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=

pkg/api/v1/atlasdeployment_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ type DeploymentSpec struct {
143143
// Configuration for deployment regions.
144144
// +optional
145145
ReplicationSpecs []ReplicationSpec `json:"replicationSpecs,omitempty"`
146+
// +optional
147+
CustomZoneMapping []CustomZoneMapping `json:"customZoneMapping,omitempty"`
148+
// +optional
149+
ManagedNamespaces []ManagedNamespace `json:"managedNamespaces,omitempty"`
146150
}
147151

148152
type AdvancedDeploymentSpec struct {
@@ -164,6 +168,10 @@ type AdvancedDeploymentSpec struct {
164168
ReplicationSpecs []*AdvancedReplicationSpec `json:"replicationSpecs,omitempty"`
165169
RootCertType string `json:"rootCertType,omitempty"`
166170
VersionReleaseSystem string `json:"versionReleaseSystem,omitempty"`
171+
// +optional
172+
CustomZoneMapping []CustomZoneMapping `json:"customZoneMapping,omitempty"`
173+
// +optional
174+
ManagedNamespaces []ManagedNamespace `json:"managedNamespaces,omitempty"`
167175
}
168176

169177
// ToAtlas converts the AdvancedDeploymentSpec to native Atlas client ToAtlas format.

pkg/api/v1/atlasdeployment_types_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ var (
2222
func init() {
2323
excludedClusterFieldsOurs["projectRef"] = true
2424

25+
// Global deployment fields
26+
excludedClusterFieldsOurs["customZoneMapping"] = true
27+
excludedClusterFieldsOurs["managedNamespaces"] = true
28+
2529
excludedClusterFieldsTheirs["backupEnabled"] = true
2630
excludedClusterFieldsTheirs["id"] = true
2731
excludedClusterFieldsTheirs["groupId"] = true
@@ -33,6 +37,12 @@ func init() {
3337
excludedClusterFieldsTheirs["replicationSpec"] = true
3438
excludedClusterFieldsTheirs["replicationFactor"] = true
3539

40+
// Termination protection
41+
excludedClusterFieldsTheirs["terminationProtectionEnabled"] = true
42+
43+
// Root cert type
44+
excludedClusterFieldsTheirs["rootCertType"] = true
45+
3646
// These fields are shown in the status
3747
excludedClusterFieldsTheirs["mongoDBVersion"] = true
3848
excludedClusterFieldsTheirs["mongoURI"] = true

pkg/api/v1/global_deployment.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package v1
2+
3+
import (
4+
"go.mongodb.org/atlas/mongodbatlas"
5+
)
6+
7+
type CustomZoneMapping struct {
8+
Location string `json:"location"`
9+
Zone string `json:"zone"`
10+
}
11+
12+
// ManagedNamespace represents the information about managed namespace configuration.
13+
type ManagedNamespace struct {
14+
Db string `json:"db"` //nolint:stylecheck // not changing this as is a breaking change
15+
Collection string `json:"collection"`
16+
CustomShardKey string `json:"customShardKey,omitempty"`
17+
NumInitialChunks int `json:"numInitialChunks,omitempty"`
18+
PresplitHashedZones *bool `json:"presplitHashedZones,omitempty"`
19+
IsCustomShardKeyHashed *bool `json:"isCustomShardKeyHashed,omitempty"` // Flag that specifies whether the custom shard key for the collection is hashed.
20+
IsShardKeyUnique *bool `json:"isShardKeyUnique,omitempty"` // Flag that specifies whether the underlying index enforces a unique constraint.
21+
}
22+
23+
func (in *ManagedNamespace) ToAtlas() mongodbatlas.ManagedNamespace {
24+
return mongodbatlas.ManagedNamespace{
25+
Db: in.Db,
26+
Collection: in.Collection,
27+
CustomShardKey: in.CustomShardKey,
28+
IsCustomShardKeyHashed: in.IsCustomShardKeyHashed,
29+
IsShardKeyUnique: in.IsShardKeyUnique,
30+
NumInitialChunks: in.NumInitialChunks,
31+
PresplitHashedZones: in.PresplitHashedZones,
32+
}
33+
}
34+
35+
func (c *CustomZoneMapping) ToAtlas() mongodbatlas.CustomZoneMapping {
36+
return mongodbatlas.CustomZoneMapping{
37+
Location: c.Location,
38+
Zone: c.Zone,
39+
}
40+
}

pkg/api/v1/status/atlasdeployment.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ type AtlasDeploymentStatus struct {
2222

2323
ServerlessPrivateEndpoints []ServerlessPrivateEndpoint `json:"serverlessPrivateEndpoints,omitempty"`
2424

25+
CustomZoneMapping *CustomZoneMapping `json:"customZoneMapping,omitempty"`
26+
27+
ManagedNamespaces []ManagedNamespace `json:"managedNamespaces,omitempty"`
28+
2529
// MongoURIUpdated is a timestamp in ISO 8601 date and time format in UTC when the connection string was last updated.
2630
// The connection string changes if you update any of the other values.
2731
MongoURIUpdated string `json:"mongoURIUpdated,omitempty"`
@@ -116,6 +120,18 @@ func AtlasDeploymentSPEOption(pe []ServerlessPrivateEndpoint) AtlasDeploymentSta
116120
}
117121
}
118122

123+
func AtlasDeploymentCustomZoneMappingOption(czm *CustomZoneMapping) AtlasDeploymentStatusOption {
124+
return func(s *AtlasDeploymentStatus) {
125+
s.CustomZoneMapping = czm
126+
}
127+
}
128+
129+
func AtlasDeploymentManagedNamespacesOption(namespaces []ManagedNamespace) AtlasDeploymentStatusOption {
130+
return func(s *AtlasDeploymentStatus) {
131+
s.ManagedNamespaces = namespaces
132+
}
133+
}
134+
119135
func AtlasDeploymentMongoDBVersionOption(mongoDBVersion string) AtlasDeploymentStatusOption {
120136
return func(s *AtlasDeploymentStatus) {
121137
s.MongoDBVersion = mongoDBVersion

pkg/api/v1/status/condition.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ const (
5454
const (
5555
DeploymentReadyType ConditionType = "DeploymentReady"
5656
ServerlessPrivateEndpointReadyType ConditionType = "ServerlessPrivateEndpointReady"
57+
ManagedNamespacesReadyType ConditionType = "ManagedNamespacesReady"
58+
CustomZoneMappingReadyType ConditionType = "CustomZoneMappingReady"
5759
)
5860

5961
// AtlasDatabaseUser condition types
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package status
2+
3+
import (
4+
"go.mongodb.org/atlas/mongodbatlas"
5+
)
6+
7+
type CustomZoneMapping struct {
8+
CustomZoneMapping map[string]string `json:"customZoneMapping,omitempty"`
9+
ZoneMappingState string `json:"zoneMappingState,omitempty"`
10+
ZoneMappingErrMessage string `json:"zoneMappingErrMessage,omitempty"`
11+
}
12+
13+
type ManagedNamespace struct {
14+
Db string `json:"db"` //nolint:stylecheck // not changing this as is a breaking change
15+
Collection string `json:"collection"`
16+
CustomShardKey string `json:"customShardKey,omitempty"`
17+
NumInitialChunks int `json:"numInitialChunks,omitempty"`
18+
IsCustomShardKeyHashed *bool `json:"isCustomShardKeyHashed,omitempty"` // Flag that specifies whether the custom shard key for the collection is hashed.
19+
IsShardKeyUnique *bool `json:"isShardKeyUnique,omitempty"` // Flag that specifies whether the underlying index enforces a unique constraint.
20+
Status string `json:"status,omitempty"`
21+
PresplitHashedZones *bool `json:"presplitHashedZones,omitempty"`
22+
ErrMessage string `json:"errMessage,omitempty"`
23+
}
24+
25+
func NewFailedToCreateManagedNamespaceStatus(namespace mongodbatlas.ManagedNamespace, err error) ManagedNamespace {
26+
return ManagedNamespace{
27+
Db: namespace.Db,
28+
Collection: namespace.Collection,
29+
CustomShardKey: namespace.CustomShardKey,
30+
IsCustomShardKeyHashed: namespace.IsCustomShardKeyHashed,
31+
IsShardKeyUnique: namespace.IsShardKeyUnique,
32+
NumInitialChunks: namespace.NumInitialChunks,
33+
PresplitHashedZones: namespace.PresplitHashedZones,
34+
Status: StatusFailed,
35+
ErrMessage: err.Error(),
36+
}
37+
}
38+
39+
func NewCreatedManagedNamespaceStatus(namespace mongodbatlas.ManagedNamespace) ManagedNamespace {
40+
return ManagedNamespace{
41+
Db: namespace.Db,
42+
Collection: namespace.Collection,
43+
CustomShardKey: namespace.CustomShardKey,
44+
IsCustomShardKeyHashed: namespace.IsCustomShardKeyHashed,
45+
IsShardKeyUnique: namespace.IsShardKeyUnique,
46+
NumInitialChunks: namespace.NumInitialChunks,
47+
PresplitHashedZones: namespace.PresplitHashedZones,
48+
Status: StatusReady,
49+
}
50+
}

0 commit comments

Comments
 (0)