8000 MLCronJob status update · arangodb/kube-arangodb@49a90e7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 49a90e7

Browse files
committed
MLCronJob status update
1 parent a7bd9cb commit 49a90e7

File tree

7 files changed

+95
-4
lines changed

7 files changed

+95
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- (Feature) (ML) Extension Storage Condition
3030
- (Improvement) (ML) Switch to fsnotify for file watching for MacOS support
3131
- (Feature) (ML) Unify Images, Resources and Lifecycle
32+
- (Improvement) (ML) CronJob status update
3233

3334
## [1.2.35](https://github.com/arangodb/kube-arangodb/tree/1.2.35) (2023-11-06)
3435
- (Maintenance) Update go-driver to v1.6.0, update IsNotFound() checks

examples/ml/ml-cronjob.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: ml.arangodb.com/v1alpha1
2+
kind: ArangoMLCronJob
3+
metadata:
4+
name: example-arangomlcronjob
5+
namespace: default
6+
spec:
7+
schedule: "*/1 * * * *"
8+
jobTemplate:
9+
spec:
10+
template:
11+
spec:
12+
containers:
13+
- name: curl-google
14+
image: appropriate/curl
15+
args:
16+
- curl
17+
- https://www.google.com
18+
restartPolicy: OnFailure

pkg/apis/ml/v1alpha1/cronjob_spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
package v1alpha1
2222

2323
import (
24-
batchApi "k8s.io/api/batch/v1beta1"
24+
batchApi "k8s.io/api/batch/v1"
2525

2626
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
2727
)

pkg/apis/ml/v1alpha1/cronjob_status.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
package v1alpha1
2222

2323
import (
24-
batchApi "k8s.io/api/batch/v1beta1"
24+
batchApi "k8s.io/api/batch/v1"
2525

2626
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
27+
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
2728
)
2829

