-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(autok3s): support command start and stop
Signed-off-by: NewGr8Player <273221594@qq.com>
- Loading branch information
1 parent
1b47c1a
commit f3435e8
Showing
8 changed files
with
486 additions
and
10 deletions.
There are no files selected for viewing
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,62 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/cnrancher/autok3s/cmd/common" | ||
"github.com/cnrancher/autok3s/pkg/providers" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var ( | ||
startCmd = &cobra.Command{ | ||
Use: "start", | ||
Short: "Start k3s cluster", | ||
Example: ` autok3s start --name cluster`, | ||
} | ||
stProvider = "" | ||
stP providers.Provider | ||
) | ||
|
||
func init() { | ||
startCmd.Flags().StringVarP(&stProvider, "provider", "p", stProvider, "Provider is a module which provides an interface for managing cloud resources") | ||
} | ||
|
||
func StartCommand() *cobra.Command { | ||
|
||
pStr := common.FlagHackLookup("--provider") | ||
|
||
if pStr != "" { | ||
if reg, err := providers.Register(pStr); err != nil { | ||
logrus.Fatalln(err) | ||
} else { | ||
stP = reg | ||
} | ||
|
||
startCmd.Flags().AddFlagSet(stP.GetCredentialFlags(startCmd)) | ||
startCmd.Flags().AddFlagSet(stP.GetStartFlags(startCmd)) | ||
} | ||
|
||
startCmd.Run = func(cmd *cobra.Command, args []string) { | ||
common.BindPFlags(cmd, stP) | ||
|
||
// read options from config. | ||
if err := viper.ReadInConfig(); err != nil { | ||
logrus.Fatalln(err) | ||
} | ||
|
||
// sync config data to local cfg path. | ||
if err := viper.WriteConfig(); err != nil { | ||
logrus.Fatalln(err) | ||
} | ||
|
||
stP.GenerateClusterName() | ||
|
||
if err := stP.StartK3sCluster(); err != nil { | ||
logrus.Fatalln(err) | ||
} | ||
} | ||
|
||
return startCmd | ||
} |
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,64 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/cnrancher/autok3s/cmd/common" | ||
"github.com/cnrancher/autok3s/pkg/providers" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var ( | ||
stopCmd = &cobra.Command{ | ||
Use: "stop", | ||
Short: "Stop k3s cluster", | ||
Example: ` autok3s stop --name cluster`, | ||
} | ||
spProvider = "" | ||
spForce = false | ||
spP providers.Provider | ||
) | ||
|
||
func init() { | ||
stopCmd.Flags().StringVarP(&spProvider, "provider", "p", spProvider, "Provider is a module which provides an interface for managing cloud resources") | ||
stopCmd.Flags().BoolVarP(&spForce, "force", "f", spForce, "Force stop cluster") | ||
} | ||
|
||
func StopCommand() *cobra.Command { | ||
|
||
pStr := common.FlagHackLookup("--provider") | ||
|
||
if pStr != "" { | ||
if reg, err := providers.Register(pStr); err != nil { | ||
logrus.Fatalln(err) | ||
} else { | ||
spP = reg | ||
} | ||
|
||
stopCmd.Flags().AddFlagSet(spP.GetCredentialFlags(stopCmd)) | ||
stopCmd.Flags().AddFlagSet(spP.GetStopFlags(stopCmd)) | ||
} | ||
|
||
stopCmd.Run = func(cmd *cobra.Command, args []string) { | ||
common.BindPFlags(cmd, spP) | ||
|
||
// read options from config. | ||
if err := viper.ReadInConfig(); err != nil { | ||
logrus.Fatalln(err) | ||
} | ||
|
||
// sync config data to local cfg path. | ||
if err := viper.WriteConfig(); err != nil { | ||
logrus.Fatalln(err) | ||
} | ||
|
||
spP.GenerateClusterName() | ||
|
||
if err := spP.StopK3sCluster(spForce); err != nil { | ||
logrus.Fatalln(err) | ||
} | ||
} | ||
|
||
return stopCmd | ||
} |
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
Oops, something went wrong.