kubectl resource builder: don't check extension for single files

`kubectl create -f filename` doesn't need to check the extension
of filename. This fixes that behavior.
pull/6/head
Jeff Lowdermilk 2015-07-07 13:43:55 -07:00
parent e29b76d46e
commit 8d4167e7f6
3 changed files with 42 additions and 4 deletions

13
examples/pod Normal file
View File

@ -0,0 +1,13 @@
# Copy of pod.yaml without file extension for test
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
name: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80

View File

@ -228,7 +228,7 @@ func TestNodeBuilder(t *testing.T) {
func TestPathBuilderWithMultiple(t *testing.T) {
b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClient()).
FilenameParam(false, "../../../examples/guestbook/redis-master-controller.yaml").
FilenameParam(false, "../../../examples/guestbook/redis-master-controller.yaml").
FilenameParam(false, "../../../examples/pod").
NamespaceParam("test").DefaultNamespace()
test := &testVisitor{}
@ -239,8 +239,12 @@ func TestPathBuilderWithMultiple(t *testing.T) {
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
}
info := test.Infos[1]
if info.Name != "redis-master" || info.Namespace != "test" || info.Object == nil {
info := test.Infos[0]
if _, ok := info.Object.(*api.ReplicationController); !ok || info.Name != "redis-master" || info.Namespace != "test" {
t.Errorf("unexpected info: %#v", info)
}
info = test.Infos[1]
if _, ok := info.Object.(*api.Pod); !ok || info.Name != "nginx" || info.Namespace != "test" {
t.Errorf("unexpected info: %#v", info)
}
}
@ -687,6 +691,26 @@ func TestSingularObject(t *testing.T) {
}
}
func TestSingularObjectNoExtension(t *testing.T) {
obj, err := NewBuilder(latest.RESTMapper, api.Scheme, fakeClient()).
NamespaceParam("test").DefaultNamespace().
FilenameParam(false, "../../../examples/pod").
Flatten().
Do().Object()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
pod, ok := obj.(*api.Pod)
if !ok {
t.Fatalf("unexpected object: %#v", obj)
}
if pod.Name != "nginx" || pod.Namespace != "test" {
t.Errorf("unexpected pod: %#v", pod)
}
}
func TestSingularRootScopedObject(t *testing.T) {
node := &api.Node{ObjectMeta: api.ObjectMeta{Name: "test"}, Spec: api.NodeSpec{ExternalID: "test"}}
r := streamTestObject(node)

View File

@ -381,7 +381,8 @@ func ExpandPathsToFileVisitors(mapper *Mapper, paths string, recursive bool, ext
}
return nil
}
if ignoreFile(path, extensions) {
// Don't check extension if the filepath was passed explicitly
if path != paths && ignoreFile(path, extensions) {
return nil
}