diff --git a/pkg/apis/zalando.org/v1/types.go b/pkg/apis/zalando.org/v1/types.go index e11b3f4..9679af5 100644 --- a/pkg/apis/zalando.org/v1/types.go +++ b/pkg/apis/zalando.org/v1/types.go @@ -50,11 +50,11 @@ type Schedule struct { Type ScheduleType `json:"type"` // Defines the details of a Repeating schedule. // +optional - Period SchedulePeriod `json:"period"` + Period *SchedulePeriod `json:"period,omitempty"` // Defines the starting date of a OneTime schedule. It has to // be a RFC3339 formated date. // +optional - Date ScheduleDate `json:"date"` + Date *ScheduleDate `json:"date,omitempty"` // The duration in minutes that the configured value will be // returned for the defined schedule. DurationMinutes int `json:"durationMinutes"` diff --git a/pkg/apis/zalando.org/v1/zz_generated.deepcopy.go b/pkg/apis/zalando.org/v1/zz_generated.deepcopy.go index f46bc75..4e125d3 100644 --- a/pkg/apis/zalando.org/v1/zz_generated.deepcopy.go +++ b/pkg/apis/zalando.org/v1/zz_generated.deepcopy.go @@ -170,7 +170,16 @@ func (in *ScalingScheduleSpec) DeepCopy() *ScalingScheduleSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Schedule) DeepCopyInto(out *Schedule) { *out = *in - in.Period.DeepCopyInto(&out.Period) + if in.Period != nil { + in, out := &in.Period, &out.Period + *out = new(SchedulePeriod) + (*in).DeepCopyInto(*out) + } + if in.Date != nil { + in, out := &in.Date, &out.Date + *out = new(ScheduleDate) + **out = **in + } return } diff --git a/pkg/collector/scaling_schedule_collector.go b/pkg/collector/scaling_schedule_collector.go index 664dbf4..8281765 100644 --- a/pkg/collector/scaling_schedule_collector.go +++ b/pkg/collector/scaling_schedule_collector.go @@ -276,7 +276,7 @@ func calculateMetrics(schedules []v1.Schedule, now time.Time, objectReference cu } } case v1.OneTimeSchedule: - scheduledTime, err := time.Parse(time.RFC3339, string(schedule.Date)) + scheduledTime, err := time.Parse(time.RFC3339, string(*schedule.Date)) if err != nil { return nil, ErrInvalidScheduleDate } diff --git a/pkg/collector/scaling_schedule_collector_test.go b/pkg/collector/scaling_schedule_collector_test.go index 3d83df9..e0f8fc5 100644 --- a/pkg/collector/scaling_schedule_collector_test.go +++ b/pkg/collector/scaling_schedule_collector_test.go @@ -670,23 +670,25 @@ func getSchedules(schedules []schedule) (result []v1.Schedule) { for _, schedule := range schedules { switch schedule.kind { case string(v1.OneTimeSchedule): + date := v1.ScheduleDate(schedule.date) result = append(result, v1.Schedule{ Type: v1.OneTimeSchedule, - Date: v1.ScheduleDate(schedule.date), + Date: &date, DurationMinutes: schedule.duration, Value: schedule.value, }, ) case string(v1.RepeatingSchedule): + period := v1.SchedulePeriod{ + StartTime: schedule.startTime, + Days: schedule.days, + Timezone: schedule.timezone, + } result = append(result, v1.Schedule{ - Type: v1.RepeatingSchedule, - Period: v1.SchedulePeriod{ - StartTime: schedule.startTime, - Days: schedule.days, - Timezone: schedule.timezone, - }, + Type: v1.RepeatingSchedule, + Period: &period, DurationMinutes: schedule.duration, Value: schedule.value, },