Skip to content

Commit 521e30f

Browse files
committed
feat(crd): add security context and resource configuration support
Add comprehensive security and resource configuration options to the MCPServer CRD to enable production-ready deployments following Kubernetes security best practices. Signed-off-by: skhedim <sebastien.khedim@gmail.com>
1 parent dc97609 commit 521e30f

5 files changed

Lines changed: 2136 additions & 14 deletions

File tree

api/v1alpha1/mcpserver_types.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,74 @@ type MCPServerDeployment struct {
250250
// These containers will share the same pod and can share volumes with the main container.
251251
// +optional
252252
Sidecars []corev1.Container `json:"sidecars,omitempty"`
253+
254+
// Labels defines additional labels to add to the pod template.
255+
// These labels will be merged with the default labels.
256+
// +optional
257+
Labels map[string]string `json:"labels,omitempty"`
258+
259+
// Annotations defines additional annotations to add to the pod template.
260+
// These annotations will be merged with the default annotations.
261+
// +optional
262+
Annotations map[string]string `json:"annotations,omitempty"`
263+
264+
// Resources defines the compute resource requirements for the main MCP server container.
265+
// Use this to specify CPU and memory requests and limits.
266+
// Example:
267+
// resources:
268+
// requests:
269+
// cpu: "100m"
270+
// memory: "128Mi"
271+
// limits:
272+
// cpu: "500m"
273+
// memory: "512Mi"
274+
// +optional
275+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
276+
277+
// SecurityContext defines the security context for the main MCP server container.
278+
// Use this to configure container-level security settings such as:
279+
// - runAsUser/runAsGroup: Run as specific user/group
280+
// - runAsNonRoot: Ensure container doesn't run as root
281+
// - readOnlyRootFilesystem: Make root filesystem read-only
282+
// - allowPrivilegeEscalation: Prevent privilege escalation
283+
// - capabilities: Add or drop Linux capabilities
284+
// +optional
285+
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
286+
287+
// PodSecurityContext defines the security context for the entire pod.
288+
// Use this to configure pod-level security settings such as:
289+
// - runAsUser/runAsGroup: Default user/group for all containers
290+
// - fsGroup: Group ownership of mounted volumes
291+
// - seccompProfile: Seccomp profile for the pod
292+
// - sysctls: Kernel parameters to set
293+
// +optional
294+
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
295+
296+
// Tolerations defines the tolerations for the pod.
297+
// Use this to schedule pods on nodes with matching taints.
298+
// +optional
299+
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
300+
301+
// Affinity defines the affinity rules for the pod.
302+
// Use this to control pod placement based on node labels, pod labels,
303+
// or other scheduling constraints.
304+
// +optional
305+
Affinity *corev1.Affinity `json:"affinity,omitempty"`
306+
307+
// NodeSelector defines the node selector for the pod.
308+
// Use this to constrain pods to nodes with specific labels.
309+
// +optional
310+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
311+
312+
// Replicas defines the number of desired pod replicas.
313+
// Defaults to 1 if not specified.
314+
// +optional
315+
// +kubebuilder:default=1
316+
Replicas *int32 `json:"replicas,omitempty"`
317+
318+
// ImagePullSecrets defines the list of secrets to use for pulling container images.
319+
// +optional
320+
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
253321
}
254322

255323
// InitContainerConfig defines the configuration for the init container.
@@ -264,6 +332,16 @@ type InitContainerConfig struct {
264332
// +optional
265333
// +kubebuilder:validation:Enum=Always;Never;IfNotPresent
266334
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
335+
336+
// Resources defines the compute resource requirements for the init container.
337+
// Use this to specify CPU and memory requests and limits for the init container.
338+
// +optional
339+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
340+
341+
// SecurityContext defines the security context for the init container.
342+
// If not specified, the main container's security context will be used.
343+
// +optional
344+
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
267345
}
268346

269347
// ServiceAccountConfig defines the configuration for the ServiceAccount.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 70 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)