Skip to content

Commit

Permalink
Add debugHelpersRegistry property
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed May 19, 2020
1 parent a5f26d6 commit c04909c
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 50 deletions.
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/config/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func TestGetConfigStructWithIndex(t *testing.T) {
description: "survey flag set",
cfg: &config.ContextConfig{},
survey: true,
expectedIdx: []int{5},
expectedIdx: []int{6},
},
{
description: "no survey flag set",
Expand Down
14 changes: 8 additions & 6 deletions pkg/skaffold/config/global_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ type GlobalConfig struct {
// ContextConfig is the context-specific config information provided in
// the global Skaffold config.
type ContextConfig struct {
Kubecontext string `yaml:"kube-context,omitempty"`
DefaultRepo string `yaml:"default-repo,omitempty"`
LocalCluster *bool `yaml:"local-cluster,omitempty"`
InsecureRegistries []string `yaml:"insecure-registries,omitempty"`
UpdateCheck *bool `yaml:"update-check,omitempty"`
Survey *SurveyConfig `yaml:"survey,omitempty"`
Kubecontext string `yaml:"kube-context,omitempty"`
DefaultRepo string `yaml:"default-repo,omitempty"`
LocalCluster *bool `yaml:"local-cluster,omitempty"`
InsecureRegistries []string `yaml:"insecure-registries,omitempty"`
// DebugHelpersRegistry is the registry from which the debug helper images are used.
DebugHelpersRegistry string `yaml:"debug-helpers-registry,omitempty"`
UpdateCheck *bool `yaml:"update-check,omitempty"`
Survey *SurveyConfig `yaml:"survey,omitempty"`
}

// SurveyConfig is the survey config information
Expand Down
13 changes: 13 additions & 0 deletions pkg/skaffold/config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,19 @@ func GetInsecureRegistries(configFile string) ([]string, error) {
return cfg.InsecureRegistries, nil
}

func GetDebugHelpersRegistry(configFile string) (string, error) {
cfg, err := GetConfigForCurrentKubectx(configFile)
if err != nil {
return "", err
}

if cfg.DebugHelpersRegistry == "" {
return constants.DefaultDebugHelpersRegistry, nil
}

return cfg.DebugHelpersRegistry, nil
}

func isDefaultLocal(kubeContext string) bool {
if kubeContext == constants.DefaultMinikubeContext ||
kubeContext == constants.DefaultDockerForDesktopContext ||
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ const (

DefaultBusyboxImage = "busybox"

// DefaultDebugHelpersRegistry is the default location used for the helper images for `debug`.
DefaultDebugHelpersRegistry = "gcr.io/gcp-dev-tools/duct-tape"

UpdateCheckEnvironmentVariable = "SKAFFOLD_UPDATE_CHECK"

DefaultSkaffoldDir = ".skaffold"
Expand Down
11 changes: 6 additions & 5 deletions pkg/skaffold/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/client-go/kubernetes/scheme"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/kubectl"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
Expand All @@ -49,26 +50,26 @@ var (
)

// ApplyDebuggingTransforms applies language-platform-specific transforms to a list of manifests.
func ApplyDebuggingTransforms(l kubectl.ManifestList, builds []build.Artifact, insecureRegistries map[string]bool) (kubectl.ManifestList, error) {
func ApplyDebuggingTransforms(l kubectl.ManifestList, builds []build.Artifact, registries deploy.Registries) (kubectl.ManifestList, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

retriever := func(image string) (imageConfiguration, error) {
if artifact := findArtifact(image, builds); artifact != nil {
return retrieveImageConfiguration(ctx, artifact, insecureRegistries)
return retrieveImageConfiguration(ctx, artifact, registries.InsecureRegistries)
}
return imageConfiguration{}, fmt.Errorf("no build artifact for %q", image)
}
return applyDebuggingTransforms(l, retriever)
return applyDebuggingTransforms(l, retriever, registries.DebugHelpersRegistry)
}

func applyDebuggingTransforms(l kubectl.ManifestList, retriever configurationRetriever) (kubectl.ManifestList, error) {
func applyDebuggingTransforms(l kubectl.ManifestList, retriever configurationRetriever, debugHelpersRegistry string) (kubectl.ManifestList, error) {
var updated kubectl.ManifestList
for _, manifest := range l {
obj, _, err := decodeFromYaml(manifest, nil, nil)
if err != nil {
logrus.Debugf("Unable to interpret manifest for debugging: %v\n", err)
} else if transformManifest(obj, retriever) {
} else if transformManifest(obj, retriever, debugHelpersRegistry) {
manifest, err = encodeAsYaml(obj)
if err != nil {
return nil, fmt.Errorf("marshalling yaml: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/skaffold/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ spec:
return imageConfiguration{}, nil
}

result, err := applyDebuggingTransforms(kubectl.ManifestList{[]byte(test.in)}, retriever)
result, err := applyDebuggingTransforms(kubectl.ManifestList{[]byte(test.in)}, retriever, "HELPERS")

t.CheckErrorAndDeepEqual(test.shouldErr, err, test.out, result.String())
})
Expand All @@ -529,7 +529,7 @@ func TestWorkingDir(t *testing.T) {
return imageConfiguration{workingDir: "/a/dir"}, nil
}

result := transformManifest(pod, retriever)
result := transformManifest(pod, retriever, "HELPERS")
testutil.CheckDeepEqual(t, true, result)
debugConfig := pod.ObjectMeta.Annotations["debug.cloud.google.com/config"]
testutil.CheckDeepEqual(t, true, strings.Contains(debugConfig, `"workingDir":"/a/dir"`))
Expand All @@ -548,7 +548,7 @@ func TestArtifactImage(t *testing.T) {
return imageConfiguration{artifact: "gcr.io/random/image"}, nil
}

result := transformManifest(pod, retriever)
result := transformManifest(pod, retriever, "HELPERS")
testutil.CheckDeepEqual(t, true, result)
debugConfig := pod.ObjectMeta.Annotations["debug.cloud.google.com/config"]
testutil.CheckDeepEqual(t, true, strings.Contains(debugConfig, `"artifact":"gcr.io/random/image"`))
Expand Down
23 changes: 11 additions & 12 deletions pkg/skaffold/debug/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ func isEntrypointLauncher(entrypoint []string) bool {

// transformManifest attempts to configure a manifest for debugging.
// Returns true if changed, false otherwise.
func transformManifest(obj runtime.Object, retrieveImageConfiguration configurationRetriever) bool {
func transformManifest(obj runtime.Object, retrieveImageConfiguration configurationRetriever, debugHelpersRegistry string) bool {
one := int32(1)
switch o := obj.(type) {
case *v1.Pod:
return transformPodSpec(&o.ObjectMeta, &o.Spec, retrieveImageConfiguration)
return transformPodSpec(&o.ObjectMeta, &o.Spec, retrieveImageConfiguration, debugHelpersRegistry)
case *v1.PodList:
changed := false
for i := range o.Items {
if transformPodSpec(&o.Items[i].ObjectMeta, &o.Items[i].Spec, retrieveImageConfiguration) {
if transformPodSpec(&o.Items[i].ObjectMeta, &o.Items[i].Spec, retrieveImageConfiguration, debugHelpersRegistry) {
changed = true
}
}
Expand All @@ -157,26 +157,26 @@ func transformManifest(obj runtime.Object, retrieveImageConfiguration configurat
if o.Spec.Replicas != nil {
o.Spec.Replicas = &one
}
return transformPodSpec(&o.Spec.Template.ObjectMeta, &o.Spec.Template.Spec, retrieveImageConfiguration)
return transformPodSpec(&o.Spec.Template.ObjectMeta, &o.Spec.Template.Spec, retrieveImageConfiguration, debugHelpersRegistry)
case *appsv1.Deployment:
if o.Spec.Replicas != nil {
o.Spec.Replicas = &one
}
return transformPodSpec(&o.Spec.Template.ObjectMeta, &o.Spec.Template.Spec, retrieveImageConfiguration)
return transformPodSpec(&o.Spec.Template.ObjectMeta, &o.Spec.Template.Spec, retrieveImageConfiguration, debugHelpersRegistry)
case *appsv1.DaemonSet:
return transformPodSpec(&o.Spec.Template.ObjectMeta, &o.Spec.Template.Spec, retrieveImageConfiguration)
return transformPodSpec(&o.Spec.Template.ObjectMeta, &o.Spec.Template.Spec, retrieveImageConfiguration, debugHelpersRegistry)
case *appsv1.ReplicaSet:
if o.Spec.Replicas != nil {
o.Spec.Replicas = &one
}
return transformPodSpec(&o.Spec.Template.ObjectMeta, &o.Spec.Template.Spec, retrieveImageConfiguration)
return transformPodSpec(&o.Spec.Template.ObjectMeta, &o.Spec.Template.Spec, retrieveImageConfiguration, debugHelpersRegistry)
case *appsv1.StatefulSet:
if o.Spec.Replicas != nil {
o.Spec.Replicas = &one
}
return transformPodSpec(&o.Spec.Template.ObjectMeta, &o.Spec.Template.Spec, retrieveImageConfiguration)
return transformPodSpec(&o.Spec.Template.ObjectMeta, &o.Spec.Template.Spec, retrieveImageConfiguration, debugHelpersRegistry)
case *batchv1.Job:
return transformPodSpec(&o.Spec.Template.ObjectMeta, &o.Spec.Template.Spec, retrieveImageConfiguration)
return transformPodSpec(&o.Spec.Template.ObjectMeta, &o.Spec.Template.Spec, retrieveImageConfiguration, debugHelpersRegistry)

default:
group, version, _, description := describe(obj)
Expand All @@ -196,7 +196,7 @@ 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 {
func transformPodSpec(metadata *metav1.ObjectMeta, podSpec *v1.PodSpec, retrieveImageConfiguration configurationRetriever, debugHelpersRegistry string) bool {
// skip annotated podspecs — allows users to customize their own image
if _, found := metadata.Annotations[DebugConfigAnnotation]; found {
return false
Expand Down Expand Up @@ -245,11 +245,10 @@ func transformPodSpec(metadata *metav1.ObjectMeta, podSpec *v1.PodSpec, retrieve
// this volume is mounted in the containers at `/dbg`
supportVolumeMount := v1.VolumeMount{Name: debuggingSupportFilesVolume, MountPath: "/dbg"}
// the initContainers are responsible for populating the contents of `/dbg`
// TODO make this pluggable for airgapped clusters? or is making container `imagePullPolicy:IfNotPresent` sufficient?
for imageID := range requiredSupportImages {
supportFilesInitContainer := v1.Container{
Name: fmt.Sprintf("install-%s-support", imageID),
Image: fmt.Sprintf("gcr.io/gcp-dev-tools/duct-tape/%s", imageID),
Image: fmt.Sprintf("%s/%s", debugHelpersRegistry, imageID),
VolumeMounts: []v1.VolumeMount{supportVolumeMount},
}
podSpec.InitContainers = append(podSpec.InitContainers, supportFilesInitContainer)
Expand Down
18 changes: 9 additions & 9 deletions pkg/skaffold/debug/transform_go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func TestTransformManifestDelve(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-go-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/go",
Image: "HELPERS/go",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestTransformManifestDelve(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-go-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/go",
Image: "HELPERS/go",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestTransformManifestDelve(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-go-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/go",
Image: "HELPERS/go",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand Down Expand Up @@ -390,7 +390,7 @@ func TestTransformManifestDelve(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-go-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/go",
Image: "HELPERS/go",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand Down Expand Up @@ -431,7 +431,7 @@ func TestTransformManifestDelve(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-go-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/go",
Image: "HELPERS/go",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand Down Expand Up @@ -472,7 +472,7 @@ func TestTransformManifestDelve(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-go-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/go",
Image: "HELPERS/go",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand Down Expand Up @@ -515,7 +515,7 @@ func TestTransformManifestDelve(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-go-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/go",
Image: "HELPERS/go",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand Down Expand Up @@ -568,7 +568,7 @@ func TestTransformManifestDelve(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-go-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/go",
Image: "HELPERS/go",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand All @@ -586,7 +586,7 @@ func TestTransformManifestDelve(t *testing.T) {
retriever := func(image string) (imageConfiguration, error) {
return imageConfiguration{}, nil
}
result := transformManifest(value, retriever)
result := transformManifest(value, retriever, "HELPERS")

t.CheckDeepEqual(test.transformed, result)
t.CheckDeepEqual(test.out, value)
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/debug/transform_jvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func TestTransformManifestJVM(t *testing.T) {
retriever := func(image string) (imageConfiguration, error) {
return imageConfiguration{}, nil
}
result := transformManifest(value, retriever)
result := transformManifest(value, retriever, "HELPERS")

t.CheckDeepEqual(test.transformed, result)
t.CheckDeepEqual(test.out, value)
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/debug/transform_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func TestTransformManifestNodeJS(t *testing.T) {
retriever := func(image string) (imageConfiguration, error) {
return imageConfiguration{}, nil
}
result := transformManifest(value, retriever)
result := transformManifest(value, retriever, "HELPERS")

t.CheckDeepEqual(test.transformed, result)
t.CheckDeepEqual(test.out, value)
Expand Down
18 changes: 9 additions & 9 deletions pkg/skaffold/debug/transform_python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func TestTransformManifestPython(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-python-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/python",
Image: "HELPERS/python",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand Down Expand Up @@ -306,7 +306,7 @@ func TestTransformManifestPython(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-python-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/python",
Image: "HELPERS/python",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestTransformManifestPython(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-python-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/python",
Image: "HELPERS/python",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand Down Expand Up @@ -390,7 +390,7 @@ func TestTransformManifestPython(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-python-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/python",
Image: "HELPERS/python",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand Down Expand Up @@ -430,7 +430,7 @@ func TestTransformManifestPython(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-python-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/python",
Image: "HELPERS/python",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand Down Expand Up @@ -470,7 +470,7 @@ func TestTransformManifestPython(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-python-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/python",
Image: "HELPERS/python",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand Down Expand Up @@ -512,7 +512,7 @@ func TestTransformManifestPython(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-python-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/python",
Image: "HELPERS/python",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand Down Expand Up @@ -564,7 +564,7 @@ func TestTransformManifestPython(t *testing.T) {
}},
InitContainers: []v1.Container{{
Name: "install-python-support",
Image: "gcr.io/gcp-dev-tools/duct-tape/python",
Image: "HELPERS/python",
VolumeMounts: []v1.VolumeMount{{Name: "debugging-support-files", MountPath: "/dbg"}},
}},
Volumes: []v1.Volume{{
Expand All @@ -582,7 +582,7 @@ func TestTransformManifestPython(t *testing.T) {
retriever := func(image string) (imageConfiguration, error) {
return imageConfiguration{}, nil
}
result := transformManifest(value, retriever)
result := transformManifest(value, retriever, "HELPERS")

t.CheckDeepEqual(test.transformed, result)
t.CheckDeepEqual(test.out, value)
Expand Down
Loading

0 comments on commit c04909c

Please sign in to comment.