From 8de702922c9124df790d657b5d4b50771a5bed02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ja=C3=ABl=20Gareau?= Date: Thu, 2 Jan 2025 16:34:41 -0500 Subject: [PATCH] fix(clustertool): localtime should be fetched after NTP time (#30581) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes #30580 By swapping the localtime and the NTP time in the code, we ensure the time it takes to receive an answer from the NTP server is not actually counted as a time discrepancy. I also increase the threshold from 5 to 10 seconds since problem always seems to be at just above 5 seconds. **⚙️ Type of change** - [ ] ⚙️ Feature/App addition - [x] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** I compiled clustertool from source with the proposed modification. It solved the issue. **📃 Notes:** **✔️ Checklist:** - [x] ⚖️ My code follows the style guidelines of this project - [x] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [x] ⚠️ My changes generate no new warnings - [ ] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [ ] ⬆️ I increased versions for any altered app according to semantic versioning - [x] I made sure the title starts with `feat(chart-name):`, `fix(chart-name):` or `chore(chart-name):` **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --- clustertool/pkg/helper/time.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clustertool/pkg/helper/time.go b/clustertool/pkg/helper/time.go index 2fbcde0e1180..17168e9d343c 100644 --- a/clustertool/pkg/helper/time.go +++ b/clustertool/pkg/helper/time.go @@ -12,9 +12,7 @@ import ( // checkSystemTime compares the system time with an NTP server time and returns whether it's correct within the given threshold func CheckSystemTime() bool { log.Info().Msg("Checking if System Time is correct...") - threshold := 5 * time.Second - // Get the current system time - systemTime := time.Now() + threshold := 10 * time.Second // Get the time from an NTP server ntpTime, err := ntp.Time("pool.ntp.org") @@ -23,6 +21,9 @@ func CheckSystemTime() bool { return true } + // Get the current system time + systemTime := time.Now() + // Calculate the difference between system time and NTP time timeDifference := systemTime.Sub(ntpTime)