Skip to content

Commit

Permalink
refactor: optimize imports && make golint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Cluas committed Nov 30, 2020
1 parent 82cc023 commit 9c1ec27
Show file tree
Hide file tree
Showing 37 changed files with 191 additions and 152 deletions.
5 changes: 3 additions & 2 deletions cert/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewSelfSignedCACert(key crypto.Signer, commonName string, organization []st
return x509.ParseCertificate(certDERBytes)
}

// Create as ca
// NewCaCertAndKey Create as ca.
func NewCaCertAndKey(cfg Config) (*x509.Certificate, crypto.Signer, error) {
_, err := os.Stat(pathForKey(cfg.Path, cfg.BaseName))
if !os.IsNotExist(err) {
Expand All @@ -106,6 +106,7 @@ func NewCaCertAndKey(cfg Config) (*x509.Certificate, crypto.Signer, error) {
return cert, key, nil
}

// LoadCaCertAndKeyFromDisk load ca cert and key form disk.
func LoadCaCertAndKeyFromDisk(cfg Config) (*x509.Certificate, crypto.Signer, error) {
certs, err := certutil.CertsFromFile(pathForCert(cfg.Path, cfg.BaseName))
if err != nil {
Expand Down Expand Up @@ -142,7 +143,7 @@ func TryLoadKeyFromDisk(pkiPath string) (crypto.Signer, error) {
return key, nil
}

// cmd/kubeadm/app/util/pkiutil/pki_helpers.go NewCertAndKey
// NewCaCertAndKeyFromRoot cmd/kubeadm/app/util/pkiutil/pki_helpers.go NewCertAndKey
func NewCaCertAndKeyFromRoot(cfg Config, caCert *x509.Certificate, caKey crypto.Signer) (*x509.Certificate, crypto.Signer, error) {
key, err := NewPrivateKey(x509.UnknownPublicKeyAlgorithm)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cert/cert_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/wonderivan/logger"
)

// return sealos cert command
func CertCMD(altNames []string, hostIP, hostName, serviceCIRD, DNSDomain string) string {
// CMD return sealos cert command
func CMD(altNames []string, hostIP, hostName, serviceCIRD, DNSDomain string) string {
cmd := "sealos cert "
if hostIP != "" {
cmd += fmt.Sprintf(" --node-ip %s", hostIP)
Expand All @@ -35,6 +35,7 @@ func CertCMD(altNames []string, hostIP, hostName, serviceCIRD, DNSDomain string)
return cmd
}

// GenerateCert generate all cert.
func GenerateCert(certPATH, certEtcdPATH string, altNames []string, hostIP, hostName, serviceCIRD, DNSDomian string) {
certConfig, err := NewSealosCertMetaData(certPATH, certEtcdPATH, altNames, serviceCIRD, hostName, hostIP, DNSDomian)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cert/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"path/filepath"

"github.com/pkg/errors"
"github.com/wonderivan/logger"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/client-go/util/keyutil"

"github.com/wonderivan/logger"
)

// clientCertAuth struct holds info required to build a client certificate to provide authentication info in a kubeconfig object
Expand Down
3 changes: 2 additions & 1 deletion cmd/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
package cmd

import (
"github.com/fanux/sealos/cert"
"github.com/spf13/cobra"

"github.com/fanux/sealos/cert"
)

type Flag struct {
Expand Down
6 changes: 4 additions & 2 deletions cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ package cmd
import (
"errors"
"fmt"
"github.com/fanux/sealos/install"
"os"

"github.com/spf13/cobra"
"github.com/wonderivan/logger"
"golang.org/x/crypto/ssh/terminal"
"os"

"github.com/fanux/sealos/install"
)

// cleanCmd represents the clean command
Expand Down
4 changes: 2 additions & 2 deletions cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"os"

"github.com/fanux/sealgate/cloud"
"github.com/fanux/sealos/install"

"github.com/spf13/cobra"

"github.com/fanux/sealos/install"
)

var p bool
Expand Down
14 changes: 7 additions & 7 deletions cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ package cmd
import (
"bytes"
"fmt"
"github.com/spf13/cobra"
"github.com/wonderivan/logger"
"io"
"os"

"github.com/spf13/cobra"

"github.com/wonderivan/logger"
)

const defaultCopyRight = `
Expand All @@ -43,7 +45,7 @@ const defaultCopyRight = `
var (
completionShells = map[string]func(out io.Writer, boilerPlate string, cmd *cobra.Command) error{
"bash": runCompletionBash,
"zsh": runCompletionZsh,
"zsh": runCompletionZsh,
}
completionExample = `
# Installing bash completion on macOS using homebrew
Expand Down Expand Up @@ -79,7 +81,7 @@ func init() {
}

func NewCmdCompletion(out io.Writer, boilerPlate string) *cobra.Command {
shells := []string{}
var shells []string
for s := range completionShells {
shells = append(shells, s)
}
Expand All @@ -88,7 +90,7 @@ func NewCmdCompletion(out io.Writer, boilerPlate string) *cobra.Command {
Use: "completion bash",
DisableFlagsInUseLine: true,
Short: "Output shell completion code for the specified shell (bash or zsh)",
Example: completionExample,
Example: completionExample,
Run: func(cmd *cobra.Command, args []string) {
err := RunCompletion(out, boilerPlate, cmd, args)
if err != nil {
Expand Down Expand Up @@ -127,7 +129,6 @@ func runCompletionBash(out io.Writer, copyRight string, sealos *cobra.Command) e
return sealos.GenBashCompletion(out)
}


func runCompletionZsh(out io.Writer, copyRight string, sealos *cobra.Command) error {
zshHead := "#compdef sealos\n"

Expand Down Expand Up @@ -242,4 +243,3 @@ __sealos_bash_source <(__sealos_convert_bash_to_zsh)
out.Write([]byte(zshTail))
return nil
}

4 changes: 2 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package cmd

import (
"github.com/fanux/sealos/install"

"github.com/spf13/cobra"

"github.com/fanux/sealos/install"
)

// configCmd represents the config command
Expand Down
6 changes: 4 additions & 2 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ limitations under the License.
package cmd

import (
"os"

"github.com/spf13/cobra"

"github.com/fanux/sealos/install"
"github.com/fanux/sealos/pkg/appmanager"
"github.com/spf13/cobra"
"os"
)

var (
Expand Down
20 changes: 11 additions & 9 deletions cmd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ package cmd

import (
"fmt"
"github.com/fanux/sealos/install"
"github.com/spf13/cobra"
"github.com/wonderivan/logger"
"os"
"time"

"github.com/spf13/cobra"

"github.com/fanux/sealos/install"
"github.com/wonderivan/logger"
)

var exampleCmd = `
Expand Down Expand Up @@ -83,11 +85,11 @@ func NewEtcdSaveCommand() *cobra.Command {
cmd.Flags().BoolVar(&install.InDocker, "docker", false, "snapshot your kubernets etcd in container, will add unix timestamp to snapshot name")
cmd.Flags().StringVar(&install.SnapshotName, "name", install.ETCDSNAPSHOTDEFAULTNAME, "Specify snapshot name")
cmd.Flags().StringVar(&install.EtcdBackDir, "backupPath", install.ETCDDEFAULTBACKUPDIR, "Specify snapshot backup dir")
cmd.Flags().StringVar(&install.BucketName, "bucket","","oss bucketName to save snapshot")
cmd.Flags().StringVar(&install.AccessKeyId, "aliId","","aliyun accessKeyId to save snapshot")
cmd.Flags().StringVar(&install.AccessKeySecrets, "aliKey","","aliyun accessKeySecrets to save snapshot")
cmd.Flags().StringVar(&install.OssEndpoint, "ep","","aliyun endpoints to save snapshot")
cmd.Flags().StringVar(&install.ObjectPath, "objectPath","","aliyun oss objectPath to save snapshot, like: /sealos/snapshots/")
cmd.Flags().StringVar(&install.BucketName, "bucket", "", "oss bucketName to save snapshot")
cmd.Flags().StringVar(&install.AccessKeyId, "aliId", "", "aliyun accessKeyId to save snapshot")
cmd.Flags().StringVar(&install.AccessKeySecrets, "aliKey", "", "aliyun accessKeySecrets to save snapshot")
cmd.Flags().StringVar(&install.OssEndpoint, "ep", "", "aliyun endpoints to save snapshot")
cmd.Flags().StringVar(&install.ObjectPath, "objectPath", "", "aliyun oss objectPath to save snapshot, like: /sealos/snapshots/")

return cmd
}
Expand All @@ -101,7 +103,7 @@ func NewEtcdRestoreCommand() *cobra.Command {
cmd.Flags().StringVar(&install.SnapshotName, "name", install.ETCDSNAPSHOTDEFAULTNAME, "Specify snapshot name")
cmd.Flags().StringVar(&install.EtcdBackDir, "backupPath", install.ETCDDEFAULTBACKUPDIR, "Specify snapshot backup dir")
cmd.Flags().StringVar(&install.RestorePath, "restorePath", install.ETCDDEFAULTRESTOREDIR, "Specify snapshot restore dir")
cmd.Flags().BoolVarP(&force, "force","f", false, "restore need interactive to confirm")
cmd.Flags().BoolVarP(&force, "force", "f", false, "restore need interactive to confirm")
return cmd
}

Expand Down
14 changes: 7 additions & 7 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ limitations under the License.
package cmd

import (
"github.com/fanux/sealos/install"
"github.com/spf13/cobra"

"github.com/fanux/sealos/install"
)

// execCmd represents the exec command
Expand All @@ -32,12 +33,11 @@ var (
sealos exec --src /data/foo --dst /root/foo --node 192.168.0.2
`
execCmd = &cobra.Command{
Use: "exec",
Short: "support exec cmd or copy file by Label/nodes ",
Example: exampleExecCmd,
Run: ExecCmdFunc,
}

Use: "exec",
Short: "support exec cmd or copy file by Label/nodes ",
Example: exampleExecCmd,
Run: ExecCmdFunc,
}
)

func init() {
Expand Down
16 changes: 9 additions & 7 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ package cmd

import (
"fmt"
"github.com/fanux/sealos/install"
"os"

"github.com/spf13/cobra"

"github.com/fanux/sealos/install"
"github.com/wonderivan/logger"
"os"
)

var contact = `
Expand Down Expand Up @@ -81,7 +83,7 @@ var initCmd = &cobra.Command{
if cfgFile != "" && len(install.MasterIPs) == 0 {
err := c.Load(cfgFile)
if err != nil {
logger.Error("load cfgFile %s err: %q",cfgFile , err)
logger.Error("load cfgFile %s err: %q", cfgFile, err)
os.Exit(1)
}
} else {
Expand All @@ -94,7 +96,7 @@ var initCmd = &cobra.Command{
},
PreRun: func(cmd *cobra.Command, args []string) {
// 使用了cfgFile 就不进行preRun了
if cfgFile == "" && install.ExitInitCase() {
if cfgFile == "" && install.ExitInitCase() {
cmd.Help()
os.Exit(install.ErrorExitOSCase)
}
Expand Down Expand Up @@ -141,13 +143,13 @@ func init() {
// initCmd.Flags().StringVar(&install.CertEtcdPath, "cert-etcd-path", "/root/.sealos/pki/etcd", "etcd cert file path")
}

func NewInitGenerateCmd() *cobra.Command {
func NewInitGenerateCmd() *cobra.Command {
return &cobra.Command{
Use: "gen",
Use: "gen",
Short: "show default sealos init config",
Run: func(cmd *cobra.Command, args []string) {
c := &install.SealConfig{}
c.ShowDefaultConfig()
},
}
}
}
6 changes: 4 additions & 2 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
package cmd

import (
"os"

"github.com/spf13/cobra"

"github.com/fanux/sealos/install"
"github.com/fanux/sealos/pkg/appmanager"
"github.com/spf13/cobra"
"os"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion cmd/ipvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ limitations under the License.
package cmd

import (
"github.com/fanux/sealos/install"
"github.com/spf13/cobra"

"github.com/fanux/sealos/install"
)

// ipvsCmd represents the ipvs command
Expand Down
5 changes: 3 additions & 2 deletions cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
package cmd

import (
"github.com/fanux/sealos/install"
"github.com/wonderivan/logger"
"os"

"github.com/spf13/cobra"

"github.com/fanux/sealos/install"
"github.com/wonderivan/logger"
)

// joinCmd represents the join command
Expand Down
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ package cmd

import (
"fmt"
"github.com/wonderivan/logger"
"os"

homedir "github.com/mitchellh/go-homedir"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/wonderivan/logger"
)

var cfgFile string
Expand Down
Loading

0 comments on commit 9c1ec27

Please sign in to comment.