Skip to content

Commit

Permalink
Merge pull request #30 from spowelljr/increaseUpdateCheck
Browse files Browse the repository at this point in the history
Check for updates every 12 hours
  • Loading branch information
spowelljr authored Aug 22, 2022
2 parents 5497f43 + 79b0b25 commit 3f22cfa
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"log"
"net/http"
"os"
"time"

"github.com/blang/semver/v4"
admissionv1 "k8s.io/api/admission/v1"
Expand Down Expand Up @@ -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"`
}
Expand All @@ -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()

Expand Down

0 comments on commit 3f22cfa

Please sign in to comment.