Created
October 19, 2016 17:25
-
-
Save jpeeler/b926ad460c8693791cb756d078693818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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