From 8de2ac4136bbe2347874069604651e02889db048 Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 29 Jan 2021 14:48:00 +0300 Subject: [PATCH 01/42] Update mongodbatlas library & corresponding specs --- .../atlas.mongodb.com_atlasclusters.yaml | 66 ++++++++++++---- go.mod | 2 +- go.sum | 4 +- pkg/api/v1/status/atlascluster.go | 78 +++++++++++++++---- pkg/api/v1/status/zz_generated.deepcopy.go | 52 ++++++++++--- 5 files changed, 155 insertions(+), 47 deletions(-) diff --git a/config/crd/bases/atlas.mongodb.com_atlasclusters.yaml b/config/crd/bases/atlas.mongodb.com_atlasclusters.yaml index 646e10d954..35b962d662 100644 --- a/config/crd/bases/atlas.mongodb.com_atlasclusters.yaml +++ b/config/crd/bases/atlas.mongodb.com_atlasclusters.yaml @@ -354,28 +354,60 @@ spec: description: ConnectionStrings is a set of connection strings that your applications use to connect to this cluster. properties: - awsPrivateLink: - additionalProperties: - type: string - description: 'Deprecated: use connectionStrings.privateEndpoint[n].connectionString - instead. Private-endpoint-aware mongodb://connection strings - for each AWS PrivateLink private endpoint. Atlas returns this - parameter only if you deployed a AWS PrivateLink private endpoint - to the same regions as all of this cluster''s nodes.' - type: object - awsPrivateLinkSrv: - additionalProperties: - type: string - description: 'Deprecated: use connectionStrings.privateEndpoint[n].srvConnectionString - instead. Private-endpoint-aware mongodb+srv:// connection strings - for each AWS PrivateLink private endpoint.' - type: object private: - description: Network-peering-endpoint-aware mongodb://connection + description: Network-peering-endpoint-aware mongodb:// connection strings for each interface VPC endpoint you configured to connect to this cluster. Atlas returns this parameter only if you created a network peering connection to this cluster. type: string + privateEndpoint: + description: Private endpoint connection strings. Each object + describes the connection strings you can use to connect to this + cluster through a private endpoint. Atlas returns this parameter + only if you deployed a private endpoint to all regions to which + you deployed this cluster's nodes. + items: + description: PrivateEndpoint connection strings. Each object + describes the connection strings you can use to connect to + this cluster through a private endpoint. Atlas returns this + parameter only if you deployed a private endpoint to all regions + to which you deployed this cluster's nodes. + properties: + connectionString: + description: Private-endpoint-aware mongodb:// connection + string for this private endpoint. + type: string + endpoints: + description: Private endpoint through which you connect + to Atlas when you use connectionStrings.privateEndpoint[n].connectionString + or connectionStrings.privateEndpoint[n].srvConnectionString. + items: + description: Endpoint through which you connect to Atlas + properties: + endpointId: + description: Unique identifier of the private endpoint. + type: string + providerName: + description: Cloud provider to which you deployed + the private endpoint. Atlas returns AWS or AZURE. + type: string + region: + description: Region to which you deployed the private + endpoint. + type: string + type: object + type: array + srvConnectionString: + description: Private-endpoint-aware mongodb+srv:// connection + string for this private endpoint. + type: string + type: + description: "Type of MongoDB process that you connect to + with the connection strings \n Atlas returns: \n • MONGOD + for replica sets, or \n • MONGOS for sharded clusters" + type: string + type: object + type: array privateSrv: description: Network-peering-endpoint-aware mongodb+srv:// connection strings for each interface VPC endpoint you configured to connect diff --git a/go.mod b/go.mod index d12bae7ecb..1d51f960a1 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/onsi/ginkgo v1.14.2 github.com/onsi/gomega v1.10.1 github.com/stretchr/testify v1.7.0 - go.mongodb.org/atlas v0.5.1-0.20201208094933-0e2a93147ccd + go.mongodb.org/atlas v0.7.1 go.uber.org/zap v1.16.0 k8s.io/api v0.18.6 k8s.io/apimachinery v0.18.6 diff --git a/go.sum b/go.sum index add7d25281..ed10a7d766 100644 --- a/go.sum +++ b/go.sum @@ -311,8 +311,8 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= -go.mongodb.org/atlas v0.5.1-0.20201208094933-0e2a93147ccd h1:522hIBk7NjCNro3wxslqPjnMUlg/A1JZVHTWudcOC50= -go.mongodb.org/atlas v0.5.1-0.20201208094933-0e2a93147ccd/go.mod h1:CIaBeO8GLHhtYLw7xSSXsw7N90Z4MFY87Oy9qcPyuEs= +go.mongodb.org/atlas v0.7.1 h1:hNBtwtKgmhB9vmSX/JyN/cArmhzyy4ihKpmXSMIc4mw= +go.mongodb.org/atlas v0.7.1/go.mod h1:CIaBeO8GLHhtYLw7xSSXsw7N90Z4MFY87Oy9qcPyuEs= go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= go.mongodb.org/mongo-driver v1.1.1/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= go.mongodb.org/mongo-driver v1.1.2/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= diff --git a/pkg/api/v1/status/atlascluster.go b/pkg/api/v1/status/atlascluster.go index 765056a8a9..8fdf0ec07a 100755 --- a/pkg/api/v1/status/atlascluster.go +++ b/pkg/api/v1/status/atlascluster.go @@ -21,7 +21,7 @@ type AtlasClusterStatus struct { MongoURIUpdated string `json:"mongoURIUpdated,omitempty"` } -// ConnectionStrings is a copy of mongodbatlas.ConnectionStrings for deepcopy compatibility purposes. +// ConnectionStrings contains configuration for applications use to connect to this cluster type ConnectionStrings struct { // Public mongodb:// connection string for this cluster. Standard string `json:"standard,omitempty"` @@ -29,18 +29,12 @@ type ConnectionStrings struct { // Public mongodb+srv:// connection string for this cluster. StandardSrv string `json:"standardSrv,omitempty"` - // TODO: update when the replacement is implemented in mongodbatlas + // Private endpoint connection strings. + // Each object describes the connection strings you can use to connect to this cluster through a private endpoint. + // Atlas returns this parameter only if you deployed a private endpoint to all regions to which you deployed this cluster's nodes. + PrivateEndpoint []PrivateEndpoint `json:"privateEndpoint,omitempty"` - // Deprecated: use connectionStrings.privateEndpoint[n].connectionString instead. - // Private-endpoint-aware mongodb://connection strings for each AWS PrivateLink private endpoint. - // Atlas returns this parameter only if you deployed a AWS PrivateLink private endpoint to the same regions as all of this cluster's nodes. - AwsPrivateLink map[string]string `json:"awsPrivateLink,omitempty"` - - // Deprecated: use connectionStrings.privateEndpoint[n].srvConnectionString instead. - // Private-endpoint-aware mongodb+srv:// connection strings for each AWS PrivateLink private endpoint. - AwsPrivateLinkSrv map[string]string `json:"awsPrivateLinkSrv,omitempty"` - - // Network-peering-endpoint-aware mongodb://connection strings for each interface VPC endpoint you configured to connect to this cluster. + // Network-peering-endpoint-aware mongodb:// connection strings for each interface VPC endpoint you configured to connect to this cluster. // Atlas returns this parameter only if you created a network peering connection to this cluster. Private string `json:"private,omitempty"` @@ -50,8 +44,41 @@ type ConnectionStrings struct { PrivateSrv string `json:"privateSrv,omitempty"` } -// Check compatibility with library type. -var _ = ConnectionStrings(mongodbatlas.ConnectionStrings{}) +// PrivateEndpoint connection strings. Each object describes the connection strings +// you can use to connect to this cluster through a private endpoint. +// Atlas returns this parameter only if you deployed a private endpoint to all regions +// to which you deployed this cluster's nodes. +type PrivateEndpoint struct { + // Private-endpoint-aware mongodb:// connection string for this private endpoint. + ConnectionString string `json:"connectionString,omitempty"` + + // Private endpoint through which you connect to Atlas when you use connectionStrings.privateEndpoint[n].connectionString or connectionStrings.privateEndpoint[n].srvConnectionString. + Endpoints []Endpoint `json:"endpoints,omitempty"` + + // Private-endpoint-aware mongodb+srv:// connection string for this private endpoint. + SRVConnectionString string `json:"srvConnectionString,omitempty"` + + // Type of MongoDB process that you connect to with the connection strings + // + // Atlas returns: + // + // • MONGOD for replica sets, or + // + // • MONGOS for sharded clusters + Type string `json:"type,omitempty"` +} + +// Endpoint through which you connect to Atlas +type Endpoint struct { + // Unique identifier of the private endpoint. + EndpointID string `json:"endpointId,omitempty"` + + // Cloud provider to which you deployed the private endpoint. Atlas returns AWS or AZURE. + ProviderName string `json:"providerName,omitempty"` + + // Region to which you deployed the private endpoint. + Region string `json:"region,omitempty"` +} // +k8s:deepcopy-gen=false @@ -72,7 +99,28 @@ func AtlasClusterMongoDBVersionOption(mongoDBVersion string) AtlasClusterStatusO func AtlasClusterConnectionStringsOption(connectionStrings *mongodbatlas.ConnectionStrings) AtlasClusterStatusOption { return func(s *AtlasClusterStatus) { - cs := ConnectionStrings(*connectionStrings) + pe := make([]PrivateEndpoint, 0, len(connectionStrings.PrivateEndpoint)) + for _, v := range connectionStrings.PrivateEndpoint { + endpoints := make([]Endpoint, 0, len(v.Endpoints)) + for _, e := range v.Endpoints { + endpoints = append(endpoints, Endpoint(e)) + } + + pe = append(pe, PrivateEndpoint{ + ConnectionString: v.ConnectionString, + Endpoints: endpoints, + SRVConnectionString: v.SRVConnectionString, + Type: v.Type, + }) + } + + cs := ConnectionStrings{ + Standard: connectionStrings.Standard, + StandardSrv: connectionStrings.StandardSrv, + Private: connectionStrings.Private, + PrivateSrv: connectionStrings.PrivateSrv, + PrivateEndpoint: pe, + } s.ConnectionStrings = &cs } } diff --git a/pkg/api/v1/status/zz_generated.deepcopy.go b/pkg/api/v1/status/zz_generated.deepcopy.go index db28e9c32a..8becc4f1c0 100644 --- a/pkg/api/v1/status/zz_generated.deepcopy.go +++ b/pkg/api/v1/status/zz_generated.deepcopy.go @@ -92,18 +92,11 @@ func (in *Condition) DeepCopy() *Condition { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ConnectionStrings) DeepCopyInto(out *ConnectionStrings) { *out = *in - if in.AwsPrivateLink != nil { - in, out := &in.AwsPrivateLink, &out.AwsPrivateLink - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - if in.AwsPrivateLinkSrv != nil { - in, out := &in.AwsPrivateLinkSrv, &out.AwsPrivateLinkSrv - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val + if in.PrivateEndpoint != nil { + in, out := &in.PrivateEndpoint, &out.PrivateEndpoint + *out = make([]PrivateEndpoint, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) } } } @@ -117,3 +110,38 @@ func (in *ConnectionStrings) DeepCopy() *ConnectionStrings { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Endpoint) DeepCopyInto(out *Endpoint) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Endpoint. +func (in *Endpoint) DeepCopy() *Endpoint { + if in == nil { + return nil + } + out := new(Endpoint) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PrivateEndpoint) DeepCopyInto(out *PrivateEndpoint) { + *out = *in + if in.Endpoints != nil { + in, out := &in.Endpoints, &out.Endpoints + *out = make([]Endpoint, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrivateEndpoint. +func (in *PrivateEndpoint) DeepCopy() *PrivateEndpoint { + if in == nil { + return nil + } + out := new(PrivateEndpoint) + in.DeepCopyInto(out) + return out +} From 625446c34de786a9b7f46bd16afb01a439da580b Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 29 Jan 2021 14:57:58 +0300 Subject: [PATCH 02/42] Add more test cases --- test/int/cluster_test.go | 93 ++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 34d15e0809..084fcf95a5 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -28,6 +28,7 @@ var _ = Describe("AtlasCluster", func() { connectionSecret corev1.Secret createdProject *mdbv1.AtlasProject createdCluster *mdbv1.AtlasCluster + enabled = true ) BeforeEach(func() { @@ -79,64 +80,71 @@ var _ = Describe("AtlasCluster", func() { Expect(err).ToNot(HaveOccurred()) }) + doCommonChecks := func() { + Expect(createdCluster.Status.ConnectionStrings).NotTo(BeNil()) + Expect(createdCluster.Status.ConnectionStrings.Standard).NotTo(BeNil()) + Expect(createdCluster.Status.ConnectionStrings.StandardSrv).NotTo(BeNil()) + Expect(createdCluster.Status.MongoDBVersion).NotTo(BeNil()) + Expect(createdCluster.Status.MongoURIUpdated).NotTo(BeNil()) + Expect(createdCluster.Status.StateName).To(Equal("IDLE")) + Expect(createdCluster.Status.Conditions).To(ConsistOf(testutil.MatchConditions( + status.TrueCondition(status.ClusterReadyType), + status.TrueCondition(status.ReadyType), + ))) + Expect(createdCluster.Status.ObservedGeneration).To(Equal(createdCluster.Generation)) + } + Describe("Create/Update the cluster", func() { It("Should Succeed", func() { expectedCluster := testAtlasCluster(namespace.Name, "test-cluster", createdProject.Name) - By(fmt.Sprintf("Creating the Cluster %s", kube.ObjectKeyFromObject(expectedCluster))) + By(fmt.Sprintf("Creating the Cluster %s", kube.ObjectKeyFromObject(expectedCluster)), func() { + createdCluster.ObjectMeta = expectedCluster.ObjectMeta + Expect(k8sClient.Create(context.Background(), expectedCluster)).ToNot(HaveOccurred()) - createdCluster.ObjectMeta = expectedCluster.ObjectMeta - Expect(k8sClient.Create(context.Background(), expectedCluster)).ToNot(HaveOccurred()) + validatePending := clusterPendingFunc("CREATING", "cluster is provisioning", workflow.ClusterCreating) + Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validatePending), + 1200, interval).Should(BeTrue()) - validatePending := clusterPendingFunc("CREATING", "cluster is provisioning", workflow.ClusterCreating) - Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validatePending), - 1200, interval).Should(BeTrue()) + doCommonChecks() - Expect(createdCluster.Status.ConnectionStrings).NotTo(BeNil()) - Expect(createdCluster.Status.ConnectionStrings.Standard).NotTo(BeNil()) - Expect(createdCluster.Status.ConnectionStrings.StandardSrv).NotTo(BeNil()) - Expect(createdCluster.Status.MongoDBVersion).NotTo(BeNil()) - Expect(createdCluster.Status.MongoURIUpdated).NotTo(BeNil()) - Expect(createdCluster.Status.StateName).To(Equal("IDLE")) + // Atlas + atlasCluster, _, err := atlasClient.Clusters.Get(context.Background(), createdProject.Status.ID, createdCluster.Spec.Name) + Expect(err).ToNot(HaveOccurred()) - expectedConditionsMatchers := testutil.MatchConditions( - status.TrueCondition(status.ClusterReadyType), - status.TrueCondition(status.ReadyType), - ) - Expect(createdCluster.Status.Conditions).To(ConsistOf(expectedConditionsMatchers)) - Expect(createdCluster.Status.ObservedGeneration).To(Equal(createdCluster.Generation)) + // Unfortunately we cannot do global checks on cluster/providerSettings fields as Atlas adds default values + Expect(atlasCluster.Name).To(Equal(expectedCluster.Spec.Name)) + Expect(atlasCluster.ProviderSettings.InstanceSizeName).To(Equal(expectedCluster.Spec.ProviderSettings.InstanceSizeName)) + Expect(atlasCluster.ProviderSettings.ProviderName).To(Equal(expectedCluster.Spec.ProviderSettings.ProviderName)) + Expect(atlasCluster.ProviderSettings.RegionName).To(Equal(expectedCluster.Spec.ProviderSettings.RegionName)) + }) - // Atlas - atlasCluster, _, err := atlasClient.Clusters.Get(context.Background(), createdProject.Status.ID, createdCluster.Spec.Name) - Expect(err).ToNot(HaveOccurred()) + // TODO check connectivity to cluster - // Unfortunately we cannot do global checks on cluster/providerSettings fields as Atlas adds default values - Expect(atlasCluster.Name).To(Equal(expectedCluster.Spec.Name)) - Expect(atlasCluster.ProviderSettings.InstanceSizeName).To(Equal(expectedCluster.Spec.ProviderSettings.InstanceSizeName)) - Expect(atlasCluster.ProviderSettings.ProviderName).To(Equal(expectedCluster.Spec.ProviderSettings.ProviderName)) - Expect(atlasCluster.ProviderSettings.RegionName).To(Equal(expectedCluster.Spec.ProviderSettings.RegionName)) + By("Updating the Cluster labels", func() { + createdCluster.Spec.Labels = []mdbv1.LabelSpec{{Key: "int-test", Value: "true"}} + Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) - // TODO check connectivity to cluster + validatePending := clusterPendingFunc("UPDATING", "cluster is updating", workflow.ClusterUpdating) + Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validatePending), + 1200, interval).Should(BeTrue()) - By("Updating the Cluster") - createdCluster.Spec.Labels = []mdbv1.LabelSpec{{Key: "int-test", Value: "true"}} - Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) + doCommonChecks() + }) - validatePending = clusterPendingFunc("UPDATING", "cluster is updating", workflow.ClusterUpdating) - Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validatePending), - 1200, interval).Should(BeTrue()) + By("Updating the Cluster backups settings", func() { + createdCluster.Spec.ProviderBackupEnabled = &enabled + Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) - Expect(createdCluster.Status.ConnectionStrings).NotTo(BeNil()) - Expect(createdCluster.Status.ConnectionStrings.Standard).NotTo(BeNil()) - Expect(createdCluster.Status.ConnectionStrings.StandardSrv).NotTo(BeNil()) - Expect(createdCluster.Status.MongoDBVersion).NotTo(BeNil()) - Expect(createdCluster.Status.MongoURIUpdated).NotTo(BeNil()) - Expect(createdCluster.Status.StateName).To(Equal("IDLE")) - Expect(createdCluster.Status.Conditions).To(ConsistOf(expectedConditionsMatchers)) - Expect(createdCluster.Status.ObservedGeneration).To(Equal(createdCluster.Generation)) + validatePending := clusterPendingFunc("UPDATING", "cluster is updating", workflow.ClusterUpdating) + Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validatePending), + 1200, interval).Should(BeTrue()) + + doCommonChecks() + }) // Atlas - atlasCluster, _, err = atlasClient.Clusters.Get(context.Background(), createdProject.Status.ID, createdCluster.Spec.Name) + atlasCluster, _, err := atlasClient.Clusters.Get(context.Background(), createdProject.Status.ID, createdCluster.Spec.Name) Expect(err).ToNot(HaveOccurred()) createdAtlasCluster, err := createdCluster.Spec.Cluster() @@ -149,6 +157,7 @@ var _ = Describe("AtlasCluster", func() { Expect(atlasCluster.ProviderSettings.InstanceSizeName).To(Equal(createdAtlasCluster.ProviderSettings.InstanceSizeName)) Expect(atlasCluster.ProviderSettings.ProviderName).To(Equal(createdAtlasCluster.ProviderSettings.ProviderName)) Expect(atlasCluster.ProviderSettings.RegionName).To(Equal(createdAtlasCluster.ProviderSettings.RegionName)) + Expect(atlasCluster.ProviderBackupEnabled).To(Equal(createdAtlasCluster.ProviderBackupEnabled)) }) }) }) From 47b7b4121873d5698e0a4ca2b84292df1916b8c3 Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 29 Jan 2021 17:48:52 +0300 Subject: [PATCH 03/42] Reorganize tests --- test/int/cluster_test.go | 74 ++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 084fcf95a5..fce6963ffd 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -28,7 +28,6 @@ var _ = Describe("AtlasCluster", func() { connectionSecret corev1.Secret createdProject *mdbv1.AtlasProject createdCluster *mdbv1.AtlasCluster - enabled = true ) BeforeEach(func() { @@ -94,6 +93,16 @@ var _ = Describe("AtlasCluster", func() { Expect(createdCluster.Status.ObservedGeneration).To(Equal(createdCluster.Generation)) } + performUpdate := func() { + Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) + + validatePending := clusterPendingFunc("UPDATING", "cluster is updating", workflow.ClusterUpdating) + Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validatePending), + 1200, interval).Should(BeTrue()) + + doCommonChecks() + } + Describe("Create/Update the cluster", func() { It("Should Succeed", func() { expectedCluster := testAtlasCluster(namespace.Name, "test-cluster", createdProject.Name) @@ -123,41 +132,40 @@ var _ = Describe("AtlasCluster", func() { By("Updating the Cluster labels", func() { createdCluster.Spec.Labels = []mdbv1.LabelSpec{{Key: "int-test", Value: "true"}} - Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) - - validatePending := clusterPendingFunc("UPDATING", "cluster is updating", workflow.ClusterUpdating) - Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validatePending), - 1200, interval).Should(BeTrue()) - - doCommonChecks() + performUpdate() }) By("Updating the Cluster backups settings", func() { - createdCluster.Spec.ProviderBackupEnabled = &enabled - Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) + createdCluster.Spec.ProviderBackupEnabled = boolptr(true) + performUpdate() + }) - validatePending := clusterPendingFunc("UPDATING", "cluster is updating", workflow.ClusterUpdating) - Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validatePending), - 1200, interval).Should(BeTrue()) + By("Decreasing the Cluster disk size", func() { + createdCluster.Spec.DiskSizeGB = intptr(10) + performUpdate() + }) - doCommonChecks() + By("Increasing the Cluster disk size", func() { + createdCluster.Spec.DiskSizeGB = intptr(10) + performUpdate() }) - // Atlas - atlasCluster, _, err := atlasClient.Clusters.Get(context.Background(), createdProject.Status.ID, createdCluster.Spec.Name) - Expect(err).ToNot(HaveOccurred()) - - createdAtlasCluster, err := createdCluster.Spec.Cluster() - Expect(err).ToNot(HaveOccurred()) - - Expect(atlasCluster.Name).To(Equal(createdAtlasCluster.Name)) - print(createdCluster.Labels) - print(createdAtlasCluster.Labels) - Expect(atlasCluster.Labels).To(Equal(createdAtlasCluster.Labels)) - Expect(atlasCluster.ProviderSettings.InstanceSizeName).To(Equal(createdAtlasCluster.ProviderSettings.InstanceSizeName)) - Expect(atlasCluster.ProviderSettings.ProviderName).To(Equal(createdAtlasCluster.ProviderSettings.ProviderName)) - Expect(atlasCluster.ProviderSettings.RegionName).To(Equal(createdAtlasCluster.ProviderSettings.RegionName)) - Expect(atlasCluster.ProviderBackupEnabled).To(Equal(createdAtlasCluster.ProviderBackupEnabled)) + By("Verifying Cluster state in Atlas", func() { + atlasCluster, _, err := atlasClient.Clusters.Get(context.Background(), createdProject.Status.ID, createdCluster.Spec.Name) + Expect(err).ToNot(HaveOccurred()) + + createdAtlasCluster, err := createdCluster.Spec.Cluster() + Expect(err).ToNot(HaveOccurred()) + + Expect(atlasCluster.Name).To(Equal(createdAtlasCluster.Name)) + print(createdCluster.Labels) + print(createdAtlasCluster.Labels) + Expect(atlasCluster.Labels).To(Equal(createdAtlasCluster.Labels)) + Expect(atlasCluster.ProviderSettings.InstanceSizeName).To(Equal(createdAtlasCluster.ProviderSettings.InstanceSizeName)) + Expect(atlasCluster.ProviderSettings.ProviderName).To(Equal(createdAtlasCluster.ProviderSettings.ProviderName)) + Expect(atlasCluster.ProviderSettings.RegionName).To(Equal(createdAtlasCluster.ProviderSettings.RegionName)) + Expect(atlasCluster.ProviderBackupEnabled).To(Equal(createdAtlasCluster.ProviderBackupEnabled)) + }) }) }) }) @@ -231,3 +239,11 @@ func removeAtlasProject(projectID string) func() bool { return true } } + +func intptr(i int) *int { + return &i +} + +func boolptr(b bool) *bool { + return &b +} From 0918c4a649d80c0a911494e50cfb611ec11d5d36 Mon Sep 17 00:00:00 2001 From: Pavel Vasilev Date: Mon, 1 Feb 2021 14:47:26 +0300 Subject: [PATCH 04/42] Fix disk size condition --- test/int/cluster_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 1e1fc18685..3f2e05a995 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -134,7 +134,7 @@ var _ = Describe("AtlasCluster", func() { }) By("Increasing the Cluster disk size", func() { - createdCluster.Spec.DiskSizeGB = intptr(10) + createdCluster.Spec.DiskSizeGB = intptr(64) performUpdate() }) From 657ab6f9c973265005a0d7cee2edbe8ca433bcf0 Mon Sep 17 00:00:00 2001 From: Pavel Vasilev Date: Mon, 1 Feb 2021 17:03:17 +0300 Subject: [PATCH 05/42] Remove disk size increase test (takes too long) --- test/int/cluster_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 3f2e05a995..81c6b79e88 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -133,11 +133,6 @@ var _ = Describe("AtlasCluster", func() { performUpdate() }) - By("Increasing the Cluster disk size", func() { - createdCluster.Spec.DiskSizeGB = intptr(64) - performUpdate() - }) - By("Verifying Cluster state in Atlas", func() { atlasCluster, _, err := atlasClient.Clusters.Get(context.Background(), createdProject.Status.ID, createdCluster.Spec.Name) Expect(err).ToNot(HaveOccurred()) From e868edc608a5dc75cf62bfc18d022d1478492a8c Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 3 Feb 2021 12:55:48 +0300 Subject: [PATCH 06/42] PR comments --- test/int/cluster_test.go | 85 ++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index fce6963ffd..cbe360fef7 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -7,17 +7,18 @@ import ( "net/http" "time" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "go.mongodb.org/atlas/mongodbatlas" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlas" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/workflow" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/kube" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/testutil" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "go.mongodb.org/atlas/mongodbatlas" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) var _ = Describe("AtlasCluster", func() { @@ -28,6 +29,7 @@ var _ = Describe("AtlasCluster", func() { connectionSecret corev1.Secret createdProject *mdbv1.AtlasProject createdCluster *mdbv1.AtlasCluster + lastGeneration int ) BeforeEach(func() { @@ -39,6 +41,9 @@ var _ = Describe("AtlasCluster", func() { GenerateName: "test", }, } + + lastGeneration = 0 + By("Creating the namespace " + namespace.Name) Expect(k8sClient.Create(context.Background(), &namespace)).ToNot(HaveOccurred()) @@ -80,17 +85,38 @@ var _ = Describe("AtlasCluster", func() { }) doCommonChecks := func() { - Expect(createdCluster.Status.ConnectionStrings).NotTo(BeNil()) - Expect(createdCluster.Status.ConnectionStrings.Standard).NotTo(BeNil()) - Expect(createdCluster.Status.ConnectionStrings.StandardSrv).NotTo(BeNil()) - Expect(createdCluster.Status.MongoDBVersion).NotTo(BeNil()) - Expect(createdCluster.Status.MongoURIUpdated).NotTo(BeNil()) - Expect(createdCluster.Status.StateName).To(Equal("IDLE")) - Expect(createdCluster.Status.Conditions).To(ConsistOf(testutil.MatchConditions( - status.TrueCondition(status.ClusterReadyType), - status.TrueCondition(status.ReadyType), - ))) - Expect(createdCluster.Status.ObservedGeneration).To(Equal(createdCluster.Generation)) + By("Checking observed Cluster state", func() { + Expect(createdCluster.Status.ConnectionStrings).NotTo(BeNil()) + Expect(createdCluster.Status.ConnectionStrings.Standard).NotTo(BeNil()) + Expect(createdCluster.Status.ConnectionStrings.StandardSrv).NotTo(BeNil()) + Expect(createdCluster.Status.MongoDBVersion).NotTo(BeNil()) + Expect(createdCluster.Status.MongoURIUpdated).NotTo(BeNil()) + Expect(createdCluster.Status.StateName).To(Equal("IDLE")) + Expect(createdCluster.Status.Conditions).To(ConsistOf(testutil.MatchConditions( + status.TrueCondition(status.ClusterReadyType), + status.TrueCondition(status.ReadyType), + ))) + Expect(createdCluster.Status.ObservedGeneration).To(Equal(createdCluster.Generation)) + Expect(createdCluster.Status.ObservedGeneration).To(Equal(lastGeneration + 1)) + lastGeneration++ + }) + + By("Verifying Cluster state in Atlas", func() { + atlasCluster, _, err := atlasClient.Clusters.Get(context.Background(), createdProject.Status.ID, createdCluster.Spec.Name) + Expect(err).ToNot(HaveOccurred()) + + createdAtlasCluster, err := createdCluster.Spec.Cluster() + Expect(err).ToNot(HaveOccurred()) + + Expect(atlasCluster.Name).To(Equal(createdAtlasCluster.Name)) + print(createdCluster.Labels) + print(createdAtlasCluster.Labels) + Expect(atlasCluster.Labels).To(Equal(createdAtlasCluster.Labels)) + Expect(atlasCluster.ProviderSettings.InstanceSizeName).To(Equal(createdAtlasCluster.ProviderSettings.InstanceSizeName)) + Expect(atlasCluster.ProviderSettings.ProviderName).To(Equal(createdAtlasCluster.ProviderSettings.ProviderName)) + Expect(atlasCluster.ProviderSettings.RegionName).To(Equal(createdAtlasCluster.ProviderSettings.RegionName)) + Expect(atlasCluster.ProviderBackupEnabled).To(Equal(createdAtlasCluster.ProviderBackupEnabled)) + }) } performUpdate := func() { @@ -116,16 +142,6 @@ var _ = Describe("AtlasCluster", func() { 1200, interval).Should(BeTrue()) doCommonChecks() - - // Atlas - atlasCluster, _, err := atlasClient.Clusters.Get(context.Background(), createdProject.Status.ID, createdCluster.Spec.Name) - Expect(err).ToNot(HaveOccurred()) - - // Unfortunately we cannot do global checks on cluster/providerSettings fields as Atlas adds default values - Expect(atlasCluster.Name).To(Equal(expectedCluster.Spec.Name)) - Expect(atlasCluster.ProviderSettings.InstanceSizeName).To(Equal(expectedCluster.Spec.ProviderSettings.InstanceSizeName)) - Expect(atlasCluster.ProviderSettings.ProviderName).To(Equal(expectedCluster.Spec.ProviderSettings.ProviderName)) - Expect(atlasCluster.ProviderSettings.RegionName).To(Equal(expectedCluster.Spec.ProviderSettings.RegionName)) }) // TODO check connectivity to cluster @@ -149,23 +165,6 @@ var _ = Describe("AtlasCluster", func() { createdCluster.Spec.DiskSizeGB = intptr(10) performUpdate() }) - - By("Verifying Cluster state in Atlas", func() { - atlasCluster, _, err := atlasClient.Clusters.Get(context.Background(), createdProject.Status.ID, createdCluster.Spec.Name) - Expect(err).ToNot(HaveOccurred()) - - createdAtlasCluster, err := createdCluster.Spec.Cluster() - Expect(err).ToNot(HaveOccurred()) - - Expect(atlasCluster.Name).To(Equal(createdAtlasCluster.Name)) - print(createdCluster.Labels) - print(createdAtlasCluster.Labels) - Expect(atlasCluster.Labels).To(Equal(createdAtlasCluster.Labels)) - Expect(atlasCluster.ProviderSettings.InstanceSizeName).To(Equal(createdAtlasCluster.ProviderSettings.InstanceSizeName)) - Expect(atlasCluster.ProviderSettings.ProviderName).To(Equal(createdAtlasCluster.ProviderSettings.ProviderName)) - Expect(atlasCluster.ProviderSettings.RegionName).To(Equal(createdAtlasCluster.ProviderSettings.RegionName)) - Expect(atlasCluster.ProviderBackupEnabled).To(Equal(createdAtlasCluster.ProviderBackupEnabled)) - }) }) }) }) From e416aaa40546e58364fd179733c7fba524806ecd Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 3 Feb 2021 14:04:38 +0300 Subject: [PATCH 07/42] Fixes after merge --- test/int/cluster_test.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index a34b650070..a03aa2e9df 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -28,7 +28,7 @@ var _ = Describe("AtlasCluster", func() { connectionSecret corev1.Secret createdProject *mdbv1.AtlasProject createdCluster *mdbv1.AtlasCluster - lastGeneration int + lastGeneration int64 ) BeforeEach(func() { @@ -146,11 +146,6 @@ var _ = Describe("AtlasCluster", func() { createdCluster.Spec.DiskSizeGB = intptr(10) performUpdate() }) - - By("Increasing the Cluster disk size", func() { - createdCluster.Spec.DiskSizeGB = intptr(10) - performUpdate() - }) }) }) }) From ba5f2ba1194fb95ea81b62344e17e67de1d83c96 Mon Sep 17 00:00:00 2001 From: Pavel Vasilev Date: Wed, 3 Feb 2021 16:47:52 +0300 Subject: [PATCH 08/42] Small fixes --- pkg/api/v1/status/zz_generated.deepcopy.go | 2 ++ test/int/cluster_test.go | 8 +++----- test/int/integration_suite_test.go | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/api/v1/status/zz_generated.deepcopy.go b/pkg/api/v1/status/zz_generated.deepcopy.go index 9469fb6d32..8becc4f1c0 100644 --- a/pkg/api/v1/status/zz_generated.deepcopy.go +++ b/pkg/api/v1/status/zz_generated.deepcopy.go @@ -12,6 +12,8 @@ a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 package status +import () + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AtlasClusterStatus) DeepCopyInto(out *AtlasClusterStatus) { *out = *in diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index a03aa2e9df..b5786cc479 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -46,11 +46,11 @@ var _ = Describe("AtlasCluster", func() { StringData: map[string]string{"orgId": connection.OrgID, "publicApiKey": connection.PublicKey, "privateApiKey": connection.PrivateKey}, } By(fmt.Sprintf("Creating the Secret %s", kube.ObjectKeyFromObject(&connectionSecret))) - Expect(k8sClient.Create(context.Background(), &connectionSecret)).ToNot(HaveOccurred()) + Expect(k8sClient.Create(context.Background(), &connectionSecret)).To(Succeed()) createdProject = testAtlasProject(namespace.Name, namespace.Name, connectionSecret.Name) By("Creating the project " + createdProject.Name) - Expect(k8sClient.Create(context.Background(), createdProject)).ToNot(HaveOccurred()) + Expect(k8sClient.Create(context.Background(), createdProject)).To(Succeed()) Eventually(testutil.WaitFor(k8sClient, createdProject, status.TrueCondition(status.ReadyType)), 10, interval).Should(BeTrue()) }) @@ -97,9 +97,7 @@ var _ = Describe("AtlasCluster", func() { Expect(err).ToNot(HaveOccurred()) Expect(atlasCluster.Name).To(Equal(createdAtlasCluster.Name)) - print(createdCluster.Labels) - print(createdAtlasCluster.Labels) - Expect(atlasCluster.Labels).To(Equal(createdAtlasCluster.Labels)) + Expect(atlasCluster.Labels).To(ConsistOf(createdAtlasCluster.Labels)) Expect(atlasCluster.ProviderSettings.InstanceSizeName).To(Equal(createdAtlasCluster.ProviderSettings.InstanceSizeName)) Expect(atlasCluster.ProviderSettings.ProviderName).To(Equal(createdAtlasCluster.ProviderSettings.ProviderName)) Expect(atlasCluster.ProviderSettings.RegionName).To(Equal(createdAtlasCluster.ProviderSettings.RegionName)) diff --git a/test/int/integration_suite_test.go b/test/int/integration_suite_test.go index 981ef03d6f..eb5c013443 100644 --- a/test/int/integration_suite_test.go +++ b/test/int/integration_suite_test.go @@ -25,10 +25,6 @@ import ( "testing" "github.com/go-logr/zapr" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlas" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlascluster" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlasproject" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/httputil" "go.mongodb.org/atlas/mongodbatlas" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" @@ -37,13 +33,18 @@ import ( ctrl "sigs.k8s.io/controller-runtime" ctrzap "sigs.k8s.io/controller-runtime/pkg/log/zap" - mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "k8s.io/client-go/kubernetes/scheme" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" "sigs.k8s.io/controller-runtime/pkg/envtest/printer" + + mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlas" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlascluster" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlasproject" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/httputil" // +kubebuilder:scaffold:imports ) @@ -113,7 +114,6 @@ var _ = SynchronizedBeforeSuite(func() []byte { }) var _ = SynchronizedAfterSuite(func() { - }, func() { By("tearing down the test environment") err := testEnv.Stop() From 4cdeb410a3b69a566a49b926d12b4abcfae76ad2 Mon Sep 17 00:00:00 2001 From: Pavel Vasilev Date: Wed, 3 Feb 2021 16:47:52 +0300 Subject: [PATCH 09/42] Small fixes --- pkg/api/v1/status/zz_generated.deepcopy.go | 2 ++ test/int/cluster_test.go | 8 +++----- test/int/integration_suite_test.go | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/api/v1/status/zz_generated.deepcopy.go b/pkg/api/v1/status/zz_generated.deepcopy.go index 9469fb6d32..8becc4f1c0 100644 --- a/pkg/api/v1/status/zz_generated.deepcopy.go +++ b/pkg/api/v1/status/zz_generated.deepcopy.go @@ -12,6 +12,8 @@ a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 package status +import () + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AtlasClusterStatus) DeepCopyInto(out *AtlasClusterStatus) { *out = *in diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index a03aa2e9df..b5786cc479 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -46,11 +46,11 @@ var _ = Describe("AtlasCluster", func() { StringData: map[string]string{"orgId": connection.OrgID, "publicApiKey": connection.PublicKey, "privateApiKey": connection.PrivateKey}, } By(fmt.Sprintf("Creating the Secret %s", kube.ObjectKeyFromObject(&connectionSecret))) - Expect(k8sClient.Create(context.Background(), &connectionSecret)).ToNot(HaveOccurred()) + Expect(k8sClient.Create(context.Background(), &connectionSecret)).To(Succeed()) createdProject = testAtlasProject(namespace.Name, namespace.Name, connectionSecret.Name) By("Creating the project " + createdProject.Name) - Expect(k8sClient.Create(context.Background(), createdProject)).ToNot(HaveOccurred()) + Expect(k8sClient.Create(context.Background(), createdProject)).To(Succeed()) Eventually(testutil.WaitFor(k8sClient, createdProject, status.TrueCondition(status.ReadyType)), 10, interval).Should(BeTrue()) }) @@ -97,9 +97,7 @@ var _ = Describe("AtlasCluster", func() { Expect(err).ToNot(HaveOccurred()) Expect(atlasCluster.Name).To(Equal(createdAtlasCluster.Name)) - print(createdCluster.Labels) - print(createdAtlasCluster.Labels) - Expect(atlasCluster.Labels).To(Equal(createdAtlasCluster.Labels)) + Expect(atlasCluster.Labels).To(ConsistOf(createdAtlasCluster.Labels)) Expect(atlasCluster.ProviderSettings.InstanceSizeName).To(Equal(createdAtlasCluster.ProviderSettings.InstanceSizeName)) Expect(atlasCluster.ProviderSettings.ProviderName).To(Equal(createdAtlasCluster.ProviderSettings.ProviderName)) Expect(atlasCluster.ProviderSettings.RegionName).To(Equal(createdAtlasCluster.ProviderSettings.RegionName)) diff --git a/test/int/integration_suite_test.go b/test/int/integration_suite_test.go index 981ef03d6f..eb5c013443 100644 --- a/test/int/integration_suite_test.go +++ b/test/int/integration_suite_test.go @@ -25,10 +25,6 @@ import ( "testing" "github.com/go-logr/zapr" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlas" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlascluster" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlasproject" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/httputil" "go.mongodb.org/atlas/mongodbatlas" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" @@ -37,13 +33,18 @@ import ( ctrl "sigs.k8s.io/controller-runtime" ctrzap "sigs.k8s.io/controller-runtime/pkg/log/zap" - mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "k8s.io/client-go/kubernetes/scheme" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" "sigs.k8s.io/controller-runtime/pkg/envtest/printer" + + mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlas" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlascluster" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlasproject" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/httputil" // +kubebuilder:scaffold:imports ) @@ -113,7 +114,6 @@ var _ = SynchronizedBeforeSuite(func() []byte { }) var _ = SynchronizedAfterSuite(func() { - }, func() { By("tearing down the test environment") err := testEnv.Stop() From a6ba48f8309a4276e6994c07b01f10dcadb7f9ac Mon Sep 17 00:00:00 2001 From: Pavel Vasilev Date: Wed, 3 Feb 2021 20:38:14 +0300 Subject: [PATCH 10/42] Make atlas tests generic & reusable --- test/int/cluster_test.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index b5786cc479..85570a24dc 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -88,7 +88,9 @@ var _ = Describe("AtlasCluster", func() { Expect(createdCluster.Status.ObservedGeneration).To(Equal(lastGeneration + 1)) lastGeneration++ }) + } + checkAtlasState := func(additionalChecks ...func(c *mongodbatlas.Cluster)) { By("Verifying Cluster state in Atlas", func() { atlasCluster, _, err := atlasClient.Clusters.Get(context.Background(), createdProject.Status.ID, createdCluster.Spec.Name) Expect(err).ToNot(HaveOccurred()) @@ -101,7 +103,10 @@ var _ = Describe("AtlasCluster", func() { Expect(atlasCluster.ProviderSettings.InstanceSizeName).To(Equal(createdAtlasCluster.ProviderSettings.InstanceSizeName)) Expect(atlasCluster.ProviderSettings.ProviderName).To(Equal(createdAtlasCluster.ProviderSettings.ProviderName)) Expect(atlasCluster.ProviderSettings.RegionName).To(Equal(createdAtlasCluster.ProviderSettings.RegionName)) - Expect(atlasCluster.ProviderBackupEnabled).To(Equal(createdAtlasCluster.ProviderBackupEnabled)) + + for _, check := range additionalChecks { + check(atlasCluster) + } }) } @@ -126,6 +131,7 @@ var _ = Describe("AtlasCluster", func() { 1800, interval).Should(BeTrue()) doCommonChecks() + checkAtlasState() }) // TODO check connectivity to cluster @@ -133,16 +139,26 @@ var _ = Describe("AtlasCluster", func() { By("Updating the Cluster labels", func() { createdCluster.Spec.Labels = []mdbv1.LabelSpec{{Key: "int-test", Value: "true"}} performUpdate() + checkAtlasState() }) By("Updating the Cluster backups settings", func() { createdCluster.Spec.ProviderBackupEnabled = boolptr(true) performUpdate() + checkAtlasState(func(c *mongodbatlas.Cluster) { + Expect(c.ProviderBackupEnabled).To(Equal(createdCluster.Spec.ProviderBackupEnabled)) + }) }) By("Decreasing the Cluster disk size", func() { createdCluster.Spec.DiskSizeGB = intptr(10) performUpdate() + checkAtlasState(func(c *mongodbatlas.Cluster) { + Expect(*c.DiskSizeGB).To(BeEquivalentTo(*createdCluster.Spec.DiskSizeGB)) + + // check whether https://github.com/mongodb/go-client-mongodb-atlas/issues/140 is fixed + Expect(c.DiskSizeGB).To(BeAssignableToTypeOf(float64ptr(0)), "DiskSizeGB is no longer a *float64, please check the spec!") + }) }) }) }) @@ -242,6 +258,10 @@ func intptr(i int) *int { return &i } +func float64ptr(f float64) *float64 { + return &f +} + func boolptr(b bool) *bool { return &b } From 42df9c4b13589a53ac03741da8773a163c3cc7c0 Mon Sep 17 00:00:00 2001 From: Pavel Vasilev Date: Fri, 5 Feb 2021 12:57:08 +0300 Subject: [PATCH 11/42] Initial test impl --- .../atlas.mongodb.com_atlasclusters.yaml | 3 ++ pkg/api/v1/atlascluster_types.go | 3 ++ pkg/api/v1/zz_generated.deepcopy.go | 5 ++ .../atlascluster/atlascluster_controller.go | 7 ++- test/int/cluster_test.go | 46 +++++++++++++++++++ 5 files changed, 60 insertions(+), 4 deletions(-) diff --git a/config/crd/bases/atlas.mongodb.com_atlasclusters.yaml b/config/crd/bases/atlas.mongodb.com_atlasclusters.yaml index ad295dfbaa..d836663a74 100644 --- a/config/crd/bases/atlas.mongodb.com_atlasclusters.yaml +++ b/config/crd/bases/atlas.mongodb.com_atlasclusters.yaml @@ -139,6 +139,9 @@ spec: maximum: 50 minimum: 1 type: integer + paused: + description: Flag that indicates whether the cluster is paused. + type: boolean pitEnabled: description: Flag that indicates the cluster uses continuous cloud backups. diff --git a/pkg/api/v1/atlascluster_types.go b/pkg/api/v1/atlascluster_types.go index d1534ae6f0..a83663e051 100644 --- a/pkg/api/v1/atlascluster_types.go +++ b/pkg/api/v1/atlascluster_types.go @@ -84,6 +84,9 @@ type AtlasClusterSpec struct { // +optional NumShards *int `json:"numShards,omitempty"` + // Flag that indicates whether the cluster is paused. + Paused *bool `json:"paused,omitempty"` + // Flag that indicates the cluster uses continuous cloud backups. // +optional PitEnabled *bool `json:"pitEnabled,omitempty"` diff --git a/pkg/api/v1/zz_generated.deepcopy.go b/pkg/api/v1/zz_generated.deepcopy.go index c566f65338..5c6e50b547 100644 --- a/pkg/api/v1/zz_generated.deepcopy.go +++ b/pkg/api/v1/zz_generated.deepcopy.go @@ -104,6 +104,11 @@ func (in *AtlasClusterSpec) DeepCopyInto(out *AtlasClusterSpec) { *out = new(int) **out = **in } + if in.Paused != nil { + in, out := &in.Paused, &out.Paused + *out = new(bool) + **out = **in + } if in.PitEnabled != nil { in, out := &in.PitEnabled, &out.PitEnabled *out = new(bool) diff --git a/pkg/controller/atlascluster/atlascluster_controller.go b/pkg/controller/atlascluster/atlascluster_controller.go index e781c0bfc2..b5a564ed67 100644 --- a/pkg/controller/atlascluster/atlascluster_controller.go +++ b/pkg/controller/atlascluster/atlascluster_controller.go @@ -28,15 +28,14 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/source" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/watch" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/workflow" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/kube" - mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlas" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/customresource" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/statushandler" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/watch" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/workflow" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/kube" ) // AtlasClusterReconciler reconciles an AtlasCluster object diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 85570a24dc..43dca32314 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -160,6 +160,30 @@ var _ = Describe("AtlasCluster", func() { Expect(c.DiskSizeGB).To(BeAssignableToTypeOf(float64ptr(0)), "DiskSizeGB is no longer a *float64, please check the spec!") }) }) + + By("Pausing the Cluster", func() { + createdCluster.Spec.Paused = boolptr(true) + Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) + + Eventually( + testutil.WaitFor( + k8sClient, + createdCluster, + status.FalseCondition(status.ClusterReadyType).WithReason(string(workflow.Internal)), + validateClusterFailingFunc(), + ), + 1200, + interval, + ).Should(BeTrue()) + }) + + By("Unpausing the Cluster", func() { + createdCluster.Spec.Paused = boolptr(false) + Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) + + Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validateClusterFailingFunc()), + 1200, interval).Should(BeTrue()) + }) }) }) }) @@ -207,6 +231,28 @@ func validateClusterUpdatingFunc() func(a mdbv1.AtlasCustomResource) { } } +func validateClusterFailingFunc() func(a mdbv1.AtlasCustomResource) { + isIdle := true + return func(a mdbv1.AtlasCustomResource) { + c := a.(*mdbv1.AtlasCluster) + // It's ok if the first invocations see IDLE + if c.Status.StateName != "IDLE" { + isIdle = false + } + + // When the create request has been made to Atlas - we expect the following status + if isIdle { + return + } + + expectedConditionsMatchers := testutil.MatchConditions( + status.FalseCondition(status.ClusterReadyType).WithReason(string(workflow.ClusterNotCreatedInAtlas)).WithMessage("cluster is updating"), + status.FalseCondition(status.ReadyType), + ) + Expect(c.Status.Conditions).To(ConsistOf(expectedConditionsMatchers)) + } +} + // TODO builders func testAtlasCluster(namespace, name, projectName string) *mdbv1.AtlasCluster { return &mdbv1.AtlasCluster{ From 78cb6db5624f4a960a5c679627eba51eba34d619 Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 5 Feb 2021 14:14:01 +0300 Subject: [PATCH 12/42] Add special case for Paused --- pkg/api/v1/atlascluster_types.go | 3 +++ pkg/controller/atlascluster/cluster.go | 21 +++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/api/v1/atlascluster_types.go b/pkg/api/v1/atlascluster_types.go index d1534ae6f0..55c25331f8 100644 --- a/pkg/api/v1/atlascluster_types.go +++ b/pkg/api/v1/atlascluster_types.go @@ -84,6 +84,9 @@ type AtlasClusterSpec struct { // +optional NumShards *int `json:"numShards,omitempty"` + // Flag that indicates whether the cluster should be paused. + Paused *bool `json:"paused,omitempty"` + // Flag that indicates the cluster uses continuous cloud backups. // +optional PitEnabled *bool `json:"pitEnabled,omitempty"` diff --git a/pkg/controller/atlascluster/cluster.go b/pkg/controller/atlascluster/cluster.go index 76be61fa60..be4ee6fb4c 100644 --- a/pkg/controller/atlascluster/cluster.go +++ b/pkg/controller/atlascluster/cluster.go @@ -48,15 +48,28 @@ func (r *AtlasClusterReconciler) ensureClusterState(log *zap.SugaredLogger, conn switch c.StateName { case "IDLE": + if done, err := clusterMatchesSpec(log, c, cluster.Spec); err != nil { + return c, workflow.Terminate(workflow.Internal, err.Error()) + } else if done { + return c, workflow.OK() + } + spec, err := cluster.Spec.Cluster() if err != nil { return c, workflow.Terminate(workflow.Internal, err.Error()) } - if done, err := clusterMatchesSpec(log, c, cluster.Spec); err != nil { - return c, workflow.Terminate(workflow.Internal, err.Error()) - } else if done { - return c, workflow.OK() + if cluster.Spec.Paused != nil { + if c.Paused == nil || *c.Paused != *cluster.Spec.Paused { + // paused is different from Atlas + // we need to first send a special (un)pause request before reconciling everything else + spec = &mongodbatlas.Cluster{ + Paused: cluster.Spec.Paused, + } + } else { + // otherwise, don't send the paused field + spec.Paused = nil + } } c, _, err = client.Clusters.Update(ctx, project.Status.ID, cluster.Spec.Name, spec) From f43235148a4b13467827aadc5bde95e281ab537f Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 5 Feb 2021 14:55:33 +0300 Subject: [PATCH 13/42] Run make generate manifests --- config/crd/bases/atlas.mongodb.com_atlasclusters.yaml | 3 +++ pkg/api/v1/zz_generated.deepcopy.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/config/crd/bases/atlas.mongodb.com_atlasclusters.yaml b/config/crd/bases/atlas.mongodb.com_atlasclusters.yaml index ad295dfbaa..2a9c65ec90 100644 --- a/config/crd/bases/atlas.mongodb.com_atlasclusters.yaml +++ b/config/crd/bases/atlas.mongodb.com_atlasclusters.yaml @@ -139,6 +139,9 @@ spec: maximum: 50 minimum: 1 type: integer + paused: + description: Flag that indicates whether the cluster should be paused. + type: boolean pitEnabled: description: Flag that indicates the cluster uses continuous cloud backups. diff --git a/pkg/api/v1/zz_generated.deepcopy.go b/pkg/api/v1/zz_generated.deepcopy.go index c566f65338..5c6e50b547 100644 --- a/pkg/api/v1/zz_generated.deepcopy.go +++ b/pkg/api/v1/zz_generated.deepcopy.go @@ -104,6 +104,11 @@ func (in *AtlasClusterSpec) DeepCopyInto(out *AtlasClusterSpec) { *out = new(int) **out = **in } + if in.Paused != nil { + in, out := &in.Paused, &out.Paused + *out = new(bool) + **out = **in + } if in.PitEnabled != nil { in, out := &in.PitEnabled, &out.PitEnabled *out = new(bool) From 286f2f0e00d153ef320945be1b129b36309d349b Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 5 Feb 2021 15:24:14 +0300 Subject: [PATCH 14/42] Fix matched condition in Pause --- pkg/util/testutil/conditions.go | 7 +++++-- test/int/cluster_test.go | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/util/testutil/conditions.go b/pkg/util/testutil/conditions.go index c64724e519..798daaa462 100644 --- a/pkg/util/testutil/conditions.go +++ b/pkg/util/testutil/conditions.go @@ -1,6 +1,8 @@ package testutil import ( + "regexp" + "github.com/onsi/gomega/format" "github.com/onsi/gomega/types" @@ -40,9 +42,10 @@ func (m *conditionMatcher) Match(actual interface{}) (success bool, err error) { if m.ExpectedCondition.Type != "" && c.Type != m.ExpectedCondition.Type { return false, nil } - // Add regexp when necessary if m.ExpectedCondition.Message != "" && c.Message != m.ExpectedCondition.Message { - return false, nil + if !regexp.MustCompile(m.ExpectedCondition.Message).MatchString(c.Message) { + return false, nil + } } return true, nil diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 43dca32314..ca1ef8aa14 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -169,7 +169,10 @@ var _ = Describe("AtlasCluster", func() { testutil.WaitFor( k8sClient, createdCluster, - status.FalseCondition(status.ClusterReadyType).WithReason(string(workflow.Internal)), + status. + FalseCondition(status.ClusterReadyType). + WithReason(string(workflow.ClusterNotCreatedInAtlas)). + WithMessage(`\(request \\"CANNOT_UPDATE_AND_PAUSE_CLUSTER\\"\) Cannot update and pause cluster test-atlas-cluster at the same time\.$`), validateClusterFailingFunc(), ), 1200, From a097a090459ab1ec72b7a3cb292a9eccdc9fc062 Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 5 Feb 2021 15:25:05 +0300 Subject: [PATCH 15/42] Fix matched condition for unpause --- test/int/cluster_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index ca1ef8aa14..73e90bd633 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -184,8 +184,19 @@ var _ = Describe("AtlasCluster", func() { createdCluster.Spec.Paused = boolptr(false) Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) - Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validateClusterFailingFunc()), - 1200, interval).Should(BeTrue()) + Eventually( + testutil.WaitFor( + k8sClient, + createdCluster, + status. + FalseCondition(status.ClusterReadyType). + WithReason(string(workflow.ClusterNotCreatedInAtlas)). + validateClusterFailingFunc(), + ), + 1200, + interval, + ).Should(BeTrue()) + }) }) }) }) From 51d2ec9f953698a42fd84802f87de5f0c534c79e Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 5 Feb 2021 15:29:38 +0300 Subject: [PATCH 16/42] Fix typo --- test/int/cluster_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 73e90bd633..b84c347440 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -190,14 +190,13 @@ var _ = Describe("AtlasCluster", func() { createdCluster, status. FalseCondition(status.ClusterReadyType). - WithReason(string(workflow.ClusterNotCreatedInAtlas)). + WithReason(string(workflow.ClusterNotCreatedInAtlas)), validateClusterFailingFunc(), ), 1200, interval, ).Should(BeTrue()) }) - }) }) }) }) From 6755c282d1aad914fa184e479828f89db72a8352 Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 8 Feb 2021 11:53:39 +0300 Subject: [PATCH 17/42] Add int tests for cluster (un)pause --- test/int/cluster_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 93998c7c34..88689c5b21 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -160,6 +160,22 @@ var _ = Describe("AtlasCluster", func() { Expect(c.DiskSizeGB).To(BeAssignableToTypeOf(float64ptr(0)), "DiskSizeGB is no longer a *float64, please check the spec!") }) }) + + By("Pausing the cluster", func() { + createdCluster.Spec.Paused = boolptr(true) + performUpdate() + checkAtlasState(func(c *mongodbatlas.Cluster) { + Expect(c.Paused).To(Equal(createdCluster.Spec.Paused)) + }) + }) + + By("Unpausing the cluster", func() { + createdCluster.Spec.Paused = boolptr(false) + performUpdate() + checkAtlasState(func(c *mongodbatlas.Cluster) { + Expect(c.Paused).To(Equal(createdCluster.Spec.Paused)) + }) + }) }) }) }) From 3b00aab416209af0d87a1d94bc797e9fcddbad81 Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 8 Feb 2021 13:17:28 +0300 Subject: [PATCH 18/42] Support "REPAIRING" state (for pause) --- test/int/cluster_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 88689c5b21..8faf28c335 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -213,7 +213,7 @@ func validateClusterUpdatingFunc() func(a mdbv1.AtlasCustomResource) { } // When the create request has been made to Atlas - we expect the following status if !isIdle { - Expect(c.Status.StateName).To(Equal("UPDATING"), fmt.Sprintf("Current conditions: %+v", c.Status.Conditions)) + Expect(c.Status.StateName).To(Or(Equal("UPDATING"), Equal("REPAIRING")), fmt.Sprintf("Current conditions: %+v", c.Status.Conditions)) expectedConditionsMatchers := testutil.MatchConditions( status.FalseCondition(status.ClusterReadyType).WithReason(string(workflow.ClusterUpdating)).WithMessage("cluster is updating"), status.FalseCondition(status.ReadyType), From 3cd01f8897939f46b5d35ddd91ae90d367abf481 Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 9 Feb 2021 14:43:14 +0300 Subject: [PATCH 19/42] Add tests between pause/unpause --- test/int/cluster_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 8faf28c335..c2e482e70e 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -169,6 +169,18 @@ var _ = Describe("AtlasCluster", func() { }) }) + By("Updating the Cluster configuration while paused (should fail)", func() { + createdCluster.Spec.ProviderBackupEnabled = boolptr(false) + + Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) + + Eventually( + testutil.WaitFor(k8sClient, createdCluster, status.FalseCondition(status.ClusterReadyType).WithReason(string(workflow.ClusterNotCreatedInAtlas))), + 60, + interval, + ).Should(BeTrue()) + }) + By("Unpausing the cluster", func() { createdCluster.Spec.Paused = boolptr(false) performUpdate() @@ -176,6 +188,12 @@ var _ = Describe("AtlasCluster", func() { Expect(c.Paused).To(Equal(createdCluster.Spec.Paused)) }) }) + + By("Checking that modifications were applied after unpausing", func() { + checkAtlasState(func(c *mongodbatlas.Cluster) { + Expect(c.ProviderBackupEnabled).To(Equal(createdCluster.Spec.ProviderBackupEnabled)) + }) + }) }) }) }) From 5686ceb3ad4eee7851baa71601bc7a4e7294e86d Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 9 Feb 2021 17:10:08 +0300 Subject: [PATCH 20/42] Fix lastGeneration in tests --- test/int/cluster_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index c2e482e70e..21eb328d2b 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -179,6 +179,8 @@ var _ = Describe("AtlasCluster", func() { 60, interval, ).Should(BeTrue()) + + lastGeneration++ }) By("Unpausing the cluster", func() { From ba12fab8a234c1a2365c1a23790345a2df19adf0 Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 9 Feb 2021 20:40:34 +0300 Subject: [PATCH 21/42] Reduce project remove timeout --- test/int/cluster_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 21eb328d2b..3de036d38c 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -67,7 +67,7 @@ var _ = Describe("AtlasCluster", func() { // This is a bit strange but the delete request right after the cluster is removed may fail with "Still active cluster" error // UI shows the cluster being deleted though. Seems to be the issue only if removal is done using API, // if the cluster is terminated using UI - it stays in "Deleting" state - Eventually(removeAtlasProject(createdProject.Status.ID), 600, interval).Should(BeTrue()) + Eventually(removeAtlasProject(createdProject.Status.ID), 20, interval).Should(BeTrue()) } removeControllersAndNamespace() }) From 6f60768b7ba15cfee31605fc0398ca3f79e9cc4b Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 9 Feb 2021 21:02:25 +0300 Subject: [PATCH 22/42] Add common checks to post-pause --- test/int/cluster_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 37d640acaf..6d407f1f51 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -192,6 +192,7 @@ var _ = Describe("AtlasCluster", func() { }) By("Checking that modifications were applied after unpausing", func() { + doCommonChecks() checkAtlasState(func(c *mongodbatlas.Cluster) { Expect(c.ProviderBackupEnabled).To(Equal(createdCluster.Spec.ProviderBackupEnabled)) }) From 0c1d6d230c54a850f7bc899de27af5f62d155b49 Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 9 Feb 2021 21:26:01 +0300 Subject: [PATCH 23/42] Fix atlas cluster unit test --- pkg/api/v1/atlascluster_types_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/api/v1/atlascluster_types_test.go b/pkg/api/v1/atlascluster_types_test.go index 48078d2cf8..91218baa25 100644 --- a/pkg/api/v1/atlascluster_types_test.go +++ b/pkg/api/v1/atlascluster_types_test.go @@ -10,8 +10,10 @@ import ( "go.mongodb.org/atlas/mongodbatlas" ) -var excludedClusterFieldsOurs = map[string]bool{} -var excludedClusterFieldsTheirs = map[string]bool{} +var ( + excludedClusterFieldsOurs = map[string]bool{} + excludedClusterFieldsTheirs = map[string]bool{} +) func init() { excludedClusterFieldsOurs["projectRef"] = true @@ -32,9 +34,6 @@ func init() { excludedClusterFieldsTheirs["connectionStrings"] = true excludedClusterFieldsTheirs["srvAddress"] = true excludedClusterFieldsTheirs["stateName"] = true - - // CLOUDP-80765 - excludedClusterFieldsTheirs["paused"] = true } func TestCompatibility(t *testing.T) { From 6146120bc2a6652df30e196b19a2bbe1695231c3 Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 9 Feb 2021 21:37:02 +0300 Subject: [PATCH 24/42] Rework tests --- test/int/cluster_test.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 6d407f1f51..0f6b185cd5 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -86,7 +86,6 @@ var _ = Describe("AtlasCluster", func() { ))) Expect(createdCluster.Status.ObservedGeneration).To(Equal(createdCluster.Generation)) Expect(createdCluster.Status.ObservedGeneration).To(Equal(lastGeneration + 1)) - lastGeneration++ }) } @@ -116,7 +115,7 @@ var _ = Describe("AtlasCluster", func() { Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validateClusterUpdatingFunc()), 1200, interval).Should(BeTrue()) - doCommonChecks() + lastGeneration++ } Describe("Create/Update the cluster", func() { @@ -130,6 +129,8 @@ var _ = Describe("AtlasCluster", func() { Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validateClusterCreatingFunc()), 1800, interval).Should(BeTrue()) + lastGeneration++ + doCommonChecks() checkAtlasState() }) @@ -139,12 +140,14 @@ var _ = Describe("AtlasCluster", func() { By("Updating the Cluster labels", func() { createdCluster.Spec.Labels = []mdbv1.LabelSpec{{Key: "int-test", Value: "true"}} performUpdate() + doCommonChecks() checkAtlasState() }) By("Updating the Cluster backups settings", func() { createdCluster.Spec.ProviderBackupEnabled = boolptr(true) performUpdate() + doCommonChecks() checkAtlasState(func(c *mongodbatlas.Cluster) { Expect(c.ProviderBackupEnabled).To(Equal(createdCluster.Spec.ProviderBackupEnabled)) }) @@ -153,6 +156,7 @@ var _ = Describe("AtlasCluster", func() { By("Decreasing the Cluster disk size", func() { createdCluster.Spec.DiskSizeGB = intptr(10) performUpdate() + doCommonChecks() checkAtlasState(func(c *mongodbatlas.Cluster) { Expect(*c.DiskSizeGB).To(BeEquivalentTo(*createdCluster.Spec.DiskSizeGB)) @@ -164,6 +168,7 @@ var _ = Describe("AtlasCluster", func() { By("Pausing the cluster", func() { createdCluster.Spec.Paused = boolptr(true) performUpdate() + doCommonChecks() checkAtlasState(func(c *mongodbatlas.Cluster) { Expect(c.Paused).To(Equal(createdCluster.Spec.Paused)) }) @@ -173,19 +178,17 @@ var _ = Describe("AtlasCluster", func() { createdCluster.Spec.ProviderBackupEnabled = boolptr(false) Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) - Eventually( testutil.WaitFor(k8sClient, createdCluster, status.FalseCondition(status.ClusterReadyType).WithReason(string(workflow.ClusterNotCreatedInAtlas))), 60, interval, ).Should(BeTrue()) - - lastGeneration++ }) By("Unpausing the cluster", func() { createdCluster.Spec.Paused = boolptr(false) performUpdate() + doCommonChecks() checkAtlasState(func(c *mongodbatlas.Cluster) { Expect(c.Paused).To(Equal(createdCluster.Spec.Paused)) }) From f3bf39c73c735ca5b45f1af75a49bdd1789551ca Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 10 Feb 2021 12:42:47 +0300 Subject: [PATCH 25/42] Starting lastGeneration should be 0 --- test/int/cluster_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 0f6b185cd5..e1b2ae41a3 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -129,8 +129,6 @@ var _ = Describe("AtlasCluster", func() { Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validateClusterCreatingFunc()), 1800, interval).Should(BeTrue()) - lastGeneration++ - doCommonChecks() checkAtlasState() }) From d0a6cdfc5ee50dfbdcc7b54d9976ca5a0e278053 Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 10 Feb 2021 17:02:59 +0300 Subject: [PATCH 26/42] Add more fail tests --- test/int/cluster_test.go | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 6d2b2786ca..3e822b2ded 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -198,6 +198,47 @@ var _ = Describe("AtlasCluster", func() { Expect(c.ProviderBackupEnabled).To(Equal(createdCluster.Spec.ProviderBackupEnabled)) }) }) + + By("Renaming the Cluster (should fail)", func() { + oldName := createdCluster.Spec.Name + createdCluster.Spec.Name = oldName + "-rnm" + + Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) + Eventually( + testutil.WaitFor(k8sClient, createdCluster, status.FalseCondition(status.ClusterReadyType).WithReason(string(workflow.ClusterNotCreatedInAtlas))), + 60, + interval, + ).Should(BeTrue()) + + By("Renaming the Cluster back", func() { + createdCluster.Spec.Name = oldName + performUpdate() + doCommonChecks() + checkAtlasState() + }) + }) + + By("Setting AutoScaling.Compute.Enabled to false (should fail)", func() { + createdCluster.Spec.ProviderSettings.AutoScaling = &mdbv1.AutoScalingSpec{ + Compute: &mdbv1.ComputeSpec{ + Enabled: boolptr(false), + }, + } + + Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) + Eventually( + testutil.WaitFor(k8sClient, createdCluster, status.FalseCondition(status.ClusterReadyType).WithReason(string(workflow.ClusterNotCreatedInAtlas))), + 60, + interval, + ).Should(BeTrue()) + + By("Fixing the Cluster", func() { + createdCluster.Spec.ProviderSettings.AutoScaling = nil + performUpdate() + doCommonChecks() + checkAtlasState() + }) + }) }) }) }) From 110483f3e9cb758103df125f0e51ace48f63e499 Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 10 Feb 2021 17:04:49 +0300 Subject: [PATCH 27/42] More lastGeneration stuff --- test/int/cluster_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index e1b2ae41a3..86aed11a45 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -181,6 +181,8 @@ var _ = Describe("AtlasCluster", func() { 60, interval, ).Should(BeTrue()) + + lastGeneration++ }) By("Unpausing the cluster", func() { From 745e31f5c6d85137828e3c2bd915e8515627ec83 Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 10 Feb 2021 17:10:10 +0300 Subject: [PATCH 28/42] Remove unused func --- test/int/cluster_test.go | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index f7044a268b..bb183f95f4 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -288,28 +288,6 @@ func validateClusterUpdatingFunc() func(a mdbv1.AtlasCustomResource) { } } -func validateClusterFailingFunc() func(a mdbv1.AtlasCustomResource) { - isIdle := true - return func(a mdbv1.AtlasCustomResource) { - c := a.(*mdbv1.AtlasCluster) - // It's ok if the first invocations see IDLE - if c.Status.StateName != "IDLE" { - isIdle = false - } - - // When the create request has been made to Atlas - we expect the following status - if isIdle { - return - } - - expectedConditionsMatchers := testutil.MatchConditions( - status.FalseCondition(status.ClusterReadyType).WithReason(string(workflow.ClusterNotCreatedInAtlas)).WithMessageRegexp("cluster is updating"), - status.FalseCondition(status.ReadyType), - ) - Expect(c.Status.Conditions).To(ConsistOf(expectedConditionsMatchers)) - } -} - // TODO builders func testAtlasCluster(namespace, name, projectName string) *mdbv1.AtlasCluster { return &mdbv1.AtlasCluster{ From aaea167755aa2e27c49bcd15f27b895af5620c83 Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 10 Feb 2021 19:29:41 +0300 Subject: [PATCH 29/42] Add ClusterNotUpdatedInAtlas; stub WithMessageRegexp --- pkg/controller/atlascluster/cluster.go | 2 +- pkg/controller/workflow/reason.go | 1 + test/int/cluster_test.go | 27 +++++++++++++++++++++++--- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/pkg/controller/atlascluster/cluster.go b/pkg/controller/atlascluster/cluster.go index be4ee6fb4c..dec1487ca1 100644 --- a/pkg/controller/atlascluster/cluster.go +++ b/pkg/controller/atlascluster/cluster.go @@ -74,7 +74,7 @@ func (r *AtlasClusterReconciler) ensureClusterState(log *zap.SugaredLogger, conn c, _, err = client.Clusters.Update(ctx, project.Status.ID, cluster.Spec.Name, spec) if err != nil { - return c, workflow.Terminate(workflow.ClusterNotCreatedInAtlas, err.Error()) + return c, workflow.Terminate(workflow.ClusterNotUpdatedInAtlas, err.Error()) } return c, workflow.InProgress(workflow.ClusterUpdating, "cluster is updating") diff --git a/pkg/controller/workflow/reason.go b/pkg/controller/workflow/reason.go index 096a01398b..5097175be8 100644 --- a/pkg/controller/workflow/reason.go +++ b/pkg/controller/workflow/reason.go @@ -20,6 +20,7 @@ const ( // Atlas Cluster reasons const ( ClusterNotCreatedInAtlas ConditionReason = "ClusterNotCreatedInAtlas" + ClusterNotUpdatedInAtlas ConditionReason = "ClusterNotUpdatedInAtlas" ClusterCreating ConditionReason = "ClusterCreating" ClusterUpdating ConditionReason = "ClusterUpdating" ) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index c72ac980c8..e8a0125341 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -180,7 +180,14 @@ var _ = Describe("AtlasCluster", func() { Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) Eventually( - testutil.WaitFor(k8sClient, createdCluster, status.FalseCondition(status.ClusterReadyType).WithReason(string(workflow.ClusterNotCreatedInAtlas))), + testutil.WaitFor( + k8sClient, + createdCluster, + status. + FalseCondition(status.ClusterReadyType). + WithReason(string(workflow.ClusterNotUpdatedInAtlas)),. + WithMessageRegexp("TODOTODO") + ), 60, interval, ).Should(BeTrue()) @@ -210,7 +217,14 @@ var _ = Describe("AtlasCluster", func() { Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) Eventually( - testutil.WaitFor(k8sClient, createdCluster, status.FalseCondition(status.ClusterReadyType).WithReason(string(workflow.ClusterNotCreatedInAtlas))), + testutil.WaitFor( + k8sClient, + createdCluster, + status. + FalseCondition(status.ClusterReadyType). + WithReason(string(workflow.ClusterNotUpdatedInAtlas)). + WithMessageRegexp("TODOTODO"), + ), 60, interval, ).Should(BeTrue()) @@ -232,7 +246,14 @@ var _ = Describe("AtlasCluster", func() { Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) Eventually( - testutil.WaitFor(k8sClient, createdCluster, status.FalseCondition(status.ClusterReadyType).WithReason(string(workflow.ClusterNotCreatedInAtlas))), + testutil.WaitFor( + k8sClient, + createdCluster, + status. + FalseCondition(status.ClusterReadyType). + WithReason(string(workflow.ClusterNotUpdatedInAtlas)). + WithMessageRegexp("TODOTODO"), + ), 60, interval, ).Should(BeTrue()) From bb998f07c87f78879a8ee63b8cc82abb2314d822 Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 10 Feb 2021 20:43:25 +0300 Subject: [PATCH 30/42] Fix --- test/int/cluster_test.go | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index e8a0125341..d8a69f2c32 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -185,8 +185,8 @@ var _ = Describe("AtlasCluster", func() { createdCluster, status. FalseCondition(status.ClusterReadyType). - WithReason(string(workflow.ClusterNotUpdatedInAtlas)),. - WithMessageRegexp("TODOTODO") + WithReason(string(workflow.ClusterNotUpdatedInAtlas)). + WithMessageRegexp("TODOTODO"), ), 60, interval, @@ -265,6 +265,35 @@ var _ = Describe("AtlasCluster", func() { checkAtlasState() }) }) + + By("Setting incorrect instance size (should fail)", func() { + createdCluster.Spec.ProviderSettings.AutoScaling = &mdbv1.AutoScalingSpec{ + Compute: &mdbv1.ComputeSpec{ + Enabled: boolptr(false), + }, + } + + Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) + Eventually( + testutil.WaitFor( + k8sClient, + createdCluster, + status. + FalseCondition(status.ClusterReadyType). + WithReason(string(workflow.ClusterNotUpdatedInAtlas)). + WithMessageRegexp("TODOTODO"), + ), + 60, + interval, + ).Should(BeTrue()) + + By("Fixing the Cluster", func() { + createdCluster.Spec.ProviderSettings.AutoScaling = nil + performUpdate() + doCommonChecks() + checkAtlasState() + }) + }) }) }) }) From 5f06c4cf27069a8ebc998958af3ff585755a6e40 Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 10 Feb 2021 21:02:34 +0300 Subject: [PATCH 31/42] Add a test for create failure --- test/int/cluster_test.go | 43 +++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index d8a69f2c32..c9a34e05b3 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -122,6 +122,32 @@ var _ = Describe("AtlasCluster", func() { } Describe("Create/Update the cluster", func() { + It("Should fail, then be fixed", func() { + invalidCluster := testAtlasCluster(namespace.Name, "test-cluster", createdProject.Name) + invalidCluster.Spec.MongoDBMajorVersion = "42.42" + + By(fmt.Sprintf("Creating the Cluster %s", kube.ObjectKeyFromObject(invalidCluster)), func() { + createdCluster.ObjectMeta = invalidCluster.ObjectMeta + Expect(k8sClient.Create(context.Background(), invalidCluster)).ToNot(HaveOccurred()) + + Eventually( + testutil.WaitFor( + k8sClient, + createdCluster, + status. + FalseCondition(status.ClusterReadyType). + WithReason(string(workflow.ClusterNotUpdatedInAtlas)). + WithMessageRegexp("TODOTODO"), + ), + 1800, + interval, + ).Should(BeTrue()) + + doCommonChecks() + checkAtlasState() + }) + }) + It("Should Succeed", func() { expectedCluster := testAtlasCluster(namespace.Name, "test-cluster", createdProject.Name) @@ -186,7 +212,7 @@ var _ = Describe("AtlasCluster", func() { status. FalseCondition(status.ClusterReadyType). WithReason(string(workflow.ClusterNotUpdatedInAtlas)). - WithMessageRegexp("TODOTODO"), + WithMessageRegexp("CANNOT_UPDATE_PAUSED_CLUSTER"), ), 60, interval, @@ -229,6 +255,8 @@ var _ = Describe("AtlasCluster", func() { interval, ).Should(BeTrue()) + lastGeneration++ + By("Renaming the Cluster back", func() { createdCluster.Spec.Name = oldName performUpdate() @@ -258,6 +286,8 @@ var _ = Describe("AtlasCluster", func() { interval, ).Should(BeTrue()) + lastGeneration++ + By("Fixing the Cluster", func() { createdCluster.Spec.ProviderSettings.AutoScaling = nil performUpdate() @@ -267,11 +297,8 @@ var _ = Describe("AtlasCluster", func() { }) By("Setting incorrect instance size (should fail)", func() { - createdCluster.Spec.ProviderSettings.AutoScaling = &mdbv1.AutoScalingSpec{ - Compute: &mdbv1.ComputeSpec{ - Enabled: boolptr(false), - }, - } + oldSizeName := createdCluster.Spec.ProviderSettings.InstanceSizeName + createdCluster.Spec.ProviderSettings.InstanceSizeName = "M42" Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) Eventually( @@ -287,8 +314,10 @@ var _ = Describe("AtlasCluster", func() { interval, ).Should(BeTrue()) + lastGeneration++ + By("Fixing the Cluster", func() { - createdCluster.Spec.ProviderSettings.AutoScaling = nil + createdCluster.Spec.ProviderSettings.InstanceSizeName = oldSizeName performUpdate() doCommonChecks() checkAtlasState() From 39bcdc0604afdfe0e287d1e98952844feb5e491a Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 10 Feb 2021 22:24:04 +0300 Subject: [PATCH 32/42] Remove rename test --- test/int/cluster_test.go | 42 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index c9a34e05b3..606d612fd9 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -126,7 +126,7 @@ var _ = Describe("AtlasCluster", func() { invalidCluster := testAtlasCluster(namespace.Name, "test-cluster", createdProject.Name) invalidCluster.Spec.MongoDBMajorVersion = "42.42" - By(fmt.Sprintf("Creating the Cluster %s", kube.ObjectKeyFromObject(invalidCluster)), func() { + By(fmt.Sprintf("Creating the Cluster %s with invalid parameters", kube.ObjectKeyFromObject(invalidCluster)), func() { createdCluster.ObjectMeta = invalidCluster.ObjectMeta Expect(k8sClient.Create(context.Background(), invalidCluster)).ToNot(HaveOccurred()) @@ -136,13 +136,19 @@ var _ = Describe("AtlasCluster", func() { createdCluster, status. FalseCondition(status.ClusterReadyType). - WithReason(string(workflow.ClusterNotUpdatedInAtlas)). - WithMessageRegexp("TODOTODO"), + WithReason(string(workflow.ClusterNotCreatedInAtlas)). + WithMessageRegexp("UNEXPECTED_ERROR"), ), - 1800, + 60, interval, ).Should(BeTrue()) + lastGeneration++ + }) + + By("Fixing the cluster", func() { + invalidCluster.Spec.MongoDBMajorVersion = "4.2" + performUpdate() doCommonChecks() checkAtlasState() }) @@ -237,34 +243,6 @@ var _ = Describe("AtlasCluster", func() { }) }) - By("Renaming the Cluster (should fail)", func() { - oldName := createdCluster.Spec.Name - createdCluster.Spec.Name = oldName + "-rnm" - - Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) - Eventually( - testutil.WaitFor( - k8sClient, - createdCluster, - status. - FalseCondition(status.ClusterReadyType). - WithReason(string(workflow.ClusterNotUpdatedInAtlas)). - WithMessageRegexp("TODOTODO"), - ), - 60, - interval, - ).Should(BeTrue()) - - lastGeneration++ - - By("Renaming the Cluster back", func() { - createdCluster.Spec.Name = oldName - performUpdate() - doCommonChecks() - checkAtlasState() - }) - }) - By("Setting AutoScaling.Compute.Enabled to false (should fail)", func() { createdCluster.Spec.ProviderSettings.AutoScaling = &mdbv1.AutoScalingSpec{ Compute: &mdbv1.ComputeSpec{ From ebb2e768105ad0efd619c2a0247d01d9ebf06157 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 11 Feb 2021 00:02:19 +0300 Subject: [PATCH 33/42] Fix WithMessageRegexp --- test/int/cluster_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 606d612fd9..7c66dafd9c 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -258,7 +258,7 @@ var _ = Describe("AtlasCluster", func() { status. FalseCondition(status.ClusterReadyType). WithReason(string(workflow.ClusterNotUpdatedInAtlas)). - WithMessageRegexp("TODOTODO"), + WithMessageRegexp("INVALID_ATTRIBUTE"), ), 60, interval, @@ -286,7 +286,7 @@ var _ = Describe("AtlasCluster", func() { status. FalseCondition(status.ClusterReadyType). WithReason(string(workflow.ClusterNotUpdatedInAtlas)). - WithMessageRegexp("TODOTODO"), + WithMessageRegexp("INVALID_ATTRIBUTE"), ), 60, interval, From c7da9354b72e54349f6c633c8565d03bfd6e7b54 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 11 Feb 2021 12:51:51 +0300 Subject: [PATCH 34/42] Change message regexp --- test/int/cluster_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 7c66dafd9c..7d8ce7900c 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -286,7 +286,7 @@ var _ = Describe("AtlasCluster", func() { status. FalseCondition(status.ClusterReadyType). WithReason(string(workflow.ClusterNotUpdatedInAtlas)). - WithMessageRegexp("INVALID_ATTRIBUTE"), + WithMessageRegexp("INVALID_ENUM_VALUE"), ), 60, interval, From ff2744ec932cf07ed13775575b8711c9721400cb Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 11 Feb 2021 12:55:59 +0300 Subject: [PATCH 35/42] Rework create failure case --- test/int/cluster_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 7d8ce7900c..81f7dc4dfb 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -124,7 +124,7 @@ var _ = Describe("AtlasCluster", func() { Describe("Create/Update the cluster", func() { It("Should fail, then be fixed", func() { invalidCluster := testAtlasCluster(namespace.Name, "test-cluster", createdProject.Name) - invalidCluster.Spec.MongoDBMajorVersion = "42.42" + invalidCluster.Spec.Name = "" By(fmt.Sprintf("Creating the Cluster %s with invalid parameters", kube.ObjectKeyFromObject(invalidCluster)), func() { createdCluster.ObjectMeta = invalidCluster.ObjectMeta @@ -147,7 +147,7 @@ var _ = Describe("AtlasCluster", func() { }) By("Fixing the cluster", func() { - invalidCluster.Spec.MongoDBMajorVersion = "4.2" + invalidCluster.Spec.Name = "fixed-cluster" performUpdate() doCommonChecks() checkAtlasState() From 43bd6bda433a53cff4fd531d97103e43ef8bd09b Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 11 Feb 2021 13:02:20 +0300 Subject: [PATCH 36/42] Revert timeout --- test/int/cluster_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 81f7dc4dfb..def955ead5 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -70,7 +70,7 @@ var _ = Describe("AtlasCluster", func() { // This is a bit strange but the delete request right after the cluster is removed may fail with "Still active cluster" error // UI shows the cluster being deleted though. Seems to be the issue only if removal is done using API, // if the cluster is terminated using UI - it stays in "Deleting" state - Eventually(removeAtlasProject(createdProject.Status.ID), 20, interval).Should(BeTrue()) + Eventually(removeAtlasProject(createdProject.Status.ID), 600, interval).Should(BeTrue()) } removeControllersAndNamespace() }) From dc84a4045a3f3e59becdf2d940b59cc3f9e5643c Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 11 Feb 2021 13:46:36 +0300 Subject: [PATCH 37/42] Fix reason for invalid name --- test/int/cluster_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index def955ead5..24ec0f84ee 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -136,8 +136,8 @@ var _ = Describe("AtlasCluster", func() { createdCluster, status. FalseCondition(status.ClusterReadyType). - WithReason(string(workflow.ClusterNotCreatedInAtlas)). - WithMessageRegexp("UNEXPECTED_ERROR"), + WithReason(string(workflow.Internal)). + WithMessageRegexp("name is invalid because must be set"), ), 60, interval, From e09e1c2cfd73accf65af5aa7e1327340d6ea04b7 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 11 Feb 2021 14:23:15 +0300 Subject: [PATCH 38/42] Fix invalid cluster used for update --- test/int/cluster_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 24ec0f84ee..fde4d7ec96 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -123,12 +123,12 @@ var _ = Describe("AtlasCluster", func() { Describe("Create/Update the cluster", func() { It("Should fail, then be fixed", func() { - invalidCluster := testAtlasCluster(namespace.Name, "test-cluster", createdProject.Name) - invalidCluster.Spec.Name = "" + expectedCluster := testAtlasCluster(namespace.Name, "test-cluster", createdProject.Name) + expectedCluster.Spec.Name = "" - By(fmt.Sprintf("Creating the Cluster %s with invalid parameters", kube.ObjectKeyFromObject(invalidCluster)), func() { - createdCluster.ObjectMeta = invalidCluster.ObjectMeta - Expect(k8sClient.Create(context.Background(), invalidCluster)).ToNot(HaveOccurred()) + By(fmt.Sprintf("Creating the Cluster %s with invalid parameters", kube.ObjectKeyFromObject(expectedCluster)), func() { + createdCluster.ObjectMeta = expectedCluster.ObjectMeta + Expect(k8sClient.Create(context.Background(), expectedCluster)).ToNot(HaveOccurred()) Eventually( testutil.WaitFor( @@ -147,7 +147,7 @@ var _ = Describe("AtlasCluster", func() { }) By("Fixing the cluster", func() { - invalidCluster.Spec.Name = "fixed-cluster" + createdCluster.Spec.Name = "fixed-cluster" performUpdate() doCommonChecks() checkAtlasState() From f10e557cfffa5ca01d7066ba1e823c4073a4bb74 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 11 Feb 2021 16:07:45 +0300 Subject: [PATCH 39/42] Fix conditions --- test/int/cluster_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index fde4d7ec96..55f2790b34 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -148,7 +148,14 @@ var _ = Describe("AtlasCluster", func() { By("Fixing the cluster", func() { createdCluster.Spec.Name = "fixed-cluster" - performUpdate() + + Expect(k8sClient.Update(context.Background(), createdCluster)).To(Succeed()) + + Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validateClusterCreatingFunc()), + 1200, interval).Should(BeTrue()) + + lastGeneration++ + doCommonChecks() checkAtlasState() }) From 421479b7d7740e476f861d9324f7a11de2af00b7 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 11 Feb 2021 16:45:50 +0300 Subject: [PATCH 40/42] Try to fix generation? --- test/int/cluster_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 55f2790b34..28bbfe8fbb 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -122,7 +122,7 @@ var _ = Describe("AtlasCluster", func() { } Describe("Create/Update the cluster", func() { - It("Should fail, then be fixed", func() { + FIt("Should fail, then be fixed", func() { expectedCluster := testAtlasCluster(namespace.Name, "test-cluster", createdProject.Name) expectedCluster.Spec.Name = "" @@ -154,7 +154,7 @@ var _ = Describe("AtlasCluster", func() { Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validateClusterCreatingFunc()), 1200, interval).Should(BeTrue()) - lastGeneration++ + // lastGeneration++ doCommonChecks() checkAtlasState() From 7d98c08f216968ec76b29a16c9728d31aeb11351 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 11 Feb 2021 16:58:09 +0300 Subject: [PATCH 41/42] Unfocus tests --- test/int/cluster_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 28bbfe8fbb..9733eb065f 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -122,7 +122,7 @@ var _ = Describe("AtlasCluster", func() { } Describe("Create/Update the cluster", func() { - FIt("Should fail, then be fixed", func() { + It("Should fail, then be fixed", func() { expectedCluster := testAtlasCluster(namespace.Name, "test-cluster", createdProject.Name) expectedCluster.Spec.Name = "" @@ -154,8 +154,6 @@ var _ = Describe("AtlasCluster", func() { Eventually(testutil.WaitFor(k8sClient, createdCluster, status.TrueCondition(status.ReadyType), validateClusterCreatingFunc()), 1200, interval).Should(BeTrue()) - // lastGeneration++ - doCommonChecks() checkAtlasState() }) From 63c1603d11f303887e8817e08f7728a05fa00b64 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 11 Feb 2021 19:19:55 +0300 Subject: [PATCH 42/42] Add comment for create failed test --- test/int/cluster_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/int/cluster_test.go b/test/int/cluster_test.go index 9733eb065f..a81cd9c2b4 100644 --- a/test/int/cluster_test.go +++ b/test/int/cluster_test.go @@ -136,7 +136,7 @@ var _ = Describe("AtlasCluster", func() { createdCluster, status. FalseCondition(status.ClusterReadyType). - WithReason(string(workflow.Internal)). + WithReason(string(workflow.Internal)). // Internal due to reconciliation failing on the initial GET request WithMessageRegexp("name is invalid because must be set"), ), 60,