mirror of
https://github.com/zalando-incubator/kube-metrics-adapter.git
synced 2025-07-05 19:47:24 +00:00
Switch Schedule optional fields to pointers
The `Date` and `Period` fields inside the `Schedule` type of the `[Cluster]ScalingSchedule` CRDs are optional, but in its current configuration the generated clients can't update or create these resources since the empty fields do not pass the validation. This commit updates the `[Cluster]ScalingSchedule.Schedule[*]` `Date` and `Period` field to pointers, this way a null value is not validated and the clients are able to update and create resources. It also updates the collector code and tests to reflect the change. Signed-off-by: Jonathan Juares Beber <jonathanbeber@gmail.com>
This commit is contained in:
@ -50,11 +50,11 @@ type Schedule struct {
|
|||||||
Type ScheduleType `json:"type"`
|
Type ScheduleType `json:"type"`
|
||||||
// Defines the details of a Repeating schedule.
|
// Defines the details of a Repeating schedule.
|
||||||
// +optional
|
// +optional
|
||||||
Period SchedulePeriod `json:"period"`
|
Period *SchedulePeriod `json:"period,omitempty"`
|
||||||
// Defines the starting date of a OneTime schedule. It has to
|
// Defines the starting date of a OneTime schedule. It has to
|
||||||
// be a RFC3339 formated date.
|
// be a RFC3339 formated date.
|
||||||
// +optional
|
// +optional
|
||||||
Date ScheduleDate `json:"date"`
|
Date *ScheduleDate `json:"date,omitempty"`
|
||||||
// The duration in minutes that the configured value will be
|
// The duration in minutes that the configured value will be
|
||||||
// returned for the defined schedule.
|
// returned for the defined schedule.
|
||||||
DurationMinutes int `json:"durationMinutes"`
|
DurationMinutes int `json:"durationMinutes"`
|
||||||
|
@ -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.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *Schedule) DeepCopyInto(out *Schedule) {
|
func (in *Schedule) DeepCopyInto(out *Schedule) {
|
||||||
*out = *in
|
*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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ func calculateMetrics(schedules []v1.Schedule, now time.Time, objectReference cu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case v1.OneTimeSchedule:
|
case v1.OneTimeSchedule:
|
||||||
scheduledTime, err := time.Parse(time.RFC3339, string(schedule.Date))
|
scheduledTime, err := time.Parse(time.RFC3339, string(*schedule.Date))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrInvalidScheduleDate
|
return nil, ErrInvalidScheduleDate
|
||||||
}
|
}
|
||||||
|
@ -670,23 +670,25 @@ func getSchedules(schedules []schedule) (result []v1.Schedule) {
|
|||||||
for _, schedule := range schedules {
|
for _, schedule := range schedules {
|
||||||
switch schedule.kind {
|
switch schedule.kind {
|
||||||
case string(v1.OneTimeSchedule):
|
case string(v1.OneTimeSchedule):
|
||||||
|
date := v1.ScheduleDate(schedule.date)
|
||||||
result = append(result,
|
result = append(result,
|
||||||
v1.Schedule{
|
v1.Schedule{
|
||||||
Type: v1.OneTimeSchedule,
|
Type: v1.OneTimeSchedule,
|
||||||
Date: v1.ScheduleDate(schedule.date),
|
Date: &date,
|
||||||
DurationMinutes: schedule.duration,
|
DurationMinutes: schedule.duration,
|
||||||
Value: schedule.value,
|
Value: schedule.value,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
case string(v1.RepeatingSchedule):
|
case string(v1.RepeatingSchedule):
|
||||||
|
period := v1.SchedulePeriod{
|
||||||
|
StartTime: schedule.startTime,
|
||||||
|
Days: schedule.days,
|
||||||
|
Timezone: schedule.timezone,
|
||||||
|
}
|
||||||
result = append(result,
|
result = append(result,
|
||||||
v1.Schedule{
|
v1.Schedule{
|
||||||
Type: v1.RepeatingSchedule,
|
Type: v1.RepeatingSchedule,
|
||||||
Period: v1.SchedulePeriod{
|
Period: &period,
|
||||||
StartTime: schedule.startTime,
|
|
||||||
Days: schedule.days,
|
|
||||||
Timezone: schedule.timezone,
|
|
||||||
},
|
|
||||||
DurationMinutes: schedule.duration,
|
DurationMinutes: schedule.duration,
|
||||||
Value: schedule.value,
|
Value: schedule.value,
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user