diff --git a/CHANGELOG.md b/CHANGELOG.md index bd9d49a69..e2f4f7495 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pkg/apis/ml/v1alpha1/batchjob_spec.go b/pkg/apis/ml/v1alpha1/batchjob_spec.go index 119c386bf..f02377a58 100644 --- a/pkg/apis/ml/v1alpha1/batchjob_spec.go +++ b/pkg/apis/ml/v1alpha1/batchjob_spec.go @@ -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...) } diff --git a/pkg/apis/ml/v1alpha1/batchjob_status.go b/pkg/apis/ml/v1alpha1/batchjob_status.go index d80b42bea..baa219de1 100644 --- a/pkg/apis/ml/v1alpha1/batchjob_status.go +++ b/pkg/apis/ml/v1alpha1/batchjob_status.go @@ -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"` } diff --git a/pkg/apis/ml/v1alpha1/cronjob_spec.go b/pkg/apis/ml/v1alpha1/cronjob_spec.go index 78ca9453d..99366a0a6 100644 --- a/pkg/apis/ml/v1alpha1/cronjob_spec.go +++ b/pkg/apis/ml/v1alpha1/cronjob_spec.go @@ -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"` } diff --git a/pkg/apis/ml/v1alpha1/cronjob_status.go b/pkg/apis/ml/v1alpha1/cronjob_status.go index 8d0bcdd11..b929cfb8d 100644 --- a/pkg/apis/ml/v1alpha1/cronjob_status.go +++ b/pkg/apis/ml/v1alpha1/cronjob_status.go @@ -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" ) @@ -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")) -} diff --git a/pkg/apis/ml/v1alpha1/extension_conditions.go b/pkg/apis/ml/v1alpha1/extension_conditions.go index 5ecb04f51..59b34cea8 100644 --- a/pkg/apis/ml/v1alpha1/extension_conditions.go +++ b/pkg/apis/ml/v1alpha1/extension_conditions.go @@ -31,4 +31,5 @@ const ( ExtensionStatefulSetReadyCondition api.ConditionType = "ExtensionDeploymentReady" LicenseValidCondition api.ConditionType = "LicenseValid" CronJobSyncedCondition api.ConditionType = "CronJobSynced" + BatchJobSyncedCondition api.ConditionType = "BatchJobSynced" ) diff --git a/pkg/util/tests/kubernetes.go b/pkg/util/tests/kubernetes.go index eb967b64b..95cfee903 100644 --- a/pkg/util/tests/kubernetes.go +++ b/pkg/util/tests/kubernetes.go @@ -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) @@ -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) @@ -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) @@ -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) @@ -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() @@ -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