You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
kubectl get all -A
kubectl apply -f simple/nginx.yaml
kubectl get all -A --field-selector metadata.namespace!=kube-system,metadata.namespace!=default
kubectl delete -f simple/nginx.yaml
kubectl get all -A --field-selector metadata.namespace!=kube-system,metadata.namespace!=default
CUE
cue import -l 'kind' -l 'metadata.name' -p demo -f simple/nginx.yaml
cue export simple/nginx.cue
cue export -e '{"apiVersion": "v1", "kind": "List", "items": [for x in [Namespace, Deployment] for y in x {y}]}' simple/nginx.cue
cue export -e '{"apiVersion": "v1", "kind": "List", "items": [for x in [Namespace, Deployment] for y in x {y}]}' simple/nginx.cue | kubectl apply -f -
kubectl get all -A --field-selector metadata.namespace!=kube-system,metadata.namespace!=default
cue export -e '{"apiVersion": "v1", "kind": "List", "items": [for x in [Namespace, Deployment] for y in x {y}]}' simple/nginx.cue | kubectl delete -f -
kubectl get all -A --field-selector metadata.namespace!=kube-system,metadata.namespace!=default
Pulling Up Configuration
cue mod init
cat >demo.cue <<EOFpackage demoNamespace: [Name=string]: { apiVersion: "v1" kind: "Namespace" metadata: { name: Name labels: name: Name }}Deployment: [Name=string]: { apiVersion: "apps/v1" kind: "Deployment" metadata: { name: Name labels: app: Name } spec: { selector: matchLabels: app: Name template: metadata: labels: app: Name }}EOF
cue trim -s ./simple
cue export ./simple
cue export -e '{"apiVersion": "v1", "kind": "List", "items": [for x in [Namespace, Deployment] for y in x {y}]}' ./simple | kubectl apply -f -
kubectl get all -A --field-selector metadata.namespace!=kube-system,metadata.namespace!=default
cue export -e '{"apiVersion": "v1", "kind": "List", "items": [for x in [Namespace, Deployment] for y in x {y}]}' ./simple | kubectl delete -f -
kubectl get all -A --field-selector metadata.namespace!=kube-system,metadata.namespace!=default
Multiple Configurations
cue import -l 'kind' -l 'metadata.name' -p demo -f ./multi
cue trim -s ./multi
cat > multi/multi.cue <<EOFpackage demoDeployment: [_]: spec: template: spec: containers: [{ name: "nginx" image: "nginx" ports: [{ containerPort: 80 }]}]EOF
cue trim -s ./multi
cue export ./multi
cue export -e '{"apiVersion": "v1", "kind": "List", "items": [for x in [Namespace, Deployment] for y in x {y}]}' ./multi | kubectl apply -f -
kubectl get all -A --field-selector metadata.namespace!=kube-system,metadata.namespace!=default
cue export -e '{"apiVersion": "v1", "kind": "List", "items": [for x in [Namespace, Deployment] for y in x {y}]}' ./multi | kubectl delete -f -
kubectl get all -A --field-selector metadata.namespace!=kube-system,metadata.namespace!=default
Tiered Configuration
cue import -l 'kind' -l 'metadata.name' -p demo -f ./org/**/*.yaml
cue trim -s ./org/*/*/
cat > org/org.cue <<EOFpackage demoDeployment: [_]: spec: template: spec: containers: [{ name: "nginx" image: "nginx" ports: [{ containerPort: 80 }]}]EOF
cue trim -s ./org/*/*/
cat >> org/org.cue <<EOF_org: string | *"org"_dept: string | *"none"_org_dept: "\(_org)-\(_dept)"_ns: "ns-\(_org_dept)"_app: "app-\(_org_dept)"_env: *"scratch" | "dev" | "qa" | "prod"Namespace: "\(_ns)": {}Namespace: [_]: metadata: name: _nsDeployment: "\(_app)": {}Deployment: [_]: metadata: namespace: _nsDeployment: [_]: metadata: name: _appNamespace: [_]: metadata: labels: environment: _envDeployment: [_]: { metadata: labels: environment: _env spec: { selector: matchLabels: environment: _env template: metadata: labels: environment: _env }}EOF# This will throw some errors, but it highlights what we need to do
cue trim -s ./org/*/*/
cat >org/dept-a/dept-a.cue <<EOFpackage demo_dept: "dept-a"EOF
cat >org/dept-b/dept-b.cue <<EOFpackage demo_dept: "dept-b"EOF
cue trim -s ./org/*/*/
cue export -e '{"apiVersion": "v1", "kind": "List", "items": [for x in [Namespace, Deployment] for y in x {y}]}' ./org/dept-a/dev | kubectl apply -f -
kubectl get all -A --field-selector metadata.namespace!=kube-system,metadata.namespace!=default
cue export -e '{"apiVersion": "v1", "kind": "List", "items": [for x in [Namespace, Deployment] for y in x {y}]}' ./org/dept-a/dev | kubectl delete -f -
fordin dept-a dept-b;doforein dev prod;do
cat >>org/$d/$e/*.cue <<EOF_env: "$e"EOFdonedone
cue trim -s ./org/*/*/
cue export -e '{"apiVersion": "v1", "kind": "List", "items": [for x in [Namespace, Deployment] for y in x {y}]}' ./org/dept-a/dev | kubectl apply -f -
kubectl get all -A --field-selector metadata.namespace!=kube-system,metadata.namespace!=default
cue export -e '{"apiVersion": "v1", "kind": "List", "items": [for x in [Namespace, Deployment] for y in x {y}]}' ./org/dept-a/dev | kubectl delete -f -
fordin dept-a dept-b;doforein dev prod;do
cat >org/$d/$e/*.cue <<EOFpackage demo_env: "$e"EOFdonedone
cue export -e '{"apiVersion": "v1", "kind": "List", "items": [for x in [Namespace, Deployment] for y in x {y}]}' ./org/dept-a/dev | kubectl apply -f -
kubectl get all -A --field-selector metadata.namespace!=kube-system,metadata.namespace!=default
kubectl describe deployment app-org-dept-a -n ns-org-dept-a
cue export -e '{"apiVersion": "v1", "kind": "List", "items": [for x in [Namespace, Deployment] for y in x {y}]}' ./org/dept-a/dev | kubectl delete -f -
CUE Scripting
cat >demo_tool.cue <<EOFpackage demoimport ( "encoding/json" "tool/cli")command: demo: cli.Print & { out: { apiVersion: "v1" kind: "List" items: [for x in [Namespace, Deployment] for y in x {y}] } text: json.Marshal(out)}EOF
cue cmd demo ./org/dept-a/dev
cue cmd demo ./org/dept-a/dev | jq
cue cmd demo ./org/dept-a/dev | kubectl apply -f -
kubectl get all -A --field-selector metadata.namespace!=kube-system,metadata.namespace!=default
cue cmd demo ./org/dept-a/dev | kubectl delete -f -
cue export -e Namespace ./simple
cue export -e '[Namespace, Deployment]' ./simple
cue export -e '[for x in [Namespace, Deployment] {x}]' ./simple
cue export -e '[for x in [Namespace, Deployment] for y in x {y}]' ./simple
cue export -e '{"apiVersion": "v1", "kind": "List", "items": [for x in [Namespace, Deployment] for y in x {y}]}' ./simple