Skip to content

Commit 7f7dbaa

Browse files
committed
fix warnings and import cycle (UT/integration)
1 parent b53ff7b commit 7f7dbaa

File tree

13 files changed

+35
-21
lines changed

13 files changed

+35
-21
lines changed

cmd/skaffold/app/cmd/config/set_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func TestGetConfigStructWithIndex(t *testing.T) {
415415
description: "survey flag set",
416416
cfg: &config.ContextConfig{},
417417
survey: true,
418-
expectedIdx: []int{7},
418+
expectedIdx: []int{9},
419419
},
420420
{
421421
description: "no survey flag set",

docs-v2/content/en/schemas/v4beta12.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,18 @@
17661766
"[\"golang:1.10.1-alpine3.7\", \"alpine:3.7\"]"
17671767
]
17681768
},
1769+
"cacheTo": {
1770+
"items": {
1771+
"type": "string"
1772+
},
1773+
"type": "array",
1774+
"description": "the Docker images used as cache destination. If omitted, cacheFrom is used with max mode to export all layers.",
1775+
"x-intellij-html-description": "the Docker images used as cache destination. If omitted, cacheFrom is used with max mode to export all layers.",
1776+
"default": "[]",
1777+
"examples": [
1778+
"[\"type=registry,ref=gcr.io/k8s-skaffold/example:cache,mode=max\"]"
1779+
]
1780+
},
17691781
"cliFlags": {
17701782
"items": {
17711783
"type": "string"
@@ -1830,6 +1842,7 @@
18301842
"network",
18311843
"addHost",
18321844
"cacheFrom",
1845+
"cacheTo",
18331846
"cliFlags",
18341847
"pullParent",
18351848
"noCache",

pkg/skaffold/build/cache/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func NewCache(ctx context.Context, cfg Config, isLocalImage func(imageName strin
121121
}
122122

123123
// for backward compatibility, extended build capabilities with BuildKit are disabled by default
124-
buildx := cfg.DetectBuildX()
124+
buildx := cfg.DetectBuildX() && docker.IsBuildXDetected()
125125

126126
return &cache{
127127
artifactCache: artifactCache,

pkg/skaffold/build/cache/lookup.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (c *cache) lookup(ctx context.Context, out io.Writer, a *latest.Artifact, t
8787
}
8888

8989
if isLocal, err := c.isLocalImage(a.ImageName); err != nil {
90-
log.Entry(ctx).Debugf("isLocalImage failed %w", err)
90+
log.Entry(ctx).Debugf("isLocalImage failed %v", err)
9191
return failed{err}
9292
} else if isLocal {
9393
return c.lookupLocal(ctx, hash, tag, entry)
@@ -128,7 +128,7 @@ func (c *cache) lookupRemote(ctx context.Context, hash, tag string, platforms []
128128
return found{hash: hash}
129129
}
130130
} else {
131-
log.Entry(ctx).Debugf("RemoteDigest error %w", err)
131+
log.Entry(ctx).Debugf("RemoteDigest error %v", err)
132132
}
133133

134134
// Image exists remotely with a different tag
@@ -162,7 +162,7 @@ func (c *cache) tryImport(ctx context.Context, a *latest.Artifact, tag string, h
162162
_, err := c.client.ServerVersion(ctx)
163163
load = err == nil
164164
if !load {
165-
log.Entry(ctx).Debugf("Docker client error, disabling image load as using buildx: %w", err)
165+
log.Entry(ctx).Debugf("Docker client error, disabling image load as using buildx: %v", err)
166166
}
167167
}
168168
if load {

pkg/skaffold/build/docker/docker.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, name string
143143
var metadata *os.File
144144
if b.buildx {
145145
metadata, err = os.CreateTemp("", "metadata.json")
146+
if err != nil {
147+
return "", fmt.Errorf("unable create temp file: %w", err)
148+
}
146149
metadata.Close()
147150
defer os.Remove(metadata.Name())
148151
args = append(args, "--metadata-file", metadata.Name())
@@ -215,7 +218,7 @@ func (b *Builder) adjustCache(ctx context.Context, a *latest.Artifact, artifactT
215218
tag, _ := config.GetCacheTag(b.cfg.GlobalConfig())
216219
imgRef, err := docker.ParseReference(artifactTag)
217220
if err != nil {
218-
log.Entry(ctx).Errorf("couldn't parse image tag: %w", err)
221+
log.Entry(ctx).Errorf("couldn't parse image tag: %v", err)
219222
} else if tag != "" {
220223
cacheTag = fmt.Sprintf("%s/%s:%s", imgRef.Repo, cacheRef, tag)
221224
}
@@ -273,7 +276,7 @@ func getBuildxDigest(ctx context.Context, filename string) (string, error) {
273276
return digest, nil
274277
}
275278
}
276-
log.Entry(ctx).Warnf("No digest found in buildx metadata: %w", err)
279+
log.Entry(ctx).Warnf("No digest found in buildx metadata: %v", err)
277280
// if image is not pushed, it could not contain the digest log for debugging:
278281
log.Entry(ctx).Debugf("Full buildx metadata: %s", data)
279282
return "", err

pkg/skaffold/build/docker/docker_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func TestDockerCLIBuild(t *testing.T) {
187187
}
188188
t.Override(&util.OSEnviron, func() []string { return []string{"KEY=VALUE"} })
189189

190-
builder := NewArtifactBuilder(fakeLocalDaemonWithExtraEnv(test.extraEnv), test.cfg, test.localBuild.UseDockerCLI, test.localBuild.UseBuildkit, false, mockArtifactResolver{make(map[string]string)}, nil)
190+
builder := NewArtifactBuilder(fakeLocalDaemonWithExtraEnv(test.extraEnv), test.cfg, test.localBuild.UseDockerCLI, test.localBuild.UseBuildkit, false, false, mockArtifactResolver{make(map[string]string)}, nil)
191191

192192
artifact := &latest.Artifact{
193193
Workspace: ".",
@@ -268,7 +268,7 @@ func TestDockerCLICheckCacheFromArgs(t *testing.T) {
268268
)
269269
t.Override(&util.DefaultExecCommand, mockCmd)
270270

271-
builder := NewArtifactBuilder(fakeLocalDaemonWithExtraEnv([]string{}), mockConfig{}, true, util.Ptr(false), false, mockArtifactResolver{make(map[string]string)}, nil)
271+
builder := NewArtifactBuilder(fakeLocalDaemonWithExtraEnv([]string{}), mockConfig{}, true, util.Ptr(false), false, false, mockArtifactResolver{make(map[string]string)}, nil)
272272
_, err := builder.Build(context.Background(), io.Discard, &a, test.tag, platform.Matcher{})
273273
t.CheckNoError(err)
274274
})

pkg/skaffold/build/docker/errors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Refer https://skaffold.dev/docs/references/yaml/#build-artifacts-docker for deta
6060
"docker build . --file "+dockerfilePath+" -t tag",
6161
))
6262
t.Override(&docker.DefaultAuthHelper, stubAuth{})
63-
builder := NewArtifactBuilder(fakeLocalDaemonWithExtraEnv([]string{}), mockConfig{}, true, nil, false, mockArtifactResolver{make(map[string]string)}, nil)
63+
builder := NewArtifactBuilder(fakeLocalDaemonWithExtraEnv([]string{}), mockConfig{}, true, nil, false, false, mockArtifactResolver{make(map[string]string)}, nil)
6464

6565
artifact := &latest.Artifact{
6666
ImageName: "test-image",

pkg/skaffold/build/local/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func NewBuilder(ctx context.Context, bCtx BuilderContext, buildCfg *latest.Local
106106
tryImportMissing := buildCfg.TryImportMissing
107107

108108
// for backward compatibility, extended build capabilities with BuildKit are disabled by default
109-
buildx := bCtx.DetectBuildX()
109+
buildx := bCtx.DetectBuildX() && docker.IsBuildXDetected()
110110

111111
return &Builder{
112112
local: *buildCfg,

pkg/skaffold/config/util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func GetDebugHelpersRegistry(configFile string) (string, error) {
220220
func GetCacheTag(configFile string) (string, error) {
221221
cfg, err := GetConfigForCurrentKubectx(configFile)
222222
if err != nil {
223-
log.Entry(context.TODO()).Errorf("Cannot read cache-tag from config: %w", err)
223+
log.Entry(context.TODO()).Errorf("Cannot read cache-tag from config: %v", err)
224224
return "", err
225225
}
226226
if cfg.CacheTag != "" {
@@ -232,9 +232,9 @@ func GetCacheTag(configFile string) (string, error) {
232232
func GetDetectBuildX(configFile string) bool {
233233
cfg, err := GetConfigForCurrentKubectx(configFile)
234234
if err != nil {
235-
log.Entry(context.TODO()).Errorf("Cannot read detect-buildx option from config: %w", err)
235+
log.Entry(context.TODO()).Errorf("Cannot read detect-buildx option from config: %v", err)
236236
} else if cfg.DetectBuildX != nil {
237-
log.Entry(context.TODO()).Infof("Using detect-buildx=%s from config", *cfg.DetectBuildX)
237+
log.Entry(context.TODO()).Infof("Using detect-buildx=%t from config", *cfg.DetectBuildX)
238238
return *cfg.DetectBuildX
239239
}
240240
return false

pkg/skaffold/docker/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func LoadDockerConfig(access bool) (*configfile.ConfigFile, error) {
7474
defer file.Close()
7575
}
7676
if err != nil {
77-
log.Entry(context.TODO()).Warnf("cannot access docker config file %s: %w", configDir, err)
77+
log.Entry(context.TODO()).Warnf("cannot access docker config file %s: %v", configDir, err)
7878
}
7979
}
8080
return cf, err

0 commit comments

Comments
 (0)