Show fission deployment version with cli (#538)

Add version information to binary through go ldflags
This commit is contained in:
Ta-Ching Chen
2018-03-19 14:14:55 +08:00
committed by GitHub
parent 048ab6149a
commit 1447e6949d
12 changed files with 194 additions and 18 deletions
+31 -1
View File
@@ -17,9 +17,14 @@ limitations under the License.
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
version "github.com/fission/fission"
"github.com/urfave/cli"
)
@@ -41,11 +46,25 @@ func getKubeConfigPath() string {
return kubeConfig
}
func getFissionAPIVersion(apiUrl string) (string, error) {
resp, err := http.Get(apiUrl)
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
return strings.TrimRight(string(body), "\n"), nil
}
func main() {
app := cli.NewApp()
app.Name = "fission"
app.Usage = "Serverless functions for Kubernetes"
app.Version = "0.6.0"
app.Version = version.Version
// fetch the FISSION_URL env variable. If not set, port-forward to controller.
var value string
@@ -60,6 +79,17 @@ func main() {
value = fissionUrl
}
cli.VersionPrinter = func(c *cli.Context) {
clientVer := version.VersionInfo().String()
fmt.Printf("Client Version: %v\n", clientVer)
serverVer, err := getFissionAPIVersion(value)
if err != nil {
fmt.Printf("Error getting Fission API version: %v", err)
} else {
fmt.Printf("Server Version: %v", serverVer)
}
}
app.Flags = []cli.Flag{
cli.StringFlag{Name: "server", Value: value, Usage: "Fission server URL"},
}