Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade golangci-lint version and use it in smoke module #1521

Merged
merged 3 commits into from
Dec 15, 2023
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
cache-dependency-path: "**/*.sum"
- name: Build Contrib
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b /usr/local/bin v1.51.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b /usr/local/bin v1.54.2
make -e DOCKER=false nydusify-release
- name: Upload Nydusify
uses: actions/upload-artifact@master
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/convert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
cache-dependency-path: "**/*.sum"
- name: Build Contrib
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b /usr/local/bin v1.51.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b /usr/local/bin v1.54.2
make -e DOCKER=false nydusify-release
- name: Upload Nydusify
uses: actions/upload-artifact@master
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
cache-dependency-path: "**/*.sum"
- name: Build Contrib
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b /usr/bin v1.51.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b /usr/bin v1.54.2
make -e DOCKER=false nydusify-release
make -e DOCKER=false contrib-test
- name: Upload Nydusify
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
export NYDUS_NYDUSIFY_$version_export=/usr/bin/nydus-$version/nydusify
done

curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b /usr/bin v1.51.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b /usr/bin v1.54.2
sudo -E make smoke-only

nydus-unit-test:
Expand Down
2 changes: 1 addition & 1 deletion contrib/nydusify/pkg/backend/oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func calcCrc64ECMA(path string) (uint64, error) {

// Upload blob as image layer to oss backend and verify
// integrity by calculate CRC64.
func (b *OSSBackend) Upload(ctx context.Context, blobID, blobPath string, size int64, forcePush bool) (*ocispec.Descriptor, error) {
func (b *OSSBackend) Upload(_ context.Context, blobID, blobPath string, size int64, forcePush bool) (*ocispec.Descriptor, error) {
blobObjectKey := b.objectPrefix + blobID

desc := blobDesc(size, blobID)
Expand Down
12 changes: 6 additions & 6 deletions contrib/nydusify/pkg/backend/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Registry struct {
}

func (r *Registry) Upload(
ctx context.Context, blobID, blobPath string, size int64, forcePush bool,
ctx context.Context, blobID, blobPath string, size int64, _ bool,
) (*ocispec.Descriptor, error) {
// The `forcePush` option is useless for registry backend, because
// the blob existed in registry can't be pushed again.
Expand All @@ -35,26 +35,26 @@ func (r *Registry) Upload(
return &desc, nil
}

func (r *Registry) Finalize(cancel bool) error {
func (r *Registry) Finalize(_ bool) error {
return nil
}

func (r *Registry) Check(blobID string) (bool, error) {
func (r *Registry) Check(_ string) (bool, error) {
return true, nil
}

func (r *Registry) Type() Type {
return RegistryBackend
}

func (r *Registry) Reader(blobID string) (io.ReadCloser, error) {
func (r *Registry) Reader(_ string) (io.ReadCloser, error) {
panic("not implemented")
}

func (r *Registry) Size(blobID string) (int64, error) {
func (r *Registry) Size(_ string) (int64, error) {
panic("not implemented")
}

func newRegistryBackend(rawConfig []byte, remote *remote.Remote) (Backend, error) {
func newRegistryBackend(_ []byte, remote *remote.Remote) (Backend, error) {
return &Registry{remote: remote}, nil
}
6 changes: 1 addition & 5 deletions contrib/nydusify/pkg/checker/rule/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,5 @@ func (rule *FilesystemRule) Validate() error {
}
defer nydusd.Umount(false)

if err := rule.verify(); err != nil {
return err
}

return nil
return rule.verify()
}
6 changes: 1 addition & 5 deletions contrib/nydusify/pkg/checker/tool/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,5 @@ func (builder *Builder) Check(option BuilderOption) error {
cmd.Stdout = builder.stdout
cmd.Stderr = builder.stderr

if err := cmd.Run(); err != nil {
return err
}

return nil
return cmd.Run()
}
2 changes: 1 addition & 1 deletion contrib/nydusify/pkg/converter/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (pvd *Provider) Push(ctx context.Context, desc ocispec.Descriptor, ref stri
return push(ctx, pvd.store, rc, desc, ref)
}

func (pvd *Provider) Image(ctx context.Context, ref string) (*ocispec.Descriptor, error) {
func (pvd *Provider) Image(_ context.Context, ref string) (*ocispec.Descriptor, error) {
pvd.mutex.Lock()
defer pvd.mutex.Unlock()
if desc, ok := pvd.images[ref]; ok {
Expand Down
2 changes: 1 addition & 1 deletion contrib/nydusify/pkg/hook/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (p *Plugin) Server(*plugin.MuxBroker) (interface{}, error) {
return &RPCServer{Impl: p.Impl}, nil
}

func (Plugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
func (Plugin) Client(_ *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
return &RPC{client: c}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions contrib/nydusify/pkg/packer/pusher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (m *mockBackend) Upload(ctx context.Context, blobID, blobPath string, blobS
return desc.(*ocispec.Descriptor), nil
}

func (m *mockBackend) Finalize(cancel bool) error {
func (m *mockBackend) Finalize(_ bool) error {
return nil
}

Expand All @@ -36,11 +36,11 @@ func (m *mockBackend) Type() backend.Type {
return backend.OssBackend
}

func (m *mockBackend) Reader(blobID string) (io.ReadCloser, error) {
func (m *mockBackend) Reader(_ string) (io.ReadCloser, error) {
panic("not implemented")
}

func (m *mockBackend) Size(blobID string) (int64, error) {
func (m *mockBackend) Size(_ string) (int64, error) {
panic("not implemented")
}

Expand Down
2 changes: 1 addition & 1 deletion contrib/nydusify/pkg/provider/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ProgressLogger interface {

type defaultLogger struct{}

func (logger *defaultLogger) Log(ctx context.Context, msg string, fields LoggerFields) func(err error) error {
func (logger *defaultLogger) Log(_ context.Context, msg string, fields LoggerFields) func(err error) error {
if fields == nil {
fields = make(LoggerFields)
}
Expand Down
6 changes: 3 additions & 3 deletions contrib/nydusify/pkg/provider/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ type defaultSourceLayer struct {
parentChainID *digest.Digest
}

func (sp *defaultSourceProvider) Manifest(ctx context.Context) (*ocispec.Descriptor, error) {
func (sp *defaultSourceProvider) Manifest(_ context.Context) (*ocispec.Descriptor, error) {
return &sp.image.Desc, nil
}

func (sp *defaultSourceProvider) Config(ctx context.Context) (*ocispec.Image, error) {
func (sp *defaultSourceProvider) Config(_ context.Context) (*ocispec.Image, error) {
return &sp.image.Config, nil
}

func (sp *defaultSourceProvider) Layers(ctx context.Context) ([]SourceLayer, error) {
func (sp *defaultSourceProvider) Layers(_ context.Context) ([]SourceLayer, error) {
layers := sp.image.Manifest.Layers
diffIDs := sp.image.Config.RootFS.DiffIDs
if len(layers) != len(diffIDs) {
Expand Down
2 changes: 0 additions & 2 deletions contrib/nydusify/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ func UnpackFile(reader io.Reader, source, target string) error {
if err != nil {
if err == io.EOF {
break
} else {
return err
}
}
if hdr.Name == source {
Expand Down
4 changes: 2 additions & 2 deletions contrib/nydusify/plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
type LocalHook struct {
}

func (h *LocalHook) BeforePushManifest(info *hook.Info) error {
func (h *LocalHook) BeforePushManifest(_ *hook.Info) error {
return nil
}

func (h *LocalHook) AfterPushManifest(info *hook.Info) error {
func (h *LocalHook) AfterPushManifest(_ *hook.Info) error {
return nil
}

Expand Down
1 change: 1 addition & 0 deletions smoke/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ build:
# NYDUS_NYDUSIFY=/path/to/latest/nydusify \
# make test
test: build
golangci-lint run
sudo -E ./smoke.test -test.v -test.timeout 10m -test.parallel=16 -test.run=$(TESTS)

# PERFORMANCE_TEST_MODE=fs-version-5 \
Expand Down
2 changes: 1 addition & 1 deletion smoke/tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"testing"
"time"

"github.com/containerd/containerd/log"
"github.com/containerd/log"
"github.com/containerd/nydus-snapshotter/pkg/converter"
"github.com/stretchr/testify/require"

Expand Down
11 changes: 5 additions & 6 deletions smoke/tests/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

// Environment Requirement: Containerd, nerdctl >= 0.22, nydus-snapshotter, nydusd, nydus-image and nydusify.
// Prepare: setup nydus for containerd, reference: https://github.com/dragonflyoss/nydus/blob/master/docs/containerd-env-setup.md.
// TestBenchmark will dump json file(benchmark.json) which inlcudes container e2e time, image size, read-amount and read-cout.
// TestBenchmark will dump json file(benchmark.json) which includes container e2e time, image size, read-amount and read-cout.
// Example:
// {
// e2e_time: 2747131
Expand Down Expand Up @@ -68,7 +68,7 @@ func (b *BenchmarkTestSuite) TestBenchmark(t *testing.T) {
b.t.Fatalf("Benchmark don't support image " + image)
}
}
targetImageSize, conversionElapsed := b.prepareImage(b.t, ctx, mode, image)
targetImageSize, conversionElapsed := b.prepareImage(b.t, ctx, image)

// run contaienr
b.testContainerName = uuid.NewString()
Expand All @@ -86,7 +86,7 @@ func (b *BenchmarkTestSuite) TestBenchmark(t *testing.T) {
t.Logf(fmt.Sprintf("Metric: E2ETime %d ConversionElapsed %s ReadCount %d ReadAmount %d ImageSize %d", b.metric.E2ETime, b.metric.ConversionElapsed, b.metric.ReadCount, b.metric.ReadAmountTotal, b.metric.ImageSize))
}

func (b *BenchmarkTestSuite) prepareImage(t *testing.T, ctx *tool.Context, mode string, image string) (int64, int64) {
func (b *BenchmarkTestSuite) prepareImage(t *testing.T, ctx *tool.Context, image string) (int64, int64) {
if b.testImage != "" {
return 0, 0
}
Expand Down Expand Up @@ -129,10 +129,9 @@ func (b *BenchmarkTestSuite) prepareImage(t *testing.T, ctx *tool.Context, mode
if b.snapshotter == "nydus" {
b.testImage = target
return convertMetirc["TargetImageSize"], convertMetirc["ConversionElapsed"]
} else {
b.testImage = source
return convertMetirc["SourceImageSize"], 0
}
b.testImage = source
return convertMetirc["SourceImageSize"], 0
}

func (b *BenchmarkTestSuite) dumpMetric() {
Expand Down
2 changes: 1 addition & 1 deletion smoke/tests/blobcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
"testing"

"github.com/containerd/containerd/log"
"github.com/containerd/log"
"github.com/dragonflyoss/image-service/smoke/tests/texture"
"github.com/dragonflyoss/image-service/smoke/tests/tool"
"github.com/dragonflyoss/image-service/smoke/tests/tool/test"
Expand Down
6 changes: 3 additions & 3 deletions smoke/tests/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type PerformanceTestSuite struct {
testContainerName string
}

func (p *PerformanceTestSuite) TestPerformance(t *testing.T) {
func (p *PerformanceTestSuite) TestPerformance(_ *testing.T) {
ctx := tool.DefaultContext(p.t)
// choose test mode
mode := os.Getenv("PERFORMANCE_TEST_MODE")
Expand Down Expand Up @@ -51,14 +51,14 @@ func (p *PerformanceTestSuite) TestPerformance(t *testing.T) {
}
}
// prepare test image
p.prepareTestImage(p.t, ctx, mode, image)
p.prepareTestImage(p.t, ctx, image)

// run Contaienr
p.testContainerName = uuid.NewString()
tool.RunContainerWithBaseline(p.t, p.testImage, p.testContainerName, mode)
}

func (p *PerformanceTestSuite) prepareTestImage(t *testing.T, ctx *tool.Context, mode string, image string) {
func (p *PerformanceTestSuite) prepareTestImage(t *testing.T, ctx *tool.Context, image string) {
if p.testImage != "" {
return
}
Expand Down
24 changes: 12 additions & 12 deletions smoke/tests/tool/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type mountPath struct {
target string
}

var URL_WAIT = map[string]RunArgs{
var urlWait = map[string]RunArgs{
"wordpress": {
WaitURL: "http://localhost:80",
BaselineReadCount: map[string]uint64{
Expand All @@ -64,7 +64,7 @@ var URL_WAIT = map[string]RunArgs{
},
}

var CMD_STDOUT = map[string]RunArgs{
var cmdStdout = map[string]RunArgs{
"golang": {
Mount: mountPath{
source: "tests/texture/golang",
Expand Down Expand Up @@ -93,13 +93,13 @@ var CMD_STDOUT = map[string]RunArgs{

// SupportContainerImage help to check if we support the image or not
func SupportContainerImage(image string) bool {
_, existsInUrlWait := URL_WAIT[image]
_, existsInCmdStdout := CMD_STDOUT[image]
return existsInUrlWait || existsInCmdStdout
_, existsInURLWait := urlWait[image]
_, existsInCmdStdout := cmdStdout[image]
return existsInURLWait || existsInCmdStdout
}

// runUrlWaitContainer run container util geting http response from WaitUrl
func runUrlWaitContainer(t *testing.T, image string, snapshotter string, containerName string, runArgs RunArgs) {
// runURLWaitContainer run container util getting http response from WaitUrl
func runURLWaitContainer(t *testing.T, image string, snapshotter string, containerName string, runArgs RunArgs) {
cmd := fmt.Sprintf("sudo nerdctl --insecure-registry --snapshotter %s run -d --net=host", snapshotter)
if runArgs.Mount.source != "" {
currentDir, err := os.Getwd()
Expand Down Expand Up @@ -137,9 +137,9 @@ func runCmdStdoutContainer(t *testing.T, image string, snapshotter string, conta
// RunContainerWithBaseline and get metrics from api socket.
// Test will fail if performance below baseline.
func RunContainerWithBaseline(t *testing.T, image string, containerName string, mode string) {
args, ok := URL_WAIT[ImageRepo(t, image)]
args, ok := urlWait[ImageRepo(t, image)]
if ok {
runUrlWaitContainer(t, image, "nydus", containerName, args)
runURLWaitContainer(t, image, "nydus", containerName, args)
defer clearContainer(t, image, "nydus", containerName)
} else {
t.Fatalf(fmt.Sprintf("%s is not in URL_WAIT", image))
Expand All @@ -161,11 +161,11 @@ func RunContainer(t *testing.T, image string, snapshotter string, containerName
startTime := time.Now()

// runContainer
args, ok := URL_WAIT[ImageRepo(t, image)]
args, ok := urlWait[ImageRepo(t, image)]
if ok {
runUrlWaitContainer(t, image, snapshotter, containerName, args)
runURLWaitContainer(t, image, snapshotter, containerName, args)
defer clearContainer(t, image, snapshotter, containerName)
} else if args, ok := CMD_STDOUT[ImageRepo(t, image)]; ok {
} else if args, ok := cmdStdout[ImageRepo(t, image)]; ok {
runCmdStdoutContainer(t, image, snapshotter, containerName, args)
defer clearContainer(t, image, snapshotter, containerName)
}
Expand Down
2 changes: 1 addition & 1 deletion smoke/tests/tool/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ func (ctx *Context) PrepareWorkDir(t *testing.T) {
}
}

func (ctx *Context) Destroy(t *testing.T) {
func (ctx *Context) Destroy(_ *testing.T) {
os.RemoveAll(ctx.Env.WorkDir)
}
5 changes: 2 additions & 3 deletions smoke/tests/tool/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ func (c *DescartesIterator) calNext() {
carried = true
cursors[idx]++
break
} else {
carried = false
cursors[idx] = 0
}
carried = false
cursors[idx] = 0
}
if !carried {
c.noNext()
Expand Down
4 changes: 2 additions & 2 deletions smoke/tests/tool/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (l *Layer) PackRef(t *testing.T, ctx Context, blobDir string, compress bool
return ociBlobDigest, rafsBlobDigest
}

func (l *Layer) Overlay(t *testing.T, upper *Layer) *Layer {
func (l *Layer) Overlay(_ *testing.T, upper *Layer) *Layer {
// Handle whiteout/opaque files
for upperName := range upper.FileTree {
name := filepath.Base(upperName)
Expand Down Expand Up @@ -237,7 +237,7 @@ func (l *Layer) recordFileTree(t *testing.T) {
})
}

func (l *Layer) ToOCITar(t *testing.T) io.ReadCloser {
func (l *Layer) ToOCITar(_ *testing.T) io.ReadCloser {
return archive.Diff(context.Background(), "", l.workDir)
}

Expand Down
Loading