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

fix(ko): Debug port forwarding for ko:// images #7009

Merged
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
3 changes: 2 additions & 1 deletion pkg/skaffold/deploy/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func AddTagsToPodSelector(artifacts []graph.Artifact, deployerArtifacts []graph.
m[a.ImageName] = true
}
for _, artifact := range artifacts {
if _, ok := m[artifact.ImageName]; ok {
imageName := docker.SanitizeImageName(artifact.ImageName)
if _, ok := m[imageName]; ok {
podSelector.Add(artifact.Tag)
}
}
Expand Down
95 changes: 95 additions & 0 deletions pkg/skaffold/deploy/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ package util
import (
"testing"

v1 "k8s.io/api/core/v1"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes"
"github.com/GoogleContainerTools/skaffold/testutil"
)

Expand Down Expand Up @@ -85,3 +89,94 @@ func TestConsolidateNamespaces(t *testing.T) {
})
}
}

func TestAddTagsToPodSelector(t *testing.T) {
tests := []struct {
description string
artifacts []graph.Artifact
deployerArtifacts []graph.Artifact
expectedImages []string
}{
{
description: "empty image list",
},
{
description: "non-matching image results in empty list",
artifacts: []graph.Artifact{
{
ImageName: "my-image",
Tag: "my-image-tag",
},
},
deployerArtifacts: []graph.Artifact{
{
ImageName: "not-my-image",
},
},
},
{
description: "matching images appear in list",
artifacts: []graph.Artifact{
{
ImageName: "my-image1",
Tag: "registry.example.com/repo/my-image1:tag1",
},
{
ImageName: "my-image2",
Tag: "registry.example.com/repo/my-image2:tag2",
},
{
ImageName: "image-not-in-deployer",
Tag: "registry.example.com/repo/my-image3:tag3",
},
},
deployerArtifacts: []graph.Artifact{
{
ImageName: "my-image1",
},
{
ImageName: "my-image2",
},
},
expectedImages: []string{
"registry.example.com/repo/my-image1:tag1",
"registry.example.com/repo/my-image2:tag2",
},
},
{
description: "images from manifest files with ko:// scheme prefix are sanitized before matching",
artifacts: []graph.Artifact{
{
ImageName: "ko://git.example.com/Foo/bar",
Tag: "registry.example.com/repo/git.example.com/foo/bar:tag",
},
},
deployerArtifacts: []graph.Artifact{
{
ImageName: "git.example.com/foo/bar",
Tag: "ko://git.example.com/Foo/bar",
},
},
expectedImages: []string{
"registry.example.com/repo/git.example.com/foo/bar:tag",
},
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
podSelector := kubernetes.NewImageList()
AddTagsToPodSelector(test.artifacts, test.deployerArtifacts, podSelector)
for _, expectedImage := range test.expectedImages {
if exists := podSelector.Select(&v1.Pod{
Spec: v1.PodSpec{
Containers: []v1.Container{
{Image: expectedImage},
},
},
}); !exists {
t.Errorf("expected image list to contain %s", expectedImage)
}
}
})
}
}