Skip to content

Commit

Permalink
ML Jobs labels
Browse files Browse the repository at this point in the history
  • Loading branch information
jwierzbo committed Dec 14, 2023
1 parent 1e9bcb6 commit 49da4b2
Show file tree
Hide file tree
Showing 8 changed files with 1,025 additions and 930 deletions.
56 changes: 28 additions & 28 deletions docs/api/ArangoMLExtension.V1Alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ Links:

***

### .spec.jobsTemplates.prediction.affinity
### .spec.jobsTemplates.prediction.\<string\>.affinity

Type: `core.Affinity` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/scheduling.go#L37)</sup>

Expand All @@ -462,7 +462,7 @@ Links:

***

### .spec.jobsTemplates.prediction.hostIPC
### .spec.jobsTemplates.prediction.\<string\>.hostIPC

Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/container_namespace.go#L33)</sup>

Expand All @@ -472,7 +472,7 @@ Default Value: `false`

***

### .spec.jobsTemplates.prediction.hostNetwork
### .spec.jobsTemplates.prediction.\<string\>.hostNetwork

Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/container_namespace.go#L27)</sup>

Expand All @@ -483,7 +483,7 @@ Default Value: `false`

***

### .spec.jobsTemplates.prediction.hostPID
### .spec.jobsTemplates.prediction.\<string\>.hostPID

Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/container_namespace.go#L30)</sup>

Expand All @@ -493,15 +493,15 @@ Default Value: `false`

***

### .spec.jobsTemplates.prediction.image
### .spec.jobsTemplates.prediction.\<string\>.image

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/image.go#L31)</sup>

Image define image details

***

### .spec.jobsTemplates.prediction.nodeSelector
### .spec.jobsTemplates.prediction.\<string\>.nodeSelector

Type: `object` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/scheduling.go#L32)</sup>

Expand All @@ -512,7 +512,7 @@ Links:

***

### .spec.jobsTemplates.prediction.podSecurityContext
### .spec.jobsTemplates.prediction.\<string\>.podSecurityContext

Type: `core.PodSecurityContext` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/security_pod.go#L29)</sup>

Expand All @@ -523,7 +523,7 @@ Links:

***

### .spec.jobsTemplates.prediction.pullPolicy
### .spec.jobsTemplates.prediction.\<string\>.pullPolicy

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/image.go#L35)</sup>

Expand All @@ -533,15 +533,15 @@ Default Value: `IfNotPresent`

***

### .spec.jobsTemplates.prediction.pullSecrets
### .spec.jobsTemplates.prediction.\<string\>.pullSecrets

Type: `array` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/image.go#L38)</sup>

PullSecrets define Secrets used to pull Image from registry

***

### .spec.jobsTemplates.prediction.resources
### .spec.jobsTemplates.prediction.\<string\>.resources

Type: `core.ResourceRequirements` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/resources.go#L34)</sup>

Expand All @@ -552,7 +552,7 @@ Links:

***

### .spec.jobsTemplates.prediction.schedulerName
### .spec.jobsTemplates.prediction.\<string\>.schedulerName

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/scheduling.go#L47)</sup>

Expand All @@ -563,7 +563,7 @@ Default Value: `""`

***

### .spec.jobsTemplates.prediction.securityContext
### .spec.jobsTemplates.prediction.\<string\>.securityContext

Type: `core.SecurityContext` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/security_container.go#L29)</sup>

Expand All @@ -574,7 +574,7 @@ Links:

***

### .spec.jobsTemplates.prediction.shareProcessNamespace
### .spec.jobsTemplates.prediction.\<string\>.shareProcessNamespace

Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/container_namespace.go#L39)</sup>

Expand All @@ -587,7 +587,7 @@ Default Value: `false`

***

### .spec.jobsTemplates.prediction.tolerations
### .spec.jobsTemplates.prediction.\<string\>.tolerations

Type: `[]core.Toleration` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/scheduling.go#L42)</sup>

