Skip to content

Commit

Permalink
MLCronJob status update
Browse files Browse the repository at this point in the history
  • Loading branch information
jwierzbo committed Dec 5, 2023
1 parent a7bd9cb commit 49a90e7
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- (Feature) (ML) Extension Storage Condition
- (Improvement) (ML) Switch to fsnotify for file watching for MacOS support
- (Feature) (ML) Unify Images, Resources and Lifecycle
- (Improvement) (ML) CronJob 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
18 changes: 18 additions & 0 deletions examples/ml/ml-cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: ml.arangodb.com/v1alpha1
kind: ArangoMLCronJob
metadata:
name: example-arangomlcronjob
namespace: default
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: curl-google
image: appropriate/curl
args:
- curl
- https://www.google.com
restartPolicy: OnFailure
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 @@ -21,7 +21,7 @@
package v1alpha1

import (
batchApi "k8s.io/api/batch/v1beta1"
batchApi "k8s.io/api/batch/v1"

"github.com/arangodb/kube-arangodb/pkg/apis/shared"
)
Expand Down
7 changes: 6 additions & 1 deletion pkg/apis/ml/v1alpha1/cronjob_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
package v1alpha1

import (
batchApi "k8s.io/api/batch/v1beta1"
batchApi "k8s.io/api/batch/v1"

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

type ArangoMLCronJobStatus struct {
Expand All @@ -35,3 +36,7 @@ type ArangoMLCronJobStatus struct {
// +doc/link: Kubernetes Documentation|https://godoc.org/k8s.io/api/batch/v1beta1#CronJobStatus
batchApi.CronJobStatus `json:",inline"`
}

func (a *ArangoMLCronJobStatus) Validate() error {
return shared.WithErrors(shared.PrefixResourceErrors("spec"))
}
3 changes: 3 additions & 0 deletions pkg/apis/ml/v1alpha1/extension_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ const (
ExtensionBootstrapCompletedCondition api.ConditionType = "BootstrapCompleted"
ExtensionMetadataServiceValidCondition api.ConditionType = "MetadataServiceValid"
LicenseValidCondition api.ConditionType = "LicenseValid"
CronJobCreatedCondition api.ConditionType = "CronJobCreated"
CronJobActiveCondition api.ConditionType = "CronJobActive"
CronJobSucceedCondition api.ConditionType = "CronJobSucceed"
)
4 changes: 2 additions & 2 deletions pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go

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

64 changes: 64 additions & 0 deletions pkg/util/tests/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ type KubernetesObject interface {
func CreateObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSet.Interface, objects ...interface{}) func(t *testing.T) {
for _, object := range objects {
switch v := object.(type) {
case **batch.CronJob:
require.NotNil(t, v)

vl := *v
_, err := k8s.BatchV1().CronJobs(vl.GetNamespace()).Create(context.Background(), vl, meta.CreateOptions{})
require.NoError(t, err)
case **batch.Job:
require.NotNil(t, v)

Expand Down Expand Up @@ -122,6 +128,12 @@ func CreateObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSe
vl := *v
_, err := arango.MlV1alpha1().ArangoMLStorages(vl.GetNamespace()).Create(context.Background(), vl, meta.CreateOptions{})
require.NoError(t, err)
case **mlApi.ArangoMLCronJob:
require.NotNil(t, v)

vl := *v
_, err := arango.MlV1alpha1().ArangoMLCronJobs(vl.GetNamespace()).Create(context.Background(), vl, meta.CreateOptions{})
require.NoError(t, err)
default:
require.Fail(t, fmt.Sprintf("Unable to create object: %s", reflect.TypeOf(v).String()))
}
Expand Down Expand Up @@ -196,6 +208,21 @@ func UpdateObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSe
func RefreshObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSet.Interface, objects ...interface{}) {
for _, object := range objects {
switch v := object.(type) {
case **batch.CronJob:
require.NotNil(t, v)

vl := *v

vn, err := k8s.BatchV1().CronJobs(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 **batch.Job:
require.NotNil(t, v)

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

vl := *v

vn, err := arango.MlV1alpha1().ArangoMLCronJobs(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
}
default:
require.Fail(t, fmt.Sprintf("Unable to create object: %s", reflect.TypeOf(v).String()))
}
Expand All @@ -326,6 +368,12 @@ type MetaObjectMod[T meta.Object] func(t *testing.T, obj T)

func SetMetaBasedOnType(t *testing.T, object meta.Object) {
switch v := object.(type) {
case *batch.CronJob:
v.Kind = "CronJob"
v.APIVersion = "batch/v1"
v.SetSelfLink(fmt.Sprintf("/api/batch/v1/cronjobs/%s/%s",
object.GetNamespace(),
object.GetName()))
case *batch.Job:
v.Kind = "Job"
v.APIVersion = "batch/v1"
Expand Down Expand Up @@ -384,6 +432,14 @@ func SetMetaBasedOnType(t *testing.T, object meta.Object) {
ml.ArangoMLStorageResourcePlural,
object.GetNamespace(),
object.GetName()))
case *mlApi.ArangoMLCronJob:
v.Kind = ml.ArangoMLCronJobResourceKind
v.APIVersion = mlApi.SchemeGroupVersion.String()
v.SetSelfLink(fmt.Sprintf("/api/%s/%s/%s/%s",
mlApi.SchemeGroupVersion.String(),
ml.ArangoMLCronJobResourcePlural,
object.GetNamespace(),
object.GetName()))
default:
require.Fail(t, fmt.Sprintf("Unable to create object: %s", reflect.TypeOf(v).String()))
}
Expand Down Expand Up @@ -420,6 +476,10 @@ func NewItem(t *testing.T, o operation.Operation, object meta.Object) operation.
}

switch v := object.(type) {
case *batch.CronJob:
item.Group = "batch"
item.Version = "v1"
item.Kind = "CronJob"
case *batch.Job:
item.Group = "batch"
item.Version = "v1"
Expand Down Expand Up @@ -452,6 +512,10 @@ func NewItem(t *testing.T, o operation.Operation, object meta.Object) operation.
item.Group = ml.ArangoMLGroupName
item.Version = mlApi.ArangoMLVersion
item.Kind = ml.ArangoMLStorageResourceKind
case *mlApi.ArangoMLCronJob:
item.Group = ml.ArangoMLGroupName
item.Version = mlApi.ArangoMLVersion
item.Kind = ml.ArangoMLCronJobResourceKind
default:
require.Fail(t, fmt.Sprintf("Unable to create object: %s", reflect.TypeOf(v).String()))
}
Expand Down

0 comments on commit 49a90e7

Please sign in to comment.