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

[Cache] Ignore file not found #3066

Merged
merged 1 commit into from
Oct 16, 2019
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
6 changes: 6 additions & 0 deletions pkg/skaffold/build/cache/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sort"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
Expand Down Expand Up @@ -59,6 +60,11 @@ func getHashForArtifact(ctx context.Context, depLister DependencyLister, a *late
for _, d := range deps {
h, err := hashFunction(d)
if err != nil {
if os.IsNotExist(err) {
logrus.Tracef("skipping dependency for artifact cache calculation, file not found %s: %s", d, err)
continue // Ignore files that don't exist
}

return "", errors.Wrapf(err, "getting hash for %s", d)
}
inputs = append(inputs, h)
Expand Down
10 changes: 10 additions & 0 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"
"os"
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
Expand All @@ -34,6 +35,9 @@ func (m *stubDependencyLister) DependenciesForArtifact(ctx context.Context, arti
}

var mockCacheHasher = func(s string) (string, error) {
if s == "not-found" {
return "", os.ErrNotExist
}
return s, nil
}

Expand All @@ -57,6 +61,12 @@ func TestGetHashForArtifact(t *testing.T) {
artifact: &latest.Artifact{},
expected: "1caa15f7ce87536bddbac30a39768e8e3b212bf591f9b64926fa50c40b614c66",
},
{
description: "ignore file not found",
dependencies: []string{"a", "b", "not-found"},
artifact: &latest.Artifact{},
expected: "1caa15f7ce87536bddbac30a39768e8e3b212bf591f9b64926fa50c40b614c66",
},
{
description: "dependencies in different orders",
dependencies: []string{"b", "a"},
Expand Down