Adding a deployment example

This commit is contained in:
nikhiljindal
2015-09-21 16:29:47 -07:00
parent 2e5a3cfbc6
commit 60bd4012ae
3 changed files with 54 additions and 1 deletions

View File

@@ -22,6 +22,7 @@ import (
"os"
"strings"
"k8s.io/kubernetes/pkg/api"
_ "k8s.io/kubernetes/pkg/api/install"
_ "k8s.io/kubernetes/pkg/apis/experimental/install"
@@ -208,3 +209,21 @@ func (g TestGroup) ResourcePath(resource, namespace, name string) string {
func (g TestGroup) RESTMapper() meta.RESTMapper {
return latest.GroupOrDie(g.Group).RESTMapper
}
// Get codec based on runtime.Object
func GetCodecForObject(obj runtime.Object) (runtime.Codec, error) {
_, kind, err := api.Scheme.ObjectVersionAndKind(obj)
if err != nil {
return nil, fmt.Errorf("unexpected encoding error: %v", err)
}
// TODO: caesarxuchao: we should detect which group an object belongs to
// by using the version returned by Schem.ObjectVersionAndKind() once we
// split the schemes for internal objects.
// TODO: caesarxuchao: we should add a map from kind to group in Scheme.
for _, group := range Groups {
if api.Scheme.Recognizes(group.GroupAndVersion(), kind) {
return group.Codec(), nil
}
}
return nil, fmt.Errorf("unexpected kind: %v", kind)
}