Skip to content

Commit 8cadabc

Browse files
committed
refactor: update code style and improve error handling across multiple files
Signed-off-by: cuisongliu <[email protected]>
1 parent ca2f68f commit 8cadabc

File tree

305 files changed

+5329
-2722
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

305 files changed

+5329
-2722
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ run:
44
go: "1.23"
55
relative-path-mode: gomod
66
modules-download-mode: readonly
7+
skip-dirs:
8+
- tmp
79

810
issues:
911
max-issues-per-linter: 0

lifecycle/cmd/image-cri-shim/cmd/root.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ import (
2828

2929
"github.com/labring/image-cri-shim/pkg/shim"
3030
"github.com/labring/image-cri-shim/pkg/types"
31-
"github.com/spf13/cobra"
32-
3331
"github.com/labring/sealos/pkg/utils/logger"
3432
"github.com/labring/sealos/pkg/version"
33+
"github.com/spf13/cobra"
3534
)
3635

37-
var cfg *types.Config
38-
var shimAuth *types.ShimAuthConfig
39-
var cfgFile string
36+
var (
37+
cfg *types.Config
38+
shimAuth *types.ShimAuthConfig
39+
cfgFile string
40+
)
4041

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

7576
func init() {
76-
rootCmd.Flags().StringVarP(&cfgFile, "file", "f", types.DefaultImageCRIShimConfig, "image shim root config")
77+
rootCmd.Flags().
78+
StringVarP(&cfgFile, "file", "f", types.DefaultImageCRIShimConfig, "image shim root config")
7779
}
7880

