forked from kosmos-io/kosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kosmos-io#660 from village-way/release-0.4.0
Cherry-Pick: node-agent update
- Loading branch information
Showing
212 changed files
with
32,481 additions
and
155 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package logger | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var log *logrus.Logger | ||
|
||
func init() { | ||
log = logrus.New() | ||
// setup log | ||
log.Out = os.Stdout | ||
logFile, err := os.OpenFile("app.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) | ||
if err == nil { | ||
log.SetOutput(io.MultiWriter(os.Stdout, logFile)) | ||
} else { | ||
log.Info("Failed to log to file, using default stderr") | ||
} | ||
log.SetLevel(logrus.InfoLevel) | ||
} | ||
|
||
func GetLogger() *logrus.Logger { | ||
return log | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package app | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
|
||
"github.com/kosmos.io/kosmos/cmd/kubenest/node-agent/app/client" | ||
"github.com/kosmos.io/kosmos/cmd/kubenest/node-agent/app/logger" | ||
"github.com/kosmos.io/kosmos/cmd/kubenest/node-agent/app/serve" | ||
) | ||
|
||
var ( | ||
user string // username for authentication | ||
password string // password for authentication | ||
log = logger.GetLogger() | ||
) | ||
|
||
var RootCmd = &cobra.Command{ | ||
Use: "node-agent", | ||
Short: "node-agent is a tool for node to start websocket server and client", | ||
Long: `node-agent client for connect server to execute command and upload file to node | ||
node-agent serve for start websocket server to receive message from client and download file from client`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
_ = cmd.Help() | ||
}, | ||
} | ||
|
||
func initConfig() { | ||
// Tell Viper to automatically look for a .env file | ||
viper.SetConfigFile("agent.env") | ||
currentDir, _ := os.Getwd() | ||
viper.AddConfigPath(currentDir) | ||
viper.AddConfigPath("/srv/node-agent/agent.env") | ||
// If a agent.env file is found, read it in. | ||
if err := viper.ReadInConfig(); err != nil { | ||
log.Warnf("Load config file error, %s", err) | ||
} | ||
// set default value from agent.env | ||
if len(user) == 0 { | ||
user = viper.GetString("WEB_USER") | ||
} | ||
if len(password) == 0 { | ||
password = viper.GetString("WEB_PASS") | ||
} | ||
} | ||
|
||
func init() { | ||
cobra.OnInitialize(initConfig) | ||
|
||
RootCmd.PersistentFlags().StringVarP(&user, "user", "u", "", "Username for authentication") | ||
RootCmd.PersistentFlags().StringVarP(&password, "password", "p", "", "Password for authentication") | ||
// bind flags to viper | ||
err := viper.BindPFlag("WEB_USER", RootCmd.PersistentFlags().Lookup("user")) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
err = viper.BindPFlag("WEB_PASS", RootCmd.PersistentFlags().Lookup("password")) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
// bind environment variables | ||
err = viper.BindEnv("WEB_USER", "WEB_USER") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
err = viper.BindEnv("WEB_PASS", "WEB_PASS") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
RootCmd.AddCommand(client.ClientCmd) | ||
RootCmd.AddCommand(serve.ServeCmd) | ||
} |
Oops, something went wrong.