Skip to content

Commit

Permalink
fix ETCD CaCert or key file is not exist occurs panic, labring#427
Browse files Browse the repository at this point in the history
  • Loading branch information
oldthreefeng committed Aug 28, 2020
1 parent 7e53747 commit 9992ccc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
14 changes: 7 additions & 7 deletions cmd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func NewEtcdCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "etcd <subcommand>",
Short: "Simplest way to snapshot/restore your kubernets etcd",
Long: `etcd save --name snapshot`,
Long: `sealos etcd save --name snapshot`,
Example: exampleCmd,
}
cmd.AddCommand(NewEtcdSaveComand())
cmd.AddCommand(NewEtcdRestoreComand())
cmd.AddCommand(NewEtcdHealthComand())
cmd.AddCommand(NewEtcdSaveCommand())
cmd.AddCommand(NewEtcdRestoreCommand())
cmd.AddCommand(NewEtcdHealthCommand())
//cmd.Flags().BoolVar(&install.EtcdSnapshotSave, "snap-save", false, "snapshot your kubernets etcd ")
//cmd.Flags().BoolVar(&install.EtcdRestore, "snap-restore", false, "restore your kubernets etcd")
//cmd.Flags().BoolVar(&install.EtcdHealthCheck, "health", false, "check your kubernets etcd")
Expand All @@ -67,7 +67,7 @@ func NewEtcdCommand() *cobra.Command {

return cmd
}
func NewEtcdSaveComand() *cobra.Command {
func NewEtcdSaveCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "save",
Short: "Stores an etcd node backend snapshot to a given file",
Expand All @@ -85,7 +85,7 @@ func NewEtcdSaveComand() *cobra.Command {
return cmd
}

func NewEtcdRestoreComand() *cobra.Command {
func NewEtcdRestoreCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "restore",
Short: "Restores an etcd member snapshot to an etcd directory",
Expand All @@ -97,7 +97,7 @@ func NewEtcdRestoreComand() *cobra.Command {
return cmd
}

func NewEtcdHealthComand() *cobra.Command {
func NewEtcdHealthCommand() *cobra.Command {
return &cobra.Command{
Use: "health",
Short: "test your etcd status",
Expand Down
4 changes: 4 additions & 0 deletions install/etcd_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func RandStringRunes(n int) string {

func GetRestoreFlags() *EtcdFlags {
e := &EtcdFlags{}
if !e.CertFileExist() {
logger.Error("ETCD CaCert or key file is not exist.")
os.Exit(1)
}
err := e.Load("")
if err != nil {
logger.Error(err)
Expand Down
9 changes: 9 additions & 0 deletions install/etcd_save.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func GetEtcdBackFlags() *EtcdFlags {
ip, endpoint string
)
e := &EtcdFlags{}
if !e.CertFileExist() {
logger.Error("ETCD CaCert or key file is not exist.")
os.Exit(1)
}
err := e.Load("")
if err != nil {
logger.Error(err)
Expand Down Expand Up @@ -257,3 +261,8 @@ func (e *EtcdFlags) HealthCheck() {
logger.Error("unhealthy cluster")
}
}

// CertFileExist if cert file is exist return true
func (e *EtcdFlags) CertFileExist() bool {
return FileExist(EtcdCacart) && FileExist(EtcdCert) && FileExist(EtcdKey)
}
2 changes: 1 addition & 1 deletion install/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *SealosInstaller) InstallMaster0() {
s.SendKubeConfigs(s.Masters, true)

//master0 do sth
cmd := fmt.Sprintf("grep -qF '%s %s' /etc/hosts || echo %s %s >> /etc/hosts", IpFormat(s.Masters[0]), ApiServer)
cmd := fmt.Sprintf("grep -qF '%s %s' /etc/hosts || echo %s %s >> /etc/hosts", IpFormat(s.Masters[0]), ApiServer, IpFormat(s.Masters[0]), ApiServer)
_ = SSHConfig.CmdAsync(s.Masters[0], cmd)

cmd = s.Command(Version, InitMaster)
Expand Down

0 comments on commit 9992ccc

Please sign in to comment.