Update cmd typos to match unified code format. (#1149)

This commit is contained in:
zzjin
2022-06-24 10:36:56 +08:00
committed by GitHub
parent 3f115f0951
commit e9222e6645
34 changed files with 382 additions and 463 deletions
+12 -14
View File
@@ -17,15 +17,13 @@ package cmd
import (
"os"
"github.com/labring/sealos/pkg/utils/flags"
"github.com/labring/sealos/pkg/cert"
"github.com/labring/sealos/pkg/utils/flags"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)
func certCmd() *cobra.Command {
func newCertCmd() *cobra.Command {
type certFlag struct {
AltNames []string
NodeName string
@@ -37,7 +35,7 @@ func certCmd() *cobra.Command {
}
var flag certFlag
cmd := &cobra.Command{
certCmd := &cobra.Command{
Use: "cert",
Short: "generate certs",
Long: `you can specify expire time`,
@@ -50,17 +48,17 @@ func certCmd() *cobra.Command {
}
},
}
cmd.Flags().StringSliceVar(&flag.AltNames, "alt-names", []string{}, "like sealos.io or 10.103.97.2")
cmd.Flags().StringVar(&flag.NodeName, "node-name", "", "like master0")
cmd.Flags().StringVar(&flag.ServiceCIDR, "service-cidr", "", "like 10.103.97.2/24")
cmd.Flags().StringVar(&flag.NodeIP, "node-ip", "", "like 10.103.97.2")
cmd.Flags().StringVar(&flag.DNSDomain, "dns-domain", "cluster.local", "cluster dns domain")
cmd.Flags().StringVar(&flag.CertPath, "cert-path", "/etc/kubernetes/pki", "kubernetes cert file path")
cmd.Flags().StringVar(&flag.CertEtcdPath, "cert-etcd-path", "/etc/kubernetes/pki/etcd", "kubernetes etcd cert file path")
certCmd.Flags().StringSliceVar(&flag.AltNames, "alt-names", []string{}, "like sealos.io or 10.103.97.2")
certCmd.Flags().StringVar(&flag.NodeName, "node-name", "", "like master0")
certCmd.Flags().StringVar(&flag.ServiceCIDR, "service-cidr", "", "like 10.103.97.2/24")
certCmd.Flags().StringVar(&flag.NodeIP, "node-ip", "", "like 10.103.97.2")
certCmd.Flags().StringVar(&flag.DNSDomain, "dns-domain", "cluster.local", "cluster dns domain")
certCmd.Flags().StringVar(&flag.CertPath, "cert-path", "/etc/kubernetes/pki", "kubernetes cert file path")
certCmd.Flags().StringVar(&flag.CertEtcdPath, "cert-etcd-path", "/etc/kubernetes/pki/etcd", "kubernetes etcd cert file path")
return cmd
return certCmd
}
func init() {
rootCmd.AddCommand(certCmd())
rootCmd.AddCommand(newCertCmd())
}
+51 -44
View File
@@ -32,30 +32,30 @@ var (
criConfigPath string
)
func NewCRICmd() *cobra.Command {
var cmd = &cobra.Command{
func newCRICmd() *cobra.Command {
var criCmd = &cobra.Command{
Use: "cri",
Short: "cri manager",
//Run: func(cmd *cobra.Command, args []string) {
//
//},
}
cmd.AddCommand(NewIsDockerCmd())
cmd.AddCommand(NewIsRunningCmd())
cmd.AddCommand(NewListKubeContainersCmd())
cmd.AddCommand(NewRemoveContainersCmd())
cmd.AddCommand(NewPullImageCmd())
cmd.AddCommand(NewImageExistsCmd())
cmd.AddCommand(NewCGroupDriverCmd())
cmd.AddCommand(NewCRISocketCmd())
cmd.PersistentFlags().StringVar(&criSocketPath, "socket-path", "", "cri socket path")
cmd.PersistentFlags().StringVar(&criConfigPath, "config", "", "cri config file")
criCmd.AddCommand(newIsDockerCmd())
criCmd.AddCommand(newIsRunningCmd())
criCmd.AddCommand(newListKubeContainersCmd())
criCmd.AddCommand(newRemoveContainersCmd())
criCmd.AddCommand(newPullImageCmd())
criCmd.AddCommand(newImageExistsCmd())
criCmd.AddCommand(newCGroupDriverCmd())
criCmd.AddCommand(newCRISocketCmd())
criCmd.PersistentFlags().StringVar(&criSocketPath, "socket-path", "", "cri socket path")
criCmd.PersistentFlags().StringVar(&criConfigPath, "config", "", "cri config file")
return cmd
return criCmd
}
func NewCRISocketCmd() *cobra.Command {
var cmd = &cobra.Command{
func newCRISocketCmd() *cobra.Command {
var criSocketCmd = &cobra.Command{
Use: "socket",
Short: "cri manager socket",
Run: func(cmd *cobra.Command, args []string) {
@@ -67,11 +67,11 @@ func NewCRISocketCmd() *cobra.Command {
println(criSocket)
},
}
return cmd
return criSocketCmd
}
func NewIsDockerCmd() *cobra.Command {
var cmd = &cobra.Command{
func newIsDockerCmd() *cobra.Command {
var isDockerCmd = &cobra.Command{
Use: "is-docker",
Short: "cri manager is-docker",
PreRun: func(cmd *cobra.Command, args []string) {
@@ -83,12 +83,12 @@ func NewIsDockerCmd() *cobra.Command {
println(strconv.FormatBool(isDocker))
},
}
return cmd
return isDockerCmd
}
func NewIsRunningCmd() *cobra.Command {
func newIsRunningCmd() *cobra.Command {
var shortPrint bool
var cmd = &cobra.Command{
var isRunningCmd = &cobra.Command{
Use: "is-running",
Short: "cri manager is-running",
PreRun: func(cmd *cobra.Command, args []string) {
@@ -108,12 +108,13 @@ func NewIsRunningCmd() *cobra.Command {
logger.Info("container runtime is running")
},
}
cmd.Flags().BoolVar(&shortPrint, "short", false, "if true, print just result.")
return cmd
isRunningCmd.Flags().BoolVar(&shortPrint, "short", false, "if true, print just result.")
return isRunningCmd
}
func NewListKubeContainersCmd() *cobra.Command {
func newListKubeContainersCmd() *cobra.Command {
var sPrint bool
var cmd = &cobra.Command{
var listKubeContainersCmd = &cobra.Command{
Use: "list-containers",
Short: "cri manager list-containers",
PreRun: func(cmd *cobra.Command, args []string) {
@@ -133,12 +134,13 @@ func NewListKubeContainersCmd() *cobra.Command {
logger.Info("container runtime containers is %+v", containers)
},
}
cmd.Flags().BoolVar(&sPrint, "short", false, "if true, print just result.")
return cmd
listKubeContainersCmd.Flags().BoolVar(&sPrint, "short", false, "if true, print just result.")
return listKubeContainersCmd
}
func NewRemoveContainersCmd() *cobra.Command {
func newRemoveContainersCmd() *cobra.Command {
var containers []string
var cmd = &cobra.Command{
var removeContainersCmd = &cobra.Command{
Use: "remove-containers",
Short: "cri manager remove-containers",
PreRun: func(cmd *cobra.Command, args []string) {
@@ -158,12 +160,13 @@ func NewRemoveContainersCmd() *cobra.Command {
logger.Info("container runtime remove containers %+v success.", containers)
},
}
cmd.Flags().StringSliceVar(&containers, "containers", []string{}, "containers name list")
return cmd
removeContainersCmd.Flags().StringSliceVar(&containers, "containers", []string{}, "containers name list")
return removeContainersCmd
}
func NewPullImageCmd() *cobra.Command {
func newPullImageCmd() *cobra.Command {
var imageName string
var cmd = &cobra.Command{
var pullImageCmd = &cobra.Command{
Use: "pull-image",
Short: "cri manager pull-image",
PreRun: func(cmd *cobra.Command, args []string) {
@@ -183,13 +186,14 @@ func NewPullImageCmd() *cobra.Command {
logger.Info("container runtime pull image %s success.", imageName)
},
}
cmd.Flags().StringVar(&imageName, "image", "", "image name")
return cmd
pullImageCmd.Flags().StringVar(&imageName, "image", "", "image name")
return pullImageCmd
}
func NewImageExistsCmd() *cobra.Command {
func newImageExistsCmd() *cobra.Command {
var shortPrint bool
var imageName string
var cmd = &cobra.Command{
var imageExistsCmd = &cobra.Command{
Use: "image-exists",
Short: "cri manager image-exists",
PreRun: func(cmd *cobra.Command, args []string) {
@@ -213,12 +217,13 @@ func NewImageExistsCmd() *cobra.Command {
logger.Info("container runtime image name %s is exists", imageName)
},
}
cmd.Flags().BoolVar(&shortPrint, "short", false, "if true, print just result.")
return cmd
imageExistsCmd.Flags().BoolVar(&shortPrint, "short", false, "if true, print just result.")
return imageExistsCmd
}
func NewCGroupDriverCmd() *cobra.Command {
func newCGroupDriverCmd() *cobra.Command {
var shortPrint bool
var cmd = &cobra.Command{
var cGroupDriverCmd = &cobra.Command{
Use: "cgroup-driver",
Short: "cri manager cgroup-driver",
PreRun: func(cmd *cobra.Command, args []string) {
@@ -238,8 +243,8 @@ func NewCGroupDriverCmd() *cobra.Command {
logger.Info("container runtime cgroup-driver is %s", driver)
},
}
cmd.Flags().BoolVar(&shortPrint, "short", false, "if true, print just result.")
return cmd
cGroupDriverCmd.Flags().BoolVar(&shortPrint, "short", false, "if true, print just result.")
return cGroupDriverCmd
}
func criCheck() {
@@ -252,6 +257,7 @@ func criCheck() {
os.Exit(1)
}
}
func criRuntime() cri.ContainerRuntime {
rt, err := cri.NewContainerRuntime(utilsexec.New(), criSocketPath, criConfigPath)
if err != nil {
@@ -260,6 +266,7 @@ func criRuntime() cri.ContainerRuntime {
}
return rt
}
func init() {
rootCmd.AddCommand(NewCRICmd())
rootCmd.AddCommand(newCRICmd())
}
+15 -24
View File
@@ -18,34 +18,25 @@ import (
"os"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)
// hostnameCmd represents the cert command
var hostnameCmd = &cobra.Command{
Use: "hostname",
Short: "get os.hostname",
Run: func(cmd *cobra.Command, args []string) {
hostname, err := os.Hostname()
if err != nil {
logger.Error(err)
os.Exit(1)
}
print(hostname)
},
func newHostsNameCmd() *cobra.Command {
var hostsNameCmd = &cobra.Command{
Use: "hostname",
Short: "get os.hostname",
Run: func(cmd *cobra.Command, args []string) {
hostname, err := os.Hostname()
if err != nil {
logger.Error(err)
os.Exit(1)
}
print(hostname)
},
}
return hostsNameCmd
}
func init() {
rootCmd.AddCommand(hostnameCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// hostnameCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// hostnameCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.AddCommand(newHostsNameCmd())
}
+22 -32
View File
@@ -19,16 +19,15 @@ package cmd
import (
"os"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/hosts"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)
var hostsPath string
func NewHostsCmd() *cobra.Command {
var cmd = &cobra.Command{
func newHostsCmd() *cobra.Command {
var hostsCmd = &cobra.Command{
Use: "hosts",
Short: "hosts manager",
//Run: func(cmd *cobra.Command, args []string) {
@@ -36,15 +35,15 @@ func NewHostsCmd() *cobra.Command {
//},
}
// check route for host
cmd.AddCommand(NewHostsListCmd())
cmd.AddCommand(NewHostsAddCmd())
cmd.AddCommand(NewHostsDeleteCmd())
cmd.PersistentFlags().StringVar(&hostsPath, "path", "/etc/hosts", "default hosts path")
return cmd
hostsCmd.AddCommand(newHostsListCmd())
hostsCmd.AddCommand(newHostsAddCmd())
hostsCmd.AddCommand(newHostsDeleteCmd())
hostsCmd.PersistentFlags().StringVar(&hostsPath, "path", "/etc/hosts", "default hosts path")
return hostsCmd
}
func NewHostsListCmd() *cobra.Command {
var cmd = &cobra.Command{
func newHostsListCmd() *cobra.Command {
var hostsListCmd = &cobra.Command{
Use: "list",
Short: "hosts manager list",
Run: func(cmd *cobra.Command, args []string) {
@@ -52,12 +51,12 @@ func NewHostsListCmd() *cobra.Command {
hf.ListCurrentHosts()
},
}
return cmd
return hostsListCmd
}
func NewHostsAddCmd() *cobra.Command {
func newHostsAddCmd() *cobra.Command {
var ip, domain string
var cmd = &cobra.Command{
var hostsAddCmd = &cobra.Command{
Use: "add",
Short: "hosts manager add",
PreRun: func(cmd *cobra.Command, args []string) {
@@ -80,14 +79,15 @@ func NewHostsAddCmd() *cobra.Command {
logger.Info("domain %s:%s append success", domain, ip)
},
}
cmd.Flags().StringVar(&ip, "ip", "", "ip address")
cmd.Flags().StringVar(&domain, "domain", "", "domain address")
hostsAddCmd.Flags().StringVar(&ip, "ip", "", "ip address")
hostsAddCmd.Flags().StringVar(&domain, "domain", "", "domain address")
return cmd
return hostsAddCmd
}
func NewHostsDeleteCmd() *cobra.Command {
func newHostsDeleteCmd() *cobra.Command {
var domain string
var cmd = &cobra.Command{
var hostsDeleteCmd = &cobra.Command{
Use: "delete",
Short: "hosts manager delete",
PreRun: func(cmd *cobra.Command, args []string) {
@@ -102,21 +102,11 @@ func NewHostsDeleteCmd() *cobra.Command {
logger.Info("domain %s delete success", domain)
},
}
cmd.Flags().StringVar(&domain, "domain", "", "domain address")
hostsDeleteCmd.Flags().StringVar(&domain, "domain", "", "domain address")
return cmd
return hostsDeleteCmd
}
func init() {
rootCmd.AddCommand(NewHostsCmd())
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// hostnameCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// hostnameCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.AddCommand(newHostsCmd())
}
+14 -21
View File
@@ -22,20 +22,15 @@ import (
var Ipvs care.LvsCare
// ipvsCmd represents the ipvs command
var ipvsCmd = &cobra.Command{
Use: "ipvs",
Short: "sealos create or care local ipvs lb",
Run: func(cmd *cobra.Command, args []string) {
flags.PrintFlags(cmd.Flags())
Ipvs.VsAndRsCare()
},
}
func init() {
rootCmd.AddCommand(ipvsCmd)
// Here you will define your flags and configuration settings.
func newIPVSCmd() *cobra.Command {
var ipvsCmd = &cobra.Command{
Use: "ipvs",
Short: "sealos create or care local ipvs lb",
Run: func(cmd *cobra.Command, args []string) {
flags.PrintFlags(cmd.Flags())
Ipvs.VsAndRsCare()
},
}
ipvsCmd.Flags().BoolVar(&Ipvs.RunOnce, "run-once", false, "is run once mode")
ipvsCmd.Flags().BoolVarP(&Ipvs.Clean, "clean", "c", true, " clean Vip ipvs rule before join node, if Vip has no ipvs rule do nothing.")
ipvsCmd.Flags().StringVar(&Ipvs.VirtualServer, "vs", "", "virturl server like 10.54.0.2:6443")
@@ -44,11 +39,9 @@ func init() {
ipvsCmd.Flags().StringVar(&Ipvs.HealthPath, "health-path", "/healthz", "health check path")
ipvsCmd.Flags().StringVar(&Ipvs.HealthSchem, "health-schem", "https", "health check schem")
ipvsCmd.Flags().Int32Var(&Ipvs.Interval, "interval", 5, "health check interval, unit is sec.")
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// ipvsCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// ipvsCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
return ipvsCmd
}
func init() {
rootCmd.AddCommand(newIPVSCmd())
}
+11 -22
View File
@@ -18,16 +18,15 @@ import (
"fmt"
"os"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/utils/exec"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)
func NewKubeCmd() *cobra.Command {
func newKubeCmd() *cobra.Command {
var fieldSelector, selector, kubeConfig, sources, namespace string
var allNamespace bool
var cmd = &cobra.Command{
var kubeCmd = &cobra.Command{
Use: "kube",
Short: "kube resource list json",
Run: func(cmd *cobra.Command, args []string) {
@@ -61,26 +60,16 @@ func NewKubeCmd() *cobra.Command {
println(data)
},
}
cmd.Flags().BoolVar(&allNamespace, "--all-namespaces", false, " If present, list the requested object(s) across all namespaces. Namespace in current\ncontext is ignored even if specified with --namespace.")
cmd.Flags().StringVar(&namespace, "namespace", "", "kubernetes namespace")
cmd.Flags().StringVar(&sources, "sources", "nodes", "e.g. pods,deployments")
cmd.Flags().StringVar(&fieldSelector, "field-selector", "", "Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector\nkey1=value1,key2=value2). The server only supports a limited number of field queries per type.")
cmd.Flags().StringVar(&selector, "selector", "", "Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)")
cmd.Flags().StringVar(&kubeConfig, "kubeconfig", "", "Path to the kubeconfig file to use for CLI requests.")
kubeCmd.Flags().BoolVar(&allNamespace, "--all-namespaces", false, " If present, list the requested object(s) across all namespaces. Namespace in current\ncontext is ignored even if specified with --namespace.")
kubeCmd.Flags().StringVar(&namespace, "namespace", "", "kubernetes namespace")
kubeCmd.Flags().StringVar(&sources, "sources", "nodes", "e.g. pods,deployments")
kubeCmd.Flags().StringVar(&fieldSelector, "field-selector", "", "Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector\nkey1=value1,key2=value2). The server only supports a limited number of field queries per type.")
kubeCmd.Flags().StringVar(&selector, "selector", "", "Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)")
kubeCmd.Flags().StringVar(&kubeConfig, "kubeconfig", "", "Path to the kubeconfig file to use for CLI requests.")
return cmd
return kubeCmd
}
func init() {
rootCmd.AddCommand(NewKubeCmd())
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// hostnameCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// hostnameCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.AddCommand(newKubeCmd())
}
+20 -30
View File
@@ -18,15 +18,14 @@ import (
"io/ioutil"
"os"
"github.com/labring/sealos/pkg/utils/file"
"github.com/labring/sealos/pkg/passwd"
"github.com/labring/sealos/pkg/utils/file"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)
func NewPasswordCmd() *cobra.Command {
var cmd = &cobra.Command{
func newPasswordCmd() *cobra.Command {
var passwordCmd = &cobra.Command{
Use: "password",
Short: "generator password",
//Run: func(cmd *cobra.Command, args []string) {
@@ -34,15 +33,15 @@ func NewPasswordCmd() *cobra.Command {
//},
}
// check route for host
cmd.AddCommand(NewRegistryCmd())
cmd.AddCommand(NewContainerdCmd())
return cmd
passwordCmd.AddCommand(newRegistryCmd())
passwordCmd.AddCommand(newContainerdCmd())
return passwordCmd
}
func NewRegistryCmd() *cobra.Command {
func newRegistryCmd() *cobra.Command {
var pwdPath, username, password string
var printBool bool
var cmd = &cobra.Command{
var registryCmd = &cobra.Command{
Use: "registry",
Short: "generator registry password and file",
Run: func(cmd *cobra.Command, args []string) {
@@ -65,17 +64,18 @@ func NewRegistryCmd() *cobra.Command {
},
}
// manually to set host via gateway
cmd.Flags().StringVar(&pwdPath, "path", "/etc/registry/registry_htpasswd", "default password file")
cmd.Flags().StringVar(&username, "username", "admin", "username")
cmd.Flags().StringVar(&password, "password", "admin", "password")
registryCmd.Flags().StringVar(&pwdPath, "path", "/etc/registry/registry_htpasswd", "default password file")
registryCmd.Flags().StringVar(&username, "username", "admin", "username")
registryCmd.Flags().StringVar(&password, "password", "admin", "password")
cmd.Flags().BoolVar(&printBool, "print", false, "is print")
registryCmd.Flags().BoolVar(&printBool, "print", false, "is print")
return cmd
return registryCmd
}
func NewContainerdCmd() *cobra.Command {
func newContainerdCmd() *cobra.Command {
var username, password string
var cmd = &cobra.Command{
var containerdCmd = &cobra.Command{
Use: "containerd",
Short: "generator containerd password",
Run: func(cmd *cobra.Command, args []string) {
@@ -84,22 +84,12 @@ func NewContainerdCmd() *cobra.Command {
},
}
// manually to set host via gateway
cmd.Flags().StringVar(&username, "username", "admin", "username")
cmd.Flags().StringVar(&password, "password", "admin", "password")
containerdCmd.Flags().StringVar(&username, "username", "admin", "username")
containerdCmd.Flags().StringVar(&password, "password", "admin", "password")
return cmd
return containerdCmd
}
func init() {
rootCmd.AddCommand(NewPasswordCmd())
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// hostnameCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// hostnameCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.AddCommand(newPasswordCmd())
}
+30 -32
View File
@@ -21,17 +21,15 @@ import (
"os"
"strings"
"github.com/labring/sealos/pkg/utils/flags"
"github.com/docker/docker/api/types"
"github.com/labring/sealos/pkg/buildimage"
"github.com/labring/sealos/pkg/passwd"
"github.com/labring/sealos/pkg/registry"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/labring/sealos/pkg/utils/file"
"github.com/labring/sealos/pkg/utils/flags"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/utils/maps"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
)
@@ -43,41 +41,41 @@ var (
registryPullAuthBasic bool
)
func NewRegistryImageCmd() *cobra.Command {
var cmd = &cobra.Command{
func newRegistryImageCmd() *cobra.Command {
var registryImageCmd = &cobra.Command{
Use: "registry",
Short: "registry images manager",
//Run: func(cmd *cobra.Command, args []string) {
//
//},
}
cmd.AddCommand(NewRegistryImagePullCmd())
return cmd
registryImageCmd.AddCommand(newRegistryImagePullCmd())
return registryImageCmd
}
func NewRegistryImagePullCmd() *cobra.Command {
var cmd = &cobra.Command{
func newRegistryImagePullCmd() *cobra.Command {
var registryImagePullCmd = &cobra.Command{
Use: "pull",
Short: "registry images manager pull to local dir",
//Run: func(cmd *cobra.Command, args []string) {
//
//},
}
cmd.PersistentFlags().StringVar(&registryPullArch, "arch", "amd64", "pull images arch")
cmd.PersistentFlags().StringVar(&registryPullRegistryDir, "data-dir", "/var/lib/registry", "registry data dir path")
cmd.PersistentFlags().StringSliceVar(&registryPullAuths, "auths", []string{}, "auths data for login mirror registry, format example is \"address=docker.io&&auth=YWRtaW46YWRtaW4=\".")
cmd.PersistentFlags().IntVar(&registryPullMaxPullProcs, "max-pull-procs", 5, "maximum number of goroutines for pulling")
cmd.PersistentFlags().BoolVar(&registryPullAuthBasic, "basic-auth", false, "pull image auth policy,default is token auth")
cmd.AddCommand(NewRegistryImagePullRawCmd())
cmd.AddCommand(NewRegistryImagePullYamlCmd())
cmd.AddCommand(NewRegistryImagePullDefaultCmd())
return cmd
registryImagePullCmd.PersistentFlags().StringVar(&registryPullArch, "arch", "amd64", "pull images arch")
registryImagePullCmd.PersistentFlags().StringVar(&registryPullRegistryDir, "data-dir", "/var/lib/registry", "registry data dir path")
registryImagePullCmd.PersistentFlags().StringSliceVar(&registryPullAuths, "auths", []string{}, "auths data for login mirror registry, format example is \"address=docker.io&&auth=YWRtaW46YWRtaW4=\".")
registryImagePullCmd.PersistentFlags().IntVar(&registryPullMaxPullProcs, "max-pull-procs", 5, "maximum number of goroutines for pulling")
registryImagePullCmd.PersistentFlags().BoolVar(&registryPullAuthBasic, "basic-auth", false, "pull image auth policy,default is token auth")
registryImagePullCmd.AddCommand(newRegistryImagePullRawCmd())
registryImagePullCmd.AddCommand(newRegistryImagePullYamlCmd())
registryImagePullCmd.AddCommand(newRegistryImagePullDefaultCmd())
return registryImagePullCmd
}
func NewRegistryImagePullRawCmd() *cobra.Command {
func newRegistryImagePullRawCmd() *cobra.Command {
var imageFile string
var auth map[string]types.AuthConfig
var cmd = &cobra.Command{
var registryImagePullRaw = &cobra.Command{
Use: "raw",
Short: "registry images manager pull to local dir by raw type",
Run: func(cmd *cobra.Command, args []string) {
@@ -103,14 +101,14 @@ func NewRegistryImagePullRawCmd() *cobra.Command {
},
}
cmd.PersistentFlags().StringVarP(&imageFile, "image-file", "f", "ImageFile", "ImageFile path")
return cmd
registryImagePullRaw.PersistentFlags().StringVarP(&imageFile, "image-file", "f", "ImageFile", "ImageFile path")
return registryImagePullRaw
}
func NewRegistryImagePullYamlCmd() *cobra.Command {
func newRegistryImagePullYamlCmd() *cobra.Command {
var yamlPath string
var auth map[string]types.AuthConfig
var cmd = &cobra.Command{
var registryImagePullYaml = &cobra.Command{
Use: "yaml",
Short: "registry images manager pull to local dir by yaml type",
Run: func(cmd *cobra.Command, args []string) {
@@ -136,14 +134,14 @@ func NewRegistryImagePullYamlCmd() *cobra.Command {
},
}
cmd.PersistentFlags().StringVarP(&yamlPath, "yaml-path", "p", "", "yaml data dir path")
return cmd
registryImagePullYaml.PersistentFlags().StringVarP(&yamlPath, "yaml-path", "p", "", "yaml data dir path")
return registryImagePullYaml
}
func NewRegistryImagePullDefaultCmd() *cobra.Command {
func newRegistryImagePullDefaultCmd() *cobra.Command {
var images []string
var auth map[string]types.AuthConfig
var cmd = &cobra.Command{
var registryImagePullDefault = &cobra.Command{
Use: "default",
Short: "registry images manager pull to local dir by default type",
Run: func(cmd *cobra.Command, args []string) {
@@ -160,8 +158,8 @@ func NewRegistryImagePullDefaultCmd() *cobra.Command {
},
}
cmd.PersistentFlags().StringSliceVar(&images, "images", []string{}, "images list")
return cmd
registryImagePullDefault.PersistentFlags().StringSliceVar(&images, "images", []string{}, "images list")
return registryImagePullDefault
}
func validateRegistryImagePull() map[string]types.AuthConfig {
@@ -195,5 +193,5 @@ func validateRegistryImagePull() map[string]types.AuthConfig {
}
func init() {
rootCmd.AddCommand(NewRegistryImageCmd())
rootCmd.AddCommand(newRegistryImageCmd())
}
-1
View File
@@ -19,7 +19,6 @@ import (
"os"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)
+22 -22
View File
@@ -27,26 +27,22 @@ var (
routeGatewayIP string
)
func NewRouteCmd() *cobra.Command {
func newRouteCmd() *cobra.Command {
// routeCmd represents the route command
var cmd = &cobra.Command{
var routeCmd = &cobra.Command{
Use: "route",
Short: "set default route gateway",
}
// check route for host
cmd.Flags().StringVar(&routeHost, "host", "", "route host ip address for iFace")
cmd.AddCommand(NewCheckRouteCmd())
cmd.AddCommand(NewDelRouteCmd())
cmd.AddCommand(NewAddRouteCmd())
return cmd
routeCmd.Flags().StringVar(&routeHost, "host", "", "route host ip address for iFace")
routeCmd.AddCommand(newCheckRouteCmd())
routeCmd.AddCommand(newDelRouteCmd())
routeCmd.AddCommand(newAddRouteCmd())
return routeCmd
}
func init() {
rootCmd.AddCommand(NewRouteCmd())
}
func NewCheckRouteCmd() *cobra.Command {
var cmd = &cobra.Command{
func newCheckRouteCmd() *cobra.Command {
var checkRouteCmd = &cobra.Command{
Use: "check",
Short: "check route host via gateway",
Run: func(cmd *cobra.Command, args []string) {
@@ -56,11 +52,11 @@ func NewCheckRouteCmd() *cobra.Command {
}
},
}
return cmd
return checkRouteCmd
}
func NewAddRouteCmd() *cobra.Command {
var cmd = &cobra.Command{
func newAddRouteCmd() *cobra.Command {
var addRouteCmd = &cobra.Command{
Use: "add",
Short: "set route host via gateway",
Run: func(cmd *cobra.Command, args []string) {
@@ -72,12 +68,12 @@ func NewAddRouteCmd() *cobra.Command {
},
}
// manually to set host via gateway
cmd.Flags().StringVar(&routeGatewayIP, "gateway", "", "route gateway ,ex ip route add host via gateway")
return cmd
addRouteCmd.Flags().StringVar(&routeGatewayIP, "gateway", "", "route gateway ,ex ip route add host via gateway")
return addRouteCmd
}
func NewDelRouteCmd() *cobra.Command {
var cmd = &cobra.Command{
func newDelRouteCmd() *cobra.Command {
var delRouteCmd = &cobra.Command{
Use: "del",
Short: "del route host via gateway, like ip route del host via gateway",
Run: func(cmd *cobra.Command, args []string) {
@@ -89,6 +85,10 @@ func NewDelRouteCmd() *cobra.Command {
},
}
// manually to set host via gateway
cmd.Flags().StringVar(&routeGatewayIP, "gateway", "", "route gateway ,ex ip route del host via gateway")
return cmd
delRouteCmd.Flags().StringVar(&routeGatewayIP, "gateway", "", "route gateway ,ex ip route del host via gateway")
return delRouteCmd
}
func init() {
rootCmd.AddCommand(newRouteCmd())
}
+15 -26
View File
@@ -20,18 +20,17 @@ import (
"os"
"path"
"github.com/labring/sealos/pkg/ipvs"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/file"
"github.com/labring/sealos/pkg/ipvs"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)
var staticPodPath string
func NewStaticPodCmd() *cobra.Command {
var cmd = &cobra.Command{
func newStaticPodCmd() *cobra.Command {
var staticPodCmd = &cobra.Command{
Use: "static-pod",
Short: "generator static pod",
//Run: func(cmd *cobra.Command, args []string) {
@@ -39,16 +38,16 @@ func NewStaticPodCmd() *cobra.Command {
//},
}
// check route for host
cmd.AddCommand(NewLvscareCmd())
cmd.PersistentFlags().StringVar(&staticPodPath, "path", constants.KubernetesEtcStaticPod, "default kubernetes static pod path")
return cmd
staticPodCmd.AddCommand(newLvscareCmd())
staticPodCmd.PersistentFlags().StringVar(&staticPodPath, "path", constants.KubernetesEtcStaticPod, "default kubernetes static pod path")
return staticPodCmd
}
func NewLvscareCmd() *cobra.Command {
func newLvscareCmd() *cobra.Command {
var vip, image, name string
var masters []string
var printBool bool
var cmd = &cobra.Command{
var lvscareCmd = &cobra.Command{
Use: "lvscare",
Short: "generator lvscare static pod file",
PreRun: func(cmd *cobra.Command, args []string) {
@@ -82,24 +81,14 @@ func NewLvscareCmd() *cobra.Command {
},
}
// manually to set host via gateway
cmd.Flags().StringVar(&vip, "vip", "10.103.97.2:6443", "default vip IP")
cmd.Flags().StringVar(&name, "name", constants.LvsCareStaticPodName, "generator lvscare static pod name")
cmd.Flags().StringVar(&image, "image", constants.DefaultLvsCareImage, "generator lvscare static pod image")
cmd.Flags().StringSliceVar(&masters, "masters", []string{}, "generator masters addrs")
cmd.Flags().BoolVar(&printBool, "print", false, "is print yaml")
return cmd
lvscareCmd.Flags().StringVar(&vip, "vip", "10.103.97.2:6443", "default vip IP")
lvscareCmd.Flags().StringVar(&name, "name", constants.LvsCareStaticPodName, "generator lvscare static pod name")
lvscareCmd.Flags().StringVar(&image, "image", constants.DefaultLvsCareImage, "generator lvscare static pod image")
lvscareCmd.Flags().StringSliceVar(&masters, "masters", []string{}, "generator masters addrs")
lvscareCmd.Flags().BoolVar(&printBool, "print", false, "is print yaml")
return lvscareCmd
}
func init() {
rootCmd.AddCommand(NewStaticPodCmd())
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// hostnameCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// hostnameCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.AddCommand(newStaticPodCmd())
}
+4 -16
View File
@@ -18,14 +18,13 @@ import (
"os"
"github.com/labring/sealos/pkg/token"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/util/json"
)
func NewTokenCmd() *cobra.Command {
var cmd = &cobra.Command{
func newTokenCmd() *cobra.Command {
var tokenCmd = &cobra.Command{
Use: "token",
Short: "token generator",
Run: func(cmd *cobra.Command, args []string) {
@@ -38,20 +37,9 @@ func NewTokenCmd() *cobra.Command {
println(string(data))
},
}
return cmd
return tokenCmd
}
func init() {
rootCmd.AddCommand(NewTokenCmd())
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// hostnameCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// hostnameCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.AddCommand(newTokenCmd())
}
+22 -20
View File
@@ -24,27 +24,29 @@ import (
var shortPrint bool
var versionCmd = &cobra.Command{
Use: "version",
Short: "version",
Args: cobra.NoArgs,
Example: `sealos version`,
RunE: func(cmd *cobra.Command, args []string) error {
marshalled, err := json.Marshal(version.Get())
if err != nil {
return err
}
if shortPrint {
fmt.Println(version.Get().String())
} else {
fmt.Println(string(marshalled))
}
return nil
},
func newVersionCmd() *cobra.Command {
var versionCmd = &cobra.Command{
Use: "version",
Short: "version",
Args: cobra.NoArgs,
Example: `sealos version`,
RunE: func(cmd *cobra.Command, args []string) error {
marshalled, err := json.Marshal(version.Get())
if err != nil {
return err
}
if shortPrint {
fmt.Println(version.Get().String())
} else {
fmt.Println(string(marshalled))
}
return nil
},
}
versionCmd.Flags().BoolVar(&shortPrint, "short", false, "if true, print just the version number.")
return versionCmd
}
func init() {
rootCmd.AddCommand(versionCmd)
versionCmd.Flags().BoolVar(&shortPrint, "short", false, "if true, print just the version number.")
rootCmd.AddCommand(newVersionCmd())
}
+16 -15
View File
@@ -17,26 +17,27 @@ package cmd
import (
"errors"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/apply"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)
// addCmd represents the delete command
func newAddCmd() *cobra.Command {
var deleteCmd = &cobra.Command{
Use: "add",
Short: "add some node",
Args: cobra.NoArgs,
Example: `
const exampleAdd = `
add to nodes :
sealos add --nodes x.x.x.x
add to default cluster:
add to default cluster:
sealos add --masters x.x.x.x --nodes x.x.x.x
sealos add --masters x.x.x.x-x.x.x.y --nodes x.x.x.x-x.x.x.y
`,
`
// addCmd represents the delete command
func newAddCmd() *cobra.Command {
var addCmd = &cobra.Command{
Use: "add",
Short: "add some node",
Args: cobra.NoArgs,
Example: exampleAdd,
RunE: func(cmd *cobra.Command, args []string) error {
//return errors.New("add feature no support")
applier, err := apply.NewScaleApplierFromArgs(addArgs, "add")
@@ -56,10 +57,10 @@ add to default cluster:
},
}
addArgs = &apply.ScaleArgs{}
deleteCmd.Flags().StringVarP(&addArgs.Masters, "masters", "m", "", "reduce Count or IPList to masters")
deleteCmd.Flags().StringVarP(&addArgs.Nodes, "nodes", "n", "", "reduce Count or IPList to nodes")
deleteCmd.Flags().StringVarP(&addArgs.ClusterName, "cluster", "c", "default", "delete a kubernetes cluster with cluster name")
return deleteCmd
addCmd.Flags().StringVarP(&addArgs.Masters, "masters", "m", "", "reduce Count or IPList to masters")
addCmd.Flags().StringVarP(&addArgs.Nodes, "nodes", "n", "", "reduce Count or IPList to nodes")
addCmd.Flags().StringVarP(&addArgs.ClusterName, "cluster", "c", "default", "delete a kubernetes cluster with cluster name")
return addCmd
}
var addArgs *apply.ScaleArgs
+21 -18
View File
@@ -22,25 +22,28 @@ import (
var clusterFile string
// applyCmd represents the apply command
var applyCmd = &cobra.Command{
Use: "apply",
Short: "apply a kubernetes cluster",
Example: `sealos apply -f Clusterfile`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
applier, err := apply.NewApplierFromFile(clusterFile)
if err != nil {
return err
}
return applier.Apply()
},
PostRun: func(cmd *cobra.Command, args []string) {
logger.Info(contact)
},
func newApplyCmd() *cobra.Command {
// applyCmd represents the apply command
var applyCmd = &cobra.Command{
Use: "apply",
Short: "apply a kubernetes cluster",
Example: `sealos apply -f Clusterfile`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
applier, err := apply.NewApplierFromFile(clusterFile)
if err != nil {
return err
}
return applier.Apply()
},
PostRun: func(cmd *cobra.Command, args []string) {
logger.Info(contact)
},
}
applyCmd.Flags().StringVarP(&clusterFile, "Clusterfile", "f", "Clusterfile", "apply a kubernetes cluster")
return applyCmd
}
func init() {
rootCmd.AddCommand(applyCmd)
applyCmd.Flags().StringVarP(&clusterFile, "Clusterfile", "f", "Clusterfile", "apply a kubernetes cluster")
rootCmd.AddCommand(newApplyCmd())
}
+2 -5
View File
@@ -19,11 +19,9 @@ import (
"os"
"runtime"
"github.com/labring/sealos/pkg/image/types"
"github.com/labring/sealos/pkg/image"
"github.com/labring/sealos/pkg/image/types"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)
@@ -66,6 +64,5 @@ func newBuildCmd() *cobra.Command {
}
func init() {
buildCmd := newBuildCmd()
rootCmd.AddCommand(buildCmd)
rootCmd.AddCommand(newBuildCmd())
}
+2 -3
View File
@@ -60,11 +60,10 @@ func newCreateCmd() *cobra.Command {
return nil
},
}
createCmd.Flags().StringVarP(&clusterName, "cluster-name", "c", "default", "set custom cluster name")
return createCmd
}
func init() {
createCmd := newCreateCmd()
rootCmd.AddCommand(createCmd)
createCmd.Flags().StringVarP(&clusterName, "cluster-name", "c", "default", "set custom cluster name")
rootCmd.AddCommand(newCreateCmd())
}
+8 -11
View File
@@ -17,18 +17,18 @@ package cmd
import (
"errors"
"github.com/labring/sealos/pkg/apply/processor"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/apply"
"github.com/labring/sealos/pkg/apply/processor"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)
var exampledelete = `
var deleteArgs apply.ScaleArgs
var exampleDelete = `
delete nodes:
sealos delete --nodes x.x.x.x
if accidentally deleted;
if accidentally deleted;
Use 'sealos add' to recover:
sealos add --nodes x.x.x.x
@@ -48,12 +48,12 @@ func newDeleteCmd() *cobra.Command {
Use: "delete",
Short: "delete some node",
Args: cobra.NoArgs,
Example: exampledelete,
Example: exampleDelete,
RunE: func(cmd *cobra.Command, args []string) error {
if err := processor.ConfirmDeleteNodes(); err != nil {
return err
}
applier, err := apply.NewScaleApplierFromArgs(deleteArgs, "delete")
applier, err := apply.NewScaleApplierFromArgs(&deleteArgs, "delete")
if err != nil {
return err
}
@@ -69,7 +69,6 @@ func newDeleteCmd() *cobra.Command {
logger.Info(contact)
},
}
deleteArgs = &apply.ScaleArgs{}
deleteCmd.Flags().StringVarP(&deleteArgs.Masters, "masters", "m", "", "reduce Count or IPList to masters")
deleteCmd.Flags().StringVarP(&deleteArgs.Nodes, "nodes", "n", "", "reduce Count or IPList to nodes")
deleteCmd.Flags().StringVarP(&deleteArgs.ClusterName, "cluster", "c", "default", "delete a kubernetes cluster with cluster name")
@@ -77,8 +76,6 @@ func newDeleteCmd() *cobra.Command {
return deleteCmd
}
var deleteArgs *apply.ScaleArgs
func init() {
rootCmd.AddCommand(newDeleteCmd())
}
+20 -18
View File
@@ -27,35 +27,37 @@ var roles string
var clusterName string
var ips []string
func newExecCmd() *cobra.Command {
var cluster *v1beta1.Cluster
var cmd = &cobra.Command{
Use: "exec",
Short: "exec a shell command or script on all node.",
Example: `
var exampleExec = `
exec to default cluster: default
sealos exec "cat /etc/hosts"
specify the cluster name(If there is only one cluster in the $HOME/.sealos directory, it should be applied. ):
sealos exec -c my-cluster "cat /etc/hosts"
set role label to exec cmd:
sealos exec -c my-cluster -r master,slave,node1 "cat /etc/hosts"
sealos exec -c my-cluster -r master,slave,node1 "cat /etc/hosts"
set ips to exec cmd:
sealos exec -c my-cluster --ips 172.16.1.38 "cat /etc/hosts"
`,
Args: cobra.ExactArgs(1),
sealos exec -c my-cluster --ips 172.16.1.38 "cat /etc/hosts"
`
func newExecCmd() *cobra.Command {
var cluster *v1beta1.Cluster
var execCmd = &cobra.Command{
Use: "exec",
Short: "exec a shell command or script on all node.",
Example: exampleExec,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(ips) > 0 {
execCmd, err := ssh.NewExecCmdFromIPs(cluster, ips)
execIPCmd, err := ssh.NewExecCmdFromIPs(cluster, ips)
if err != nil {
return err
}
return execCmd.RunCmd(args[0])
return execIPCmd.RunCmd(args[0])
}
execCmd, err := ssh.NewExecCmdFromRoles(cluster, roles)
execRoleCmd, err := ssh.NewExecCmdFromRoles(cluster, roles)
if err != nil {
return err
}
return execCmd.RunCmd(args[0])
return execRoleCmd.RunCmd(args[0])
},
PreRunE: func(cmd *cobra.Command, args []string) error {
cls, err := clusterfile.GetClusterFromName(clusterName)
@@ -66,10 +68,10 @@ set ips to exec cmd:
return nil
},
}
cmd.Flags().StringVarP(&clusterName, "cluster-name", "c", "default", "submit one cluster name")
cmd.Flags().StringVarP(&roles, "roles", "r", "", "set role label to roles")
cmd.Flags().StringSliceVar(&ips, "ips", []string{}, "ssh ips list on node")
return cmd
execCmd.Flags().StringVarP(&clusterName, "cluster-name", "c", "default", "submit one cluster name")
execCmd.Flags().StringVarP(&roles, "roles", "r", "", "set role label to roles")
execCmd.Flags().StringSliceVar(&ips, "ips", []string{}, "ssh ips list on node")
return execCmd
}
func init() {
+1 -2
View File
@@ -37,6 +37,5 @@ func newImagesCmd() *cobra.Command {
}
func init() {
imagesCmd := newImagesCmd()
rootCmd.AddCommand(imagesCmd)
rootCmd.AddCommand(newImagesCmd())
}
+1 -2
View File
@@ -39,6 +39,5 @@ func newLoadCmd() *cobra.Command {
}
func init() {
loadCmd := newLoadCmd()
rootCmd.AddCommand(loadCmd)
rootCmd.AddCommand(newLoadCmd())
}
+1 -3
View File
@@ -19,7 +19,6 @@ import (
"github.com/labring/sealos/pkg/image"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)
@@ -52,6 +51,5 @@ func newLoginCmd() *cobra.Command {
}
func init() {
loginCmd := newLoginCmd()
rootCmd.AddCommand(loginCmd)
rootCmd.AddCommand(newLoginCmd())
}
+1 -2
View File
@@ -37,6 +37,5 @@ func newLogoutCmd() *cobra.Command {
}
func init() {
logoutCmd := newLogoutCmd()
rootCmd.AddCommand(logoutCmd)
rootCmd.AddCommand(newLogoutCmd())
}
+1 -2
View File
@@ -37,6 +37,5 @@ func newPruneCmd() *cobra.Command {
}
func init() {
pruneCmd := newPruneCmd()
rootCmd.AddCommand(pruneCmd)
rootCmd.AddCommand(newPruneCmd())
}
+1 -2
View File
@@ -37,6 +37,5 @@ func newPullCmd() *cobra.Command {
}
func init() {
pullCmd := newPullCmd()
rootCmd.AddCommand(pullCmd)
rootCmd.AddCommand(newPullCmd())
}
+1 -2
View File
@@ -37,6 +37,5 @@ func newPushCmd() *cobra.Command {
}
func init() {
pushCmd := newPushCmd()
rootCmd.AddCommand(pushCmd)
rootCmd.AddCommand(newPushCmd())
}
+7 -10
View File
@@ -19,7 +19,6 @@ import (
"github.com/labring/sealos/pkg/apply/processor"
"github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)
@@ -28,7 +27,7 @@ reset you current cluster:
sealos reset --name xxx [--force]
`
var resetArgs *apply.ResetArgs
var resetArgs apply.ResetArgs
func newResetCmd() *cobra.Command {
var resetCmd = &cobra.Command{
@@ -41,7 +40,7 @@ func newResetCmd() *cobra.Command {
if err := processor.ConfirmDeleteNodes(); err != nil {
return err
}
applier, err := apply.NewApplierFromResetArgs(resetArgs)
applier, err := apply.NewApplierFromResetArgs(&resetArgs)
if err != nil {
return err
}
@@ -51,13 +50,6 @@ func newResetCmd() *cobra.Command {
logger.Info(contact)
},
}
return resetCmd
}
func init() {
resetArgs = &apply.ResetArgs{}
resetCmd := newResetCmd()
rootCmd.AddCommand(resetCmd)
resetCmd.Flags().StringVarP(&resetArgs.Masters, "masters", "m", "", "set Count or IPList to masters")
resetCmd.Flags().StringVarP(&resetArgs.Nodes, "nodes", "n", "", "set Count or IPList to nodes")
resetCmd.Flags().StringVarP(&resetArgs.User, "user", "u", v1beta1.DefaultUserRoot, "set baremetal server username")
@@ -67,4 +59,9 @@ func init() {
resetCmd.Flags().StringVar(&resetArgs.PkPassword, "pk-passwd", "", "set baremetal server private key password")
resetCmd.Flags().StringVar(&resetArgs.ClusterName, "name", "default", "set cluster name variables")
resetCmd.Flags().BoolVar(&processor.ForceDelete, "force", false, "we also can input an --force flag to reset cluster by force")
return resetCmd
}
func init() {
rootCmd.AddCommand(newResetCmd())
}
+1 -2
View File
@@ -39,6 +39,5 @@ func newRMICmd() *cobra.Command {
}
func init() {
rmiCmd := newRMICmd()
rootCmd.AddCommand(rmiCmd)
rootCmd.AddCommand(newRMICmd())
}
-1
View File
@@ -22,7 +22,6 @@ import (
"github.com/labring/sealos/pkg/utils/file"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
+20 -23
View File
@@ -15,26 +15,25 @@
package cmd
import (
"github.com/labring/sealos/pkg/apply/processor"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/apply"
"github.com/labring/sealos/pkg/apply/processor"
"github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)
var contact = `
___ ___ ___ ___ ___ ___
/\ \ /\ \ /\ \ /\__\ /\ \ /\ \
/::\ \ /::\ \ /::\ \ /:/ / /::\ \ /::\ \
/:/\ \ \ /:/\:\ \ /:/\:\ \ /:/ / /:/\:\ \ /:/\ \ \
_\:\~\ \ \ /::\~\:\ \ /::\~\:\ \ /:/ / /:/ \:\ \ _\:\~\ \ \
___ ___ ___ ___ ___ ___
/\ \ /\ \ /\ \ /\__\ /\ \ /\ \
/::\ \ /::\ \ /::\ \ /:/ / /::\ \ /::\ \
/:/\ \ \ /:/\:\ \ /:/\:\ \ /:/ / /:/\:\ \ /:/\ \ \
_\:\~\ \ \ /::\~\:\ \ /::\~\:\ \ /:/ / /:/ \:\ \ _\:\~\ \ \
/\ \:\ \ \__\ /:/\:\ \:\__\ /:/\:\ \:\__\ /:/__/ /:/__/ \:\__\ /\ \:\ \ \__\
\:\ \:\ \/__/ \:\~\:\ \/__/ \/__\:\/:/ / \:\ \ \:\ \ /:/ / \:\ \:\ \/__/
\:\ \:\__\ \:\ \:\__\ \::/ / \:\ \ \:\ /:/ / \:\ \:\__\
\:\/:/ / \:\ \/__/ /:/ / \:\ \ \:\/:/ / \:\/:/ /
\::/ / \:\__\ /:/ / \:\__\ \::/ / \::/ /
\/__/ \/__/ \/__/ \/__/ \/__/ \/__/
\:\ \:\__\ \:\ \:\__\ \::/ / \:\ \ \:\ /:/ / \:\ \:\__\
\:\/:/ / \:\ \/__/ /:/ / \:\ \ \:\/:/ / \:\/:/ /
\::/ / \:\__\ /:/ / \:\__\ \::/ / \::/ /
\/__/ \/__/ \/__/ \/__/ \/__/ \/__/
Website :https://www.sealos.io/
Address :github.com/labring/sealos
@@ -45,7 +44,7 @@ create cluster to your baremetal server, appoint the iplist:
sealos run labring/kubernetes:v1.24.0 --masters 192.168.0.2,192.168.0.3,192.168.0.4 \
--nodes 192.168.0.5,192.168.0.6,192.168.0.7 --passwd xxx
multi image:
sealos run labring/kubernetes:v1.24.0 calico:v3.22.1 \
sealos run labring/kubernetes:v1.24.0 calico:v3.22.1 \
--masters 192.168.64.2,192.168.64.22,192.168.64.20 --nodes 192.168.64.21,192.168.64.19
Specify server InfraSSH port :
All servers use the same InfraSSH port (default port: 22)
@@ -54,12 +53,12 @@ create cluster to your baremetal server, appoint the iplist:
Different InfraSSH port numbers exist
sealos run labring/kubernetes:v1.24.0 --masters 192.168.0.2,192.168.0.3:23,192.168.0.4:24 \
--nodes 192.168.0.5:25,192.168.0.6:25,192.168.0.7:27 --passwd xxx
create a cluster with custom environment variables:
sealos run -e DashBoardPort=8443 mydashboard:latest --masters 192.168.0.2,192.168.0.3,192.168.0.4 \
--nodes 192.168.0.5,192.168.0.6,192.168.0.7 --passwd xxx
`
var runArgs *apply.RunArgs
var runArgs apply.RunArgs
func newRunCmd() *cobra.Command {
var runCmd = &cobra.Command{
@@ -68,7 +67,7 @@ func newRunCmd() *cobra.Command {
Long: `sealos run labring/kubernetes:v1.24.0 --masters [arg] --nodes [arg]`,
Example: exampleRun,
RunE: func(cmd *cobra.Command, args []string) error {
applier, err := apply.NewApplierFromArgs(args, runArgs)
applier, err := apply.NewApplierFromArgs(args, &runArgs)
if err != nil {
return err
}
@@ -78,13 +77,6 @@ func newRunCmd() *cobra.Command {
logger.Info(contact)
},
}
return runCmd
}
func init() {
runArgs = &apply.RunArgs{}
runCmd := newRunCmd()
rootCmd.AddCommand(runCmd)
runCmd.Flags().StringVarP(&runArgs.Masters, "masters", "m", "", "set Count or IPList to masters")
runCmd.Flags().StringVarP(&runArgs.Nodes, "nodes", "n", "", "set Count or IPList to nodes")
runCmd.Flags().StringVarP(&runArgs.User, "user", "u", v1beta1.DefaultUserRoot, "set baremetal server username")
@@ -96,4 +88,9 @@ func init() {
runCmd.Flags().StringSliceVarP(&runArgs.CustomEnv, "env", "e", []string{}, "set custom environment variables")
runCmd.Flags().BoolVarP(&processor.ForceOverride, "force", "f", false, "we also can input an --force flag to run app in this cluster by force")
runCmd.Flags().StringVar(&runArgs.ClusterName, "name", "default", "set cluster name variables")
return runCmd
}
func init() {
rootCmd.AddCommand(newRunCmd())
}
+1 -2
View File
@@ -39,6 +39,5 @@ func newSaveCmd() *cobra.Command {
}
func init() {
saveCmd := newSaveCmd()
rootCmd.AddCommand(saveCmd)
rootCmd.AddCommand(newSaveCmd())
}
+16 -14
View File
@@ -28,23 +28,25 @@ import (
// var clusterName string
// var ips []string
func newScpCmd() *cobra.Command {
var cluster *v1beta1.Cluster
var cmd = &cobra.Command{
Use: "scp",
// Aliases: []string{"cp"},
Short: "copy local file to remote on all node.",
Example: `
const exampleScp = `
copy file to default cluster: default
sealos scp "/root/aa.txt" "/root/dd.txt"
specify the cluster name(If there is only one cluster in the $HOME/.sealos directory, it should be applied. ):
sealos scp -c my-cluster "/root/aa.txt" "/root/dd.txt"
set role label to copy file:
sealos scp -c my-cluster -r master,slave,node1 "cat /etc/hosts"
sealos scp -c my-cluster -r master,slave,node1 "cat /etc/hosts"
set ips to copy file:
sealos scp -c my-cluster --ips 172.16.1.38 "/root/aa.txt" "/root/dd.txt"
`,
Args: cobra.ExactArgs(2),
`
func newScpCmd() *cobra.Command {
var cluster *v1beta1.Cluster
var scpCmd = &cobra.Command{
Use: "scp",
// Aliases: []string{"cp"},
Short: "copy local file to remote on all node.",
Example: exampleScp,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
if len(ips) > 0 {
sshCmd, err := ssh.NewExecCmdFromIPs(cluster, ips)
@@ -68,10 +70,10 @@ set ips to copy file:
return nil
},
}
cmd.Flags().StringVarP(&clusterName, "cluster-name", "c", "default", "submit one cluster name")
cmd.Flags().StringVarP(&roles, "roles", "r", "", "set role label to roles")
cmd.Flags().StringSliceVar(&ips, "ips", []string{}, "ssh ips list on node")
return cmd
scpCmd.Flags().StringVarP(&clusterName, "cluster-name", "c", "default", "submit one cluster name")
scpCmd.Flags().StringVarP(&roles, "roles", "r", "", "set role label to roles")
scpCmd.Flags().StringSliceVar(&ips, "ips", []string{}, "ssh ips list on node")
return scpCmd
}
func init() {
+1 -2
View File
@@ -37,6 +37,5 @@ func newTagCmd() *cobra.Command {
}
func init() {
tagCmd := newTagCmd()
rootCmd.AddCommand(tagCmd)
rootCmd.AddCommand(newTagCmd())
}
+22 -20
View File
@@ -24,27 +24,29 @@ import (
var shortPrint bool
var versionCmd = &cobra.Command{
Use: "version",
Short: "version",
Args: cobra.NoArgs,
Example: `sealos version`,
RunE: func(cmd *cobra.Command, args []string) error {
marshalled, err := json.Marshal(version.Get())
if err != nil {
return err
}
if shortPrint {
fmt.Println(version.Get().String())
} else {
fmt.Println(string(marshalled))
}
return nil
},
func newVersionCmd() *cobra.Command {
var versionCmd = &cobra.Command{
Use: "version",
Short: "version",
Args: cobra.NoArgs,
Example: `sealos version`,
RunE: func(cmd *cobra.Command, args []string) error {
marshalled, err := json.Marshal(version.Get())
if err != nil {
return err
}
if shortPrint {
fmt.Println(version.Get().String())
} else {
fmt.Println(string(marshalled))
}
return nil
},
}
versionCmd.Flags().BoolVar(&shortPrint, "short", false, "if true, print just the version number.")
return versionCmd
}
func init() {
rootCmd.AddCommand(versionCmd)
versionCmd.Flags().BoolVar(&shortPrint, "short", false, "if true, print just the version number.")
rootCmd.AddCommand(newVersionCmd())
}