Skip to content

Instantly share code, notes, and snippets.

@jpeeler
Created October 19, 2016 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpeeler/b926ad460c8693791cb756d078693818 to your computer and use it in GitHub Desktop.
Save jpeeler/b926ad460c8693791cb756d078693818 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"gopkg.in/yaml.v2"
"github.com/davecgh/go-spew/spew"
)
func main() {
var data = `
system:
items:
- secretName: mysecret
items:
- key: username
path: my-group/my-username
- configMapName: myconfigmap
items:
- key: config
path: my-group/my-config
`
/*
apiVersion: v1
kind: Pod
metadata:
name: volume-test
spec:
containers:
- name: container-test
image: jpeeler/scratch
volumeMounts:
- name: all-in-one
mountPath: "/system-volume"
readOnly: true
volumes:
- name: all-in-one
*/
/*
- downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
- path: "cpu_limit"
resourceFieldRef:
containerName: container-test
resource: limits.cpu
*/
type KeyToPath struct {
Key string `yaml:"key"`
Path string `yaml:"path"`
mode *int32 `yaml:"mode,omitempty"`
}
type VolumeKeys struct {
SecretName string `yaml:"secretName,omitempty"`
ConfigMapName string `yaml:"configMapName,omitempty"`
DownwardAPI string `yaml:"downwardAPI,omitempty"`
Items []KeyToPath `yaml:"items,omitempty"`
// JPEELER: this part is probably invalid
//DItems []DownwardAPIVolumeFile `json:"items,omitempty"`
}
type VolumeAllInOneSource struct {
Items []VolumeKeys `yaml:"items,omitempty"`
}
type VolumeSource struct {
VolumeAIO *VolumeAllInOneSource `yaml:"system"`
}
res := VolumeSource{}
//var res VolumeSource
fmt.Println(data)
if err := yaml.Unmarshal([]byte(data), &res); err != nil {
panic(err)
}
fmt.Printf("--- config:\n%+v\n\n", res)
spew.Dump(res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment