Skip to content

Commit

Permalink
Use updated cronSchedule in CreateLaunchPlanModel (#4564)
Browse files Browse the repository at this point in the history
Signed-off-by: pmahindrakar-oss <[email protected]>
  • Loading branch information
pmahindrakar-oss authored Dec 13, 2023
1 parent b14f1ac commit 3f4ba2e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
15 changes: 14 additions & 1 deletion flyteadmin/pkg/manager/impl/testutils/mock_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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{},
}
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion flyteadmin/pkg/repositories/transformers/launch_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion flyteadmin/pkg/repositories/transformers/launch_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 3f4ba2e

Please sign in to comment.