Expand All @@ -598,7 +598,7 @@ Links:

***

### .spec.jobsTemplates.training.affinity
### .spec.jobsTemplates.training.\<string\>.affinity

Type: `core.Affinity` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/scheduling.go#L37)</sup>

Expand All @@ -609,7 +609,7 @@ Links:

***

### .spec.jobsTemplates.training.hostIPC
### .spec.jobsTemplates.training.\<string\>.hostIPC

Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/container_namespace.go#L33)</sup>

Expand All @@ -619,7 +619,7 @@ Default Value: `false`

***

### .spec.jobsTemplates.training.hostNetwork
### .spec.jobsTemplates.training.\<string\>.hostNetwork

Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/container_namespace.go#L27)</sup>

Expand All @@ -630,7 +630,7 @@ Default Value: `false`

***

### .spec.jobsTemplates.training.hostPID
### .spec.jobsTemplates.training.\<string\>.hostPID

Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/container_namespace.go#L30)</sup>

Expand All @@ -640,15 +640,15 @@ Default Value: `false`

***

### .spec.jobsTemplates.training.image
### .spec.jobsTemplates.training.\<string\>.image

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/image.go#L31)</sup>

Image define image details

***

### .spec.jobsTemplates.training.nodeSelector
### .spec.jobsTemplates.training.\<string\>.nodeSelector

Type: `object` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/scheduling.go#L32)</sup>

Expand All @@ -659,7 +659,7 @@ Links:

***

### .spec.jobsTemplates.training.podSecurityContext
### .spec.jobsTemplates.training.\<string\>.podSecurityContext

Type: `core.PodSecurityContext` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/security_pod.go#L29)</sup>

Expand All @@ -670,7 +670,7 @@ Links:

***

### .spec.jobsTemplates.training.pullPolicy
### .spec.jobsTemplates.training.\<string\>.pullPolicy

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/image.go#L35)</sup>

Expand All @@ -680,15 +680,15 @@ Default Value: `IfNotPresent`

***

### .spec.jobsTemplates.training.pullSecrets
### .spec.jobsTemplates.training.\<string\>.pullSecrets

Type: `array` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/image.go#L38)</sup>

PullSecrets define Secrets used to pull Image from registry

***

### .spec.jobsTemplates.training.resources
### .spec.jobsTemplates.training.\<string\>.resources

Type: `core.ResourceRequirements` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/resources.go#L34)</sup>

Expand All @@ -699,7 +699,7 @@ Links:

***

### .spec.jobsTemplates.training.schedulerName
### .spec.jobsTemplates.training.\<string\>.schedulerName

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/scheduling.go#L47)</sup>

Expand All @@ -710,7 +710,7 @@ Default Value: `""`

***

### .spec.jobsTemplates.training.securityContext
### .spec.jobsTemplates.training.\<string\>.securityContext

Type: `core.SecurityContext` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/security_container.go#L29)</sup>

Expand All @@ -721,7 +721,7 @@ Links:

***

### .spec.jobsTemplates.training.shareProcessNamespace
### .spec.jobsTemplates.training.\<string\>.shareProcessNamespace

Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/container_namespace.go#L39)</sup>

Expand All @@ -734,7 +734,7 @@ Default Value: `false`

***

### .spec.jobsTemplates.training.tolerations
### .spec.jobsTemplates.training.\<string\>.tolerations

Type: `[]core.Toleration` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/scheduling.go#L42)</sup>

Expand Down
66 changes: 62 additions & 4 deletions pkg/apis/ml/v1alpha1/batchjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
package v1alpha1

