go - Generate YAML manifest from Kubernetes types -


i'm looking writing tool generates kubernetes definitions programatically our project.

i've found api types in kubernetes can found in k8s.io/kubernetes/pkg/api. output yaml based on these types.

given object this:

ns := &api.namespace{     objectmeta: api.objectmeta{         name: "test",     }, } 

what's best way generate yaml output expected kubectl create?

found it, future reference, here's might want do:

package main  import (     "os"      "k8s.io/kubernetes/pkg/api/unversioned"     "k8s.io/kubernetes/pkg/api/v1"     "k8s.io/kubernetes/pkg/runtime/serializer/json" )  func main() {     ns := &v1.namespace{         typemeta: unversioned.typemeta{             kind:       "namespace",             apiversion: "v1",         },          objectmeta: v1.objectmeta{             name: "test",         },     }      e := json.newyamlserializer(json.defaultmetafactory, nil, nil)      err := e.encodetostream(ns, os.stdout)     if err != nil {         panic(err)     } } 

this might not best practice (better suggestions welcome), job.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -