Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "io/ioutil"
- "os"
- "strings"
- log "github.com/sirupsen/logrus"
- apps "k8s.io/api/apps/v1"
- core "k8s.io/api/core/v1"
- "k8s.io/apimachinery/pkg/runtime"
- "k8s.io/apimachinery/pkg/runtime/serializer"
- )
- func main() {
- filepath := os.Args[1]
- input, err := ioutil.ReadFile(filepath)
- if err != nil {
- log.Fatal(err)
- }
- fmt.Print(string(input))
- splitInput := strings.Split(string(input), "---")
- fmt.Print(splitInput)
- // Create a new runtime scheme to populate
- scheme := runtime.NewScheme()
- // Add the first set of definitions to the scheme
- // These are the types our deserializer will know how to handle
- err = apps.AddToScheme(scheme)
- if err != nil {
- log.Fatal(err)
- }
- // Add another set of definitions to the scheme
- err = core.AddToScheme(scheme)
- if err != nil {
- log.Fatal(err)
- }
- // Create the universal deserializer from the scheme we created
- factory := serializer.NewCodecFactory(scheme)
- decoder := factory.UniversalDeserializer()
- for _, input := range splitInput {
- obj, _, err := decoder.Decode([]byte(input), nil, nil)
- if err != nil {
- log.Fatal(err)
- }
- log.Info(obj)
- }
- }
Add Comment
Please, Sign In to add comment