Merge pull request #8103 from AkihiroSuda/go-1.20

Go 1.20.1
This commit is contained in:
Maksym Pavlenko 2023-02-15 20:09:28 -08:00 committed by GitHub
commit 24cf85f5a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 99 additions and 45 deletions

View File

@ -43,7 +43,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.19.6"
go-version: "1.20.1"
- uses: actions/checkout@v3
with:

View File

@ -12,7 +12,7 @@ on:
env:
# Go version we currently use to build containerd across all CI.
# Note: don't forget to update `Binaries` step, as it contains the matrix of all supported Go versions.
GO_VERSION: "1.19.6"
GO_VERSION: "1.20.1"
permissions: # added using https://github.com/step-security/secure-workflows
contents: read
@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v3
- uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1
version: v1.51.1
skip-cache: true
args: --timeout=8m
@ -207,7 +207,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04, macos-12, windows-2019, windows-2022]
go-version: ["1.19.6", "1.18.10"]
go-version: ["1.20.1", "1.19.6"]
steps:
- uses: actions/setup-go@v3
with:

View File

@ -34,7 +34,7 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: 1.19.6
go-version: 1.20.1
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL

View File

@ -42,6 +42,8 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
# FIXME: go-fuzz fails with Go 1.20: `cgo_unix_cgo_res.cgo2.c:(.text+0x32): undefined reference to `__res_search'`
# https://github.com/containerd/containerd/pull/8103#issuecomment-1429256152
go-version: 1.18
- uses: actions/checkout@v3
- run: script/go-test-fuzz.sh

View File

@ -28,7 +28,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.19.6"
go-version: "1.20.1"
- uses: actions/checkout@v3
with:

View File

@ -7,7 +7,7 @@ on:
- ".github/workflows/nightly.yml"
env:
GO_VERSION: "1.19.6"
GO_VERSION: "1.20.1"
permissions: # added using https://github.com/step-security/secure-workflows
contents: read

View File

@ -13,7 +13,7 @@ on:
name: Release
env:
GO_VERSION: "1.19.6"
GO_VERSION: "1.20.1"
permissions: # added using https://github.com/step-security/secure-workflows
contents: read

View File

