Merge pull request #506 from zalando-incubator/fix-null-pointer

Fix nil pointer dereference
This commit is contained in:
Zak Lawrence A 2022-12-21 15:48:01 +01:00 committed by GitHub
commit c50d9ccd18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -331,7 +331,7 @@ func calculateMetrics(spec v1.ScalingScheduleSpec, defaultScalingWindow time.Dur
}
// If no end time was provided, set it to equal the start time
if (string(*schedule.EndDate)) == "" {
if schedule.EndDate == nil || string(*schedule.EndDate) == "" {
scheduledEndTime = scheduledTime
} else {
scheduledEndTime, err = time.Parse(time.RFC3339, string(*schedule.EndDate))

View File

@ -249,6 +249,19 @@ func TestScalingScheduleCollector(t *testing.T) {
},
err: ErrInvalidScheduleDate,
},
{
msg: "Return error for one time config end date not in RFC3339 format",
schedules: []schedule{
{
date: nowTime.Add(-time.Minute * 20).Format(time.RFC3339),
endDate: nowTime.Add(1 * time.Hour).Format(time.RFC822),
kind: "OneTime",
duration: 15,
value: 100,
},
},
err: ErrInvalidScheduleDate,
},
{
msg: "Return the right value for two one time config",
schedules: []schedule{