Guest User

Untitled

a guest
Dec 12th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "io/ioutil"
  6. "os"
  7. "strings"
  8.  
  9. log "github.com/sirupsen/logrus"
  10. apps "k8s.io/api/apps/v1"
  11. core "k8s.io/api/core/v1"
  12. "k8s.io/apimachinery/pkg/runtime"
  13. "k8s.io/apimachinery/pkg/runtime/serializer"
  14. )
  15.  
  16. func main() {
  17. filepath := os.Args[1]
  18.  
  19. input, err := ioutil.ReadFile(filepath)
  20. if err != nil {
  21. log.Fatal(err)
  22. }
  23.  
  24. fmt.Print(string(input))
  25.  
  26. splitInput := strings.Split(string(input), "---")
  27. fmt.Print(splitInput)
  28.  
  29. // Create a new runtime scheme to populate
  30. scheme := runtime.NewScheme()
  31.  
  32. // Add the first set of definitions to the scheme
  33. // These are the types our deserializer will know how to handle
  34. err = apps.AddToScheme(scheme)
  35. if err != nil {
  36. log.Fatal(err)
  37. }
  38.  
  39. // Add another set of definitions to the scheme
  40. err = core.AddToScheme(scheme)
  41. if err != nil {
  42. log.Fatal(err)
  43. }
  44.  
  45. // Create the universal deserializer from the scheme we created
  46. factory := serializer.NewCodecFactory(scheme)
  47. decoder := factory.UniversalDeserializer()
  48.  
  49. for _, input := range splitInput {
  50. obj, _, err := decoder.Decode([]byte(input), nil, nil)
  51. if err != nil {
  52. log.Fatal(err)
  53. }
  54.  
  55. log.Info(obj)
  56. }
  57. }
Add Comment
Please, Sign In to add comment