From 7a077b0b61820b47d3cdc88e22f40f658798e8cd Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 10 Aug 2022 16:48:18 -0700 Subject: [PATCH 1/3] check for updates every 12 hours --- server.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/server.go b/server.go index ce9fb10..0c7310e 100644 --- a/server.go +++ b/server.go @@ -21,6 +21,7 @@ import ( "log" "net/http" "os" + "time" "github.com/blang/semver/v4" admissionv1 "k8s.io/api/admission/v1" @@ -347,12 +348,21 @@ func updateCheck() error { return nil } -func main() { - log.Print("GCP Auth Webhook started!") - +func updateTicker() { if err := updateCheck(); err != nil { log.Println(err) } + for range time.Tick(12 * time.Hour) { + if err := updateCheck(); err != nil { + log.Println(err) + } + } +} + +func main() { + log.Print("GCP Auth Webhook started!") + + go updateTicker() mux := http.NewServeMux() From 7440adc4f45931c540b7cad7b882541e5b2ef57a Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 10 Aug 2022 16:57:19 -0700 Subject: [PATCH 2/3] clean up error logging --- server.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/server.go b/server.go index 0c7310e..9d848c6 100644 --- a/server.go +++ b/server.go @@ -312,7 +312,7 @@ func needsEnvVar(c corev1.Container, name string) bool { return true } -func updateCheck() error { +func updateCheck() { type release struct { Name string `json:"name"` } @@ -321,41 +321,35 @@ func updateCheck() error { resp, err := http.Get("https://storage.googleapis.com/minikube-gcp-auth/releases.json") if err != nil { - return fmt.Errorf("failed to get releases file: %v", err) + log.Printf("failed to get releases file: %v", err) } defer resp.Body.Close() if err := json.NewDecoder(resp.Body).Decode(&releases); err != nil { - return fmt.Errorf("failed to decode releases file: %v", err) + log.Printf("failed to decode releases file: %v", err) } if len(releases) == 0 { - return fmt.Errorf("no releases found in releases file") + log.Printf("no releases found in releases file") } currVersion, err := semver.ParseTolerant(Version) if err != nil { - return fmt.Errorf("unable to parse current version: %v", err) + log.Printf("unable to parse current version: %v", err) } name := releases[0].Name latestVersion, err := semver.ParseTolerant(name) if err != nil { - return fmt.Errorf("unable to parse latest version: %v", err) + log.Printf("unable to parse latest version: %v", err) } if currVersion.LT(latestVersion) { log.Printf("gcp-auth-webhook %s is available!", name) } - - return nil } func updateTicker() { - if err := updateCheck(); err != nil { - log.Println(err) - } + updateCheck() for range time.Tick(12 * time.Hour) { - if err := updateCheck(); err != nil { - log.Println(err) - } + updateCheck() } } From 79b0b25a3bbf039e9addf9e1222a5494c05a2901 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Mon, 22 Aug 2022 14:12:46 -0700 Subject: [PATCH 3/3] replace Printf with Print --- server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.go b/server.go index 9d848c6..6d0cb93 100644 --- a/server.go +++ b/server.go @@ -328,7 +328,7 @@ func updateCheck() { log.Printf("failed to decode releases file: %v", err) } if len(releases) == 0 { - log.Printf("no releases found in releases file") + log.Print("no releases found in releases file") } currVersion, err := semver.ParseTolerant(Version)