Skip to content
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

Support Pause/Unpause MCP in Openshift #61

Merged
merged 2 commits into from
Jan 22, 2025

Conversation

adrianchiris
Copy link
Collaborator

Implement MCPManager which pauses/unpauses MCP
in openshift environments.

  • Add Openshift detection logic
  • Implement MCPManager
  • Integrate MCPManager in nodemaintenance controller

@adrianchiris adrianchiris changed the title Support Pause/Unpause MCP in Openshift WIP: Support Pause/Unpause MCP in Openshift Jan 14, 2025
@coveralls
Copy link

coveralls commented Jan 14, 2025

Pull Request Test Coverage Report for Build 12904981600

Details

  • 149 of 262 (56.87%) changed or added relevant lines in 4 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-1.1%) to 68.936%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/openshift/utils.go 18 22 81.82%
cmd/maintenance-manager/main.go 0 19 0.0%
internal/openshift/mcp.go 126 164 76.83%
internal/controller/nodemaintenance_controller.go 5 57 8.77%
Files with Coverage Reduction New Missed Lines %
internal/controller/nodemaintenance_controller.go 1 55.12%
Totals Coverage Status
Change from base Build 12804513564: -1.1%
Covered Lines: 1205
Relevant Lines: 1748

💛 - Coveralls

@adrianchiris
Copy link
Collaborator Author

adrianchiris commented Jan 14, 2025

code is complete, i need to test on ocp setup.

LMK if you prefer i split to multiple commits

Implement MCPManager which pauses/unpauses MCP
in openshift environments.

- Add Openshift detection logic
- Implement MCPManager
- Integrate MCPManager in nodemaintenance controller

Signed-off-by: adrianc <[email protected]>
@adrianchiris adrianchiris force-pushed the mcp-support branch 2 times, most recently from 8def208 to a6e78a6 Compare January 16, 2025 14:33
@adrianchiris adrianchiris changed the title WIP: Support Pause/Unpause MCP in Openshift Support Pause/Unpause MCP in Openshift Jan 16, 2025
@adrianchiris adrianchiris requested a review from rollandf January 19, 2025 06:23
reqLog.Info("Handle Scheduled NodeMaintenance")
var err error
var res ctrl.Result
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the res? It always the same, no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: my preference is to explicitly return a separate instance of ctrl.Result in each return statement.

Copy link
Collaborator Author

@adrianchiris adrianchiris Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the res? It always the same, no?

we need to return a non empty result in case of L237

removed the res and returning ctrl.Result

cmd/maintenance-manager/main.go Show resolved Hide resolved
@@ -248,7 +269,11 @@ func (r *NodeMaintenanceReconciler) handleCordonState(ctx context.Context, reqLo
}
}

// TODO(adrianc): unpause MCP in OCP when support is added.
err = r.MCPManager.UnpauseMCP(ctx, node, nm)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

if err := r.MCPManager.UnpauseMCP(ctx, node, nm); err != nil  {
	return err
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aligned for mcp manager, though the rest of the code does not follow this style.

@@ -289,7 +314,11 @@ func (r *NodeMaintenanceReconciler) handleWaitPodCompletionState(ctx context.Con
}
}

// TODO(adrianc): unpause MCP in OCP when support is added.
err = r.MCPManager.UnpauseMCP(ctx, node, nm)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use the single line if err :=

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if err = (&controller.NodeMaintenanceReconciler{
Client: mgrClient,
Scheme: mgr.GetScheme(),
CordonHandler: cordon.NewCordonHandler(mgrClient, k8sInterface),
WaitPodCompletionHandler: podcompletion.NewPodCompletionHandler(mgrClient),
DrainManager: drain.NewManager(ctrl.Log.WithName("DrainManager"), ctx, k8sInterface),
MCPManager: openshift.NewMCPManager(ocpUtils, mgrClient),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just an opinion

IMO, It would be better to explicitly select the manager in main.go and skip initializing MCPManager for non-OpenShift clusters. This helps avoid confusion in the Reconciler code, where it's not immediately clear that certain logic applies only to OpenShift.

Copy link
Collaborator Author

@adrianchiris adrianchiris Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, you prefer to have in the controller code :

if r.MCPManager != nil {
   // do stuff with MCPManager
}

?

i was kinda on the fence between the two approaches. lemme rework this then.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to have an "if openshift" check everywhere to decide if we need to make a call to MCPManager or not. This means we will call openshift-specific logic very explicitly.

The current implementation is also ok, but for me it is a bit harder to follow. It is ok to keep everything as is if you prefer so.

reqLog.Info("Handle Scheduled NodeMaintenance")
var err error
var res ctrl.Result
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: my preference is to explicitly return a separate instance of ctrl.Result in each return statement.

- drop no-op MCP manager
- style changes

Signed-off-by: adrianc <[email protected]>
@adrianchiris adrianchiris merged commit 176e532 into Mellanox:main Jan 22, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants