Skip to content

Commit

Permalink
Validation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jwierzbo committed Dec 15, 2023
1 parent 49da4b2 commit 31facbb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
30 changes: 15 additions & 15 deletions pkg/apis/ml/v1alpha1/batchjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
meta "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/arangodb/kube-arangodb/pkg/apis/ml"
"github.com/arangodb/kube-arangodb/pkg/util/constants"
mlShared "github.com/arangodb/kube-arangodb/pkg/handlers/enterprise/ml/shared"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)

Expand Down Expand Up @@ -73,54 +73,54 @@ func (a *ArangoMLBatchJob) SetStatus(status ArangoMLBatchJobStatus) {
}

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

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

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

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

t, ok := a.Labels[constants.MLJobTypeLabel]
t, ok := a.Labels[mlShared.MLJobTypeLabel]
if !ok {
return errors.Newf("Job missing label: %s", constants.MLJobTypeLabel)
return errors.Newf("Job missing label: %s", mlShared.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)
if jobType != mlShared.MLJobTrainingType && jobType != mlShared.MLJobPredictionType {
return errors.Newf("Job label (%s) has unexpected value: %s", mlShared.MLJobTypeLabel, t)
}

s, ok := a.Labels[constants.MLJobScheduleLabel]
s, ok := a.Labels[mlShared.MLJobScheduleLabel]
if !ok {
return errors.Newf("Job missing label: %s", constants.MLJobTypeLabel)
return errors.Newf("Job missing label: %s", mlShared.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)
if scheduleType != mlShared.MLJobScheduleCPU && scheduleType != mlShared.MLJobScheduleGPU {
return errors.Newf("Job label (%s) has unexpected value: %s", mlShared.MLJobScheduleLabel, s)
}

return nil
Expand Down
8 changes: 2 additions & 6 deletions pkg/apis/ml/v1alpha1/extension_spec_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,11 @@ func (j *ArangoMLJobsTemplates) Validate() error {

var errs []error
for _, template := range j.Prediction {
if err := template.Validate(); err != nil {
errs = append(errs, shared.PrefixResourceErrors("prediction", err))
}
errs = append(errs, shared.PrefixResourceErrors("prediction", template.Validate()))
}

for _, template := range j.Training {
if err := template.Validate(); err != nil {
errs = append(errs, shared.PrefixResourceErrors("training", err))
}
errs = append(errs, shared.PrefixResourceErrors("training", template.Validate()))
}

return shared.WithErrors(errs...)
Expand Down
10 changes: 0 additions & 10 deletions pkg/util/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@ const (
ClusterSyncLabelRole = "clustersync/role"
LabelRole = "role"
LabelRoleLeader = "leader"

MLDeploymentLabel = "cloud.arangodb.com/deployment"
MLJobTypeLabel = "job.cloud.arangodb.com/type"
MLJobScheduleLabel = "job.cloud.arangodb.com/schedule"

MLJobTrainingType = "training"
MLJobPredictionType = "prediction"

MLJobScheduleCPU = "cpu"
MLJobScheduleGPU = "gpu"
)

func ManagedFinalizers() []string {
Expand Down

0 comments on commit 31facbb

Please sign in to comment.