Skip to content

Commit e1b1ad3

Browse files
Merge pull request #60464 from roycaihw/loadconfig
Automatic merge from submit-queue (batch tested with PRs 63598, 63913, 63459, 63963, 60464). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Client-go raises error on duplicated name in kubeconfig (for NamedCluster, NamedContext, NamedUser, NamedExtension) **What this PR does / why we need it**: Client should detect duplicated name when loading `name-value` based lists in kubeconfig: `users`, `clusters`, `contexts`. Currently if there are multiple value with same name, `client-python` will pick the first one, while `client-go` will pick the last. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: ref: kubernetes-client/python#445, kubernetes-client/python-base#47 **Special notes for your reviewer**: **Release note**: ```release-note kubectl and client-go now detects duplicated name for user, cluster and context when loading kubeconfig and reports error ``` /sig api-machinery cc @brendandburns @mbohlool Kubernetes-commit: 7909712ca574c536901bc7858dfbf72a3a6ee7dd
2 parents fd32386 + 0e3c65c commit e1b1ad3

File tree

3 files changed

+240
-55
lines changed

3 files changed

+240
-55
lines changed

Godeps/Godeps.json

+51-51
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/clientcmd/api/v1/conversion.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1
1818

1919
import (
20+
"fmt"
2021
"sort"
2122

2223
"k8s.io/apimachinery/pkg/conversion"
@@ -105,7 +106,11 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
105106
if err := s.Convert(&curr.Cluster, newCluster, 0); err != nil {
106107
return err
107108
}
108-
(*out)[curr.Name] = newCluster
109+
if (*out)[curr.Name] == nil {
110+
(*out)[curr.Name] = newCluster
111+
} else {
112+
return fmt.Errorf("error converting *[]NamedCluster into *map[string]*api.Cluster: duplicate name \"%v\" in list: %v", curr.Name, *in)
113+
}
109114
}
110115

111116
return nil
@@ -136,7 +141,11 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
136141
if err := s.Convert(&curr.AuthInfo, newAuthInfo, 0); err != nil {
137142
return err
138143
}
139-
(*out)[curr.Name] = newAuthInfo
144+
if (*out)[curr.Name] == nil {
145+
(*out)[curr.Name] = newAuthInfo
146+
} else {
147+
return fmt.Errorf("error converting *[]NamedAuthInfo into *map[string]*api.AuthInfo: duplicate name \"%v\" in list: %v", curr.Name, *in)
148+
}
140149
}
141150

142151
return nil
@@ -167,7 +176,11 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
167176
if err := s.Convert(&curr.Context, newContext, 0); err != nil {
168177
return err
169178
}
170-
(*out)[curr.Name] = newContext
179+
if (*out)[curr.Name] == nil {
180+
(*out)[curr.Name] = newContext
181+
} else {
182+
return fmt.Errorf("error converting *[]NamedContext into *map[string]*api.Context: duplicate name \"%v\" in list: %v", curr.Name, *in)
183+
}
171184
}
172185

173186
return nil
@@ -198,7 +211,11 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
198211
if err := s.Convert(&curr.Extension, &newExtension, 0); err != nil {
199212
return err
200213
}
201-
(*out)[curr.Name] = newExtension
214+
if (*out)[curr.Name] == nil {
215+
(*out)[curr.Name] = newExtension
216+
} else {
217+
return fmt.Errorf("error converting *[]NamedExtension into *map[string]runtime.Object: duplicate name \"%v\" in list: %v", curr.Name, *in)
218+
}
202219
}
203220

204221
return nil

0 commit comments

Comments
 (0)