From 49b7fab00ae5bb28614102cb9cb891eff177dad0 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Thu, 29 Aug 2024 14:45:39 +0200 Subject: [PATCH 1/5] Added batchId field to the radixbatch --- charts/radix-operator/Chart.yaml | 4 ++-- charts/radix-operator/templates/radixbatch.yaml | 3 +++ pkg/apis/radix/v1/radixbatchtypes.go | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/charts/radix-operator/Chart.yaml b/charts/radix-operator/Chart.yaml index 92055057c..a48bd69ac 100644 --- a/charts/radix-operator/Chart.yaml +++ b/charts/radix-operator/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 name: radix-operator -version: 1.38.0 -appVersion: 1.58.0 +version: 1.38.1 +appVersion: 1.58.1 kubeVersion: ">=1.24.0" description: Radix Operator keywords: diff --git a/charts/radix-operator/templates/radixbatch.yaml b/charts/radix-operator/templates/radixbatch.yaml index 6edf463ee..98bf64b86 100644 --- a/charts/radix-operator/templates/radixbatch.yaml +++ b/charts/radix-operator/templates/radixbatch.yaml @@ -51,6 +51,9 @@ spec: spec: description: RadixBatchSpec is the specification of batch jobs. properties: + batchId: + description: Defines a user defined ID of the batch. + type: string jobs: description: List of batch jobs to run. items: diff --git a/pkg/apis/radix/v1/radixbatchtypes.go b/pkg/apis/radix/v1/radixbatchtypes.go index ae7fdb65a..cd1a5b4d7 100644 --- a/pkg/apis/radix/v1/radixbatchtypes.go +++ b/pkg/apis/radix/v1/radixbatchtypes.go @@ -36,6 +36,10 @@ type RadixBatchSpec struct { // Reference to the RadixDeployment containing the job component spec. RadixDeploymentJobRef RadixDeploymentJobComponentSelector `json:"radixDeploymentJobRef"` + // Defines a user defined ID of the batch. + // +optional + BatchId string `json:"batchId,omitempty"` + // List of batch jobs to run. // +listType:=map // +listMapKey:=name @@ -238,6 +242,10 @@ type RadixBatchCondition struct { // RadixBatchStatus represents the current state of a RadixBatch type RadixBatchStatus struct { + // Defines a user defined ID of the batch. + // +optional + BatchId string `json:"batchId,omitempty"` + // Status for each job defined in spec.jobs // +optional JobStatuses []RadixBatchJobStatus `json:"jobStatuses,omitempty"` From f8a24d3d138b8d44475fb412d106d6b79e2c9cd4 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Thu, 29 Aug 2024 15:47:15 +0200 Subject: [PATCH 2/5] Removed batchId field from status --- pkg/apis/radix/v1/radixbatchtypes.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/apis/radix/v1/radixbatchtypes.go b/pkg/apis/radix/v1/radixbatchtypes.go index cd1a5b4d7..632395635 100644 --- a/pkg/apis/radix/v1/radixbatchtypes.go +++ b/pkg/apis/radix/v1/radixbatchtypes.go @@ -242,10 +242,6 @@ type RadixBatchCondition struct { // RadixBatchStatus represents the current state of a RadixBatch type RadixBatchStatus struct { - // Defines a user defined ID of the batch. - // +optional - BatchId string `json:"batchId,omitempty"` - // Status for each job defined in spec.jobs // +optional JobStatuses []RadixBatchJobStatus `json:"jobStatuses,omitempty"` From 380db19b1eaba19627859e8c5e67537ffb7664f4 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Thu, 29 Aug 2024 16:17:42 +0200 Subject: [PATCH 3/5] Added unit-test --- pkg/apis/batch/syncer_test.go | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/pkg/apis/batch/syncer_test.go b/pkg/apis/batch/syncer_test.go index 1c0ae2e29..b9b7e33ef 100644 --- a/pkg/apis/batch/syncer_test.go +++ b/pkg/apis/batch/syncer_test.go @@ -2299,6 +2299,64 @@ func (s *syncerTestSuite) Test_BatchStatus() { } } +type expectedBatchStatusProps struct { + conditionType radixv1.RadixBatchConditionType +} + +func (s *syncerTestSuite) Test_BatchId() { + namespace, rdName := "any-ns", "any-rd" + type scenario struct { + name string + batchId string + } + + scenarios := []scenario{ + { + name: "no batch-id", + batchId: "", + }, + { + name: "exists batch-id", + batchId: "some-batch-id", + }, + } + rd := &radixv1.RadixDeployment{ + ObjectMeta: metav1.ObjectMeta{Name: rdName}, + Spec: radixv1.RadixDeploymentSpec{ + AppName: "any-app", + Jobs: []radixv1.RadixDeployJobComponent{{Name: "any-job"}}, + }, + } + _, err := s.radixClient.RadixV1().RadixDeployments(namespace).Create(context.Background(), rd, metav1.CreateOptions{}) + s.Require().NoError(err) + + for _, ts := range scenarios { + s.T().Run(ts.name, func(t *testing.T) { + batchName := utils.RandString(10) + batch := &radixv1.RadixBatch{ + ObjectMeta: metav1.ObjectMeta{Name: batchName, Labels: radixlabels.ForBatchScheduleJobType()}, + Spec: radixv1.RadixBatchSpec{ + BatchId: ts.batchId, + RadixDeploymentJobRef: radixv1.RadixDeploymentJobComponentSelector{ + LocalObjectReference: radixv1.LocalObjectReference{Name: rdName}, + Job: "any-job", + }, + Jobs: []radixv1.RadixBatchJob{{Name: "job1"}}, + }, + } + batch, err := s.radixClient.RadixV1().RadixBatches(namespace).Create(context.Background(), batch, metav1.CreateOptions{}) + s.Require().NoError(err) + sut := s.createSyncer(batch, nil) + s.Require().NoError(sut.OnSync(context.Background())) + + batch, err = s.radixClient.RadixV1().RadixBatches(namespace).Get(context.Background(), batch.GetName(), metav1.GetOptions{}) + s.Require().NoError(err) + + s.Require().Equal(ts.batchId, batch.Spec.BatchId, "Invalid batchId") + }) + } +} + func getRadixBatchJobsMap(batch *radixv1.RadixBatch) map[string]*radixv1.RadixBatchJob { batchJobsMap := make(map[string]*radixv1.RadixBatchJob) for i := 0; i < len(batch.Spec.Jobs); i++ { From e302dace4e367c1188a00541c847380548d21b7c Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Fri, 30 Aug 2024 08:41:10 +0200 Subject: [PATCH 4/5] Removed unit-test --- pkg/apis/batch/syncer_test.go | 54 ----------------------------------- 1 file changed, 54 deletions(-) diff --git a/pkg/apis/batch/syncer_test.go b/pkg/apis/batch/syncer_test.go index b9b7e33ef..c34e13832 100644 --- a/pkg/apis/batch/syncer_test.go +++ b/pkg/apis/batch/syncer_test.go @@ -2303,60 +2303,6 @@ type expectedBatchStatusProps struct { conditionType radixv1.RadixBatchConditionType } -func (s *syncerTestSuite) Test_BatchId() { - namespace, rdName := "any-ns", "any-rd" - type scenario struct { - name string - batchId string - } - - scenarios := []scenario{ - { - name: "no batch-id", - batchId: "", - }, - { - name: "exists batch-id", - batchId: "some-batch-id", - }, - } - rd := &radixv1.RadixDeployment{ - ObjectMeta: metav1.ObjectMeta{Name: rdName}, - Spec: radixv1.RadixDeploymentSpec{ - AppName: "any-app", - Jobs: []radixv1.RadixDeployJobComponent{{Name: "any-job"}}, - }, - } - _, err := s.radixClient.RadixV1().RadixDeployments(namespace).Create(context.Background(), rd, metav1.CreateOptions{}) - s.Require().NoError(err) - - for _, ts := range scenarios { - s.T().Run(ts.name, func(t *testing.T) { - batchName := utils.RandString(10) - batch := &radixv1.RadixBatch{ - ObjectMeta: metav1.ObjectMeta{Name: batchName, Labels: radixlabels.ForBatchScheduleJobType()}, - Spec: radixv1.RadixBatchSpec{ - BatchId: ts.batchId, - RadixDeploymentJobRef: radixv1.RadixDeploymentJobComponentSelector{ - LocalObjectReference: radixv1.LocalObjectReference{Name: rdName}, - Job: "any-job", - }, - Jobs: []radixv1.RadixBatchJob{{Name: "job1"}}, - }, - } - batch, err := s.radixClient.RadixV1().RadixBatches(namespace).Create(context.Background(), batch, metav1.CreateOptions{}) - s.Require().NoError(err) - sut := s.createSyncer(batch, nil) - s.Require().NoError(sut.OnSync(context.Background())) - - batch, err = s.radixClient.RadixV1().RadixBatches(namespace).Get(context.Background(), batch.GetName(), metav1.GetOptions{}) - s.Require().NoError(err) - - s.Require().Equal(ts.batchId, batch.Spec.BatchId, "Invalid batchId") - }) - } -} - func getRadixBatchJobsMap(batch *radixv1.RadixBatch) map[string]*radixv1.RadixBatchJob { batchJobsMap := make(map[string]*radixv1.RadixBatchJob) for i := 0; i < len(batch.Spec.Jobs); i++ { From 1622b9a60b8d338238eda81c8947a88eca47ff0d Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Fri, 30 Aug 2024 08:42:25 +0200 Subject: [PATCH 5/5] Removed unit-test --- pkg/apis/batch/syncer_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/apis/batch/syncer_test.go b/pkg/apis/batch/syncer_test.go index c34e13832..1c0ae2e29 100644 --- a/pkg/apis/batch/syncer_test.go +++ b/pkg/apis/batch/syncer_test.go @@ -2299,10 +2299,6 @@ func (s *syncerTestSuite) Test_BatchStatus() { } } -type expectedBatchStatusProps struct { - conditionType radixv1.RadixBatchConditionType -} - func getRadixBatchJobsMap(batch *radixv1.RadixBatch) map[string]*radixv1.RadixBatchJob { batchJobsMap := make(map[string]*radixv1.RadixBatchJob) for i := 0; i < len(batch.Spec.Jobs); i++ {