7981
func run(cfg *types.Config, auth *types.ShimAuthConfig) {
80-
logger.Info("socket info shim: %v ,image: %v, registry: %v", cfg.ImageShimSocket, cfg.RuntimeSocket, cfg.Address)
82+
logger.Info(
83+
"socket info shim: %v ,image: %v, registry: %v",
84+
cfg.ImageShimSocket,
85+
cfg.RuntimeSocket,
86+
cfg.Address,
87+
)
8188
imgShim, err := shim.NewShim(cfg, auth)
8289
if err != nil {
8390
logger.Fatal("failed to new image_shim, %s", err)
@@ -115,7 +122,12 @@ func run(cfg *types.Config, auth *types.ShimAuthConfig) {
115122
logger.Info("shutting down the image_shim")
116123
}
117124

118-
func watchAuthConfig(ctx context.Context, path string, imgShim shim.Shim, interval time.Duration) error {
125+
func watchAuthConfig(
126+
ctx context.Context,
127+
path string,
128+
imgShim shim.Shim,
129+
interval time.Duration,
130+
) error {
119131
if path == "" {
120132
logger.Warn("config file path is empty, skip dynamic auth reload")
121133
return nil

lifecycle/cmd/image-cri-shim/cmd/root_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ registries:
146146

147147
mirror, ok = auth.CRIConfigs["mirror.example.com"]
148148
if !ok {
149-
t.Fatalf("expected registry credentials for mirror.example.com after update, got %#v", auth.CRIConfigs)
149+
t.Fatalf(
150+
"expected registry credentials for mirror.example.com after update, got %#v",
151+
auth.CRIConfigs,
152+
)
150153
}
151154
if mirror.Password != "changed" {
152155
t.Fatalf("expected updated mirror password, got %q", mirror.Password)

lifecycle/cmd/lvscare/cmd/care.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
package cmd
1616

1717
import (
18-
"github.com/spf13/cobra"
19-
2018
"github.com/labring/lvscare/care"
21-
2219
"github.com/labring/sealos/pkg/utils/flags"
2320
"github.com/labring/sealos/pkg/utils/logger"
21+
"github.com/spf13/cobra"
2422
)
2523

2624
// careCmd represents the care command

lifecycle/cmd/lvscare/cmd/version.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ import (
1919
"fmt"
2020

2121
"github.com/labring/sealos/pkg/version"
22-
2322
"github.com/spf13/cobra"
2423
)
2524

2625
var shortPrint bool
2726

2827
func newVersionCmd() *cobra.Command {
29-
var versionCmd = &cobra.Command{
28+
versionCmd := &cobra.Command{
3029
Use: "version",
3130
Short: "version",
3231
Args: cobra.NoArgs,
@@ -44,7 +43,8 @@ func newVersionCmd() *cobra.Command {
4443
return nil
4544
},
4645
}
47-
versionCmd.Flags().BoolVar(&shortPrint, "short", false, "if true, print just the version number.")
46+
versionCmd.Flags().
47+
BoolVar(&shortPrint, "short", false, "if true, print just the version number.")
4848
return versionCmd
4949
}
5050

lifecycle/cmd/sealctl/cmd/archive.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,51 @@
1515
package cmd
1616

1717
import (
18-
"github.com/spf13/cobra"
19-
2018
"github.com/labring/sealos/pkg/utils/archive"
2119
"github.com/labring/sealos/pkg/utils/flags"
20+
"github.com/spf13/cobra"
2221
)
2322

2423
func newTarCmd() *cobra.Command {
2524
var (
2625
compressionF flags.Compression
2726
output string
28-
clear bool
27+
clearSource bool
2928
)
3029
cmd := &cobra.Command{
3130
Use: "tar",
3231
Short: "creates an archive file from the directory at `path`, note that this will strip the parent dir",
3332
Args: cobra.ExactArgs(1),
3433
SilenceErrors: true,
3534
RunE: func(cmd *cobra.Command, args []string) error {
36-
return archive.Tar(args[0], output, compressionF, clear)
35+
return archive.Tar(args[0], output, compressionF, clearSource)
3736
},
3837
}
39-
cmd.Flags().Var(&compressionF, "compression", "compression algorithm, available options are tar/gzip/zstd/disable")
38+
cmd.Flags().
39+
Var(&compressionF, "compression", "compression algorithm, available options are tar/gzip/zstd/disable")
4040
cmd.Flags().StringVarP(&output, "output", "o", "", "path of archive file")
41-
cmd.Flags().BoolVar(&clear, "clear", false, "remove source after compression finished")
41+
cmd.Flags().BoolVar(&clearSource, "clear", false, "remove source after compression finished")
4242
_ = cmd.MarkFlagRequired("output")
4343
_ = cmd.MarkFlagRequired("compression")
4444
return cmd
4545
}
4646

4747
func newUntarCmd() *cobra.Command {
4848
var (
49-
clear bool
50-
output string
49+
clearSource bool
50+
output string
5151
)
5252
cmd := &cobra.Command{
5353
Use: "untar",
5454
Short: "looks for archive files match glob patterns at filesystem path `src`, and unpacks it at `dst`",
5555
Args: cobra.MinimumNArgs(1),
5656
SilenceErrors: true,
5757
RunE: func(cmd *cobra.Command, args []string) error {
58-
return archive.Untar(args, output, clear)
58+
return archive.Untar(args, output, clearSource)
5959
},
6060
}
6161
cmd.Flags().StringVarP(&output, "output", "o", "", "path to uncompress archive files")
62-
cmd.Flags().BoolVar(&clear, "clear", false, "remove source after uncompression finished")
62+
cmd.Flags().BoolVar(&clearSource, "clear", false, "remove source after uncompression finished")
6363
_ = cmd.MarkFlagRequired("output")
6464
return cmd
6565
}

lifecycle/cmd/sealctl/cmd/cert.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ package cmd
1717
import (
1818
"os"
1919

20-
"github.com/spf13/cobra"
21-
2220
"github.com/labring/sealos/pkg/cert"
2321
"github.com/labring/sealos/pkg/utils/flags"
2422
"github.com/labring/sealos/pkg/utils/logger"
23+
"github.com/spf13/cobra"
2524
)
2625

2726
func newCertCmd() *cobra.Command {
@@ -42,20 +41,31 @@ func newCertCmd() *cobra.Command {
4241
Long: `you can specify expire time`,
4342
Run: func(cmd *cobra.Command, args []string) {
4443
flags.PrintFlags(cmd.Flags())
45-
err := cert.GenerateCert(flag.CertPath, flag.CertEtcdPath, flag.AltNames, flag.NodeIP, flag.NodeName, flag.ServiceCIDR, flag.DNSDomain)
44+
err := cert.GenerateCert(
45+
flag.CertPath,
46+
flag.CertEtcdPath,
47+
flag.AltNames,
48+
flag.NodeIP,
49+
flag.NodeName,
50+
flag.ServiceCIDR,
51+
flag.DNSDomain,
52+
)
4653
if err != nil {
4754
logger.Error(err)
4855
os.Exit(1)
4956
}
5057
},
5158
}
52-
certCmd.Flags().StringSliceVar(&flag.AltNames, "alt-names", []string{}, "like sealos.io or 10.103.97.2")
59+
certCmd.Flags().
60+
StringSliceVar(&flag.AltNames, "alt-names", []string{}, "like sealos.io or 10.103.97.2")
5361
certCmd.Flags().StringVar(&flag.NodeName, "node-name", "", "like master0")
5462
certCmd.Flags().StringVar(&flag.ServiceCIDR, "service-cidr", "", "like 10.103.97.2/24")
5563
certCmd.Flags().StringVar(&flag.NodeIP, "node-ip", "", "like 10.103.97.2")
5664
certCmd.Flags().StringVar(&flag.DNSDomain, "dns-domain", "cluster.local", "cluster dns domain")
57-
certCmd.Flags().StringVar(&flag.CertPath, "cert-path", "/etc/kubernetes/pki", "kubernetes cert file path")
58-
certCmd.Flags().StringVar(&flag.CertEtcdPath, "cert-etcd-path", "/etc/kubernetes/pki/etcd", "kubernetes etcd cert file path")
65+
certCmd.Flags().
66+
StringVar(&flag.CertPath, "cert-path", "/etc/kubernetes/pki", "kubernetes cert file path")
67+
certCmd.Flags().
68+
StringVar(&flag.CertEtcdPath, "cert-etcd-path", "/etc/kubernetes/pki/etcd", "kubernetes etcd cert file path")
5969

6070
return certCmd
6171
}

lifecycle/cmd/sealctl/cmd/cri.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ import (
2121
"os"
2222

2323
"github.com/labring/image-cri-shim/pkg/cri"
24+
"github.com/labring/sealos/pkg/utils/logger"
2425
"github.com/spf13/cobra"
2526
utilsexec "k8s.io/utils/exec"
26-
27-
"github.com/labring/sealos/pkg/utils/logger"
2827
)
2928

3029
var (
@@ -33,7 +32,7 @@ var (
3332
)
3433

3534
func newCRICmd() *cobra.Command {
36-
var criCmd = &cobra.Command{
35+
criCmd := &cobra.Command{
3736
Use: "cri",
3837
Short: "cri manager",
3938
}
@@ -46,7 +45,7 @@ func newCRICmd() *cobra.Command {
4645
}
4746

4847
func newCRISocketCmd() *cobra.Command {
49-
var criSocketCmd = &cobra.Command{
48+
criSocketCmd := &cobra.Command{
5049
Use: "socket",
5150
Short: "cri manager socket",
5251
Run: func(cmd *cobra.Command, args []string) {
@@ -63,7 +62,7 @@ func newCRISocketCmd() *cobra.Command {
6362

6463
func newCGroupDriverCmd() *cobra.Command {
6564
var shortPrint bool
66-
var cGroupDriverCmd = &cobra.Command{
65+
cGroupDriverCmd := &cobra.Command{
6766
Use: "cgroup-driver",
6867
Short: "cri manager cgroup-driver",
6968
PreRun: func(cmd *cobra.Command, args []string) {

lifecycle/cmd/sealctl/cmd/hostname.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
package cmd
1616

1717
import (
18+
"fmt"
1819
"os"
1920

20-
"github.com/spf13/cobra"
21-
2221
"github.com/labring/sealos/pkg/utils/logger"
22+
"github.com/spf13/cobra"
2323
)
2424

2525
func newHostsNameCmd() *cobra.Command {
26-
var hostsNameCmd = &cobra.Command{
26+
hostsNameCmd := &cobra.Command{
2727
Use: "hostname",
2828
Short: "get os.hostname",
2929
Run: func(cmd *cobra.Command, args []string) {
@@ -32,7 +32,7 @@ func newHostsNameCmd() *cobra.Command {
3232
logger.Error(err)
3333
os.Exit(1)
3434
}
35-
print(hostname)
35+
fmt.Print(hostname)
3636
},
3737
}
3838
return hostsNameCmd

lifecycle/cmd/sealctl/cmd/hosts.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,33 @@ package cmd
1919
import (
2020
"os"
2121

22-
"github.com/spf13/cobra"
23-
2422
"github.com/labring/sealos/pkg/constants"
2523
"github.com/labring/sealos/pkg/utils/hosts"
2624
"github.com/labring/sealos/pkg/utils/logger"
25+
"github.com/spf13/cobra"
2726
)
2827

2928
var hostsPath string
3029

3130
func newHostsCmd() *cobra.Command {
32-
var hostsCmd = &cobra.Command{
31+
hostsCmd := &cobra.Command{
3332
Use: "hosts",
3433
Short: "hosts manager",
3534
//Run: func(cmd *cobra.Command, args []string) {
3635
//
37-
//},
36+
// },
3837
}
3938
// check route for host
4039
hostsCmd.AddCommand(newHostsListCmd())
4140
hostsCmd.AddCommand(newHostsAddCmd())
4241
hostsCmd.AddCommand(newHostsDeleteCmd())
43-
hostsCmd.PersistentFlags().StringVar(&hostsPath, "path", constants.DefaultHostsPath, "default hosts path")
42+
hostsCmd.PersistentFlags().
43+
StringVar(&hostsPath, "path", constants.DefaultHostsPath, "default hosts path")
4444
return hostsCmd
4545
}
4646

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

5959
func newHostsAddCmd() *cobra.Command {
6060
var ip, domain string
61-
var hostsAddCmd = &cobra.Command{
61+
hostsAddCmd := &cobra.Command{
6262
Use: "add",
6363
Short: "hosts manager add",
6464
PreRun: func(cmd *cobra.Command, args []string) {
@@ -89,7 +89,7 @@ func newHostsAddCmd() *cobra.Command {
8989

9090
func newHostsDeleteCmd() *cobra.Command {
9191
var domain string
92-
var hostsDeleteCmd = &cobra.Command{
92+
hostsDeleteCmd := &cobra.Command{
9393
Use: "delete",
9494
Short: "hosts manager delete",
9595
PreRun: func(cmd *cobra.Command, args []string) {

0 commit comments

Comments
 (0)