Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kubernetes GV convert
package main
import (
"os"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
"k8s.io/client-go/kubernetes/scheme"
)
func main() {
decode := scheme.Codecs.UniversalDeserializer().Decode
yaml := `
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: foo
namespace: bar
spec:
rules:
- host: fuga.example.com
http:
paths:
- backend:
serviceName: fuga-api
servicePort: 8080
`
obj, _, err := decode([]byte(yaml), nil, nil)
if err != nil {
panic(err)
}
ingress := new(networkingv1beta1.Ingress)
err = scheme.Scheme.Convert(obj, ingress, nil)
if err != nil {
panic(err)
}
encoder := json.NewSerializer(json.DefaultMetaFactory, scheme.Scheme, scheme.Scheme, false)
encoder.Encode(ingress, os.Stdout)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.