2930
type ArangoMLCronJobStatus struct {
@@ -35,3 +36,7 @@ type ArangoMLCronJobStatus struct {
3536
// +doc/link: Kubernetes Documentation|https://godoc.org/k8s.io/api/batch/v1beta1#CronJobStatus
3637
batchApi.CronJobStatus `json:",inline"`
3738
}
39+
40+
func (a *ArangoMLCronJobStatus) Validate() error {
41+
return shared.WithErrors(shared.PrefixResourceErrors("spec"))
42+
}

pkg/apis/ml/v1alpha1/extension_conditions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ const (
2828
ExtensionBootstrapCompletedCondition api.ConditionType = "BootstrapCompleted"
2929
ExtensionMetadataServiceValidCondition api.ConditionType = "MetadataServiceValid"
3030
LicenseValidCondition api.ConditionType = "LicenseValid"
31+
CronJobCreatedCondition api.ConditionType = "CronJobCreated"
32+
CronJobActiveCondition api.ConditionType = "CronJobActive"
33+
CronJobSucceedCondition api.ConditionType = "CronJobSucceed"
3134
)

pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/util/tests/kubernetes.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ type KubernetesObject interface {
7474
func CreateObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSet.Interface, objects ...interface{}) func(t *testing.T) {
7575
for _, object := range objects {
7676
switch v := object.(type) {
77+
case **batch.CronJob:
78+
require.NotNil(t, v)
79+
80+
vl := *v
81+
_, err := k8s.BatchV1().CronJobs(vl.GetNamespace()).Create(context.Background(), vl, meta.CreateOptions{})
82+
require.NoError(t, err)
7783
case **batch.Job:
7884
require.NotNil(t, v)
7985

@@ -122,6 +128,12 @@ func CreateObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSe
122128
vl := *v
123129
_, err := arango.MlV1alpha1().ArangoMLStorages(vl.GetNamespace()).Create(context.Background(), vl, meta.CreateOptions{})
124130
require.NoError(t, err)
131+
case **mlApi.ArangoMLCronJob:
132+
require.NotNil(t, v)
133+
134+
vl := *v
135+
_, err := arango.MlV1alpha1().ArangoMLCronJobs(vl.GetNamespace()).Create(context.Background(), vl, meta.CreateOptions{})
136+
require.NoError(t, err)
125137
default:
126138
require.Fail(t, fmt.Sprintf("Unable to create object: %s", reflect.TypeOf(v).String()))
127139
}
@@ -196,6 +208,21 @@ func UpdateObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSe
196208
func RefreshObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSet.Interface, objects ...interface{}) {
197209
for _, object := range objects {
198210
switch v := object.(type) {
211+
case **batch.CronJob:
212+
require.NotNil(t, v)
213+
214+
vl := *v
215+
216+
vn, err := k8s.BatchV1().CronJobs(vl.GetNamespace()).Get(context.Background(), vl.GetName(), meta.GetOptions{})
217+
if err != nil {
218+
if kerrors.IsNotFound(err) {
219+
*v = nil
220+
} else {
221+
require.NoError(t, err)
222+
}
223+
} else {
224+
*v = vn
225+
}
199226
case **batch.Job:
200227
require.NotNil(t, v)
201228

@@ -316,6 +343,21 @@ func RefreshObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientS
316343
} else {
317344
*v = vn
318345
}
346+
case **mlApi.ArangoMLCronJob:
347+
require.NotNil(t, v)
348+
349+
vl := *v
350+
351+
vn, err := arango.MlV1alpha1().ArangoMLCronJobs(vl.GetNamespace()).Get(context.Background(), vl.GetName(), meta.GetOptions{})
352+
if err != nil {
353+
if kerrors.IsNotFound(err) {
354+
*v = nil
355+
} else {
356+
require.NoError(t, err)
357+
}
358+
} else {
359+
*v = vn
360+
}
319361
default:
320362
require.Fail(t, fmt.Sprintf("Unable to create object: %s", reflect.TypeOf(v).String()))
321363
}
@@ -326,6 +368,12 @@ type MetaObjectMod[T meta.Object] func(t *testing.T, obj T)
326368

327369
func SetMetaBasedOnType(t *testing.T, object meta.Object) {
328370
switch v := object.(type) {
371+
case *batch.CronJob:
372+
v.Kind = "CronJob"
373+
v.APIVersion = "batch/v1"
374+
v.SetSelfLink(fmt.Sprintf("/api/batch/v1/cronjobs/%s/%s",
375+
object.GetNamespace(),
376+
object.GetName()))
329377
case *batch.Job:
330378
v.Kind = "Job"
331379
v.APIVersion = "batch/v1"
@@ -384,6 +432,14 @@ func SetMetaBasedOnType(t *testing.T, object meta.Object) {
384432
ml.ArangoMLStorageResourcePlural,
385433
object.GetNamespace(),
386434
object.GetName()))
435+
case *mlApi.ArangoMLCronJob:
436+
v.Kind = ml.ArangoMLCronJobResourceKind
437+
v.APIVersion = mlApi.SchemeGroupVersion.String()
438+
v.SetSelfLink(fmt.Sprintf("/api/%s/%s/%s/%s",
439+
mlApi.SchemeGroupVersion.String(),
440+
ml.ArangoMLCronJobResourcePlural,
441+
object.GetNamespace(),
442+
object.GetName()))
387443
default:
388444
require.Fail(t, fmt.Sprintf("Unable to create object: %s", reflect.TypeOf(v).String()))
389445
}
@@ -420,6 +476,10 @@ func NewItem(t *testing.T, o operation.Operation, object meta.Object) operation.
420476
}
421477

422478
switch v := object.(type) {
479+
case *batch.CronJob:
480+
item.Group = "batch"
481+
item.Version = "v1"
482+
item.Kind = "CronJob"
423483
case *batch.Job:
424484
item.Group = "batch"
425485
item.Version = "v1"
@@ -452,6 +512,10 @@ func NewItem(t *testing.T, o operation.Operation, object meta.Object) operation.
452512
item.Group = ml.ArangoMLGroupName
453513
item.Version = mlApi.ArangoMLVersion
454514
item.Kind = ml.ArangoMLStorageResourceKind
515+
case *mlApi.ArangoMLCronJob:
516+
item.Group = ml.ArangoMLGroupName
517+
item.Version = mlApi.ArangoMLVersion
518+
item.Kind = ml.ArangoMLCronJobResourceKind
455519
default:
456520
require.Fail(t, fmt.Sprintf("Unable to create object: %s", reflect.TypeOf(v).String()))
457521
}

0 commit comments

Comments
 (0)
0