import (
"strings"

meta "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/arangodb/kube-arangodb/pkg/apis/ml"
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -39,7 +43,7 @@ type ArangoMLBatchJobList struct {
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ArangoMLBatchJob contains definition and status of the ArangoML BatchJob.
// ArangoMLBatchJob contains the definition and status of the ArangoML BatchJob.
type ArangoMLBatchJob struct {
meta.TypeMeta `json:",inline"`
meta.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -49,13 +53,13 @@ type ArangoMLBatchJob struct {
}

// AsOwner creates an OwnerReference for the given BatchJob
func (d *ArangoMLBatchJob) AsOwner() meta.OwnerReference {
func (a *ArangoMLBatchJob) AsOwner() meta.OwnerReference {
trueVar := true
return meta.OwnerReference{
APIVersion: SchemeGroupVersion.String(),
Kind: ml.ArangoMLBatchJobResourceKind,
Name: d.Name,
UID: d.UID,
Name: a.Name,
UID: a.UID,
Controller: &trueVar,
}
}
Expand All @@ -67,3 +71,57 @@ func (a *ArangoMLBatchJob) GetStatus() ArangoMLBatchJobStatus {
func (a *ArangoMLBatchJob) SetStatus(status ArangoMLBatchJobStatus) {
a.Status = status
}

func (a *ArangoMLBatchJob) GetJobType() string {
val, ok := a.Labels[constants.MLJobTypeLabel]
if !ok {
return ""
}
return strings.ToLower(val)
}

func (a *ArangoMLBatchJob) GetScheduleType() string {
val, ok := a.Labels[constants.MLJobScheduleLabel]
if !ok {
return ""
}
return strings.ToLower(val)
}

func (a *ArangoMLBatchJob) GetMLDeploymentName() string {
val, ok := a.Labels[constants.MLJobScheduleLabel]
if !ok {
return ""
}
return val
}

func (a *ArangoMLBatchJob) ValidateLabels() error {
depl, ok := a.Labels[constants.MLDeploymentLabel]
if !ok {
return errors.Newf("Job missing label: %s", constants.MLDeploymentLabel)
}
if depl == "" {
return errors.Newf("Job empty value for label: %s", constants.MLDeploymentLabel)
}

t, ok := a.Labels[constants.MLJobTypeLabel]
if !ok {
return errors.Newf("Job missing label: %s", constants.MLJobTypeLabel)
}
jobType := strings.ToLower(t)
if jobType != constants.MLJobTrainingType && jobType != constants.MLJobPredictionType {
return errors.Newf("Job label (%s) has unexpected value: %s", constants.MLJobTypeLabel, t)
}

s, ok := a.Labels[constants.MLJobScheduleLabel]
if !ok {
return errors.Newf("Job missing label: %s", constants.MLJobTypeLabel)
}
scheduleType := strings.ToLower(s)
if scheduleType != constants.MLJobScheduleCPU && scheduleType != constants.MLJobScheduleGPU {
return errors.Newf("Job label (%s) has unexpected value: %s", constants.MLJobScheduleLabel, s)
}

return nil
}
4 changes: 4 additions & 0 deletions pkg/apis/ml/v1alpha1/batchjob_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,9 @@ func (a *ArangoMLBatchJobSpec) Validate() error {
err = append(err, shared.PrefixResourceErrors("spec", errors.Newf("JobSpec is not defined")))
}

if len(a.JobSpec.Template.Spec.Containers) != 1 {
err = append(err, shared.PrefixResourceErrors("spec.template.spec.containers", errors.Newf("Exactly one container is required")))
}

return shared.WithErrors(err...)
}
5 changes: 5 additions & 0 deletions pkg/apis/ml/v1alpha1/cronjob_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@ func (a *ArangoMLCronJobSpec) Validate() error {
err = append(err, shared.PrefixResourceErrors("spec", errors.Newf("CronJobSpec is not defined")))
}

if len(a.CronJobSpec.JobTemplate.Spec.Template.Spec.Containers) != 1 {
err = append(err, shared.PrefixResourceErrors("spec.jobTemplate.spec.template.spec.containers",
errors.Newf("Exactly one container is required")))
}

return shared.WithErrors(err...)
}
Loading

0 comments on commit 49da4b2

Please sign in to comment.