Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ run:
go: "1.23"
relative-path-mode: gomod
modules-download-mode: readonly
timeout: 5m

issues:
max-issues-per-linter: 0
Expand Down
28 changes: 20 additions & 8 deletions lifecycle/cmd/image-cri-shim/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ import (

"github.com/labring/image-cri-shim/pkg/shim"
"github.com/labring/image-cri-shim/pkg/types"
"github.com/spf13/cobra"

"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/version"
"github.com/spf13/cobra"
)

var cfg *types.Config
var shimAuth *types.ShimAuthConfig
var cfgFile string
var (
cfg *types.Config
shimAuth *types.ShimAuthConfig
cfgFile string
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -73,11 +74,17 @@ func Execute() {
}

func init() {
rootCmd.Flags().StringVarP(&cfgFile, "file", "f", types.DefaultImageCRIShimConfig, "image shim root config")
rootCmd.Flags().
StringVarP(&cfgFile, "file", "f", types.DefaultImageCRIShimConfig, "image shim root config")
}

func run(cfg *types.Config, auth *types.ShimAuthConfig) {
logger.Info("socket info shim: %v ,image: %v, registry: %v", cfg.ImageShimSocket, cfg.RuntimeSocket, cfg.Address)
logger.Info(
"socket info shim: %v ,image: %v, registry: %v",
cfg.ImageShimSocket,
cfg.RuntimeSocket,
cfg.Address,
)
imgShim, err := shim.NewShim(cfg, auth)
if err != nil {
logger.Fatal("failed to new image_shim, %s", err)
Expand Down Expand Up @@ -115,7 +122,12 @@ func run(cfg *types.Config, auth *types.ShimAuthConfig) {
logger.Info("shutting down the image_shim")
}

func watchAuthConfig(ctx context.Context, path string, imgShim shim.Shim, interval time.Duration) error {
func watchAuthConfig(
ctx context.Context,
path string,
imgShim shim.Shim,
interval time.Duration,
) error {
if path == "" {
logger.Warn("config file path is empty, skip dynamic auth reload")
return nil
Expand Down
5 changes: 4 additions & 1 deletion lifecycle/cmd/image-cri-shim/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ registries:

mirror, ok = auth.CRIConfigs["mirror.example.com"]
if !ok {
t.Fatalf("expected registry credentials for mirror.example.com after update, got %#v", auth.CRIConfigs)
t.Fatalf(
"expected registry credentials for mirror.example.com after update, got %#v",
auth.CRIConfigs,
)
}
if mirror.Password != "changed" {
t.Fatalf("expected updated mirror password, got %q", mirror.Password)
Expand Down
4 changes: 1 addition & 3 deletions lifecycle/cmd/lvscare/cmd/care.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
package cmd

import (
"github.com/spf13/cobra"

"github.com/labring/lvscare/care"

"github.com/labring/sealos/pkg/utils/flags"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)

// careCmd represents the care command
Expand Down
6 changes: 3 additions & 3 deletions lifecycle/cmd/lvscare/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ import (
"fmt"

"github.com/labring/sealos/pkg/version"

"github.com/spf13/cobra"
)

var shortPrint bool

func newVersionCmd() *cobra.Command {
var versionCmd = &cobra.Command{
versionCmd := &cobra.Command{
Use: "version",
Short: "version",
Args: cobra.NoArgs,
Expand All @@ -44,7 +43,8 @@ func newVersionCmd() *cobra.Command {
return nil
},
}
versionCmd.Flags().BoolVar(&shortPrint, "short", false, "if true, print just the version number.")
versionCmd.Flags().
BoolVar(&shortPrint, "short", false, "if true, print just the version number.")
return versionCmd
}

Expand Down
20 changes: 10 additions & 10 deletions lifecycle/cmd/sealctl/cmd/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,51 @@
package cmd

import (
"github.com/spf13/cobra"

"github.com/labring/sealos/pkg/utils/archive"
"github.com/labring/sealos/pkg/utils/flags"
"github.com/spf13/cobra"
)

func newTarCmd() *cobra.Command {
var (
compressionF flags.Compression
output string
clear bool
clearSource bool
)
cmd := &cobra.Command{
Use: "tar",
Short: "creates an archive file from the directory at `path`, note that this will strip the parent dir",
Args: cobra.ExactArgs(1),
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
return archive.Tar(args[0], output, compressionF, clear)
return archive.Tar(args[0], output, compressionF, clearSource)
},
}
cmd.Flags().Var(&compressionF, "compression", "compression algorithm, available options are tar/gzip/zstd/disable")
cmd.Flags().
Var(&compressionF, "compression", "compression algorithm, available options are tar/gzip/zstd/disable")
cmd.Flags().StringVarP(&output, "output", "o", "", "path of archive file")
cmd.Flags().BoolVar(&clear, "clear", false, "remove source after compression finished")
cmd.Flags().BoolVar(&clearSource, "clear", false, "remove source after compression finished")
_ = cmd.MarkFlagRequired("output")
_ = cmd.MarkFlagRequired("compression")
return cmd
}

func newUntarCmd() *cobra.Command {
var (
clear bool
output string
clearSource bool
output string
)
cmd := &cobra.Command{
Use: "untar",
Short: "looks for archive files match glob patterns at filesystem path `src`, and unpacks it at `dst`",
Args: cobra.MinimumNArgs(1),
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
return archive.Untar(args, output, clear)
return archive.Untar(args, output, clearSource)
},
}
cmd.Flags().StringVarP(&output, "output", "o", "", "path to uncompress archive files")
cmd.Flags().BoolVar(&clear, "clear", false, "remove source after uncompression finished")
cmd.Flags().BoolVar(&clearSource, "clear", false, "remove source after uncompression finished")
_ = cmd.MarkFlagRequired("output")
return cmd
}
Expand Down
22 changes: 16 additions & 6 deletions lifecycle/cmd/sealctl/cmd/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ package cmd
import (
"os"

"github.com/spf13/cobra"

"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 newCertCmd() *cobra.Command {
Expand All @@ -42,20 +41,31 @@ func newCertCmd() *cobra.Command {
Long: `you can specify expire time`,
Run: func(cmd *cobra.Command, args []string) {
flags.PrintFlags(cmd.Flags())
err := cert.GenerateCert(flag.CertPath, flag.CertEtcdPath, flag.AltNames, flag.NodeIP, flag.NodeName, flag.ServiceCIDR, flag.DNSDomain)
err := cert.GenerateCert(
flag.CertPath,
flag.CertEtcdPath,
flag.AltNames,
flag.NodeIP,
flag.NodeName,
flag.ServiceCIDR,
flag.DNSDomain,
)
if err != nil {
logger.Error(err)
os.Exit(1)
}
},
}
certCmd.Flags().StringSliceVar(&flag.AltNames, "alt-names", []string{}, "like sealos.io or 10.103.97.2")
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")
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 certCmd
}
9 changes: 4 additions & 5 deletions lifecycle/cmd/sealctl/cmd/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import (
"os"

"github.com/labring/image-cri-shim/pkg/cri"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
utilsexec "k8s.io/utils/exec"

"github.com/labring/sealos/pkg/utils/logger"
)

var (
Expand All @@ -33,7 +32,7 @@ var (
)

func newCRICmd() *cobra.Command {
var criCmd = &cobra.Command{
criCmd := &cobra.Command{
Use: "cri",
Short: "cri manager",
}
Expand All @@ -46,7 +45,7 @@ func newCRICmd() *cobra.Command {
}

func newCRISocketCmd() *cobra.Command {
var criSocketCmd = &cobra.Command{
criSocketCmd := &cobra.Command{
Use: "socket",
Short: "cri manager socket",
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -63,7 +62,7 @@ func newCRISocketCmd() *cobra.Command {

func newCGroupDriverCmd() *cobra.Command {
var shortPrint bool
var cGroupDriverCmd = &cobra.Command{
cGroupDriverCmd := &cobra.Command{
Use: "cgroup-driver",
Short: "cri manager cgroup-driver",
PreRun: func(cmd *cobra.Command, args []string) {
Expand Down
8 changes: 4 additions & 4 deletions lifecycle/cmd/sealctl/cmd/hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)

func newHostsNameCmd() *cobra.Command {
var hostsNameCmd = &cobra.Command{
hostsNameCmd := &cobra.Command{
Use: "hostname",
Short: "get os.hostname",
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -32,7 +32,7 @@ func newHostsNameCmd() *cobra.Command {
logger.Error(err)
os.Exit(1)
}
print(hostname)
fmt.Print(hostname)
},
}
return hostsNameCmd
Expand Down
16 changes: 8 additions & 8 deletions lifecycle/cmd/sealctl/cmd/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,33 @@ package cmd
import (
"os"

"github.com/spf13/cobra"

"github.com/labring/sealos/pkg/constants"
"github.com/labring/sealos/pkg/utils/hosts"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/spf13/cobra"
)

var hostsPath string

func newHostsCmd() *cobra.Command {
var hostsCmd = &cobra.Command{
hostsCmd := &cobra.Command{
Use: "hosts",
Short: "hosts manager",
//Run: func(cmd *cobra.Command, args []string) {
//
//},
// },
}
// check route for host
hostsCmd.AddCommand(newHostsListCmd())
hostsCmd.AddCommand(newHostsAddCmd())
hostsCmd.AddCommand(newHostsDeleteCmd())
hostsCmd.PersistentFlags().StringVar(&hostsPath, "path", constants.DefaultHostsPath, "default hosts path")
hostsCmd.PersistentFlags().
StringVar(&hostsPath, "path", constants.DefaultHostsPath, "default hosts path")
return hostsCmd
}

func newHostsListCmd() *cobra.Command {
var hostsListCmd = &cobra.Command{
hostsListCmd := &cobra.Command{
Use: "list",
Short: "hosts manager list",
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -58,7 +58,7 @@ func newHostsListCmd() *cobra.Command {

func newHostsAddCmd() *cobra.Command {
var ip, domain string
var hostsAddCmd = &cobra.Command{
hostsAddCmd := &cobra.Command{
Use: "add",
Short: "hosts manager add",
PreRun: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -89,7 +89,7 @@ func newHostsAddCmd() *cobra.Command {

func newHostsDeleteCmd() *cobra.Command {
var domain string
var hostsDeleteCmd = &cobra.Command{
hostsDeleteCmd := &cobra.Command{
Use: "delete",
Short: "hosts manager delete",
PreRun: func(cmd *cobra.Command, args []string) {
Expand Down
13 changes: 5 additions & 8 deletions lifecycle/cmd/sealctl/cmd/initsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ import (
"fmt"
"strings"

"github.com/spf13/cobra"

"github.com/labring/sealos/pkg/utils/initsystem"
"github.com/spf13/cobra"
)

var (
initsystemInterface initsystem.InitSystem
)
var initsystemInterface initsystem.InitSystem

func newInitSystemCmd() *cobra.Command {
var initsystemCmd = &cobra.Command{
initsystemCmd := &cobra.Command{
Use: "initsystem",
Short: "init system management",
}
Expand Down Expand Up @@ -65,9 +62,9 @@ func newInitSystemCmd() *cobra.Command {
func createInitSystemSubCommand(verb string, runE func(string) error) *cobra.Command {
var short string
if strings.HasPrefix(verb, "is-") {
short = fmt.Sprintf("check if the initsystem service is %s", strings.TrimPrefix(verb, "is-"))
short = "check if the initsystem service is " + strings.TrimPrefix(verb, "is-")
} else {
short = fmt.Sprintf("%s the initsystem service", verb)
short = verb + " the initsystem service"
}
return &cobra.Command{
Use: verb,
Expand Down
Loading
Loading