cue: implementation of marked defaults
Change-Id: I7b0ed2b1e372a71410cbd05253ca819f08509a2a
diff --git a/doc/tutorial/basics/coalesce.md b/doc/tutorial/basics/coalesce.md
index 082708a..dde8c77 100644
--- a/doc/tutorial/basics/coalesce.md
+++ b/doc/tutorial/basics/coalesce.md
@@ -29,11 +29,11 @@
```
list: [ "Cat", "Mouse", "Dog" ]
-a: list[0] | "None"
-b: list[5] | "None"
+a: *list[0] | "None"
+b: *list[5] | "None"
n: [null]
-v: n[0] & string | "default"
+v: *n[0] & string | "default"
```
<!-- result -->
diff --git a/doc/tutorial/basics/defaults.md b/doc/tutorial/basics/defaults.md
index a46825d..c65cb67 100644
--- a/doc/tutorial/basics/defaults.md
+++ b/doc/tutorial/basics/defaults.md
@@ -19,11 +19,11 @@
<!-- CUE editor -->
```
// any positive number, 1 is the default
-replicas: 1 | uint
+replicas: uint | *1
// the default value is ambiguous
-protocol: "tcp" | "udp"
-protocol: "udp" | "tcp"
+protocol: *"tcp" | "udp"
+protocol: *"udp" | "tcp"
```
<!-- result -->
diff --git a/doc/tutorial/basics/templates.md b/doc/tutorial/basics/templates.md
index 3748cdb..bd40c2a 100644
--- a/doc/tutorial/basics/templates.md
+++ b/doc/tutorial/basics/templates.md
@@ -18,7 +18,7 @@
// The name of each element is bound to Name and visible in the struct.
job <Name>: {
name: Name
- replicas: 1 | uint
+ replicas: uint | *1
command: string
}
diff --git a/doc/tutorial/kubernetes/manual/services/cloud.cue b/doc/tutorial/kubernetes/manual/services/cloud.cue
index 27fdb1a..4ba6142 100644
--- a/doc/tutorial/kubernetes/manual/services/cloud.cue
+++ b/doc/tutorial/kubernetes/manual/services/cloud.cue
@@ -12,11 +12,10 @@
}
deployment <Name>: _base & {
- name: Name | string
-// jba: why do you need to write "Name | string"? Doesn't the grammar require that the value
-// of <Name> is a string?
+ // Allow any string, but take Name by default.
+ name: string | *Name
kind: "deployment" | "stateful" | "daemon"
- replicas: 1 | int
+ replicas: int | *1
image: string
@@ -36,10 +35,10 @@
envSpec: {"\(k)" value: v for k, v in env}
volume <Name>: {
- name: Name | string
+ name: string | *Name
mountPath: string
- subPath: null | string
- readOnly: false | true
+ subPath: string | *null
+ readOnly: *false | true
kubernetes: {}
}
}
@@ -48,11 +47,11 @@
name: Name | string
port <Name>: {
- name: Name | string
+ name: string | *Name
port: int
- targetPort: port | int
- protocol: "TCP" | "UDP"
+ targetPort: int | *port
+ protocol: *"TCP" | "UDP"
}
kubernetes: {}
@@ -66,10 +65,11 @@
// Copy over all ports exposed from containers.
port "\(Name)": {
- port: Port | int
-// jba: Port must be defined, so why do you need "| int"?
- targetPort: Port | int
-// jba: I don't think you need targetPort, because it's defined above in terms of port.
+ // Set default external port to Port.
+ port: int | *Port
+ targetPort: int | *Port
+ // TODO(verify): jba: I don't think you need targetPort, because it's defined above in terms of port.
+ // Should probably be Port fixed.
} for Name, Port in spec.expose.port
// Copy over the labels
diff --git a/doc/tutorial/kubernetes/manual/services/frontend/kube.cue b/doc/tutorial/kubernetes/manual/services/frontend/kube.cue
index b01c302..c8d47e8 100644
--- a/doc/tutorial/kubernetes/manual/services/frontend/kube.cue
+++ b/doc/tutorial/kubernetes/manual/services/frontend/kube.cue
@@ -3,7 +3,7 @@
_base label component: "frontend"
deployment <Name>: {
- expose port http: 7080 | int
+ expose port http: *7080 | int
kubernetes spec template metadata annotations: {
"prometheus.io.scrape": "true"
"prometheus.io.port": "\(expose.port.http)"
diff --git a/doc/tutorial/kubernetes/manual/services/kitchen/kube.cue b/doc/tutorial/kubernetes/manual/services/kitchen/kube.cue
index 00a5466..40344c0 100644
--- a/doc/tutorial/kubernetes/manual/services/kitchen/kube.cue
+++ b/doc/tutorial/kubernetes/manual/services/kitchen/kube.cue
@@ -30,16 +30,16 @@
// Volumes
volume "\(name)-disk": {
name: string
- mountPath: "/logs" | string
+ mountPath: *"/logs" | string
spec gcePersistentDisk: {
- pdName: name | string
+ pdName: *name | string
fsType: "ext4"
}
}
volume "secret-\(name)": {
- mountPath: "/etc/certs" | string
+ mountPath: *"/etc/certs" | string
readOnly: true
- spec secret secretName: "\(name)-secrets" | string
+ spec secret secretName: *"\(name)-secrets" | string
}
}
diff --git a/doc/tutorial/kubernetes/quick/services/frontend/kube.cue b/doc/tutorial/kubernetes/quick/services/frontend/kube.cue
index 58f084c..ce4c25e 100644
--- a/doc/tutorial/kubernetes/quick/services/frontend/kube.cue
+++ b/doc/tutorial/kubernetes/quick/services/frontend/kube.cue
@@ -8,6 +8,6 @@
"prometheus.io.port": "\(spec.containers[0].ports[0].containerPort)"
}
spec containers: [{
- ports: [{containerPort: 7080 | int}] // 7080 is the default
+ ports: [{containerPort: *7080 | int}] // 7080 is the default
}]
}
diff --git a/doc/tutorial/kubernetes/quick/services/kitchen/kube.cue b/doc/tutorial/kubernetes/quick/services/kitchen/kube.cue
index e213621..c4639d8 100644
--- a/doc/tutorial/kubernetes/quick/services/kitchen/kube.cue
+++ b/doc/tutorial/kubernetes/quick/services/kitchen/kube.cue
@@ -23,21 +23,21 @@
_hasDisks: true | bool
volumes: [{
- name: "\(Name)-disk" | string
- gcePersistentDisk pdName: "\(Name)-disk" | string
+ name: *"\(Name)-disk" | string
+ gcePersistentDisk pdName: *"\(Name)-disk" | string
gcePersistentDisk fsType: "ext4"
}, {
- name: "secret-\(Name)" | string
- secret secretName: "\(Name)-secrets" | string
+ name: *"secret-\(Name)" | string
+ secret secretName: *"\(Name)-secrets" | string
}, ...] if _hasDisks
containers: [{
volumeMounts: [{
- name: "\(Name)-disk" | string
- mountPath: "/logs" | string
+ name: *"\(Name)-disk" | string
+ mountPath: *"/logs" | string
}, {
- mountPath: "/etc/certs" | string
- name: "secret-\(Name)" | string
+ mountPath: *"/etc/certs" | string
+ name: *"secret-\(Name)" | string
readOnly: true
}, ...]
}] if _hasDisks // field comprehension using just "if"
diff --git a/doc/tutorial/kubernetes/quick/services/kube.cue b/doc/tutorial/kubernetes/quick/services/kube.cue
index a84a50e..09688f5 100644
--- a/doc/tutorial/kubernetes/quick/services/kube.cue
+++ b/doc/tutorial/kubernetes/quick/services/kube.cue
@@ -15,8 +15,8 @@
// Any port has the following properties.
ports: [...{
port: int
- protocol: "TCP" | "UDP" // from the Kubernetes definition
- name: "client" | string
+ protocol: *"TCP" | "UDP" // from the Kubernetes definition
+ name: *"client" | string
}]
selector: metadata.labels // we want those to be the same
}
@@ -66,7 +66,7 @@
// for all ports defined in all containers.
_spec spec template spec containers: [...{
ports: [...{
- _export: true | false // include the port in the service
+ _export: *true | false // include the port in the service
}]
}]
@@ -75,8 +75,8 @@
spec ports: [ {
Port = p.containerPort // Port is an alias
- port: Port | int
- targetPort: Port | int
+ port: *Port | int
+ targetPort: *Port | int
} for c in v.spec.template.spec.containers
for p in c.ports
if p._export ]