Skip to content

Commit

Permalink
BatchJob status update
Browse files Browse the repository at this point in the history
  • Loading branch information
jwierzbo committed Dec 11, 2023
1 parent d7e7757 commit 7ea359e
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- (Improvement) (ML) Job Sidecar Shutdown
- (Feature) (ML) Handler for Extension StatefulSet and Service
- (Feature) (ML) Pod & Container Config
- (Improvement) (ML) BatchJob status update

## [1.2.35](https://github.com/arangodb/kube-arangodb/tree/1.2.35) (2023-11-06)
- (Maintenance) Update go-driver to v1.6.0, update IsNotFound() checks
Expand Down
21 changes: 19 additions & 2 deletions pkg/apis/ml/v1alpha1/batchjob_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,28 @@

package v1alpha1

import "github.com/arangodb/kube-arangodb/pkg/apis/shared"
import (
batch "k8s.io/api/batch/v1"

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

type ArangoMLBatchJobSpec struct {
// +doc/type: batch.Job
// +doc/link: Kubernetes Documentation|https://godoc.org/k8s.io/api/batch/v1#JobSpec
*batch.JobSpec `json:",inline"`
}

func (a *ArangoMLBatchJobSpec) Validate() error {
return shared.WithErrors(shared.PrefixResourceErrors("spec"))
if a == nil {
return errors.Newf("Spec is not defined")
}

var err []error
if a.JobSpec == nil {
err = append(err, shared.PrefixResourceErrors("spec", errors.Newf("JobSpec is not defined")))
}

return shared.WithErrors(err...)
}
14 changes: 13 additions & 1 deletion pkg/apis/ml/v1alpha1/batchjob_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,22 @@

package v1alpha1

import api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
import (
batch "k8s.io/api/batch/v1"

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
)

type ArangoMLBatchJobStatus struct {
// Conditions specific to the entire batch job
// +doc/type: api.Conditions
Conditions api.ConditionList `json:"conditions,omitempty"`

// +doc/type: batch.JobStatus
// +doc/link: Kubernetes Documentation|https://godoc.org/k8s.io/api/batch/v1#JobStatus
*batch.JobStatus `json:",inline"`

// Ref keeps the reference to the CronJob
Ref *sharedApi.Object `json:"ref,omitempty"`
}
2 changes: 1 addition & 1 deletion pkg/apis/ml/v1alpha1/cronjob_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

type ArangoMLCronJobSpec struct {
// +doc/type: batch.CronJobSpec
// +doc/link: Kubernetes Documentation|https://godoc.org/k8s.io/api/batch/v1beta1#CronJobSpec
// +doc/link: Kubernetes Documentation|https://godoc.org/k8s.io/api/batch/v1#CronJobSpec
*batch.CronJobSpec `json:",inline"`
}

Expand Down
7 changes: 1 addition & 6 deletions pkg/apis/ml/v1alpha1/cronjob_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
batch "k8s.io/api/batch/v1"

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
)

Expand All @@ -34,13 +33,9 @@ type ArangoMLCronJobStatus struct {
Conditions api.ConditionList `json:"conditions,omitempty"`

// +doc/type: batch.CronJobStatus
// +doc/link: Kubernetes Documentation|https://godoc.org/k8s.io/api/batch/v1beta1#CronJobStatus
// +doc/link: Kubernetes Documentation|https://godoc.org/k8s.io/api/batch/v1#CronJobStatus
*batch.CronJobStatus `json:",inline"`

// Ref keeps the reference to the CronJob
Ref *sharedApi.Object `json:"ref,omitempty"`
}

func (a *ArangoMLCronJobStatus) Validate() error {
return shared.WithErrors(shared.PrefixResourceErrors("spec"))
}
1 change: 1 addition & 0 deletions pkg/apis/ml/v1alpha1/extension_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ const (
ExtensionStatefulSetReadyCondition api.ConditionType = "ExtensionDeploymentReady"
LicenseValidCondition api.ConditionType = "LicenseValid"
CronJobSyncedCondition api.ConditionType = "CronJobSynced"
BatchJobSyncedCondition api.ConditionType = "BatchJobSynced"
)
44 changes: 44 additions & 0 deletions pkg/util/tests/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ func CreateObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSe
vl := *v
_, err := k8s.RbacV1().RoleBindings(vl.GetNamespace()).Create(context.Background(), vl, meta.CreateOptions{})
require.NoError(t, err)
case **mlApi.ArangoMLBatchJob:
require.NotNil(t, v)

