hexfusion / avalanchego

Go implementation of an Avalanche node.
https://avax.network
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

experiment: schedule pod with pod.yaml #4

Closed hexfusion closed 1 year ago

hexfusion commented 1 year ago

Using go bindings consume a pod spec and schedule a new pod. We will want to decode the file to v1.Pod so we can add what we want such as env, name etc before scheduling.

podman play kube pod.yaml
package main

import (
    "fmt"

    v1 "k8s.io/api/apps/v1"
    "k8s.io/client-go/kubernetes/scheme"
)

var podYaml = `
apiVersion: v1
kind: Pod
metadata:
  labels:
    app: demo-pod
  name: demo-pod
spec:
  containers:
  - image: quay.io/libpod/alpine_nginx:latest
    name: demo
    ports:
    - containerPort: 80
      hostPort: 8000

func main() {
    decode := scheme.Codecs.UniversalDeserializer().Decode
    obj, _, err := decode([]byte(podYamlBytes, nil, nil)
    if err != nil {
        fmt.Printf("%#v", err)
    }

    pod := obj.(*v1.Pod)

    fmt.Printf("%#v\n", pod)
}

https://github.com/containers/podman/blob/main/pkg/bindings/kube/kube.go#L19