mirror of https://github.com/k3s-io/k3s
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
parent
e29b76d46e
commit
8d4167e7f6
|
@ -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
|
|
@ -228,7 +228,7 @@ func TestNodeBuilder(t *testing.T) {
|
||||||
func TestPathBuilderWithMultiple(t *testing.T) {
|
func TestPathBuilderWithMultiple(t *testing.T) {
|
||||||
b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClient()).
|
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/guestbook/redis-master-controller.yaml").
|
FilenameParam(false, "../../../examples/pod").
|
||||||
NamespaceParam("test").DefaultNamespace()
|
NamespaceParam("test").DefaultNamespace()
|
||||||
|
|
||||||
test := &testVisitor{}
|
test := &testVisitor{}
|
||||||
|
@ -239,8 +239,12 @@ func TestPathBuilderWithMultiple(t *testing.T) {
|
||||||
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
|
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
|
||||||
}
|
}
|
||||||
|
|
||||||
info := test.Infos[1]
|
info := test.Infos[0]
|
||||||
if info.Name != "redis-master" || info.Namespace != "test" || info.Object == nil {
|
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)
|
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) {
|
func TestSingularRootScopedObject(t *testing.T) {
|
||||||
node := &api.Node{ObjectMeta: api.ObjectMeta{Name: "test"}, Spec: api.NodeSpec{ExternalID: "test"}}
|
node := &api.Node{ObjectMeta: api.ObjectMeta{Name: "test"}, Spec: api.NodeSpec{ExternalID: "test"}}
|
||||||
r := streamTestObject(node)
|
r := streamTestObject(node)
|
||||||
|
|
|
@ -381,7 +381,8 @@ func ExpandPathsToFileVisitors(mapper *Mapper, paths string, recursive bool, ext
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if ignoreFile(path, extensions) {
|
// Don't check extension if the filepath was passed explicitly
|
||||||
|
if path != paths && ignoreFile(path, extensions) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue