diff --git a/cli/cmd/tapRunner.go b/cli/cmd/tapRunner.go index 2015e81ef..dff90fbb8 100644 --- a/cli/cmd/tapRunner.go +++ b/cli/cmd/tapRunner.go @@ -72,6 +72,7 @@ func RunMizuTap(podRegexQuery *regexp.Regexp, tappingOptions *MizuTapOptions) { return } + mizu.CheckNewerVersion() go portForwardApiPod(ctx, kubernetesProvider, cancel, tappingOptions) // TODO convert this to job for built in pod ttl or have the running app handle this go watchPodsForTapping(ctx, kubernetesProvider, cancel, podRegexQuery, tappingOptions) go syncApiStatus(ctx, cancel, tappingOptions) @@ -270,7 +271,7 @@ func portForwardApiPod(ctx context.Context, kubernetesProvider *kubernetes.Provi } } - case <- timeAfter: + case <-timeAfter: if !isPodReady { fmt.Printf("error: %s pod was not ready in time", mizu.AggregatorPodName) cancel() diff --git a/cli/go.mod b/cli/go.mod index 02730fa71..1ad46fbf1 100644 --- a/cli/go.mod +++ b/cli/go.mod @@ -3,6 +3,7 @@ module github.com/up9inc/mizu/cli go 1.16 require ( + github.com/google/go-github/v37 v37.0.0 github.com/gorilla/websocket v1.4.2 github.com/romana/rlog v0.0.0-20171115192701-f018bc92e7d7 github.com/spf13/cobra v1.1.3 diff --git a/cli/go.sum b/cli/go.sum index 9a79ea6a5..eef67ad62 100644 --- a/cli/go.sum +++ b/cli/go.sum @@ -203,8 +203,13 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-github/v37 v37.0.0 h1:rCspN8/6kB1BAJWZfuafvHhyfIo5fkAulaP/3bOQ/tM= +github.com/google/go-github/v37 v37.0.0/go.mod h1:LM7in3NmXDrX58GbEHy7FtNLbI2JijX93RnMKvWG3m4= +github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= +github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= diff --git a/cli/mizu/versionCheck.go b/cli/mizu/versionCheck.go index 3211f687d..b9d4f0913 100644 --- a/cli/mizu/versionCheck.go +++ b/cli/mizu/versionCheck.go @@ -1,15 +1,19 @@ package mizu import ( + "context" "encoding/json" "fmt" + "github.com/google/go-github/v37/github" + "github.com/romana/rlog" "github.com/up9inc/mizu/shared" "github.com/up9inc/mizu/shared/semver" + "io/ioutil" "net/http" "net/url" + "time" ) - func getApiVersion(port uint16) (string, error) { versionUrl, _ := url.Parse(fmt.Sprintf("http://localhost:%d/mizu/metadata/version", port)) req := &http.Request{ @@ -44,3 +48,45 @@ func CheckVersionCompatibility(port uint16) (bool, error) { fmt.Printf(Red, fmt.Sprintf("cli version (%s) is not compatible with api version (%s)\n", SemVer, apiSemVer)) return false, nil } + +func CheckNewerVersion() { + rlog.Debugf("Checking for newer version...") + start := time.Now() + client := github.NewClient(nil) + latestRelease, _, err := client.Repositories.GetLatestRelease(context.Background(), "up9inc", "mizu") + if err != nil { + rlog.Debugf("Failed to get latest release") + return + } + + versionFileUrl := "" + for _, asset := range latestRelease.Assets { + if *asset.Name == "version.txt" { + versionFileUrl = *asset.BrowserDownloadURL + break + } + } + if versionFileUrl == "" { + rlog.Debugf("Version file not found in the latest release") + return + } + + res, err := http.Get(versionFileUrl) + if err != nil { + rlog.Debugf("http.Get version asset -> %v", err) + return + } + + data, err := ioutil.ReadAll(res.Body) + res.Body.Close() + if err != nil { + rlog.Debugf("ioutil.ReadAll -> %v", err) + return + } + gitHubVersion := string(data) + gitHubVersion = gitHubVersion[:len(gitHubVersion)-1] + rlog.Debugf("Finished version validation, took %v", time.Since(start)) + if SemVer < gitHubVersion { + fmt.Printf(Yellow, fmt.Sprintf("Update available! %v -> %v (%v)\n", SemVer, gitHubVersion, *latestRelease.HTMLURL)) + } +}