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

diff: Fix overlapping filenames #71923

Merged
merged 1 commit into from
Dec 11, 2018
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
4 changes: 4 additions & 0 deletions hack/testdata/diff/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: test
17 changes: 17 additions & 0 deletions hack/testdata/diff/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
replicas: 3
selector:
matchLabels:
name: test
template:
metadata:
labels:
name: test
spec:
containers:
- name: nginx
image: nginx
8 changes: 8 additions & 0 deletions hack/testdata/diff/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
containers:
- name: nginx
image: nginx
4 changes: 4 additions & 0 deletions hack/testdata/diff/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Secret
metadata:
name: test
12 changes: 11 additions & 1 deletion pkg/kubectl/cmd/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,17 @@ func (obj InfoObject) Merged() (runtime.Object, error) {
}

func (obj InfoObject) Name() string {
return obj.Info.Name
group := ""
if obj.Info.Mapping.GroupVersionKind.Group != "" {
group = fmt.Sprintf("%v.", obj.Info.Mapping.GroupVersionKind.Group)
}
return group + fmt.Sprintf(
"%v.%v:%v.%v",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colons aren't cross-platform safe, are they?

obj.Info.Mapping.GroupVersionKind.Version,
obj.Info.Mapping.GroupVersionKind.Kind,
obj.Info.Namespace,
obj.Info.Name,
)
}

// Differ creates two DiffVersion and diffs them.
Expand Down
17 changes: 17 additions & 0 deletions test/cmd/diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,20 @@ run_kubectl_diff_tests() {
set +o nounset
set +o errexit
}

run_kubectl_diff_same_names() {
set -o nounset
set -o errexit

create_and_use_new_namespace
kube::log::status "Test kubectl diff with multiple resources with the same name"

output_message=$(KUBECTL_EXTERNAL_DIFF=find kubectl diff -Rf hack/testdata/diff/)
kube::test::if_has_string "${output_message}" 'v1.Pod:.*.test'
kube::test::if_has_string "${output_message}" 'apps.v1.Deployment:.*.test'
kube::test::if_has_string "${output_message}" 'v1.ConfigMap:.*.test'
kube::test::if_has_string "${output_message}" 'v1.Secret:.*.test'

set +o nounset
set +o errexit
}
1 change: 1 addition & 0 deletions test/cmd/legacy-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ runTests() {
# Kubectl diff #
################
record_command run_kubectl_diff_tests
record_command run_kubectl_diff_same_names

###############
# Kubectl get #
Expand Down