Commit ccdc20d9 authored by Clayton Coleman's avatar Clayton Coleman

Ignore empty objects from streams and error when nothing passed to create

Passing zero objects to create should be an error
parent 31413c87
......@@ -115,6 +115,9 @@ for version in "${kube_api_versions[@]}"; do
[ "$(kubectl get minions -t $'{{ .apiVersion }}' "${kube_flags[@]}")" == "${version}" ]
fi
# passing no arguments to create is an error
[ ! $(kubectl create) ]
kube::log::status "Testing kubectl(${version}:pods)"
kubectl get pods "${kube_flags[@]}"
kubectl create -f examples/guestbook/redis-master.json "${kube_flags[@]}"
......@@ -144,14 +147,11 @@ for version in "${kube_api_versions[@]}"; do
"apiVersion": "v1beta1",
"id": "service-${version}-test",
"port": 80,
"protocol": "TCP",
"labels": {
"name": "${version}"
}
"protocol": "TCP"
}
__EOF__
kubectl get services "something-${version}" "${kube_flags[@]}"
kubectl get services "${kube_flags[@]}"
kubectl get services "service-${version}-test" "${kube_flags[@]}"
kubectl delete service frontend "${kube_flags[@]}"
kube::log::status "Testing kubectl(${version}:replicationcontrollers)"
......
......@@ -55,6 +55,7 @@ Examples:
Flatten().
Do()
count := 0
err = r.Visit(func(info *resource.Info) error {
data, err := info.Mapping.Codec.Encode(info.Object)
if err != nil {
......@@ -66,11 +67,15 @@ Examples:
if err := resource.NewHelper(info.Client, info.Mapping).Create(info.Namespace, true, data); err != nil {
return err
}
count++
// TODO: if generation of names added to server side, change this to use the server's name
fmt.Fprintf(out, "%s\n", info.Name)
return nil
})
checkErr(err)
if count == 0 {
checkErr(fmt.Errorf("no objects passed to create"))
}
},
}
cmd.Flags().VarP(&flags.Filenames, "filename", "f", "Filename, directory, or URL to file to use to create the resource")
......
......@@ -17,6 +17,7 @@ limitations under the License.
package resource
import (
"bytes"
"fmt"
"io"
"io/ioutil"
......@@ -356,6 +357,10 @@ func (v *StreamVisitor) Visit(fn VisitorFunc) error {
}
return err
}
ext.RawJSON = bytes.TrimSpace(ext.RawJSON)
if len(ext.RawJSON) == 0 || bytes.Equal(ext.RawJSON, []byte("null")) {
continue
}
info, err := v.InfoForData(ext.RawJSON, v.Source)
if err != nil {
if v.IgnoreErrors {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment