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

Passing zero objects to create should be an error
This commit is contained in:
Clayton Coleman 2015-01-14 13:06:53 -05:00
parent 31413c8727
commit ccdc20d90c
3 changed files with 15 additions and 5 deletions

View File

@ -115,6 +115,9 @@ for version in "${kube_api_versions[@]}"; do
[ "$(kubectl get minions -t $'{{ .apiVersion }}' "${kube_flags[@]}")" == "${version}" ] [ "$(kubectl get minions -t $'{{ .apiVersion }}' "${kube_flags[@]}")" == "${version}" ]
fi fi
# passing no arguments to create is an error
[ ! $(kubectl create) ]
kube::log::status "Testing kubectl(${version}:pods)" kube::log::status "Testing kubectl(${version}:pods)"
kubectl get pods "${kube_flags[@]}" kubectl get pods "${kube_flags[@]}"
kubectl create -f examples/guestbook/redis-master.json "${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", "apiVersion": "v1beta1",
"id": "service-${version}-test", "id": "service-${version}-test",
"port": 80, "port": 80,
"protocol": "TCP", "protocol": "TCP"
"labels": {
"name": "${version}"
}
} }
__EOF__ __EOF__
kubectl get services "something-${version}" "${kube_flags[@]}"
kubectl get services "${kube_flags[@]}" kubectl get services "${kube_flags[@]}"
kubectl get services "service-${version}-test" "${kube_flags[@]}"
kubectl delete service frontend "${kube_flags[@]}" kubectl delete service frontend "${kube_flags[@]}"
kube::log::status "Testing kubectl(${version}:replicationcontrollers)" kube::log::status "Testing kubectl(${version}:replicationcontrollers)"

View File

@ -55,6 +55,7 @@ Examples:
Flatten(). Flatten().
Do() Do()
count := 0
err = r.Visit(func(info *resource.Info) error { err = r.Visit(func(info *resource.Info) error {
data, err := info.Mapping.Codec.Encode(info.Object) data, err := info.Mapping.Codec.Encode(info.Object)
if err != nil { if err != nil {
@ -66,11 +67,15 @@ Examples:
if err := resource.NewHelper(info.Client, info.Mapping).Create(info.Namespace, true, data); err != nil { if err := resource.NewHelper(info.Client, info.Mapping).Create(info.Namespace, true, data); err != nil {
return err return err
} }
count++
// TODO: if generation of names added to server side, change this to use the server's name // TODO: if generation of names added to server side, change this to use the server's name
fmt.Fprintf(out, "%s\n", info.Name) fmt.Fprintf(out, "%s\n", info.Name)
return nil return nil
}) })
checkErr(err) 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") cmd.Flags().VarP(&flags.Filenames, "filename", "f", "Filename, directory, or URL to file to use to create the resource")

View File

@ -17,6 +17,7 @@ limitations under the License.
package resource package resource
import ( import (
"bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -356,6 +357,10 @@ func (v *StreamVisitor) Visit(fn VisitorFunc) error {
} }
return err 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) info, err := v.InfoForData(ext.RawJSON, v.Source)
if err != nil { if err != nil {
if v.IgnoreErrors { if v.IgnoreErrors {