Created
January 9, 2020 16:27
-
-
Save bzub/64310cda5f53e80eb85716f3b534d05e to your computer and use it in GitHub Desktop.
kyaml: projected volume source sequence key
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" | |
"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