From 3f4ba2e93655a20f5f96a4084d6149efe52a7c0b Mon Sep 17 00:00:00 2001 From: Prafulla Mahindrakar Date: Tue, 12 Dec 2023 21:58:26 -0800 Subject: [PATCH] Use updated cronSchedule in CreateLaunchPlanModel (#4564) Signed-off-by: pmahindrakar-oss --- .../pkg/manager/impl/testutils/mock_requests.go | 15 ++++++++++++++- .../impl/validation/launch_plan_validator_test.go | 10 +++++----- .../pkg/repositories/transformers/launch_plan.go | 2 +- .../repositories/transformers/launch_plan_test.go | 13 ++++++++++++- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/flyteadmin/pkg/manager/impl/testutils/mock_requests.go b/flyteadmin/pkg/manager/impl/testutils/mock_requests.go index ed5c84f24d..e6ff69eab8 100644 --- a/flyteadmin/pkg/manager/impl/testutils/mock_requests.go +++ b/flyteadmin/pkg/manager/impl/testutils/mock_requests.go @@ -164,7 +164,7 @@ func GetLaunchPlanRequest() admin.LaunchPlanCreateRequest { } } -func GetLaunchPlanRequestWithCronSchedule(testCronExpr string) admin.LaunchPlanCreateRequest { +func GetLaunchPlanRequestWithDeprecatedCronSchedule(testCronExpr string) admin.LaunchPlanCreateRequest { lpRequest := GetLaunchPlanRequest() lpRequest.Spec.EntityMetadata = &admin.LaunchPlanMetadata{ Schedule: &admin.Schedule{ @@ -175,6 +175,19 @@ func GetLaunchPlanRequestWithCronSchedule(testCronExpr string) admin.LaunchPlanC return lpRequest } +func GetLaunchPlanRequestWithCronSchedule(testCronExpr string) admin.LaunchPlanCreateRequest { + lpRequest := GetLaunchPlanRequest() + lpRequest.Spec.EntityMetadata = &admin.LaunchPlanMetadata{ + Schedule: &admin.Schedule{ + ScheduleExpression: &admin.Schedule_CronSchedule{CronSchedule: &admin.CronSchedule{ + Schedule: testCronExpr, + }}, + KickoffTimeInputArg: "", + }, + } + return lpRequest +} + func GetLaunchPlanRequestWithFixedRateSchedule(testRateValue uint32, testRateUnit admin.FixedRateUnit) admin.LaunchPlanCreateRequest { lpRequest := GetLaunchPlanRequest() lpRequest.Spec.EntityMetadata = &admin.LaunchPlanMetadata{ diff --git a/flyteadmin/pkg/manager/impl/validation/launch_plan_validator_test.go b/flyteadmin/pkg/manager/impl/validation/launch_plan_validator_test.go index 2f1044dfde..5cdbd2097d 100644 --- a/flyteadmin/pkg/manager/impl/validation/launch_plan_validator_test.go +++ b/flyteadmin/pkg/manager/impl/validation/launch_plan_validator_test.go @@ -294,7 +294,7 @@ func TestValidateSchedule_NoSchedule(t *testing.T) { } func TestValidateSchedule_ArgNotFixed(t *testing.T) { - request := testutils.GetLaunchPlanRequestWithCronSchedule("* * * * * *") + request := testutils.GetLaunchPlanRequestWithDeprecatedCronSchedule("* * * * * *") inputMap := &core.ParameterMap{ Parameters: map[string]*core.Parameter{ "foo": { @@ -313,7 +313,7 @@ func TestValidateSchedule_ArgNotFixed(t *testing.T) { } func TestValidateSchedule_KickoffTimeArgDoesNotExist(t *testing.T) { - request := testutils.GetLaunchPlanRequestWithCronSchedule("* * * * * *") + request := testutils.GetLaunchPlanRequestWithDeprecatedCronSchedule("* * * * * *") inputMap := &core.ParameterMap{ Parameters: map[string]*core.Parameter{}, } @@ -324,7 +324,7 @@ func TestValidateSchedule_KickoffTimeArgDoesNotExist(t *testing.T) { } func TestValidateSchedule_KickoffTimeArgPointsAtWrongType(t *testing.T) { - request := testutils.GetLaunchPlanRequestWithCronSchedule("* * * * * *") + request := testutils.GetLaunchPlanRequestWithDeprecatedCronSchedule("* * * * * *") inputMap := &core.ParameterMap{ Parameters: map[string]*core.Parameter{ "foo": { @@ -344,7 +344,7 @@ func TestValidateSchedule_KickoffTimeArgPointsAtWrongType(t *testing.T) { } func TestValidateSchedule_NoRequired(t *testing.T) { - request := testutils.GetLaunchPlanRequestWithCronSchedule("* * * * * *") + request := testutils.GetLaunchPlanRequestWithDeprecatedCronSchedule("* * * * * *") inputMap := &core.ParameterMap{ Parameters: map[string]*core.Parameter{ "foo": { @@ -363,7 +363,7 @@ func TestValidateSchedule_NoRequired(t *testing.T) { } func TestValidateSchedule_KickoffTimeBound(t *testing.T) { - request := testutils.GetLaunchPlanRequestWithCronSchedule("* * * * * *") + request := testutils.GetLaunchPlanRequestWithDeprecatedCronSchedule("* * * * * *") inputMap := &core.ParameterMap{ Parameters: map[string]*core.Parameter{ "foo": { diff --git a/flyteadmin/pkg/repositories/transformers/launch_plan.go b/flyteadmin/pkg/repositories/transformers/launch_plan.go index a7522e497b..f11cdacb5f 100644 --- a/flyteadmin/pkg/repositories/transformers/launch_plan.go +++ b/flyteadmin/pkg/repositories/transformers/launch_plan.go @@ -42,7 +42,7 @@ func CreateLaunchPlanModel( scheduleType := models.LaunchPlanScheduleTypeNONE if launchPlan.Spec.EntityMetadata != nil && launchPlan.Spec.EntityMetadata.Schedule != nil { - if launchPlan.Spec.EntityMetadata.Schedule.GetCronExpression() != "" { + if launchPlan.Spec.EntityMetadata.Schedule.GetCronExpression() != "" || launchPlan.Spec.EntityMetadata.Schedule.GetCronSchedule() != nil { scheduleType = models.LaunchPlanScheduleTypeCRON } else if launchPlan.Spec.EntityMetadata.Schedule.GetRate() != nil { scheduleType = models.LaunchPlanScheduleTypeRATE diff --git a/flyteadmin/pkg/repositories/transformers/launch_plan_test.go b/flyteadmin/pkg/repositories/transformers/launch_plan_test.go index f17ef0c323..590dbfea6f 100644 --- a/flyteadmin/pkg/repositories/transformers/launch_plan_test.go +++ b/flyteadmin/pkg/repositories/transformers/launch_plan_test.go @@ -84,7 +84,18 @@ func TestToLaunchPlanModel(t *testing.T) { } func TestToLaunchPlanModelWithCronSchedule(t *testing.T) { - lpRequest := testutils.GetLaunchPlanRequestWithCronSchedule("* * * * *") + + t.Run("deprecated cron schedule", func(t *testing.T) { + lpRequest := testutils.GetLaunchPlanRequestWithDeprecatedCronSchedule("* * * * *") + testLaunchPlanWithCronInternal(t, lpRequest) + }) + t.Run("cron schedule", func(t *testing.T) { + lpRequest := testutils.GetLaunchPlanRequestWithCronSchedule("* * * * *") + testLaunchPlanWithCronInternal(t, lpRequest) + }) +} + +func testLaunchPlanWithCronInternal(t *testing.T, lpRequest admin.LaunchPlanCreateRequest) { lpRequest.Spec.DefaultInputs = expectedInputs workflowID := uint(11) launchPlanDigest := []byte("launch plan")