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

Skip podspecs that already have a debug.cloud.google.com/config annotation #4027

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
21 changes: 21 additions & 0 deletions pkg/skaffold/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,24 @@ func TestArtifactImage(t *testing.T) {
debugConfig := pod.ObjectMeta.Annotations["debug.cloud.google.com/config"]
testutil.CheckDeepEqual(t, true, strings.Contains(debugConfig, `"artifact":"gcr.io/random/image"`))
}

// TestTransformPodSpecSkips verifies that transformPodSpec skips podspecs that have a
// `debug.cloud.google.com/config` annotation.
func TestTransformPodSpecSkips(t *testing.T) {
defer func(c []containerTransformer) { containerTransforms = c }(containerTransforms)
containerTransforms = append(containerTransforms, testTransformer{})

pod := v1.Pod{
TypeMeta: metav1.TypeMeta{APIVersion: v1.SchemeGroupVersion.Version, Kind: "Pod"},
ObjectMeta: metav1.ObjectMeta{Name: "podname", Annotations: map[string]string{"debug.cloud.google.com/config": "{}"}},
Spec: v1.PodSpec{Containers: []v1.Container{{Name: "name1", Image: "image1"}}}}

retriever := func(image string) (imageConfiguration, error) {
return imageConfiguration{workingDir: "/a/dir"}, nil
}

copy := pod
result := transformManifest(&pod, retriever)
testutil.CheckDeepEqual(t, false, result)
testutil.CheckDeepEqual(t, copy, pod) // should be unchanged
}
5 changes: 5 additions & 0 deletions pkg/skaffold/debug/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ func transformManifest(obj runtime.Object, retrieveImageConfiguration configurat
// transformPodSpec attempts to configure a podspec for debugging.
// Returns true if changed, false otherwise.
func transformPodSpec(metadata *metav1.ObjectMeta, podSpec *v1.PodSpec, retrieveImageConfiguration configurationRetriever) bool {
// skip annotated podspecs — allows users to customize their own image
briandealwis marked this conversation as resolved.
Show resolved Hide resolved
if _, found := metadata.Annotations[DebugConfigAnnotation]; found {
return false
}

portAlloc := func(desiredPort int32) int32 {
return allocatePort(podSpec, desiredPort)
}
Expand Down