-
Notifications
You must be signed in to change notification settings - Fork 9
CLOUDP-324440 Save rs member ids #206
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
base: master
Are you sure you want to change the base?
Changes from all commits
ac55cad
8ae690c
c7f1de2
9a587d6
1da9a93
fc74a25
fd44784
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,22 @@ func (oc *MockedOmConnection) ConfigureProject(project *Project) { | |
oc.context.OrgID = project.OrgID | ||
} | ||
|
||
func (oc *MockedOmConnection) GetReplicaSetMemberIds() (map[string]map[string]int, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this PR: Given that we are just copy pasting the the whole functionality, we can simply wrap the omclient with this mock client and only override what is necessary. |
||
oc.addToHistory(reflect.ValueOf(oc.GetReplicaSetMemberIds)) | ||
dep, err := oc.ReadDeployment() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
finalProcessIds := make(map[string]map[string]int) | ||
|
||
for _, replicaSet := range dep.GetReplicaSets() { | ||
finalProcessIds[replicaSet.Name()] = replicaSet.MemberIds() | ||
} | ||
|
||
return finalProcessIds, nil | ||
} | ||
|
||
var _ Connection = &MockedOmConnection{} | ||
|
||
// NewEmptyMockedOmConnection is the standard function for creating mocked connections that is usually used for testing | ||
|
@@ -734,7 +750,7 @@ func (oc *MockedOmConnection) CheckResourcesAndBackupDeleted(t *testing.T, resou | |
// This can be improved for some more complicated scenarios when we have different resources in parallel - so far | ||
// just checking if deployment | ||
assert.Empty(t, oc.deployment.getProcesses()) | ||
assert.Empty(t, oc.deployment.getReplicaSets()) | ||
assert.Empty(t, oc.deployment.GetReplicaSets()) | ||
assert.Empty(t, oc.deployment.getShardedClusters()) | ||
assert.Empty(t, oc.deployment.getMonitoringVersions()) | ||
assert.Empty(t, oc.deployment.getBackupVersions()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,10 @@ type Connection interface { | |
GetPreferredHostnames(agentApiKey string) ([]PreferredHostname, error) | ||
AddPreferredHostname(agentApiKey string, value string, isRegexp bool) error | ||
|
||
// GetReplicaSetMemberIds returns a map with the replicaset name as the key. | ||
// The value is another map where the key is the replicaset member name and the value is its member id. | ||
GetReplicaSetMemberIds() (map[string]map[string]int, error) | ||
|
||
backup.GroupConfigReader | ||
backup.GroupConfigUpdater | ||
|
||
|
@@ -273,6 +277,21 @@ func (oc *HTTPOmConnection) GetAgentAuthMode() (string, error) { | |
return ac.Auth.AutoAuthMechanism, nil | ||
} | ||
|
||
func (oc *HTTPOmConnection) GetReplicaSetMemberIds() (map[string]map[string]int, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blocking: Do we need that separate method? Could we have an external function calling ReadDeployment and extracting the ids from the result? I'd prefer to limit the interface of OMConnection to the distinct API operations and have them combined for the logic like this in a different layer above it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this we'd also avoic changing the mock's implementation |
||
dep, err := oc.ReadDeployment() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
finalProcessIds := make(map[string]map[string]int) | ||
|
||
for _, replicaSet := range dep.GetReplicaSets() { | ||
finalProcessIds[replicaSet.Name()] = replicaSet.MemberIds() | ||
} | ||
|
||
return finalProcessIds, nil | ||
} | ||
|
||
var _ Connection = &HTTPOmConnection{} | ||
|
||
// NewOpsManagerConnection stores OpsManger api endpoint and authentication credentials. | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -201,8 +201,14 @@ func (r *ReconcileMongoDbMultiReplicaSet) Reconcile(ctx context.Context, request | |||||
return r.updateStatus(ctx, &mrs, status, log) | ||||||
} | ||||||
|
||||||
// Save replicasets member ids in annotation | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we can remove this comment, we can find its usage via the ide |
||||||
finalMemberIds, err := conn.GetReplicaSetMemberIds() | ||||||
if err != nil { | ||||||
return r.updateStatus(ctx, &mrs, workflow.Failed(err), log) | ||||||
} | ||||||
|
||||||
mrs.Status.FeatureCompatibilityVersion = mrs.CalculateFeatureCompatibilityVersion() | ||||||
if err := r.saveLastAchievedSpec(ctx, mrs); err != nil { | ||||||
if err := r.saveLastAchievedSpec(ctx, mrs, finalMemberIds); err != nil { | ||||||
return r.updateStatus(ctx, &mrs, workflow.Failed(xerrors.Errorf("Failed to set annotation: %w", err)), log) | ||||||
} | ||||||
|
||||||
|
@@ -627,7 +633,7 @@ func getMembersForClusterSpecItemThisReconciliation(mrs *mdbmultiv1.MongoDBMulti | |||||
} | ||||||
|
||||||
// saveLastAchievedSpec updates the MongoDBMultiCluster resource with the spec that was just achieved. | ||||||
func (r *ReconcileMongoDbMultiReplicaSet) saveLastAchievedSpec(ctx context.Context, mrs mdbmultiv1.MongoDBMultiCluster) error { | ||||||
func (r *ReconcileMongoDbMultiReplicaSet) saveLastAchievedSpec(ctx context.Context, mrs mdbmultiv1.MongoDBMultiCluster, rsMemberIds map[string]map[string]int) error { | ||||||
clusterSpecs, err := mrs.GetClusterSpecItems() | ||||||
if err != nil { | ||||||
return err | ||||||
|
@@ -657,6 +663,14 @@ func (r *ReconcileMongoDbMultiReplicaSet) saveLastAchievedSpec(ctx context.Conte | |||||
annotationsToAdd[mdbmultiv1.LastClusterNumMapping] = string(clusterNumBytes) | ||||||
} | ||||||
|
||||||
rsMemberIdsBytes, err := json.Marshal(rsMemberIds) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
if string(rsMemberIdsBytes) != "null" { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Consider checking if rsMemberIds is nil or if the marshalled byte slice is empty instead of comparing to the string "null", as this would improve clarity and robustness if the serialization behavior changes.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blocking: oh - yeah definitely please don't check for a null string. I think in other code places we have a better way of doing that |
||||||
annotationsToAdd[util.LastAchievedRsMemberIds] = string(rsMemberIdsBytes) | ||||||
} | ||||||
|
||||||
return annotations.SetAnnotations(ctx, &mrs, annotationsToAdd, r.client) | ||||||
} | ||||||
|
||||||
|
@@ -699,6 +713,10 @@ func (r *ReconcileMongoDbMultiReplicaSet) updateOmDeploymentRs(ctx context.Conte | |||||
} | ||||||
|
||||||
processIds := getReplicaSetProcessIdsFromReplicaSets(mrs.Name, existingDeployment) | ||||||
// If there is no replicaset configuration saved in OM, it might be a new project, so we check the ids saved in annotation | ||||||
if len(processIds) == 0 { | ||||||
processIds = getReplicaSetProcessIdsFromAnnotation(mrs) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as discussed offline - its the migration case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lucian-tosa Can you please explain the "migration case" that requires use of annotation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blocking: let's add a comment here on why this can happen (the migration case) for clarity |
||||||
} | ||||||
log.Debugf("Existing process Ids: %+v", processIds) | ||||||
|
||||||
certificateFileName := "" | ||||||
|
@@ -794,6 +812,16 @@ func getReplicaSetProcessIdsFromReplicaSets(replicaSetName string, deployment om | |||||
return processIds | ||||||
} | ||||||
|
||||||
func getReplicaSetProcessIdsFromAnnotation(mrs mdbmultiv1.MongoDBMultiCluster) map[string]int { | ||||||
processIds := make(map[string]map[string]int) | ||||||
if processIdsStr, ok := mrs.Annotations[util.LastAchievedRsMemberIds]; ok { | ||||||
if err := json.Unmarshal([]byte(processIdsStr), &processIds); err != nil { | ||||||
return map[string]int{} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you consider making this a fatal error? If there is some garbage in the annotation, isn't it too risky to ignore its content? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if not - we should at least log this very clearly |
||||||
} | ||||||
} | ||||||
return processIds[mrs.Name] | ||||||
} | ||||||
|
||||||
func getSRVService(mrs *mdbmultiv1.MongoDBMultiCluster) corev1.Service { | ||||||
additionalConfig := mrs.Spec.GetAdditionalMongodConfig() | ||||||
port := additionalConfig.GetPortOrDefault() | ||||||
|
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.
Can you please highlight better the introduction of OIDC? Checking the release notes, I see the new features but our main goal for this release is the OIDC, so I would suggest to add a section for OIDC. I will create a suggestion in GDocs and share with you.
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.
Just did a proposal:
https://docs.google.com/document/d/143v_VS4graZZgGp2r63WzLcPH1tcv3OvShHtM5HPiSY/edit?usp=sharing
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.
I would like to keep this PR focused on the bug fix. I think we can do this refactoring when we release. Wdyt?