Skip to content

Commit 9136753

Browse files
committed
CLOUDP-330314: Disallow project/deployment renaming
When a project is renamed in Kube, the operator will create a new project and leave the original intact, while other resources (such as AtlasDeployment) still track the original clusters in the old project. This leads to bad situations that are difficult to clean up, in particular via the operator. Similarly, when a deployment is renamed in Kube a new deployment is created in Atlas, with the old one left running. Since this is almost definitely not what the user wanted, let's ensure that name changes here are also forbidden.
1 parent 645a0dc commit 9136753

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

api/v1/atlasdeployment_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ type AdvancedDeploymentSpec struct {
127127
// Can only contain ASCII letters, numbers, and hyphens.
128128
// +kubebuilder:validation:Required
129129
// +kubebuilder:validation:Pattern:=^[a-zA-Z0-9][a-zA-Z0-9-]*$
130+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Name cannot be modified after deployment creation"
130131
Name string `json:"name,omitempty"`
131132
// Flag that indicates whether the deployment should be paused.
132133
Paused *bool `json:"paused,omitempty"`

api/v1/atlasproject_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func init() {
4343
type AtlasProjectSpec struct {
4444

4545
// Name is the name of the Project that is created in Atlas by the Operator if it doesn't exist yet.
46+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Name cannot be modified after project creation"
4647
Name string `json:"name"`
4748

4849
// RegionUsageRestrictions designate the project's AWS region when using Atlas for Government.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ spec:
197197
Can only contain ASCII letters, numbers, and hyphens.
198198
pattern: ^[a-zA-Z0-9][a-zA-Z0-9-]*$
199199
type: string
200+
x-kubernetes-validations:
201+
- message: Name cannot be modified after deployment creation
202+
rule: self == oldSelf
200203
paused:
201204
description: Flag that indicates whether the deployment should
202205
be paused.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,9 @@ spec:
746746
description: Name is the name of the Project that is created in Atlas
747747
by the Operator if it doesn't exist yet.
748748
type: string
749+
x-kubernetes-validations:
750+
- message: Name cannot be modified after project creation
751+
rule: self == oldSelf
749752
networkPeers:
750753
description: NetworkPeers is a list of Network Peers configured for
751754
the current Project.

0 commit comments

Comments
 (0)