Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time parse issue in compareTimeRanges (maintenanceWindow) #2009

Open
eloo-abi opened this issue Mar 4, 2024 · 5 comments
Open

Time parse issue in compareTimeRanges (maintenanceWindow) #2009

eloo-abi opened this issue Mar 4, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@eloo-abi
Copy link
Contributor

eloo-abi commented Mar 4, 2024

Hi,

i guess i have discovered a bug in the comparison logic of the compareTimeRanges code for checking if the maintenanceWindow needs to be updated.

func compareTimeRanges(format string, expectedWindow *string, actualWindow *string) (bool, error) {
if pointer.StringValue(expectedWindow) == "" {
// no window to set, don't bother
return false, nil
}
if pointer.StringValue(actualWindow) == "" {
// expected is set but actual is not, so we should set it
return true, nil
}
// all windows here have a "-" in between two values in the expected format, so just split
leftSpans := strings.Split(*expectedWindow, "-")
rightSpans := strings.Split(*actualWindow, "-")
for i := range leftSpans {
left, err := time.Parse(format, leftSpans[i])
if err != nil {
return false, err
}
right, err := time.Parse(format, rightSpans[i])
if err != nil {
return false, err
}
if left != right {
return true, nil
}
}
return false, nil
}

What happened?

The current implementation to check the timeRanges rely on the idea that the weekday in the string ("mon") is parsed into a time object.
But according to the docs this is not the case
https://pkg.go.dev/time#Parse

The day of the week is checked for syntax but it is otherwise ignored.

So its only compared to the hour and minute and not weekday.

This results in a wrong comparison result to update the maintenanceWindow and thus could cause a skipped update if only the weekday of a maintenanceWindow would be changed.

How can we reproduce it?

The following snippet will show the issue with a simplified function of the compareTimeRanges code.

https://go.dev/play/p/n2jRovBJBj5

What environment did it happen in?

Bug in the code

@eloo-abi eloo-abi added the bug Something isn't working label Mar 4, 2024
Copy link

github-actions bot commented Jun 3, 2024

Crossplane does not currently have enough maintainers to address every issue and pull request. This issue has been automatically marked as stale because it has had no activity in the last 90 days. It will be closed in 14 days if no further activity occurs. Leaving a comment starting with /fresh will mark this issue as not stale.

@github-actions github-actions bot added the stale label Jun 3, 2024
@eloo-abi
Copy link
Contributor Author

eloo-abi commented Jun 3, 2024

/fresh

@github-actions github-actions bot removed the stale label Jun 4, 2024
Copy link

github-actions bot commented Sep 2, 2024

Crossplane does not currently have enough maintainers to address every issue and pull request. This issue has been automatically marked as stale because it has had no activity in the last 90 days. It will be closed in 14 days if no further activity occurs. Leaving a comment starting with /fresh will mark this issue as not stale.

@github-actions github-actions bot added the stale label Sep 2, 2024
@eloo-abi
Copy link
Contributor Author

eloo-abi commented Sep 2, 2024

/fresh

@github-actions github-actions bot removed the stale label Sep 3, 2024
@MisterMX
Copy link
Collaborator

Hey, @eloo-abi we don't have the time to work on this issue but feel to provide a pull request with a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants