diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index f565c2fcb..23eeb19f8 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -1,5 +1,10 @@ name: golangci-lint on: + push: + tags: + - '!v*' + branches: + - '*' pull_request: jobs: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ad86119c0..ca1db4e5d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,9 +1,15 @@ name: test -on: [push, pull_request] +on: + push: + tags: + - '!v*' + branches: + - '*' + pull_request: jobs: - build: + unittests: runs-on: ubuntu-latest container: projecteru2/footstone:latest diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..b377e543e --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,5 @@ +run: + timeout: 5m + tests: false + skip-dirs: + - tools diff --git a/Makefile b/Makefile index d46b20042..784a76e07 100644 --- a/Makefile +++ b/Makefile @@ -40,9 +40,7 @@ libgit2: cmake --build . sudo cp libgit2.pc /usr/lib/pkgconfig/ sudo cp libgit2.so.1.0.1 /usr/lib - sudo rm -f /usr/lib/libgit2.so.28 /usr/lib/libgit2.so - sudo ln -s /usr/lib/libgit2.so.1.0.1 /usr/lib/libgit2.so.28 - sudo ln -s /usr/lib/libgit2.so.28 /usr/lib/libgit2.so + sudo ln -s /usr/lib/libgit2.so.1.0.1 /usr/lib/libgit2.so sudo cp -aR ../include/* /usr/local/include/ cloc: diff --git a/cluster/calcium/container_test.go b/cluster/calcium/container_test.go index 13cf5227a..4f84ea711 100644 --- a/cluster/calcium/container_test.go +++ b/cluster/calcium/container_test.go @@ -16,7 +16,7 @@ func TestListContainers(t *testing.T) { ctx := context.Background() ID := "testID" containers := []*types.Container{ - &types.Container{ID: ID}, + {ID: ID}, } store := &storemocks.Store{} diff --git a/cluster/calcium/create.go b/cluster/calcium/create.go index 54fa2ce86..471e8f310 100644 --- a/cluster/calcium/create.go +++ b/cluster/calcium/create.go @@ -64,7 +64,9 @@ func (c *Calcium) doCreateContainer(ctx context.Context, opts *types.DeployOptio go metrics.Client.SendDeployCount(nodeInfo.Deploy) go func(nodeInfo types.NodeInfo, index int) { defer func() { - c.store.DeleteProcessing(context.Background(), opts, nodeInfo) + if err := c.store.DeleteProcessing(context.Background(), opts, nodeInfo); err != nil { + log.Errorf("[doCreateContainer] remove processing status failed %v", err) + } wg.Done() }() @@ -212,7 +214,9 @@ func (c *Calcium) doCreateAndStartContainer( // Copy data to container if len(opts.Data) > 0 { for dst, src := range opts.Data { - src.Seek(0, io.SeekStart) + if _, err = src.Seek(0, io.SeekStart); err != nil { + return createContainerMessage + } if err = c.doSendFileToContainer(ctx, node.Engine, containerCreated.ID, dst, src, true, true); err != nil { return createContainerMessage } diff --git a/cluster/calcium/helper.go b/cluster/calcium/helper.go index c08846969..41082d6b2 100644 --- a/cluster/calcium/helper.go +++ b/cluster/calcium/helper.go @@ -169,7 +169,6 @@ func processVirtualizationInStream( log.Errorf("[processVirtualizationInStream] resize window error: %v", err) return } - return }, string(escapeCommand): func(body []byte) { @@ -191,8 +190,7 @@ func rawProcessVirtualizationInStream( defer inStream.Close() for cmd := range inCh { - cmdKey := string(cmd[:1]) - if f, ok := specialPrefixCallback[cmdKey]; ok { + if f, ok := specialPrefixCallback[string(cmd[:1])]; ok { f(cmd[1:]) continue } @@ -223,7 +221,6 @@ func processVirtualizationOutStream( if err := scanner.Err(); err != nil { log.Errorf("[processVirtualizationOutStream] failed to read output from output stream: %v", err) } - return }() return outCh } diff --git a/cluster/calcium/image_test.go b/cluster/calcium/image_test.go index 093f5dfb5..90e85c8c3 100644 --- a/cluster/calcium/image_test.go +++ b/cluster/calcium/image_test.go @@ -27,7 +27,7 @@ func TestRemoveImage(t *testing.T) { assert.Error(t, err) engine := &enginemocks.API{} nodes := []*types.Node{ - &types.Node{ + { Name: "test", Engine: engine, }, @@ -68,7 +68,7 @@ func TestCacheImage(t *testing.T) { assert.Error(t, err) engine := &enginemocks.API{} nodes := []*types.Node{ - &types.Node{ + { Name: "test", Engine: engine, }, diff --git a/cluster/calcium/lambda.go b/cluster/calcium/lambda.go index a0dc08f9d..71c80a1fc 100644 --- a/cluster/calcium/lambda.go +++ b/cluster/calcium/lambda.go @@ -40,8 +40,11 @@ func (c *Calcium) RunAndWait(ctx context.Context, opts *types.DeployOptions, inC lambda := func(message *types.CreateContainerMessage) { defer func() { - c.doRemoveContainerSync(context.Background(), []string{message.ContainerID}) - log.Infof("[RunAndWait] Container %s finished and removed", utils.ShortID(message.ContainerID)) + if err := c.doRemoveContainerSync(context.Background(), []string{message.ContainerID}); err != nil { + log.Errorf("[RunAndWait] Remove lambda container failed %v", err) + } else { + log.Infof("[RunAndWait] Container %s finished and removed", utils.ShortID(message.ContainerID)) + } wg.Done() }() @@ -89,7 +92,6 @@ func (c *Calcium) RunAndWait(ctx context.Context, opts *types.DeployOptions, inC exitData := []byte(exitDataPrefix + strconv.Itoa(int(r.Code))) runMsgCh <- &types.AttachContainerMessage{ContainerID: message.ContainerID, Data: exitData} - return } wg.Add(1) diff --git a/cluster/calcium/lock_test.go b/cluster/calcium/lock_test.go index 88e738e95..66e2ee4e3 100644 --- a/cluster/calcium/lock_test.go +++ b/cluster/calcium/lock_test.go @@ -58,7 +58,7 @@ func TestWithContainersLocked(t *testing.T) { lock.On("Unlock", mock.Anything).Return(nil) // failed to get lock lock.On("Lock", mock.Anything).Return(types.ErrNoETCD).Once() - store.On("GetContainers", mock.Anything, mock.Anything).Return([]*types.Container{&types.Container{}}, nil).Once() + store.On("GetContainers", mock.Anything, mock.Anything).Return([]*types.Container{{}}, nil).Once() err := c.withContainersLocked(ctx, []string{"c1", "c2"}, func(containers map[string]*types.Container) error { return nil }) assert.Error(t, err) // success @@ -92,7 +92,7 @@ func TestWithContainerLocked(t *testing.T) { lock.On("Unlock", mock.Anything).Return(nil) // failed to get lock lock.On("Lock", mock.Anything).Return(types.ErrNoETCD).Once() - store.On("GetContainers", mock.Anything, mock.Anything).Return([]*types.Container{&types.Container{}}, nil).Once() + store.On("GetContainers", mock.Anything, mock.Anything).Return([]*types.Container{{}}, nil).Once() err := c.withContainerLocked(ctx, "c1", func(container *types.Container) error { return nil }) assert.Error(t, err) // success diff --git a/cluster/calcium/node_test.go b/cluster/calcium/node_test.go index a51b5256c..30d5f8303 100644 --- a/cluster/calcium/node_test.go +++ b/cluster/calcium/node_test.go @@ -136,7 +136,7 @@ func TestSetNode(t *testing.T) { store.On("ListNodeContainers", mock.Anything, mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once() _, err = c.SetNode(ctx, &types.SetNodeOptions{Nodename: "test", Status: 0, ContainersDown: true}) assert.Error(t, err) - containers := []*types.Container{&types.Container{Name: "wrong_name"}, &types.Container{Name: "a_b_c"}} + containers := []*types.Container{{Name: "wrong_name"}, {Name: "a_b_c"}} store.On("ListNodeContainers", mock.Anything, mock.Anything, mock.Anything).Return(containers, nil) store.On("SetContainerStatus", mock.Anything, mock.Anything, mock.Anything, diff --git a/cluster/calcium/send_test.go b/cluster/calcium/send_test.go index 7cdd287f2..8cd0838b5 100644 --- a/cluster/calcium/send_test.go +++ b/cluster/calcium/send_test.go @@ -23,7 +23,7 @@ func TestSend(t *testing.T) { opts := &types.SendOptions{ IDs: []string{"cid"}, Data: map[string][]byte{ - "/tmp/1": []byte{}, + "/tmp/1": {}, }, } store := &storemocks.Store{} diff --git a/cluster/calcium/status_test.go b/cluster/calcium/status_test.go index 684cb7ca1..526362bab 100644 --- a/cluster/calcium/status_test.go +++ b/cluster/calcium/status_test.go @@ -34,7 +34,7 @@ func TestSetContainersStatus(t *testing.T) { // failed store.On("GetContainer", mock.Anything, mock.Anything).Return(nil, types.ErrBadCount).Once() - _, err := c.SetContainersStatus(ctx, []*types.StatusMeta{&types.StatusMeta{ID: "123"}}, nil) + _, err := c.SetContainersStatus(ctx, []*types.StatusMeta{{ID: "123"}}, nil) assert.Error(t, err) container := &types.Container{ ID: "123", @@ -47,7 +47,7 @@ func TestSetContainersStatus(t *testing.T) { mock.Anything, mock.Anything, ).Return(types.ErrBadCount).Once() - _, err = c.SetContainersStatus(ctx, []*types.StatusMeta{&types.StatusMeta{ID: "123"}}, nil) + _, err = c.SetContainersStatus(ctx, []*types.StatusMeta{{ID: "123"}}, nil) assert.Error(t, err) // success store.On("SetContainerStatus", @@ -55,7 +55,7 @@ func TestSetContainersStatus(t *testing.T) { mock.Anything, mock.Anything, ).Return(nil) - r, err := c.SetContainersStatus(ctx, []*types.StatusMeta{&types.StatusMeta{ID: "123"}}, nil) + r, err := c.SetContainersStatus(ctx, []*types.StatusMeta{{ID: "123"}}, nil) assert.NoError(t, err) assert.Len(t, r, 1) } diff --git a/core.go b/core.go index b4472a88f..862bf7db8 100644 --- a/core.go +++ b/core.go @@ -87,10 +87,18 @@ func serve() { grpcServer := grpc.NewServer(opts...) pb.RegisterCoreRPCServer(grpcServer, vibranium) - go grpcServer.Serve(s) + go func() { + if err := grpcServer.Serve(s); err != nil { + log.Fatalf("start grpc failed %v", err) + } + }() if config.Profile != "" { http.Handle("/metrics", metrics.Client.ResourceMiddleware(cluster)(promhttp.Handler())) - go http.ListenAndServe(config.Profile, nil) + go func() { + if err := http.ListenAndServe(config.Profile, nil); err != nil { + log.Errorf("start http failed %v", err) + } + }() } log.Info("[main] Cluster started successfully.") @@ -137,5 +145,5 @@ func main() { return nil } - app.Run(os.Args) + _ = app.Run(os.Args) } diff --git a/engine/docker/build.go b/engine/docker/build.go index aa45161dc..b4e56fef7 100644 --- a/engine/docker/build.go +++ b/engine/docker/build.go @@ -176,7 +176,9 @@ func (e *Engine) preparedSource(build *types.Build, scm coresource.Source, build artifactsDir := buildDir if cloneDir != "" { os.RemoveAll(cloneDir) - os.MkdirAll(cloneDir, os.ModeDir) + if err := os.MkdirAll(cloneDir, os.ModeDir); err != nil { + return "", err + } artifactsDir = cloneDir } for _, artifact := range build.Artifacts { diff --git a/engine/docker/container.go b/engine/docker/container.go index 11cf2b915..e9b720b6b 100644 --- a/engine/docker/container.go +++ b/engine/docker/container.go @@ -116,7 +116,7 @@ func (e *Engine) VirtualizationCreate(ctx context.Context, opts *enginetypes.Vir resource := makeResourceSetting(opts.Quota, opts.Memory, opts.CPU, opts.NUMANode, opts.SoftLimit) // set ulimits resource.Ulimits = []*units.Ulimit{ - &units.Ulimit{Name: "nofile", Soft: 65535, Hard: 65535}, + {Name: "nofile", Soft: 65535, Hard: 65535}, } if networkMode.IsHost() { opts.DNS = []string{} diff --git a/engine/docker/helper.go b/engine/docker/helper.go index 57aa355ef..3aafcfe3f 100644 --- a/engine/docker/helper.go +++ b/engine/docker/helper.go @@ -52,7 +52,7 @@ func mergeStream(stream io.ReadCloser) io.Reader { go func() { defer stream.Close() _, err := stdcopy.StdCopy(outw, outw, stream) - outw.CloseWithError(err) + _ = outw.CloseWithError(err) }() return outr @@ -110,7 +110,7 @@ func makeResourceSetting(cpu float64, memory int64, cpuMap map[string]int64, num resource.CPUQuota = -1 } - if cpuMap != nil && len(cpuMap) > 0 { + if len(cpuMap) > 0 { cpuIDs := []string{} for cpuID := range cpuMap { cpuIDs = append(cpuIDs, cpuID) @@ -282,7 +282,7 @@ func parseDockerImageMessages(reader io.ReadCloser) chan *enginetypes.ImageMessa ch := make(chan *enginetypes.ImageMessage) go func() { defer func() { - io.Copy(ioutil.Discard, reader) + _, _ = io.Copy(ioutil.Discard, reader) reader.Close() close(ch) }() diff --git a/engine/systemd/virtualization.go b/engine/systemd/virtualization.go index 9103ece4d..1e0f84905 100644 --- a/engine/systemd/virtualization.go +++ b/engine/systemd/virtualization.go @@ -89,7 +89,7 @@ func (s *SSHClient) VirtualizationStop(ctx context.Context, ID string) (err erro // VirtualizationRemove removes a systemd service func (s *SSHClient) VirtualizationRemove(ctx context.Context, ID string, volumes, force bool) (err error) { if force { - s.VirtualizationStop(ctx, ID) + _ = s.VirtualizationStop(ctx, ID) } // rm -f $FILE @@ -98,7 +98,7 @@ func (s *SSHClient) VirtualizationRemove(ctx context.Context, ID string, volumes } // systemctl daemon-reload - _, stderr, err := s.runSingleCommand(ctx, fmt.Sprintf(cmdSystemdReload), nil) + _, stderr, err := s.runSingleCommand(ctx, cmdSystemdReload, nil) return errors.Wrap(err, stderr.String()) } diff --git a/engine/virt/virt.go b/engine/virt/virt.go index 5588c5595..f51b112ca 100644 --- a/engine/virt/virt.go +++ b/engine/virt/virt.go @@ -40,9 +40,9 @@ type Virt struct { func MakeClient(ctx context.Context, config coretypes.Config, nodename, endpoint, ca, cert, key string) (engine.API, error) { var uri string if strings.HasPrefix(endpoint, HTTPPrefixKey) { - uri = fmt.Sprintf("http://%s/%s", strings.TrimLeft(endpoint, HTTPPrefixKey), config.Virt.APIVersion) + uri = fmt.Sprintf("http://%s/%s", strings.TrimPrefix(endpoint, HTTPPrefixKey), config.Virt.APIVersion) } else if strings.HasPrefix(endpoint, GRPCPrefixKey) { - uri = "grpc://" + strings.TrimLeft(endpoint, GRPCPrefixKey) + uri = "grpc://" + strings.TrimPrefix(endpoint, GRPCPrefixKey) } else { return nil, fmt.Errorf("invalid endpoint: %s", endpoint) } diff --git a/go.mod b/go.mod index 3b54292ca..0b2a08096 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,6 @@ require ( github.com/jinzhu/configor v1.1.1 github.com/jonboulle/clockwork v0.1.0 // indirect github.com/json-iterator/go v1.1.6 // indirect - github.com/libgit2/git2go v0.28.4 // indirect github.com/libgit2/git2go/v30 v30.0.3 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.1 // indirect diff --git a/go.sum b/go.sum index bbe2f3a37..65b481bbf 100644 --- a/go.sum +++ b/go.sum @@ -131,8 +131,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/libgit2/git2go v0.28.4 h1:xfXnDnt31R2p7Yea7023C//NglM/1v+w87peBBwLZ3U= -github.com/libgit2/git2go v0.28.4/go.mod h1:4bKN42efkbNYMZlvDfxGDxzl066GhpvIircZDsm8Y+Y= github.com/libgit2/git2go/v30 v30.0.3 h1:v+KRMhx85kHS0JzkPft7Wnt3+VUrYQrD/SQ77usTO/w= github.com/libgit2/git2go/v30 v30.0.3/go.mod h1:YReiQ7xhMoyAL4ISYFLZt+OGqn6xtLqvTC1xJ9oAH7Y= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= diff --git a/rpc/rpc.go b/rpc/rpc.go index 94f3ae169..08a4b95d9 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -442,11 +442,13 @@ func (v *Vibranium) RunAndWait(stream pb.CoreRPC_RunAndWaitServer) error { } }) } - go runAndWait(func(ch <-chan *types.AttachContainerMessage) { - for m := range ch { - log.Infof("[Async RunAndWait] %v", string(m.Data)) - } - }) + go func() { + _ = runAndWait(func(ch <-chan *types.AttachContainerMessage) { + for m := range ch { + log.Infof("[Async RunAndWait] %v", string(m.Data)) + } + }) + }() return nil } @@ -712,7 +714,7 @@ func (v *Vibranium) ExecuteContainer(stream pb.CoreRPC_ExecuteContainerServer) ( if err != nil { return } - executeContainerOpts := &types.ExecuteContainerOptions{} + var executeContainerOpts *types.ExecuteContainerOptions if executeContainerOpts, err = toCoreExecuteContainerOptions(opts); err != nil { return } diff --git a/scheduler/complex/cpu.go b/scheduler/complex/cpu.go index 62c79bcd8..80a036546 100644 --- a/scheduler/complex/cpu.go +++ b/scheduler/complex/cpu.go @@ -19,8 +19,6 @@ func min(a, b int) int { return b } -type cpuInfo = resourceInfo - func cpuPriorPlan(cpu float64, memory int64, nodesInfo []types.NodeInfo, maxShareCore, coreShare int) ([]types.NodeInfo, map[string][]types.CPUMap, int, error) { var nodeContainer = map[string][]types.CPUMap{} volTotal := 0 diff --git a/scheduler/complex/cpu_test.go b/scheduler/complex/cpu_test.go index 7bce2b086..77cd599a8 100644 --- a/scheduler/complex/cpu_test.go +++ b/scheduler/complex/cpu_test.go @@ -40,7 +40,7 @@ func TestCPUPriorPlan(t *testing.T) { func resetNodesInfo() []types.NodeInfo { return []types.NodeInfo{ - types.NodeInfo{ + { Name: "n1", CPUMap: types.CPUMap{"1": 100, "2": 100, "3": 100, "4": 100}, MemCap: 3 * int64(units.GiB), diff --git a/scheduler/complex/potassium.go b/scheduler/complex/potassium.go index 582635a9b..9db33b416 100644 --- a/scheduler/complex/potassium.go +++ b/scheduler/complex/potassium.go @@ -94,7 +94,6 @@ func (m *Potassium) SelectMemoryNodes(nodesInfo []types.NodeInfo, quota float64, if p == nodesInfoLength { return nil, 0, types.ErrInsufficientMEM } - nodesInfoLength -= p nodesInfo = nodesInfo[p:] // 这里 memCap 一定是大于 memory 的所以不用判断 cap 内容 diff --git a/scheduler/complex/resource.go b/scheduler/complex/resource.go index f94f65b79..496324d87 100644 --- a/scheduler/complex/resource.go +++ b/scheduler/complex/resource.go @@ -74,11 +74,7 @@ func (h *host) getComplexResult(full int, fragment int64, maxShare int) []types. for i := 0; i < baseLine; i++ { r := types.ResourceMap{} for id, pieces := range fullResult[i] { - if _, ok := r[id]; ok { - r[id] += pieces - } else { - r[id] = pieces - } + r[id] += pieces } for id, pieces := range fragmentResult[i] { r[id] = pieces diff --git a/scheduler/complex/utils.go b/scheduler/complex/utils.go index d47710bc1..e3bb9cca7 100644 --- a/scheduler/complex/utils.go +++ b/scheduler/complex/utils.go @@ -1,9 +1,7 @@ package complexscheduler import ( - "math/rand" "sort" - "time" "github.com/projecteru2/core/types" "github.com/projecteru2/core/utils" @@ -31,12 +29,6 @@ func onSameSource(plan []types.ResourceMap) bool { return true } -func shuffle(nodesInfo []types.NodeInfo) []types.NodeInfo { - rand.Seed(time.Now().UnixNano()) - rand.Shuffle(len(nodesInfo), func(i, j int) { nodesInfo[i], nodesInfo[j] = nodesInfo[j], nodesInfo[i] }) - return nodesInfo -} - func scoreSort(nodesInfo []types.NodeInfo, byResource types.ResourceType) []types.NodeInfo { sort.Slice(nodesInfo, func(i, j int) bool { return nodesInfo[i].GetResourceUsage(byResource) < nodesInfo[j].GetResourceUsage(byResource) diff --git a/scheduler/complex/utils_test.go b/scheduler/complex/utils_test.go index 5a11ee466..f01ba2be3 100644 --- a/scheduler/complex/utils_test.go +++ b/scheduler/complex/utils_test.go @@ -7,25 +7,9 @@ import ( "github.com/stretchr/testify/assert" ) -func TestShuffle(t *testing.T) { - ns := []types.NodeInfo{ - types.NodeInfo{ - Name: "n1", - }, - types.NodeInfo{ - Name: "n2", - }, - types.NodeInfo{ - Name: "n3", - }, - } - n2 := shuffle(ns) - assert.Len(t, ns, len(n2)) -} - func TestScoreSort(t *testing.T) { ns := []types.NodeInfo{ - types.NodeInfo{ + { Name: "n1", Usages: map[types.ResourceType]float64{ types.ResourceCPU: 0.1, @@ -33,7 +17,7 @@ func TestScoreSort(t *testing.T) { types.ResourceMemory: 0.4, }, }, - types.NodeInfo{ + { Name: "n2", Usages: map[types.ResourceType]float64{ types.ResourceCPU: 0.3, @@ -41,7 +25,7 @@ func TestScoreSort(t *testing.T) { types.ResourceMemory: 0.1, }, }, - types.NodeInfo{ + { Name: "n3", Usages: map[types.ResourceType]float64{ types.ResourceCPU: 0.2, diff --git a/source/common/common.go b/source/common/common.go index 3e3900a05..107824e82 100644 --- a/source/common/common.go +++ b/source/common/common.go @@ -87,21 +87,23 @@ func (g *GitScm) SourceCode(repository, path, revision string, submodule bool) e // Prepare submodules if submodule { - repo.Submodules.Foreach(func(sub *git.Submodule, name string) int { - sub.Init(true) - err := sub.Update(true, &git.SubmoduleUpdateOptions{ + err = repo.Submodules.Foreach(func(sub *git.Submodule, name string) int { + if err := sub.Init(true); err != nil { + log.Errorf("[SourceCode] init submodule failed %v", err) + return 0 + } + if err := sub.Update(true, &git.SubmoduleUpdateOptions{ CheckoutOpts: &git.CheckoutOpts{ Strategy: git.CheckoutForce | git.CheckoutUpdateSubmodules, }, FetchOptions: &git.FetchOptions{}, - }) - if err != nil { - log.Errorln(err) + }); err != nil { + log.Errorf("[SourceCode] update submodules failed %v", err) } return 0 }) } - return nil + return err } // Artifact download the artifact to the path, then unzip it @@ -158,7 +160,7 @@ func unzipFile(body io.ReadCloser, path string) error { p := filepath.Join(path, f.Name) if f.FileInfo().IsDir() { - os.MkdirAll(p, f.Mode()) + _ = os.MkdirAll(p, f.Mode()) continue } diff --git a/types/node_test.go b/types/node_test.go index 7bae968f4..b0c228627 100644 --- a/types/node_test.go +++ b/types/node_test.go @@ -123,8 +123,8 @@ func TestVolumePlan(t *testing.T) { assert.Equal(t, plan.IntoVolumeMap(), VolumeMap{"/dir0": 100, "/dir1": 2000}) literal := map[string]map[string]int64{ - "AUTO:/data0:rw:100": map[string]int64{"/dir0": 100}, - "AUTO:/data1:ro:2000": map[string]int64{"/dir1": 2000}, + "AUTO:/data0:rw:100": {"/dir0": 100}, + "AUTO:/data1:ro:2000": {"/dir1": 2000}, } assert.Equal(t, MustToVolumePlan(literal), plan) assert.Equal(t, plan.ToLiteral(), literal) diff --git a/types/volume.go b/types/volume.go index 849456d9b..2cfa1ddbb 100644 --- a/types/volume.go +++ b/types/volume.go @@ -152,11 +152,7 @@ func (vbs VolumeBindings) Merge(vbs2 VolumeBindings) (softVolumes VolumeBindings sizeMap := map[[3]string]int64{} // {["AUTO", "/data", "rw"]: 100} for _, vb := range append(vbs, vbs2...) { key := [3]string{vb.Source, vb.Destination, vb.Flags} - if _, ok := sizeMap[key]; ok { - sizeMap[key] += vb.SizeInBytes - } else { - sizeMap[key] = vb.SizeInBytes - } + sizeMap[key] += vb.SizeInBytes } for key, size := range sizeMap { diff --git a/utils/utils.go b/utils/utils.go index a96dbdce4..ae9e77763 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -15,8 +15,6 @@ import ( log "github.com/sirupsen/logrus" ) -type ctxKey string - const ( letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" shortenLength = 7