-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLOUDP-261715: Enabled resync for Atlas custom resources #1707
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit pick
would 10s be enough to test the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a side note: i am working on a pure unit-test approach for this. I don't think we need a full blown e2e test to assert resyncs. I will submit once ready.