diff --git a/server.go b/server.go index ce9fb10..6d0cb93 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" @@ -311,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"` } @@ -320,39 +321,42 @@ 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.Print("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() { + updateCheck() + for range time.Tick(12 * time.Hour) { + updateCheck() + } } func main() { log.Print("GCP Auth Webhook started!") - if err := updateCheck(); err != nil { - log.Println(err) - } + go updateTicker() mux := http.NewServeMux()