2017-10-26 00:02:49 +00:00
package main
import (
2019-05-28 18:51:53 +00:00
"github.com/rancher/rke/metadata"
2019-08-23 19:51:34 +00:00
"io/ioutil"
2017-10-26 00:02:49 +00:00
"os"
2018-07-02 10:29:24 +00:00
"regexp"
2019-07-16 14:04:10 +00:00
"strings"
2017-10-26 00:02:49 +00:00
2018-09-26 09:16:44 +00:00
"github.com/mattn/go-colorable"
2017-10-29 09:45:21 +00:00
"github.com/rancher/rke/cmd"
2019-07-16 14:04:10 +00:00
"github.com/rancher/rke/util"
2017-11-13 21:28:38 +00:00
"github.com/sirupsen/logrus"
2017-10-26 00:02:49 +00:00
"github.com/urfave/cli"
)
2019-07-16 14:04:10 +00:00
// VERSION gets overriden at build time using -X main.VERSION=$VERSION
var VERSION = "dev"
2018-07-02 10:29:24 +00:00
var released = regexp . MustCompile ( ` ^v[0-9]+\.[0-9]+\.[0-9]+$ ` )
2019-07-16 14:04:10 +00:00
var proxyEnvVars = [ 3 ] string { "HTTP_PROXY" , "HTTPS_PROXY" , "NO_PROXY" }
2017-10-26 00:02:49 +00:00
func main ( ) {
2018-09-26 09:16:44 +00:00
logrus . SetOutput ( colorable . NewColorableStdout ( ) )
2017-11-02 10:07:10 +00:00
if err := mainErr ( ) ; err != nil {
logrus . Fatal ( err )
}
}
func mainErr ( ) error {
2017-10-26 00:02:49 +00:00
app := cli . NewApp ( )
app . Name = "rke"
app . Version = VERSION
2018-06-23 12:51:48 +00:00
app . Usage = "Rancher Kubernetes Engine, an extremely simple, lightning fast Kubernetes installer that works everywhere"
2017-10-29 09:45:21 +00:00
app . Before = func ( ctx * cli . Context ) error {
if ctx . GlobalBool ( "debug" ) {
logrus . SetLevel ( logrus . DebugLevel )
}
2019-08-23 19:51:34 +00:00
if ctx . GlobalBool ( "quiet" ) {
logrus . SetOutput ( ioutil . Discard )
}
2018-07-02 10:29:24 +00:00
if released . MatchString ( app . Version ) {
2019-05-28 18:51:53 +00:00
metadata . RKEVersion = app . Version
2018-07-02 10:29:24 +00:00
return nil
}
logrus . Warnf ( "This is not an officially supported version (%s) of RKE. Please download the latest official release at https://github.com/rancher/rke/releases/latest" , app . Version )
2019-07-16 14:04:10 +00:00
// Print proxy related environment variables
for _ , proxyEnvVar := range proxyEnvVars {
var err error
// Lookup environment variable
if key , value , ok := util . GetEnvVar ( proxyEnvVar ) ; ok {
// If it can contain a password, strip it (HTTP_PROXY or HTTPS_PROXY)
if strings . HasPrefix ( strings . ToUpper ( proxyEnvVar ) , "HTTP" ) {
value , err = util . StripPasswordFromURL ( value )
if err != nil {
// Don't error out of provisioning when parsing of environment variable fails
logrus . Warnf ( "Error parsing proxy environment variable %s" , key )
continue
}
}
logrus . Infof ( "Using proxy environment variable %s with value [%s]" , key , value )
}
}
2017-10-26 00:02:49 +00:00
return nil
}
2017-10-29 09:45:21 +00:00
app . Author = "Rancher Labs, Inc."
app . Email = ""
app . Commands = [ ] cli . Command {
2017-11-28 11:26:15 +00:00
cmd . UpCommand ( ) ,
cmd . RemoveCommand ( ) ,
cmd . VersionCommand ( ) ,
2017-11-20 22:23:50 +00:00
cmd . ConfigCommand ( ) ,
2018-05-09 17:39:19 +00:00
cmd . EtcdCommand ( ) ,
2018-08-20 04:37:04 +00:00
cmd . CertificateCommand ( ) ,
2017-10-29 09:45:21 +00:00
}
app . Flags = [ ] cli . Flag {
cli . BoolFlag {
Name : "debug,d" ,
Usage : "Debug logging" ,
} ,
2019-08-23 19:51:34 +00:00
cli . BoolFlag {
Name : "quiet,q" ,
Usage : "Quiet mode, disables logging and only critical output will be printed" ,
} ,
2017-10-29 09:45:21 +00:00
}
2017-11-02 10:07:10 +00:00
return app . Run ( os . Args )
2017-10-26 00:02:49 +00:00
}