Skip to content

Instantly share code, notes, and snippets.

@bzub
Created January 9, 2020 16:27
Show Gist options
  • Save bzub/64310cda5f53e80eb85716f3b534d05e to your computer and use it in GitHub Desktop.
Save bzub/64310cda5f53e80eb85716f3b534d05e to your computer and use it in GitHub Desktop.
kyaml: projected volume source sequence key
package main
import (
"fmt"
"os"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
func main() {
r, err := yaml.Parse(myDeployment)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to parse.\n")
os.Exit(1)
}
cmSource, err := r.Pipe(
yaml.Lookup(
"spec", "template", "spec", "volumes",
"[name=configs]", "projected", "sources",
"[configMap.name=cm1]", // Does not work.
),
)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to lookup.\n")
os.Exit(1)
}
if cmSource == nil {
fmt.Fprintf(os.Stderr, "Projected volume not found.\n")
os.Exit(1)
}
fmt.Fprintf(os.Stdout, "%v\n", cmSource.Document().Value)
}
var myDeployment = `apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
namespace: example
spec:
selector:
matchLabels:
app.kubernetes.io/instance: my-deployment
template:
metadata:
labels:
app.kubernetes.io/instance: my-deployment
spec:
containers:
- name: example
image: k8s.gcr.io/pause:3.1
volumes:
- name: configs
projected:
sources:
- configMap:
name: cm1
optional: true
- configMap:
name: cm2
optional: true
- configMap:
name: secret1
optional: true
- configMap:
name: secret2
optional: true
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment