From 749c04b329e9c90f406d55e2c6f9bd197ddce2a2 Mon Sep 17 00:00:00 2001 From: jwierzbo Date: Wed, 6 Dec 2023 00:17:35 +0100 Subject: [PATCH 01/11] MLCronJob status update --- CHANGELOG.md | 1 + examples/ml/ml-cronjob.yaml | 18 +++++ pkg/apis/ml/v1alpha1/cronjob_spec.go | 2 +- pkg/apis/ml/v1alpha1/cronjob_status.go | 7 +- pkg/apis/ml/v1alpha1/extension_conditions.go | 3 + pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go | 4 +- pkg/util/tests/kubernetes.go | 65 ++++++++++++++++++- 7 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 examples/ml/ml-cronjob.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 341baf69f..c74677641 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/examples/ml/ml-cronjob.yaml b/examples/ml/ml-cronjob.yaml new file mode 100644 index 000000000..37c8c9edf --- /dev/null +++ b/examples/ml/ml-cronjob.yaml @@ -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 \ No newline at end of file diff --git a/pkg/apis/ml/v1alpha1/cronjob_spec.go b/pkg/apis/ml/v1alpha1/cronjob_spec.go index 835fa2651..e07162f0c 100644 --- a/pkg/apis/ml/v1alpha1/cronjob_spec.go +++ b/pkg/apis/ml/v1alpha1/cronjob_spec.go @@ -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" ) diff --git a/pkg/apis/ml/v1alpha1/cronjob_status.go b/pkg/apis/ml/v1alpha1/cronjob_status.go index 72160bbe1..491a31f6a 100644 --- a/pkg/apis/ml/v1alpha1/cronjob_status.go +++ b/pkg/apis/ml/v1alpha1/cronjob_status.go @@ -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 { @@ -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")) +} diff --git a/pkg/apis/ml/v1alpha1/extension_conditions.go b/pkg/apis/ml/v1alpha1/extension_conditions.go index 286032937..b355d5334 100644 --- a/pkg/apis/ml/v1alpha1/extension_conditions.go +++ b/pkg/apis/ml/v1alpha1/extension_conditions.go @@ -29,4 +29,7 @@ const ( ExtensionMetadataServiceValidCondition api.ConditionType = "MetadataServiceValid" ExtensionServiceAccountReadyCondition api.ConditionType = "ServiceAccountReady" LicenseValidCondition api.ConditionType = "LicenseValid" + CronJobCreatedCondition api.ConditionType = "CronJobCreated" + CronJobActiveCondition api.ConditionType = "CronJobActive" + CronJobSucceedCondition api.ConditionType = "CronJobSucceed" ) diff --git a/pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go index cad2e5fb4..4e18f1912 100644 --- a/pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go @@ -28,7 +28,7 @@ package v1alpha1 import ( v1 "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" sharedv1 "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1" - v1beta1 "k8s.io/api/batch/v1beta1" + batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -199,7 +199,7 @@ func (in *ArangoMLCronJobSpec) DeepCopyInto(out *ArangoMLCronJobSpec) { *out = *in if in.CronJobSpec != nil { in, out := &in.CronJobSpec, &out.CronJobSpec - *out = new(v1beta1.CronJobSpec) + *out = new(batchv1.CronJobSpec) (*in).DeepCopyInto(*out) } return diff --git a/pkg/util/tests/kubernetes.go b/pkg/util/tests/kubernetes.go index e6f064453..1475d7aa4 100644 --- a/pkg/util/tests/kubernetes.go +++ b/pkg/util/tests/kubernetes.go @@ -29,7 +29,6 @@ import ( "github.com/stretchr/testify/require" batch "k8s.io/api/batch/v1" core "k8s.io/api/core/v1" - rbac "k8s.io/api/rbac/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/client-go/kubernetes" @@ -96,6 +95,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) @@ -174,6 +179,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())) } @@ -278,6 +289,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) @@ -413,6 +439,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) @@ -483,6 +524,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" @@ -571,6 +618,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())) } @@ -618,6 +673,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" @@ -670,6 +729,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())) } From 51ab3ba51c826c63f760fc800cdc5c0d3d28f873 Mon Sep 17 00:00:00 2001 From: jwierzbo Date: Wed, 6 Dec 2023 13:01:33 +0100 Subject: [PATCH 02/11] MLCronJob status update --- chart/kube-arangodb/templates/ml-operator/role.yaml | 4 ++++ pkg/apis/ml/v1alpha1/cronjob_spec.go | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/chart/kube-arangodb/templates/ml-operator/role.yaml b/chart/kube-arangodb/templates/ml-operator/role.yaml index 1678e238c..6ab4dbf7c 100644 --- a/chart/kube-arangodb/templates/ml-operator/role.yaml +++ b/chart/kube-arangodb/templates/ml-operator/role.yaml @@ -52,5 +52,9 @@ rules: - "secrets" - "serviceaccounts" verbs: ["*"] + - apiGroups: ["batch"] + resources: + - "cronjobs" + verbs: ["*"] {{- end }} {{- end }} \ No newline at end of file diff --git a/pkg/apis/ml/v1alpha1/cronjob_spec.go b/pkg/apis/ml/v1alpha1/cronjob_spec.go index e07162f0c..457081ca2 100644 --- a/pkg/apis/ml/v1alpha1/cronjob_spec.go +++ b/pkg/apis/ml/v1alpha1/cronjob_spec.go @@ -24,6 +24,7 @@ import ( batchApi "k8s.io/api/batch/v1" "github.com/arangodb/kube-arangodb/pkg/apis/shared" + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) type ArangoMLCronJobSpec struct { @@ -33,5 +34,14 @@ type ArangoMLCronJobSpec struct { } 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...) } From 9a5eb5be193df20c16cd7161fcc0185cf7ee231f Mon Sep 17 00:00:00 2001 From: jwierzbo Date: Wed, 6 Dec 2023 13:25:02 +0100 Subject: [PATCH 03/11] Fix yaml --- examples/ml/ml-cronjob.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ml/ml-cronjob.yaml b/examples/ml/ml-cronjob.yaml index 37c8c9edf..130aad26a 100644 --- a/examples/ml/ml-cronjob.yaml +++ b/examples/ml/ml-cronjob.yaml @@ -15,4 +15,4 @@ spec: args: - curl - https://www.google.com - restartPolicy: OnFailure \ No newline at end of file + restartPolicy: OnFailure From c140c0203f97d1f6db33a73e4867be8719519197 Mon Sep 17 00:00:00 2001 From: jwierzbo Date: Wed, 6 Dec 2023 13:42:48 +0100 Subject: [PATCH 04/11] Fix import --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 7e791f1ff..cf22ec926 100644 --- a/Makefile +++ b/Makefile @@ -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 From f4229f770a84a3c7820cd40136d2f09b2e4b2685 Mon Sep 17 00:00:00 2001 From: jwierzbo Date: Wed, 6 Dec 2023 13:57:47 +0100 Subject: [PATCH 05/11] Fix import --- pkg/apis/ml/v1alpha1/cronjob_spec.go | 4 ++-- pkg/apis/ml/v1alpha1/cronjob_status.go | 4 ++-- pkg/util/tests/kubernetes.go | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/apis/ml/v1alpha1/cronjob_spec.go b/pkg/apis/ml/v1alpha1/cronjob_spec.go index 457081ca2..78ca9453d 100644 --- a/pkg/apis/ml/v1alpha1/cronjob_spec.go +++ b/pkg/apis/ml/v1alpha1/cronjob_spec.go @@ -21,7 +21,7 @@ package v1alpha1 import ( - batchApi "k8s.io/api/batch/v1" + batch "k8s.io/api/batch/v1" "github.com/arangodb/kube-arangodb/pkg/apis/shared" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -30,7 +30,7 @@ import ( 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 { diff --git a/pkg/apis/ml/v1alpha1/cronjob_status.go b/pkg/apis/ml/v1alpha1/cronjob_status.go index 491a31f6a..4c16550ce 100644 --- a/pkg/apis/ml/v1alpha1/cronjob_status.go +++ b/pkg/apis/ml/v1alpha1/cronjob_status.go @@ -21,7 +21,7 @@ package v1alpha1 import ( - batchApi "k8s.io/api/batch/v1" + batch "k8s.io/api/batch/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/apis/shared" @@ -34,7 +34,7 @@ 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 { diff --git a/pkg/util/tests/kubernetes.go b/pkg/util/tests/kubernetes.go index 1475d7aa4..d57b06d1b 100644 --- a/pkg/util/tests/kubernetes.go +++ b/pkg/util/tests/kubernetes.go @@ -29,6 +29,7 @@ import ( "github.com/stretchr/testify/require" batch "k8s.io/api/batch/v1" core "k8s.io/api/core/v1" + rbac "k8s.io/api/rbac/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/client-go/kubernetes" From b0ca5b82fdf611dada862ad2df2039ecfb29d7c2 Mon Sep 17 00:00:00 2001 From: jwierzbo Date: Wed, 6 Dec 2023 14:33:39 +0100 Subject: [PATCH 06/11] Doc update --- docs/api/ArangoMLCronJob.V1Alpha1.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api/ArangoMLCronJob.V1Alpha1.md b/docs/api/ArangoMLCronJob.V1Alpha1.md index ffdd057ae..21e5305ed 100644 --- a/docs/api/ArangoMLCronJob.V1Alpha1.md +++ b/docs/api/ArangoMLCronJob.V1Alpha1.md @@ -4,7 +4,7 @@ ### .spec -Type: `batch.CronJobSpec` [\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_spec.go#L32) +Type: `batch.CronJobSpec` [\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_spec.go#L33) Links: * [Kubernetes Documentation](https://godoc.org/k8s.io/api/batch/v1beta1#CronJobSpec) @@ -13,7 +13,7 @@ Links: ### .status -Type: `batch.CronJobStatus` [\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L36) +Type: `batch.CronJobStatus` [\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L37) Links: * [Kubernetes Documentation](https://godoc.org/k8s.io/api/batch/v1beta1#CronJobStatus) @@ -22,7 +22,7 @@ Links: ### .status.conditions -Type: `api.Conditions` [\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L32) +Type: `api.Conditions` [\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L33) Conditions specific to the entire cron job From 9d1c09dd31e08f084ff1f4c0176e24fbb969dc91 Mon Sep 17 00:00:00 2001 From: jwierzbo Date: Wed, 6 Dec 2023 22:43:29 +0100 Subject: [PATCH 07/11] Review fixes --- pkg/apis/ml/v1alpha1/cronjob_status.go | 2 +- pkg/apis/ml/v1alpha1/extension_conditions.go | 3 --- pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go | 6 +++++- pkg/operatorV2/operator_worker.go | 5 ++++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/apis/ml/v1alpha1/cronjob_status.go b/pkg/apis/ml/v1alpha1/cronjob_status.go index 4c16550ce..e8c2fda15 100644 --- a/pkg/apis/ml/v1alpha1/cronjob_status.go +++ b/pkg/apis/ml/v1alpha1/cronjob_status.go @@ -34,7 +34,7 @@ type ArangoMLCronJobStatus struct { // +doc/type: batch.CronJobStatus // +doc/link: Kubernetes Documentation|https://godoc.org/k8s.io/api/batch/v1beta1#CronJobStatus - batch.CronJobStatus `json:",inline"` + *batch.CronJobStatus `json:",inline"` } func (a *ArangoMLCronJobStatus) Validate() error { diff --git a/pkg/apis/ml/v1alpha1/extension_conditions.go b/pkg/apis/ml/v1alpha1/extension_conditions.go index b355d5334..286032937 100644 --- a/pkg/apis/ml/v1alpha1/extension_conditions.go +++ b/pkg/apis/ml/v1alpha1/extension_conditions.go @@ -29,7 +29,4 @@ const ( ExtensionMetadataServiceValidCondition api.ConditionType = "MetadataServiceValid" ExtensionServiceAccountReadyCondition api.ConditionType = "ServiceAccountReady" LicenseValidCondition api.ConditionType = "LicenseValid" - CronJobCreatedCondition api.ConditionType = "CronJobCreated" - CronJobActiveCondition api.ConditionType = "CronJobActive" - CronJobSucceedCondition api.ConditionType = "CronJobSucceed" ) diff --git a/pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go index 4e18f1912..1a3205e4d 100644 --- a/pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go @@ -225,7 +225,11 @@ func (in *ArangoMLCronJobStatus) DeepCopyInto(out *ArangoMLCronJobStatus) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - in.CronJobStatus.DeepCopyInto(&out.CronJobStatus) + if in.CronJobStatus != nil { + in, out := &in.CronJobStatus, &out.CronJobStatus + *out = new(batchv1.CronJobStatus) + (*in).DeepCopyInto(*out) + } return } diff --git a/pkg/operatorV2/operator_worker.go b/pkg/operatorV2/operator_worker.go index a852ad8a3..99b1febf5 100644 --- a/pkg/operatorV2/operator_worker.go +++ b/pkg/operatorV2/operator_worker.go @@ -22,6 +22,7 @@ package operator import ( "context" + "fmt" "github.com/arangodb/kube-arangodb/pkg/operatorV2/operation" "github.com/arangodb/kube-arangodb/pkg/util/errors" @@ -109,7 +110,9 @@ func (o *operator) processObject(obj interface{}) error { o.workqueue.AddRateLimited(key) if !IsReconcile(err) { - return errors.Newf("error syncing '%s': %s, re-queuing", key, err.Error()) + message := fmt.Sprintf("error syncing '%s': %s, re-queuing", key, err.Error()) + loggerWorker.Debug(message) + return errors.Newf(message) } return nil From 82a4986fe3ba25520dcdd940d19bc70d3cd84d00 Mon Sep 17 00:00:00 2001 From: jwierzbo Date: Wed, 6 Dec 2023 22:46:36 +0100 Subject: [PATCH 08/11] Review fixes --- chart/kube-arangodb/templates/ml-operator/role.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/chart/kube-arangodb/templates/ml-operator/role.yaml b/chart/kube-arangodb/templates/ml-operator/role.yaml index 6ab4dbf7c..1678e238c 100644 --- a/chart/kube-arangodb/templates/ml-operator/role.yaml +++ b/chart/kube-arangodb/templates/ml-operator/role.yaml @@ -52,9 +52,5 @@ rules: - "secrets" - "serviceaccounts" verbs: ["*"] - - apiGroups: ["batch"] - resources: - - "cronjobs" - verbs: ["*"] {{- end }} {{- end }} \ No newline at end of file From 9bf6071f799d9a9e6b47318f6fa521be74176344 Mon Sep 17 00:00:00 2001 From: jwierzbo Date: Thu, 7 Dec 2023 16:13:33 +0100 Subject: [PATCH 09/11] CronJobSynced condition --- docs/api/ArangoMLCronJob.V1Alpha1.md | 28 ++++- pkg/apis/ml/v1alpha1/cronjob_status.go | 4 + pkg/apis/ml/v1alpha1/extension_conditions.go | 1 + pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go | 5 + pkg/util/tests/kubernetes.go | 100 ++++++++++++++++++ 5 files changed, 136 insertions(+), 2 deletions(-) diff --git a/docs/api/ArangoMLCronJob.V1Alpha1.md b/docs/api/ArangoMLCronJob.V1Alpha1.md index 21e5305ed..d619ae8fb 100644 --- a/docs/api/ArangoMLCronJob.V1Alpha1.md +++ b/docs/api/ArangoMLCronJob.V1Alpha1.md @@ -13,7 +13,7 @@ Links: ### .status -Type: `batch.CronJobStatus` [\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L37) +Type: `batch.CronJobStatus` [\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L38) Links: * [Kubernetes Documentation](https://godoc.org/k8s.io/api/batch/v1beta1#CronJobStatus) @@ -22,7 +22,31 @@ Links: ### .status.conditions -Type: `api.Conditions` [\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L33) +Type: `api.Conditions` [\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L34) Conditions specific to the entire cron job +*** + +### .status.ref.name + +Type: `string` [\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/object.go#L46) + +Name of the object + +*** + +### .status.ref.namespace + +Type: `string` [\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/object.go#L49) + +Namespace of the object. Should default to the namespace of the parent object + +*** + +### .status.ref.uid + +Type: `string` [\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/object.go#L52) + +UID keeps the information about object UID + diff --git a/pkg/apis/ml/v1alpha1/cronjob_status.go b/pkg/apis/ml/v1alpha1/cronjob_status.go index e8c2fda15..8d0bcdd11 100644 --- a/pkg/apis/ml/v1alpha1/cronjob_status.go +++ b/pkg/apis/ml/v1alpha1/cronjob_status.go @@ -25,6 +25,7 @@ import ( 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" ) type ArangoMLCronJobStatus struct { @@ -35,6 +36,9 @@ type ArangoMLCronJobStatus struct { // +doc/type: batch.CronJobStatus // +doc/link: Kubernetes Documentation|https://godoc.org/k8s.io/api/batch/v1beta1#CronJobStatus *batch.CronJobStatus `json:",inline"` + + // Ref keeps the reference to the CronJob + Ref *sharedApi.Object `json:"ref,omitempty"` } func (a *ArangoMLCronJobStatus) Validate() error { diff --git a/pkg/apis/ml/v1alpha1/extension_conditions.go b/pkg/apis/ml/v1alpha1/extension_conditions.go index 286032937..7a7c01395 100644 --- a/pkg/apis/ml/v1alpha1/extension_conditions.go +++ b/pkg/apis/ml/v1alpha1/extension_conditions.go @@ -29,4 +29,5 @@ const ( ExtensionMetadataServiceValidCondition api.ConditionType = "MetadataServiceValid" ExtensionServiceAccountReadyCondition api.ConditionType = "ServiceAccountReady" LicenseValidCondition api.ConditionType = "LicenseValid" + CronJobSyncedCondition api.ConditionType = "CronJobSynced" ) diff --git a/pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go index 1a3205e4d..76eaf9e8e 100644 --- a/pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go @@ -230,6 +230,11 @@ func (in *ArangoMLCronJobStatus) DeepCopyInto(out *ArangoMLCronJobStatus) { *out = new(batchv1.CronJobStatus) (*in).DeepCopyInto(*out) } + if in.Ref != nil { + in, out := &in.Ref, &out.Ref + *out = new(sharedv1.Object) + (*in).DeepCopyInto(*out) + } return } diff --git a/pkg/util/tests/kubernetes.go b/pkg/util/tests/kubernetes.go index d57b06d1b..7c788e86e 100644 --- a/pkg/util/tests/kubernetes.go +++ b/pkg/util/tests/kubernetes.go @@ -199,6 +199,12 @@ func CreateObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSe func UpdateObjects(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()).Update(context.Background(), vl, meta.UpdateOptions{}) + require.NoError(t, err) case **batch.Job: require.NotNil(t, v) @@ -253,6 +259,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.ArangoMLCronJob: + require.NotNil(t, v) + + vl := *v + _, err := arango.MlV1alpha1().ArangoMLCronJobs(vl.GetNamespace()).Update(context.Background(), vl, meta.UpdateOptions{}) + require.NoError(t, err) case **rbac.ClusterRole: require.NotNil(t, v) @@ -287,6 +299,94 @@ func UpdateObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSe } } +func DeleteObjects(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 + require.NoError(t, k8s.BatchV1().CronJobs(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + case **batch.Job: + require.NotNil(t, v) + + vl := *v + require.NoError(t, k8s.BatchV1().Jobs(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + case **core.Pod: + require.NotNil(t, v) + + vl := *v + require.NoError(t, k8s.CoreV1().Pods(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + case **core.Secret: + require.NotNil(t, v) + + vl := *v + require.NoError(t, k8s.CoreV1().Secrets(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + case **core.ServiceAccount: + require.NotNil(t, v) + + vl := *v + require.NoError(t, k8s.CoreV1().ServiceAccounts(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + case **api.ArangoDeployment: + require.NotNil(t, v) + + vl := *v + require.NoError(t, arango.DatabaseV1().ArangoDeployments(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + case **api.ArangoClusterSynchronization: + require.NotNil(t, v) + + vl := *v + require.NoError(t, arango.DatabaseV1().ArangoClusterSynchronizations(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + case **backupApi.ArangoBackup: + require.NotNil(t, v) + + vl := *v + require.NoError(t, arango.BackupV1().ArangoBackups(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + case **mlApi.ArangoMLExtension: + require.NotNil(t, v) + + vl := *v + require.NoError(t, arango.MlV1alpha1().ArangoMLExtensions(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + case **mlApi.ArangoMLStorage: + require.NotNil(t, v) + + vl := *v + require.NoError(t, arango.MlV1alpha1().ArangoMLStorages(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + case **mlApi.ArangoMLCronJob: + require.NotNil(t, v) + + vl := *v + require.NoError(t, arango.MlV1alpha1().ArangoMLCronJobs(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + case **rbac.ClusterRole: + require.NotNil(t, v) + + vl := *v + require.NoError(t, k8s.RbacV1().ClusterRoles().Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + case **rbac.ClusterRoleBinding: + require.NotNil(t, v) + + vl := *v + require.NoError(t, k8s.RbacV1().ClusterRoleBindings().Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + case **rbac.Role: + require.NotNil(t, v) + + vl := *v + require.NoError(t, k8s.RbacV1().Roles(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + case **rbac.RoleBinding: + require.NotNil(t, v) + + vl := *v + require.NoError(t, k8s.RbacV1().RoleBindings(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{})) + default: + require.Fail(t, fmt.Sprintf("Unable to create object: %s", reflect.TypeOf(v).String())) + } + } + + return func(t *testing.T) { + RefreshObjects(t, k8s, arango, objects...) + } +} + func RefreshObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSet.Interface, objects ...interface{}) { for _, object := range objects { switch v := object.(type) { From 2e6c83bef2b76758ff04513ec36a855b6f6b462f Mon Sep 17 00:00:00 2001 From: jwierzbo Date: Thu, 7 Dec 2023 16:28:20 +0100 Subject: [PATCH 10/11] Bump Go to 1.20.12 --- .circleci/continue_config.yml | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/continue_config.yml b/.circleci/continue_config.yml index 9feddf4ee..b63990951 100644 --- a/.circleci/continue_config.yml +++ b/.circleci/continue_config.yml @@ -16,7 +16,7 @@ parameters: executors: golang-executor: docker: - - image: gcr.io/gcr-for-testing/golang:1.20.11 + - image: gcr.io/gcr-for-testing/golang:1.20.12 machine-executor: machine: image: ubuntu-2204:current diff --git a/Makefile b/Makefile index cf22ec926..f9c248d25 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ endif TEST_BUILD ?= 0 GOBUILDARGS ?= -GOBASEVERSION := 1.20.11 +GOBASEVERSION := 1.20.12 GOVERSION := $(GOBASEVERSION)-alpine3.17 DISTRIBUTION := alpine:3.15 GOBUILDTAGS := $(RELEASE_MODE) From c6aa1ba67ce86ca566f017737f17168e99519b3b Mon Sep 17 00:00:00 2001 From: jwierzbo Date: Thu, 7 Dec 2023 20:03:31 +0100 Subject: [PATCH 11/11] Remove example --- examples/ml/ml-cronjob.yaml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 examples/ml/ml-cronjob.yaml diff --git a/examples/ml/ml-cronjob.yaml b/examples/ml/ml-cronjob.yaml deleted file mode 100644 index 130aad26a..000000000 --- a/examples/ml/ml-cronjob.yaml +++ /dev/null @@ -1,18 +0,0 @@ -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