Skip to content

Commit 97acacb

Browse files
authored
fix(backend): modelToCRDTrigger was not including periodic schedule correctly (#11475)
* fix(backend): modelToCRDTrigger was not including periodic schedule correctly Signed-off-by: Helber Belmiro <helber.belmiro@gmail.com> * Added copyright headers Signed-off-by: Helber Belmiro <helber.belmiro@gmail.com> * Fixed IsEmpty Signed-off-by: Helber Belmiro <helber.belmiro@gmail.com> --------- Signed-off-by: Helber Belmiro <helber.belmiro@gmail.com>
1 parent 54b9a25 commit 97acacb

File tree

4 files changed

+70
-30
lines changed

4 files changed

+70
-30
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2024 The Kubeflow Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package model
15+
16+
type CronSchedule struct {
17+
// Time at which scheduling starts.
18+
// If no start time is specified, the StartTime is the creation time of the schedule.
19+
CronScheduleStartTimeInSec *int64 `gorm:"column:CronScheduleStartTimeInSec;"`
20+
21+
// Time at which scheduling ends.
22+
// If no end time is specified, the EndTime is the end of time.
23+
CronScheduleEndTimeInSec *int64 `gorm:"column:CronScheduleEndTimeInSec;"`
24+
25+
// Cron string describing when a workflow should be created within the
26+
// time interval defined by StartTime and EndTime.
27+
Cron *string `gorm:"column:Schedule;"`
28+
}
29+
30+
func (c CronSchedule) IsEmpty() bool {
31+
return (c.CronScheduleStartTimeInSec == nil || *c.CronScheduleStartTimeInSec == 0) &&
32+
(c.CronScheduleEndTimeInSec == nil || *c.CronScheduleEndTimeInSec == 0) &&
33+
(c.Cron == nil || *c.Cron == "")
34+
}

backend/src/apiserver/model/job.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -189,34 +189,6 @@ type Trigger struct {
189189
PeriodicSchedule
190190
}
191191

192-
type CronSchedule struct {
193-
// Time at which scheduling starts.
194-
// If no start time is specified, the StartTime is the creation time of the schedule.
195-
CronScheduleStartTimeInSec *int64 `gorm:"column:CronScheduleStartTimeInSec;"`
196-
197-
// Time at which scheduling ends.
198-
// If no end time is specified, the EndTime is the end of time.
199-
CronScheduleEndTimeInSec *int64 `gorm:"column:CronScheduleEndTimeInSec;"`
200-
201-
// Cron string describing when a workflow should be created within the
202-
// time interval defined by StartTime and EndTime.
203-
Cron *string `gorm:"column:Schedule;"`
204-
}
205-
206-
type PeriodicSchedule struct {
207-
// Time at which scheduling starts.
208-
// If no start time is specified, the StartTime is the creation time of the schedule.
209-
PeriodicScheduleStartTimeInSec *int64 `gorm:"column:PeriodicScheduleStartTimeInSec;"`
210-
211-
// Time at which scheduling ends.
212-
// If no end time is specified, the EndTime is the end of time.
213-
PeriodicScheduleEndTimeInSec *int64 `gorm:"column:PeriodicScheduleEndTimeInSec;"`
214-
215-
// Interval describing when a workflow should be created within the
216-
// time interval defined by StartTime and EndTime.
217-
IntervalSecond *int64 `gorm:"column:IntervalSecond;"`
218-
}
219-
220192
func (j Job) GetValueOfPrimaryKey() string {
221193
return fmt.Sprint(j.UUID)
222194
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2024 The Kubeflow Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package model
15+
16+
type PeriodicSchedule struct {
17+
// Time at which scheduling starts.
18+
// If no start time is specified, the StartTime is the creation time of the schedule.
19+
PeriodicScheduleStartTimeInSec *int64 `gorm:"column:PeriodicScheduleStartTimeInSec;"`
20+
21+
// Time at which scheduling ends.
22+
// If no end time is specified, the EndTime is the end of time.
23+
PeriodicScheduleEndTimeInSec *int64 `gorm:"column:PeriodicScheduleEndTimeInSec;"`
24+
25+
// Interval describing when a workflow should be created within the
26+
// time interval defined by StartTime and EndTime.
27+
IntervalSecond *int64 `gorm:"column:IntervalSecond;"`
28+
}
29+
30+
func (p PeriodicSchedule) IsEmpty() bool {
31+
return (p.PeriodicScheduleStartTimeInSec == nil || *p.PeriodicScheduleStartTimeInSec == 0) &&
32+
(p.PeriodicScheduleEndTimeInSec == nil || *p.PeriodicScheduleEndTimeInSec == 0) &&
33+
(p.IntervalSecond == nil || *p.IntervalSecond == 0)
34+
}

backend/src/apiserver/template/template.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func modelToParametersMap(modelParameters string) (map[string]string, error) {
232232
func modelToCRDTrigger(modelTrigger model.Trigger) (scheduledworkflow.Trigger, error) {
233233
crdTrigger := scheduledworkflow.Trigger{}
234234
// CronSchedule and PeriodicSchedule can have at most one being non-empty
235-
if modelTrigger.CronSchedule != (model.CronSchedule{}) {
235+
if !modelTrigger.CronSchedule.IsEmpty() {
236236
// Check if CronSchedule is non-empty
237237
crdCronSchedule := scheduledworkflow.CronSchedule{}
238238
if modelTrigger.Cron != nil {
@@ -247,7 +247,7 @@ func modelToCRDTrigger(modelTrigger model.Trigger) (scheduledworkflow.Trigger, e
247247
crdCronSchedule.EndTime = &endTime
248248
}
249249
crdTrigger.CronSchedule = &crdCronSchedule
250-
} else if modelTrigger.PeriodicSchedule != (model.PeriodicSchedule{}) {
250+
} else if !modelTrigger.PeriodicSchedule.IsEmpty() {
251251
// Check if PeriodicSchedule is non-empty
252252
crdPeriodicSchedule := scheduledworkflow.PeriodicSchedule{}
253253
if modelTrigger.IntervalSecond != nil {

0 commit comments

Comments
 (0)