vl := *v
_, err := arango.MlV1alpha1().ArangoMLBatchJobs(vl.GetNamespace()).Create(context.Background(), vl, meta.CreateOptions{})
require.NoError(t, err)
case **mlApi.ArangoMLCronJob:
require.NotNil(t, v)

Expand Down Expand Up @@ -283,6 +289,12 @@ func UpdateObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSe
vl := *v
_, err := arango.MlV1alpha1().ArangoMLStorages(vl.GetNamespace()).Update(context.Background(), vl, meta.UpdateOptions{})
require.NoError(t, err)
case **mlApi.ArangoMLBatchJob:
require.NotNil(t, v)

vl := *v
_, err := arango.MlV1alpha1().ArangoMLBatchJobs(vl.GetNamespace()).Update(context.Background(), vl, meta.UpdateOptions{})
require.NoError(t, err)
case **mlApi.ArangoMLCronJob:
require.NotNil(t, v)

Expand Down Expand Up @@ -376,6 +388,11 @@ func DeleteObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSe

vl := *v
require.NoError(t, arango.MlV1alpha1().ArangoMLStorages(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{}))
case **mlApi.ArangoMLBatchJob:
require.NotNil(t, v)

vl := *v
require.NoError(t, arango.MlV1alpha1().ArangoMLBatchJobs(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{}))
case **mlApi.ArangoMLCronJob:
require.NotNil(t, v)

Expand Down Expand Up @@ -593,6 +610,21 @@ func RefreshObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientS
} else {
*v = vn
}
case **mlApi.ArangoMLBatchJob:
require.NotNil(t, v)

vl := *v

vn, err := arango.MlV1alpha1().ArangoMLBatchJobs(vl.GetNamespace()).Get(context.Background(), vl.GetName(), meta.GetOptions{})
if err != nil {
if kerrors.IsNotFound(err) {
*v = nil
} else {
require.NoError(t, err)
}
} else {
*v = vn
}
case **mlApi.ArangoMLCronJob:
require.NotNil(t, v)

Expand Down Expand Up @@ -784,6 +816,14 @@ func SetMetaBasedOnType(t *testing.T, object meta.Object) {
v.SetSelfLink(fmt.Sprintf("/api/rbac.authorization.k8s.io/v1/rolebingings/%s/%s",
object.GetNamespace(),
object.GetName()))
case *mlApi.ArangoMLBatchJob:
v.Kind = ml.ArangoMLBatchJobResourceKind
v.APIVersion = mlApi.SchemeGroupVersion.String()
v.SetSelfLink(fmt.Sprintf("/api/%s/%s/%s/%s",
mlApi.SchemeGroupVersion.String(),
ml.ArangoMLBatchJobResourcePlural,
object.GetNamespace(),
object.GetName()))
case *mlApi.ArangoMLCronJob:
v.Kind = ml.ArangoMLCronJobResourceKind
v.APIVersion = mlApi.SchemeGroupVersion.String()
Expand Down Expand Up @@ -903,6 +943,10 @@ func NewItem(t *testing.T, o operation.Operation, object meta.Object) operation.
item.Group = "rbac.authorization.k8s.io"
item.Version = "v1"
item.Kind = "RoleBinding"
case *mlApi.ArangoMLBatchJob:
item.Group = ml.ArangoMLGroupName
item.Version = mlApi.ArangoMLVersion
item.Kind = ml.ArangoMLBatchJobResourceKind
case *mlApi.ArangoMLCronJob:
item.Group = ml.ArangoMLGroupName
item.Version = mlApi.ArangoMLVersion
Expand Down

0 comments on commit 7ea359e

Please sign in to comment.