Skip to content

Refactor deploymentForMCPServer for platform detection. (#1063) (#1285) #1500

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RoddieKieley
Copy link
Contributor

The PR#1301 for #1285 set the security context for ProxyRunner deployments without taking into account kubernetes platform differences and detection as was introduced for #1063 via PR#1253.

This addresses that concern by refactoring the code dealing with security context, encapsulating that specific functionality better than was previously done for either #1063 or #1285.

Also while this should not directly impact #1483, assuming the operator was running it would have required manual changes to the MCPServer instances Deployment to remove the incorrectly set runAsUser, runAsGroup, and fsGroup values once it was so mentioning here.

I am marking this as Draft; while it works well here there is a good bit of code addition and change so having @jhrozek and/or @ChrisJBurns take a look as a follow up to #1063 is probably in order.

Feel free to modify/update as require and feedback welcome.

… (stacklok#1285)

Signed-off-by: Roddie Kieley <rkieley@redhat.com>
Co-authored-by: Cursor claude-4-sonnet <cursor@redhat.com>
// detectPlatform detects the Kubernetes platform type (Kubernetes vs OpenShift)
// It uses sync.Once to ensure the detection is only performed once and cached
func (r *MCPServerReconciler) detectPlatform(ctx context.Context) (kubernetes.Platform, error) {
var err error
Copy link
Contributor

Choose a reason for hiding this comment

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

this might not even be a problem, but wouldn't it be better to also cache the detection error from DetectPlatform and return the cached error on subsequent calls?

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, this might be correct as if the call fails, we just keep assuming kubernetes...

WithRunAsUser(int64(1000)).
WithRunAsGroup(int64(1000)),
)
securityBuilder := NewSecurityContextBuilder(platform)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit for readability: cine the builder and applying the config is needed for both if and else could we put the declaration earlier?

container.SecurityContext.Capabilities = &corev1apply.CapabilitiesApplyConfiguration{
Drop: []corev1.Capability{"ALL"},
// For OpenShift, override certain fields even if they exist
if platform == PlatformOpenShift {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we could have an if-else or switch for the platform that would skip setting the fields that OCP nils anyway. But that might be just personal preference and doesn't affect functionality

Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

I thinks this is great, just a few questions/comments inline

@ChrisJBurns
Copy link
Collaborator

It will be so nice to do all of this code in one place when we implement #1497 😄

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.

3 participants