@ -14,7 +14,7 @@ This doc includes:
To build the `containerd` daemon, and the `ctr` simple test client, the following build system dependencies are required:
* Go 1.18.x or above
* Go 1.19.x or above
* Protoc 3.x compiler and headers (download at the [Google protobuf releases page](https://github.com/protocolbuffers/protobuf/releases))
* Btrfs headers and libraries for your distribution. Note that building the btrfs driver can be disabled via the build tag `no_btrfs`, removing this dependency.

2
Vagrantfile vendored
View File

@ -101,7 +101,7 @@ EOF
config.vm.provision "install-golang", type: "shell", run: "once" do |sh|
sh.upload_path = "/tmp/vagrant-install-golang"
sh.env = {
'GO_VERSION': ENV['GO_VERSION'] || "1.19.6",
'GO_VERSION': ENV['GO_VERSION'] || "1.20.1",
}
sh.inline = <<~SHELL
#!/usr/bin/env bash

View File

@ -20,8 +20,8 @@ import (
"bytes"
"compress/gzip"
"context"
"crypto/rand"
"io"
"math/rand"
"os"
"path/filepath"
"runtime"

View File

@ -341,6 +341,7 @@ func createTarFile(ctx context.Context, path, extractDir string, hdr *tar.Header
}
}
//nolint:staticcheck // TypeRegA is deprecated but we may still receive an external tar with TypeRegA
case tar.TypeReg, tar.TypeRegA:
file, err := openFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, hdrInfo.Mode())
if err != nil {

View File

@ -204,7 +204,6 @@ type Stat struct {
}
func parseStat(data string) (stat Stat, err error) {
//nolint:dupword
// From proc(5), field 2 could contain space and is inside `(` and `)`.
// The following is an example:
// 89653 (gunicorn: maste) S 89630 89653 89653 0 -1 4194560 29689 28896 0 3 146 32 76 19 20 0 1 0 2971844 52965376 3920 18446744073709551615 1 1 0 0 0 0 0 16781312 137447943 0 0 0 17 1 0 0 0 0 0 0 0 0 0 0 0 0 0

View File

@ -23,12 +23,13 @@ import (
"github.com/containerd/containerd/cmd/containerd/command"
"github.com/containerd/containerd/pkg/hasher"
"github.com/containerd/containerd/pkg/seed"
"github.com/containerd/containerd/pkg/seed" //nolint:staticcheck // Global math/rand seed is deprecated, but still used by external dependencies
_ "github.com/containerd/containerd/cmd/containerd/builtins"
)
func init() {
//nolint:staticcheck // Global math/rand seed is deprecated, but still used by external dependencies
seed.WithTimeAndRand()
crypto.RegisterHash(crypto.SHA256, hasher.NewSHA256)
}

View File

@ -23,13 +23,14 @@ import (
"github.com/containerd/containerd/cmd/ctr/app"
"github.com/containerd/containerd/pkg/hasher"
"github.com/containerd/containerd/pkg/seed"
"github.com/containerd/containerd/pkg/seed" //nolint:staticcheck // Global math/rand seed is deprecated, but still used by external dependencies
"github.com/urfave/cli"
)
var pluginCmds = []cli.Command{}
func init() {
//nolint:staticcheck // Global math/rand seed is deprecated, but still used by external dependencies
seed.WithTimeAndRand()
crypto.RegisterHash(crypto.SHA256, hasher.NewSHA256)
}

View File

@ -21,12 +21,12 @@ import (
"errors"
"fmt"
"io"
"math/rand"
"sync"
"time"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/pkg/randutil"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
@ -123,7 +123,7 @@ func OpenWriter(ctx context.Context, cs Ingester, opts ...WriterOpt) (Writer, er
// error or abort. Requires asserting for an ingest manager
select {
case <-time.After(time.Millisecond * time.Duration(rand.Intn(retry))):
case <-time.After(time.Millisecond * time.Duration(randutil.Intn(retry))):
if retry < 2048 {
retry = retry << 1
}

View File

@ -20,7 +20,6 @@ import (
"context"
"fmt"
"io"
"math/rand"
"os"
"path/filepath"
"strconv"
@ -32,6 +31,7 @@ import (
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/filters"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/pkg/randutil"
"github.com/sirupsen/logrus"
"github.com/opencontainers/go-digest"
@ -473,7 +473,7 @@ func (s *store) Writer(ctx context.Context, opts ...content.WriterOpt) (content.
lockErr = nil
break
}
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1<<count)))
time.Sleep(time.Millisecond * time.Duration(randutil.Intn(1<<count)))
}
if lockErr != nil {

View File

@ -20,10 +20,10 @@ import (
"bufio"
"bytes"
"context"
"crypto/rand"
_ "crypto/sha256" // required for digest package
"fmt"
"io"
"math/rand"
"os"
"path/filepath"
"reflect"
@ -35,6 +35,7 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/content/testsuite"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/pkg/randutil"
"github.com/containerd/containerd/pkg/testutil"
"github.com/opencontainers/go-digest"
@ -268,7 +269,7 @@ func generateBlobs(t checker, nblobs, maxsize int64) map[digest.Digest][]byte {
blobs := map[digest.Digest][]byte{}
for i := int64(0); i < nblobs; i++ {
p := make([]byte, rand.Int63n(maxsize))
p := make([]byte, randutil.Int63n(maxsize))
if _, err := rand.Read(p); err != nil {
t.Fatal(err)

View File

@ -29,7 +29,7 @@
# docker run --privileged containerd-test
# ------------------------------------------------------------------------------
ARG GOLANG_VERSION=1.19.6
ARG GOLANG_VERSION=1.20.1
ARG GOLANG_IMAGE=golang
FROM ${GOLANG_IMAGE}:${GOLANG_VERSION} AS golang

View File

@ -18,11 +18,11 @@ package walking
import (
"context"
"crypto/rand"
"encoding/base64"
"errors"
"fmt"
"io"
"math/rand"
"time"
"github.com/containerd/containerd/archive"

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/containerd/containerd
go 1.18
go 1.19
require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1

View File

@ -95,6 +95,7 @@ func ImportIndex(ctx context.Context, store content.Store, reader io.Reader, opt
symlinks[hdr.Name] = path.Join(path.Dir(hdr.Name), hdr.Linkname)
}
//nolint:staticcheck // TypeRegA is deprecated but we may still receive an external tar with TypeRegA
if hdr.Typeflag != tar.TypeReg && hdr.Typeflag != tar.TypeRegA {
if hdr.Typeflag != tar.TypeDir {
log.G(ctx).WithField("file", hdr.Name).Debug("file type ignored")

View File

@ -1,6 +1,6 @@
module github.com/containerd/containerd/integration/client
go 1.18
go 1.19
require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1

View File

@ -17,9 +17,9 @@
package leases
import (
"crypto/rand"
"encoding/base64"
"fmt"
"math/rand"
"time"
)

View File

@ -19,11 +19,11 @@ package mount
import (
"errors"
"fmt"
"math/rand"
"os"
"strings"
"time"
"github.com/containerd/containerd/pkg/randutil"
"golang.org/x/sys/unix"
)
@ -152,7 +152,7 @@ func setupLoop(backingFile string, param LoopParams) (*os.File, error) {
// with EBUSY when trying to set it up.
if strings.Contains(err.Error(), ebusyString) {
// Fallback a bit to avoid live lock
time.Sleep(time.Millisecond * time.Duration(rand.Intn(retry*10)))
time.Sleep(time.Millisecond * time.Duration(randutil.Intn(retry*10)))
continue
}
return nil, err

View File

@ -24,7 +24,6 @@ import (
"github.com/stretchr/testify/assert"
)
//nolint:dupword
const procPIDStatus = `Name: cat
Umask: 0022
State: R (running)

View File

@ -17,8 +17,8 @@
package util
import (
"crypto/rand"
"encoding/hex"
"math/rand"
)
// GenerateID generates a random unique id.

View File

@ -18,21 +18,16 @@ package kmutex
import (
"context"
"math/rand"
"runtime"
"strconv"
"sync"
"testing"
"time"
"github.com/containerd/containerd/pkg/seed"
"github.com/containerd/containerd/pkg/randutil"
"github.com/stretchr/testify/assert"
)
func init() {
seed.WithTimeAndRand()
}
func TestBasic(t *testing.T) {
t.Parallel()
@ -60,7 +55,7 @@ func TestBasic(t *testing.T) {
waitLock = true
break
}
time.Sleep(time.Duration(rand.Int63n(100)) * time.Millisecond)
time.Sleep(time.Duration(randutil.Int63n(100)) * time.Millisecond)
}
assert.Equal(t, waitLock, true)
}
@ -130,7 +125,7 @@ func TestMultileAcquireOnKeys(t *testing.T) {
for i := 0; i < nloops; i++ {
km.Lock(ctx, key)
time.Sleep(time.Duration(rand.Int63n(100)) * time.Nanosecond)
time.Sleep(time.Duration(randutil.Int63n(100)) * time.Nanosecond)
km.Unlock(key)
}
@ -161,7 +156,7 @@ func TestMultiAcquireOnSameKey(t *testing.T) {
for i := 0; i < nloops; i++ {
km.Lock(ctx, key)
time.Sleep(time.Duration(rand.Int63n(100)) * time.Nanosecond)
time.Sleep(time.Duration(randutil.Int63n(100)) * time.Nanosecond)
km.Unlock(key)
}

48
pkg/randutil/randutil.go Normal file
View File

@ -0,0 +1,48 @@
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package randutil provides utilities for [cyrpto/rand].
package randutil
import (
"crypto/rand"
"math"
"math/big"
)
// Int63n is similar to [math/rand.Int63n] but uses [crypto/rand.Reader] under the hood.
func Int63n(n int64) int64 {
b, err := rand.Int(rand.Reader, big.NewInt(n))
if err != nil {
panic(err)
}
return b.Int64()
}
// Int63 is similar to [math/rand.Int63] but uses [crypto/rand.Reader] under the hood.
func Int63() int64 {
return Int63n(math.MaxInt64)
}
// Intn is similar to [math/rand.Intn] but uses [crypto/rand.Reader] under the hood.
func Intn(n int) int {
return int(Int63n(int64(n)))
}
// Int is similar to [math/rand.Int] but uses [crypto/rand.Reader] under the hood.
func Int() int {
return int(Int63())
}

View File

@ -14,6 +14,9 @@
limitations under the License.
*/
// Package seed provides an initializer for the global [math/rand] seed.
//
// Deprecated: Do not rely on the global seed.
package seed
import (
@ -23,6 +26,8 @@ import (
// WithTimeAndRand seeds the global math rand generator with nanoseconds
// XOR'ed with a crypto component if available for uniqueness.
//
// Deprecated: Do not rely on the global seed.
func WithTimeAndRand() {
var (
b [4]byte

View File

@ -18,11 +18,11 @@ package unpack
import (
"context"
"crypto/rand"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"math/rand"
"strconv"
"sync"
"sync/atomic"

View File

@ -332,6 +332,7 @@ func parseHostsFile(baseDir string, b []byte) ([]hostConfig, error) {
// HACK: we want to keep toml parsing structures private in this package, however go-toml ignores private embedded types.
// so we remap it to a public type within the func body, so technically it's public, but not possible to import elsewhere.
//nolint:unused
type HostFileConfig = hostFileConfig
c := struct {

View File

@ -18,9 +18,9 @@ package rootfs
import (
"context"
"crypto/rand"
"encoding/base64"
"fmt"
"math/rand"
"time"
"github.com/containerd/containerd/diff"

View File

@ -5,7 +5,7 @@
# lived test environment.
Set-MpPreference -DisableRealtimeMonitoring:$true
$PACKAGES= @{ mingw = "10.2.0"; git = ""; golang = "1.19.6"; make = ""; nssm = "" }
$PACKAGES= @{ mingw = "10.2.0"; git = ""; golang = "1.20.1"; make = ""; nssm = "" }
Write-Host "Downloading chocolatey package"
curl.exe -L "https://packages.chocolatey.org/chocolatey.0.10.15.nupkg" -o 'c:\choco.zip'

View File

@ -19,10 +19,10 @@ package testsuite
import (
"context"
"fmt"
"math/rand"
"os"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/pkg/randutil"
"github.com/containerd/containerd/snapshots"
"github.com/containerd/continuity/fs/fstest"
)
@ -49,7 +49,7 @@ func applyToMounts(m []mount.Mount, work string, a fstest.Applier) (err error) {
// createSnapshot creates a new snapshot in the snapshotter
// given an applier to run on top of the given parent.
func createSnapshot(ctx context.Context, sn snapshots.Snapshotter, parent, work string, a fstest.Applier) (string, error) {
n := fmt.Sprintf("%p-%d", a, rand.Int())
n := fmt.Sprintf("%p-%d", a, randutil.Int())
prepare := fmt.Sprintf("%s-prepare", n)
m, err := sn.Prepare(ctx, prepare, parent, opt)

View File

@ -21,7 +21,6 @@ import (
//nolint:revive // go-digest needs the blank import. See https://github.com/opencontainers/go-digest#usage.
_ "crypto/sha256"
"fmt"
"math/rand"
"os"
"path/filepath"
"sort"
@ -32,6 +31,7 @@ import (
"github.com/containerd/containerd/log/logtest"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/pkg/randutil"
"github.com/containerd/containerd/pkg/testutil"
"github.com/containerd/containerd/snapshots"
"github.com/containerd/continuity/fs/fstest"
@ -847,7 +847,7 @@ func checkFileFromLowerLayer(ctx context.Context, t *testing.T, snapshotter snap
}
func closeTwice(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
n := fmt.Sprintf("closeTwice-%d", rand.Int())
n := fmt.Sprintf("closeTwice-%d", randutil.Int())
prepare := fmt.Sprintf("%s-prepare", n)
// do some dummy ops to modify the snapshotter internal state