Skip to content

Commit

Permalink
feat: support more customization for the job pod
Browse files Browse the repository at this point in the history
Add the following fields to customize the LMES job pod:
- `Affinity`: for node affinity
- `SecurityContext`: for both pod and main container

Also, merge the `SideCars` which is an array of extra containers into
the final PodSpec along with the main container.

Signed-off-by: Yihong Wang <[email protected]>
  • Loading branch information
yhwang committed Oct 23, 2024
1 parent 4cbc4c0 commit b4313f0
Show file tree
Hide file tree
Showing 5 changed files with 1,294 additions and 130 deletions.
33 changes: 33 additions & 0 deletions api/lmes/v1alpha1/lmevaljob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ type LMEvalContainer struct {
// More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
// +optional
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
// SecurityContext defines the security options the container should be run with.
// If set, the fields of SecurityContext override the equivalent fields of PodSecurityContext.
// More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
// +optional
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
}

// The following Getter-ish functions avoid nil pointer panic
Expand All @@ -170,6 +175,13 @@ func (c *LMEvalContainer) GetResources() *corev1.ResourceRequirements {
return c.Resources
}

func (c *LMEvalContainer) GetSecurityContext() *corev1.SecurityContext {
if c == nil {
return nil
}
return c.SecurityContext
}

type LMEvalPodSpec struct {
// Extra container data for the lm-eval container
// +optional
Expand All @@ -181,6 +193,13 @@ type LMEvalPodSpec struct {
// FIXME: aggregate the sidecar containers into the pod
// +optional
SideCars []corev1.Container `json:"sideCars,omitempty"`
// If specified, the pod's scheduling constraints
// +optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`
// SecurityContext holds pod-level security attributes and common container settings.
// Optional: Defaults to empty. See type description for default values of each field.
// +optional
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
}

// The following Getter-ish functions avoid nil pointer panic
Expand All @@ -205,6 +224,20 @@ func (p *LMEvalPodSpec) GetSideCards() []corev1.Container {
return p.SideCars
}

func (p *LMEvalPodSpec) GetAffinity() *corev1.Affinity {
if p == nil {
return nil
}
return p.Affinity
}

func (p *LMEvalPodSpec) GetSecurityContext() *corev1.PodSecurityContext {
if p == nil {
return nil
}
return p.SecurityContext
}

// LMEvalJobSpec defines the desired state of LMEvalJob
type LMEvalJobSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
Expand Down
15 changes: 15 additions & 0 deletions api/lmes/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b4313f0

Please sign in to comment.