-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLOUDP-261715: Enabled resync for Atlas custom resources (#1707)
Enabled periodic reconciliations for Atlas custom resources
- Loading branch information
1 parent
d6606e5
commit 83375fe
Showing
5 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package int | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/kube" | ||
"github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api" | ||
akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1" | ||
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/conditions" | ||
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/events" | ||
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/resources" | ||
) | ||
|
||
var _ = Describe("Sync Period test", Label("int", "sync-period"), func() { | ||
const interval = time.Second * 2 | ||
const syncInterval = 40 * time.Second | ||
|
||
var ( | ||
connectionSecret corev1.Secret | ||
createdProject *akov2.AtlasProject | ||
previousResourceVersion string | ||
) | ||
|
||
BeforeEach(func() { | ||
prepareControllersWithSyncPeriod(false, syncInterval) | ||
|
||
createdProject = &akov2.AtlasProject{} | ||
|
||
connectionSecret = buildConnectionSecret("my-atlas-key") | ||
By(fmt.Sprintf("Creating the Secret %s", kube.ObjectKeyFromObject(&connectionSecret))) | ||
Expect(k8sClient.Create(context.Background(), &connectionSecret)).ToNot(HaveOccurred()) | ||
}) | ||
|
||
AfterEach(func() { | ||
if createdProject != nil && createdProject.Status.ID != "" { | ||
By("Removing Atlas Project " + createdProject.Status.ID) | ||
Eventually(deleteK8sObject(createdProject), 20, interval).Should(BeTrue()) | ||
Eventually(checkAtlasProjectRemoved(createdProject.Status.ID), 20, interval).Should(BeTrue()) | ||
} | ||
removeControllersAndNamespace() | ||
}) | ||
It("Should reconcile after defined SyncPeriod", func() { | ||
By("Should Succeed with creating the project", func() { | ||
expectedProject := akov2.DefaultProject(namespace.Name, connectionSecret.Name) | ||
createdProject.ObjectMeta = expectedProject.ObjectMeta | ||
Expect(k8sClient.Create(context.Background(), expectedProject)).ToNot(HaveOccurred()) | ||
|
||
Eventually(func() bool { | ||
return resources.CheckCondition(k8sClient, createdProject, api.TrueCondition(api.ReadyType)) | ||
}).WithTimeout(ProjectCreationTimeout).WithPolling(interval).Should(BeTrue()) | ||
|
||
projectReadyConditions := conditions.MatchConditions( | ||
api.TrueCondition(api.ProjectReadyType), | ||
api.TrueCondition(api.ReadyType), | ||
api.TrueCondition(api.ValidationSucceeded), | ||
) | ||
Expect(createdProject.Status.ID).NotTo(BeNil()) | ||
Expect(createdProject.Status.Conditions).To(ContainElements((projectReadyConditions))) | ||
Expect(createdProject.Status.ObservedGeneration).To(Equal(createdProject.Generation)) | ||
|
||
atlasProject, _, err := atlasClient.ProjectsApi. | ||
GetProject(context.Background(), createdProject.Status.ID). | ||
Execute() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(atlasProject.Name).To(Equal(expectedProject.Spec.Name)) | ||
|
||
events.EventExists(k8sClient, createdProject, "Normal", "Ready", "") | ||
|
||
Eventually(func(g Gomega) bool { | ||
if !resources.ReadAtlasResource(context.Background(), k8sClient, createdProject) { | ||
return false | ||
} | ||
previousResourceVersion = createdProject.ResourceVersion | ||
return true | ||
}).WithTimeout(10 * time.Second).WithPolling(2 * time.Second).Should(BeTrue()) | ||
}) | ||
|
||
By(fmt.Sprintf("Should wait for at least %f seconds", (syncInterval*2).Seconds()), func() { | ||
time.Sleep(syncInterval * 2) | ||
}) | ||
|
||
By("Project resource version should be different", func() { | ||
var currentResourceVersion string | ||
Eventually(func(g Gomega) bool { | ||
if !resources.ReadAtlasResource(context.Background(), k8sClient, createdProject) { | ||
return false | ||
} | ||
currentResourceVersion = createdProject.ResourceVersion | ||
return true | ||
}).WithTimeout(10 * time.Second).WithPolling(2 * time.Second).Should(BeTrue()) | ||
|
||
Expect(currentResourceVersion).ToNot(BeEquivalentTo(previousResourceVersion)) | ||
}) | ||
}) | ||
}) |