Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLCronJob status update #1526

Merged
merged 11 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ set-api-version/%:
synchronize: synchronize-v2alpha1-with-v1

synchronize-v2alpha1-with-v1:
@echo ">> Please use only COMMUNITY mode! Current RELEASE_MODE=$(RELEASE_MODE)"
@rm -f pkg/apis/deployment/v1/zz_generated.deepcopy.go pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go
@for file in $$(find "$(ROOT)/pkg/apis/deployment/v1/" -type f -exec $(REALPATH) --relative-to "$(ROOT)/pkg/apis/deployment/v1/" {} \;); do if [ ! -d "$(ROOT)/pkg/apis/deployment/v2alpha1/$$(dirname $${file})" ]; then mkdir -p "$(ROOT)/pkg/apis/deployment/v2alpha1/$$(dirname $${file})"; fi; done
@for file in $$(find "$(ROOT)/pkg/apis/deployment/v1/" -type f -exec $(REALPATH) --relative-to "$(ROOT)/pkg/apis/deployment/v1/" {} \;); do cat "$(ROOT)/pkg/apis/deployment/v1/$${file}" | $(SED) "s#package v1#package v2alpha1#g" | $(SED) 's#ArangoDeploymentVersion = "v1"#ArangoDeploymentVersion = "v2alpha1"#g' > "$(ROOT)/pkg/apis/deployment/v2alpha1/$${file}"; done
Expand Down
4 changes: 4 additions & 0 deletions chart/kube-arangodb/templates/ml-operator/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ rules:
- "secrets"
- "serviceaccounts"
verbs: ["*"]
- apiGroups: ["batch"]
jwierzbo marked this conversation as resolved.
Show resolved Hide resolved
resources:
- "cronjobs"
verbs: ["*"]
{{- end }}
{{- end }}
6 changes: 3 additions & 3 deletions docs/api/ArangoMLCronJob.V1Alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### .spec

Type: `batch.CronJobSpec` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_spec.go#L32)</sup>
Type: `batch.CronJobSpec` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_spec.go#L33)</sup>

Links:
* [Kubernetes Documentation](https://godoc.org/k8s.io/api/batch/v1beta1#CronJobSpec)
Expand All @@ -13,7 +13,7 @@ Links:

### .status

Type: `batch.CronJobStatus` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L36)</sup>
Type: `batch.CronJobStatus` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L37)</sup>

Links:
* [Kubernetes Documentation](https://godoc.org/k8s.io/api/batch/v1beta1#CronJobStatus)
Expand All @@ -22,7 +22,7 @@ Links:

### .status.conditions

Type: `api.Conditions` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L32)</sup>
Type: `api.Conditions` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L33)</sup>

Conditions specific to the entire cron job

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove example, we will provide example in docs later

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? it is useful for quick tests...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will generate it in examples and readme for all objects

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
16 changes: 13 additions & 3 deletions pkg/apis/ml/v1alpha1/cronjob_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,27 @@
package v1alpha1

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

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

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

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

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

return shared.WithErrors(err...)
}
9 changes: 7 additions & 2 deletions 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"
batch "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 @@ -33,5 +34,9 @@ type ArangoMLCronJobStatus struct {

// +doc/type: batch.CronJobStatus
// +doc/link: Kubernetes Documentation|https://godoc.org/k8s.io/api/batch/v1beta1#CronJobStatus
batchApi.CronJobStatus `json:",inline"`
batch.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 @@ -29,4 +29,7 @@ const (
ExtensionMetadataServiceValidCondition api.ConditionType = "MetadataServiceValid"
ExtensionServiceAccountReadyCondition api.ConditionType = "ServiceAccountReady"
LicenseValidCondition api.ConditionType = "LicenseValid"
CronJobCreatedCondition api.ConditionType = "CronJobCreated"
jwierzbo marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -96,6 +96,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 @@ -174,6 +180,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.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 @@ -278,6 +290,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 @@ -413,6 +440,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
}
case **rbac.ClusterRole:
require.NotNil(t, v)

Expand Down Expand Up @@ -483,6 +525,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 @@ -571,6 +619,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.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 @@ -618,6 +674,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 @@ -670,6 +730,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.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