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

More upgrades #9573

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
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
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
351 changes: 192 additions & 159 deletions go.mod

Large diffs are not rendered by default.

1,502 changes: 418 additions & 1,084 deletions go.sum

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion integration/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"

"github.com/GoogleContainerTools/skaffold/v2/integration/skaffold"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/debug/types"
Expand Down Expand Up @@ -145,7 +146,7 @@ func TestDockerDebug(t *testing.T) {
maxTries = 15 // try for 30 seconds max
)
for {
containers, err := client.ContainerList(context.Background(), dockertypes.ContainerListOptions{All: true})
containers, err := client.ContainerList(context.Background(), container.ListOptions{All: true})
if err != nil {
t.Fail()
}
Expand Down
3 changes: 2 additions & 1 deletion integration/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"

"github.com/GoogleContainerTools/skaffold/v2/integration/skaffold"
Expand Down Expand Up @@ -124,7 +125,7 @@ func getContainers(ctx context.Context, t *testutil.T, deployedContainers []stri
containersFilters = append(containersFilters, filters.Arg("name", c))
}

cl, err := client.ContainerList(ctx, types.ContainerListOptions{
cl, err := client.ContainerList(ctx, container.ListOptions{
Filters: filters.NewArgs(containersFilters...),
})
t.CheckNoError(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/build/buildpacks/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func (r mockArtifactResolver) GetImageTag(imageName string) (string, bool) {

type testAuthHelper struct{}

func (t testAuthHelper) GetAuthConfig(string) (registry.AuthConfig, error) {
func (t testAuthHelper) GetAuthConfig(context.Context, string) (registry.AuthConfig, error) {
return registry.AuthConfig{}, nil
}
func (t testAuthHelper) GetAllAuthConfigs(context.Context) (map[string]registry.AuthConfig, error) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/skaffold/build/buildpacks/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package buildpacks

import (
"fmt"
"io"
"path/filepath"

"github.com/buildpacks/pack/pkg/project"
Expand All @@ -29,15 +30,15 @@ import (
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/util"
)

func GetEnv(a *latest.Artifact, mode config.RunMode) (map[string]string, error) {
func GetEnv(out io.Writer, a *latest.Artifact, mode config.RunMode) (map[string]string, error) {
artifact := a.BuildpackArtifact
workspace := a.Workspace

var projectDescriptor types.Descriptor
path := filepath.Join(workspace, artifact.ProjectDescriptor)
if util.IsFile(path) {
var err error
projectDescriptor, err = project.ReadProjectDescriptor(path)
projectDescriptor, err = project.ReadProjectDescriptor(path, NewLogger(out))
if err != nil {
return nil, fmt.Errorf("failed to read project descriptor %q: %w", path, err)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/build/buildpacks/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ func (f *fetcher) Fetch(ctx context.Context, name string, options packimg.FetchO
}
return image, nil
}

func (f *fetcher) CheckReadAccess(repo string, options packimg.FetchOptions) bool {
return true
}
2 changes: 1 addition & 1 deletion pkg/skaffold/build/buildpacks/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (b *Builder) build(ctx context.Context, out io.Writer, a *latest.Artifact,

// Read `project.toml` if it exists.
path := filepath.Join(workspace, artifact.ProjectDescriptor)
projectDescriptor, err := project.ReadProjectDescriptor(path)
projectDescriptor, err := project.ReadProjectDescriptor(path, NewLogger(out))
if err != nil && !os.IsNotExist(err) {
return "", fmt.Errorf("failed to read project descriptor %q: %w", path, err)
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/skaffold/build/cache/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
)

type artifactHasher interface {
hash(context.Context, *latest.Artifact, platform.Resolver) (string, error)
hash(context.Context, io.Writer, *latest.Artifact, platform.Resolver) (string, error)
}

type artifactHasherImpl struct {
Expand All @@ -67,20 +67,20 @@ func newArtifactHasher(artifacts graph.ArtifactGraph, lister DependencyLister, m
}
}

func (h *artifactHasherImpl) hash(ctx context.Context, a *latest.Artifact, platforms platform.Resolver) (string, error) {
func (h *artifactHasherImpl) hash(ctx context.Context, out io.Writer, a *latest.Artifact, platforms platform.Resolver) (string, error) {
ctx, endTrace := instrumentation.StartTrace(ctx, "hash_GenerateHashOneArtifact", map[string]string{
"ImageName": instrumentation.PII(a.ImageName),
})
defer endTrace()

hash, err := h.safeHash(ctx, a, platforms.GetPlatforms(a.ImageName))
hash, err := h.safeHash(ctx, out, a, platforms.GetPlatforms(a.ImageName))
if err != nil {
endTrace(instrumentation.TraceEndError(err))
return "", err
}
hashes := []string{hash}
for _, dep := range sortedDependencies(a, h.artifacts) {
depHash, err := h.hash(ctx, dep, platforms)
depHash, err := h.hash(ctx, out, dep, platforms)
if err != nil {
endTrace(instrumentation.TraceEndError(err))
return "", err
Expand All @@ -94,15 +94,15 @@ func (h *artifactHasherImpl) hash(ctx context.Context, a *latest.Artifact, platf
return encode(hashes)
}

func (h *artifactHasherImpl) safeHash(ctx context.Context, a *latest.Artifact, platforms platform.Matcher) (string, error) {
func (h *artifactHasherImpl) safeHash(ctx context.Context, out io.Writer, a *latest.Artifact, platforms platform.Matcher) (string, error) {
return h.syncStore.Exec(a.ImageName,
func() (string, error) {
return singleArtifactHash(ctx, h.lister, a, h.mode, platforms)
return singleArtifactHash(ctx, out, h.lister, a, h.mode, platforms)
})
}

// singleArtifactHash calculates the hash for a single artifact, and ignores its required artifacts.
func singleArtifactHash(ctx context.Context, depLister DependencyLister, a *latest.Artifact, mode config.RunMode, m platform.Matcher) (string, error) {
func singleArtifactHash(ctx context.Context, out io.Writer, depLister DependencyLister, a *latest.Artifact, mode config.RunMode, m platform.Matcher) (string, error) {
var inputs []string

// Append the artifact's configuration
Expand Down Expand Up @@ -133,7 +133,7 @@ func singleArtifactHash(ctx context.Context, depLister DependencyLister, a *late
}

// add build args for the artifact if specified
args, err := hashBuildArgs(a, mode)
args, err := hashBuildArgs(out, a, mode)
if err != nil {
return "", fmt.Errorf("hashing build args: %w", err)
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func artifactConfig(a *latest.Artifact) (string, error) {
return string(buf), nil
}

func hashBuildArgs(artifact *latest.Artifact, mode config.RunMode) ([]string, error) {
func hashBuildArgs(out io.Writer, artifact *latest.Artifact, mode config.RunMode) ([]string, error) {
// only one of args or env is ever populated
var args map[string]*string
var env map[string]string
Expand All @@ -182,7 +182,7 @@ func hashBuildArgs(artifact *latest.Artifact, mode config.RunMode) ([]string, er
case artifact.KanikoArtifact != nil:
args, err = docker.EvalBuildArgs(mode, kaniko.GetContext(artifact.KanikoArtifact, artifact.Workspace), artifact.KanikoArtifact.DockerfilePath, artifact.KanikoArtifact.BuildArgs, nil)
case artifact.BuildpackArtifact != nil:
env, err = buildpacks.GetEnv(artifact, mode)
env, err = buildpacks.GetEnv(out, artifact, mode)
case artifact.CustomArtifact != nil && artifact.CustomArtifact.Dependencies.Dockerfile != nil:
args, err = util.EvaluateEnvTemplateMap(artifact.CustomArtifact.Dependencies.Dockerfile.BuildArgs)
default:
Expand Down
21 changes: 11 additions & 10 deletions pkg/skaffold/build/cache/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cache

import (
"context"
"io"
"os"
"testing"

Expand Down Expand Up @@ -161,7 +162,7 @@ func TestGetHashForArtifact(t *testing.T) {
}

depLister := stubDependencyLister(test.dependencies)
actual, err := newArtifactHasher(nil, depLister, test.mode).hash(context.Background(), test.artifact, test.platforms)
actual, err := newArtifactHasher(nil, depLister, test.mode).hash(context.Background(), io.Discard, test.artifact, test.platforms)

t.CheckNoError(err)
t.CheckDeepEqual(test.expected, actual)
Expand Down Expand Up @@ -245,7 +246,7 @@ func TestGetHashForArtifactWithDependencies(t *testing.T) {
return test.fileDeps[a.ImageName], nil
}

actual, err := newArtifactHasher(g, depLister, test.mode).hash(context.Background(), test.artifacts[0], platform.Resolver{})
actual, err := newArtifactHasher(g, depLister, test.mode).hash(context.Background(), io.Discard, test.artifacts[0], platform.Resolver{})

t.CheckNoError(err)
t.CheckDeepEqual(test.expected, actual)
Expand Down Expand Up @@ -308,21 +309,21 @@ func TestBuildArgs(t *testing.T) {
}
t.Override(&fileHasherFunc, mockCacheHasher)
t.Override(&artifactConfigFunc, fakeArtifactConfig)
actual, err := newArtifactHasher(nil, stubDependencyLister(nil), test.mode).hash(context.Background(), artifact, platform.Resolver{})
actual, err := newArtifactHasher(nil, stubDependencyLister(nil), test.mode).hash(context.Background(), io.Discard, artifact, platform.Resolver{})

t.CheckNoError(err)
t.CheckDeepEqual(test.expected, actual)

// Change order of buildargs
artifact.ArtifactType.DockerArtifact.BuildArgs = map[string]*string{"two": util.Ptr("2"), "one": util.Ptr("1")}
actual, err = newArtifactHasher(nil, stubDependencyLister(nil), test.mode).hash(context.Background(), artifact, platform.Resolver{})
actual, err = newArtifactHasher(nil, stubDependencyLister(nil), test.mode).hash(context.Background(), io.Discard, artifact, platform.Resolver{})

t.CheckNoError(err)
t.CheckDeepEqual(test.expected, actual)

// Change build args, get different hash
artifact.ArtifactType.DockerArtifact.BuildArgs = map[string]*string{"one": util.Ptr("1")}
actual, err = newArtifactHasher(nil, stubDependencyLister(nil), test.mode).hash(context.Background(), artifact, platform.Resolver{})
actual, err = newArtifactHasher(nil, stubDependencyLister(nil), test.mode).hash(context.Background(), io.Discard, artifact, platform.Resolver{})

t.CheckNoError(err)
if actual == test.expected {
Expand Down Expand Up @@ -355,7 +356,7 @@ func TestBuildArgsEnvSubstitution(t *testing.T) {
t.Override(&artifactConfigFunc, fakeArtifactConfig)

depLister := stubDependencyLister([]string{"graph"})
hash1, err := newArtifactHasher(nil, depLister, config.RunModes.Build).hash(context.Background(), artifact, platform.Resolver{})
hash1, err := newArtifactHasher(nil, depLister, config.RunModes.Build).hash(context.Background(), io.Discard, artifact, platform.Resolver{})

t.CheckNoError(err)

Expand All @@ -365,7 +366,7 @@ func TestBuildArgsEnvSubstitution(t *testing.T) {
return []string{"FOO=baz"}
}

hash2, err := newArtifactHasher(nil, depLister, config.RunModes.Build).hash(context.Background(), artifact, platform.Resolver{})
hash2, err := newArtifactHasher(nil, depLister, config.RunModes.Build).hash(context.Background(), io.Discard, artifact, platform.Resolver{})

t.CheckNoError(err)
if hash1 == hash2 {
Expand Down Expand Up @@ -422,7 +423,7 @@ func TestCacheHasher(t *testing.T) {
path := originalFile
depLister := stubDependencyLister([]string{tmpDir.Path(originalFile)})

oldHash, err := newArtifactHasher(nil, depLister, config.RunModes.Build).hash(context.Background(), &latest.Artifact{}, platform.Resolver{})
oldHash, err := newArtifactHasher(nil, depLister, config.RunModes.Build).hash(context.Background(), io.Discard, &latest.Artifact{}, platform.Resolver{})
t.CheckNoError(err)

test.update(originalFile, tmpDir)
Expand All @@ -431,7 +432,7 @@ func TestCacheHasher(t *testing.T) {
}

depLister = stubDependencyLister([]string{tmpDir.Path(path)})
newHash, err := newArtifactHasher(nil, depLister, config.RunModes.Build).hash(context.Background(), &latest.Artifact{}, platform.Resolver{})
newHash, err := newArtifactHasher(nil, depLister, config.RunModes.Build).hash(context.Background(), io.Discard, &latest.Artifact{}, platform.Resolver{})

t.CheckNoError(err)
t.CheckFalse(test.differentHash && oldHash == newHash)
Expand Down Expand Up @@ -565,7 +566,7 @@ func TestHashBuildArgs(t *testing.T) {
a.Workspace = tmpDir.Path(".")
a.ArtifactType.KanikoArtifact.DockerfilePath = Dockerfile
}
actual, err := hashBuildArgs(a, test.mode)
actual, err := hashBuildArgs(io.Discard, a, test.mode)
t.CheckNoError(err)
t.CheckDeepEqual(test.expected, actual)
})
Expand Down
8 changes: 4 additions & 4 deletions pkg/skaffold/build/cache/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/util"
)

func (c *cache) lookupArtifacts(ctx context.Context, tags tag.ImageTags, platforms platform.Resolver, artifacts []*latest.Artifact) []cacheDetails {
func (c *cache) lookupArtifacts(ctx context.Context, out io.Writer, tags tag.ImageTags, platforms platform.Resolver, artifacts []*latest.Artifact) []cacheDetails {
details := make([]cacheDetails, len(artifacts))
// Create a new `artifactHasher` on every new dev loop.
// This way every artifact hash is calculated at most once in a single dev loop, and recalculated on every dev loop.
Expand All @@ -48,7 +48,7 @@ func (c *cache) lookupArtifacts(ctx context.Context, tags tag.ImageTags, platfor

i := i
go func() {
details[i] = c.lookup(ctx, artifacts[i], tags[artifacts[i].ImageName], platforms, h)
details[i] = c.lookup(ctx, out, artifacts[i], tags[artifacts[i].ImageName], platforms, h)
wg.Done()
}()
}
Expand All @@ -57,13 +57,13 @@ func (c *cache) lookupArtifacts(ctx context.Context, tags tag.ImageTags, platfor
return details
}

func (c *cache) lookup(ctx context.Context, a *latest.Artifact, tag string, platforms platform.Resolver, h artifactHasher) cacheDetails {
func (c *cache) lookup(ctx context.Context, out io.Writer, a *latest.Artifact, tag string, platforms platform.Resolver, h artifactHasher) cacheDetails {
ctx, endTrace := instrumentation.StartTrace(ctx, "lookup_CacheLookupOneArtifact", map[string]string{
"ImageName": instrumentation.PII(a.ImageName),
})
defer endTrace()

hash, err := h.hash(ctx, a, platforms)
hash, err := h.hash(ctx, out, a, platforms)
if err != nil {
return failed{err: fmt.Errorf("getting hash for artifact %q: %s", a.ImageName, err)}
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/skaffold/build/cache/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"io"
"reflect"
"testing"

Expand Down Expand Up @@ -128,7 +129,7 @@ func TestLookupLocal(t *testing.T) {
}

t.Override(&newArtifactHasherFunc, func(_ graph.ArtifactGraph, _ DependencyLister, _ config.RunMode) artifactHasher { return test.hasher })
details := cache.lookupArtifacts(context.Background(), map[string]string{"artifact": "tag"}, platform.Resolver{}, []*latest.Artifact{{
details := cache.lookupArtifacts(context.Background(), io.Discard, map[string]string{"artifact": "tag"}, platform.Resolver{}, []*latest.Artifact{{
ImageName: "artifact",
}})

Expand Down Expand Up @@ -216,7 +217,7 @@ func TestLookupRemote(t *testing.T) {
cfg: &mockConfig{mode: config.RunModes.Build},
}
t.Override(&newArtifactHasherFunc, func(_ graph.ArtifactGraph, _ DependencyLister, _ config.RunMode) artifactHasher { return test.hasher })
details := cache.lookupArtifacts(context.Background(), map[string]string{"artifact": "tag"}, platform.Resolver{}, []*latest.Artifact{{
details := cache.lookupArtifacts(context.Background(), io.Discard, map[string]string{"artifact": "tag"}, platform.Resolver{}, []*latest.Artifact{{
ImageName: "artifact",
}})

Expand All @@ -232,15 +233,15 @@ type mockHasher struct {
val string
}

func (m mockHasher) hash(context.Context, *latest.Artifact, platform.Resolver) (string, error) {
func (m mockHasher) hash(context.Context, io.Writer, *latest.Artifact, platform.Resolver) (string, error) {
return m.val, nil
}

type failingHasher struct {
err error
}

func (f failingHasher) hash(context.Context, *latest.Artifact, platform.Resolver) (string, error) {
func (f failingHasher) hash(context.Context, io.Writer, *latest.Artifact, platform.Resolver) (string, error) {
return "", f.err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/build/cache/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (c *cache) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, ar
defer endTrace()

lookup := make(chan []cacheDetails)
go func() { lookup <- c.lookupArtifacts(ctx, tags, platforms, artifacts) }()
go func() { lookup <- c.lookupArtifacts(ctx, out, tags, platforms, artifacts) }()

var results []cacheDetails
select {
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/build/cache/retrieve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (b *mockBuilder) Build(ctx context.Context, out io.Writer, tags tag.ImageTa

type stubAuth struct{}

func (t stubAuth) GetAuthConfig(string) (registry.AuthConfig, error) {
func (t stubAuth) GetAuthConfig(context.Context, string) (registry.AuthConfig, error) {
return registry.AuthConfig{}, nil
}
func (t stubAuth) GetAllAuthConfigs(context.Context) (map[string]registry.AuthConfig, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/build/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func (r mockArtifactResolver) GetImageTag(imageName string) (string, bool) {

type stubAuth struct{}

func (t stubAuth) GetAuthConfig(string) (registry.AuthConfig, error) {
func (t stubAuth) GetAuthConfig(context.Context, string) (registry.AuthConfig, error) {
return registry.AuthConfig{}, nil
}
func (t stubAuth) GetAllAuthConfigs(context.Context) (map[string]registry.AuthConfig, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/build/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (

type testAuthHelper struct{}

func (t testAuthHelper) GetAuthConfig(string) (registry.AuthConfig, error) {
func (t testAuthHelper) GetAuthConfig(context.Context, string) (registry.AuthConfig, error) {
return registry.AuthConfig{}, nil
}
func (t testAuthHelper) GetAllAuthConfigs(context.Context) (map[string]registry.AuthConfig, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/skaffold/build/local/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"sync"
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/image"
"github.com/dustin/go-humanize"

"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/docker"
Expand All @@ -49,7 +49,7 @@ func newPruner(dockerAPI docker.LocalDaemon, pruneChildren bool) *pruner {
}
}

func (p *pruner) listImages(ctx context.Context, name string) ([]types.ImageSummary, error) {
func (p *pruner) listImages(ctx context.Context, name string) ([]image.Summary, error) {
imgs, err := p.localDocker.ImageList(ctx, name)
if err != nil {
return nil, err
Expand Down
Loading
Loading