Skip to content

Commit

Permalink
Merge pull request kubernetes#71923 from apelisse/fix-diff-overriding…
Browse files Browse the repository at this point in the history
…-names

diff: Fix overlapping filenames
  • Loading branch information
k8s-ci-robot authored Dec 11, 2018
2 parents f89aa18 + b6135f6 commit 425b1ff
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 1 deletion.
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",
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

0 comments on commit 425b1ff

Please sign in to comment.