Skip to content

Commit

Permalink
Merge pull request #302 from stefanprodan/config-def
Browse files Browse the repository at this point in the history
Change the `config` type to definition
  • Loading branch information
stefanprodan authored Dec 30, 2023
2 parents f44c6a8 + e47fe71 commit 27f445d
Show file tree
Hide file tree
Showing 22 changed files with 279 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import "strings"
labels: {
"\(#StdLabelName)": name
"\(#StdLabelVersion)": #Version
"\(#StdLabelManagedBy)": "Timoni"
"\(#StdLabelManagedBy)": "timoni"
}

// LabelSelector selects Pods based on the app.kubernetes.io/name label.
Expand Down
4 changes: 2 additions & 2 deletions blueprints/starter/templates/config.cue
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ import (
config: #Config

objects: {
deploy: #Deployment & {_config: config}
service: #Service & {_config: config}
deploy: #Deployment & {#config: config}
service: #Service & {#config: config}
}
}
36 changes: 18 additions & 18 deletions blueprints/starter/templates/deployment.cue
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ import (
)

#Deployment: appsv1.#Deployment & {
_config: #Config
#config: #Config
apiVersion: "apps/v1"
kind: "Deployment"
metadata: _config.metadata
metadata: #config.metadata
spec: appsv1.#DeploymentSpec & {
replicas: _config.replicas
selector: matchLabels: _config.selector.labels
replicas: #config.replicas
selector: matchLabels: #config.selector.labels
template: {
metadata: {
labels: _config.selector.labels
if _config.pod.annotations != _|_ {
annotations: _config.pod.annotations
labels: #config.selector.labels
if #config.pod.annotations != _|_ {
annotations: #config.pod.annotations
}
}
spec: corev1.#PodSpec & {
containers: [
{
name: _config.metadata.name
image: _config.image.reference
imagePullPolicy: _config.image.pullPolicy
name: #config.metadata.name
image: #config.image.reference
imagePullPolicy: #config.image.pullPolicy
ports: [
{
name: "http"
Expand All @@ -48,19 +48,19 @@ import (
initialDelaySeconds: 5
periodSeconds: 5
}
if _config.resources != _|_ {
resources: _config.resources
if #config.resources != _|_ {
resources: #config.resources
}
if _config.securityContext != _|_ {
securityContext: _config.securityContext
if #config.securityContext != _|_ {
securityContext: #config.securityContext
}
},
]
if _config.pod.affinity != _|_ {
affinity: _config.pod.affinity
if #config.pod.affinity != _|_ {
affinity: #config.pod.affinity
}
if _config.pod.imagePullSecrets != _|_ {
imagePullSecrets: _config.pod.imagePullSecrets
if #config.pod.imagePullSecrets != _|_ {
imagePullSecrets: #config.pod.imagePullSecrets
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions blueprints/starter/templates/service.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (
)

#Service: corev1.#Service & {
_config: #Config
#config: #Config
apiVersion: "v1"
kind: "Service"
metadata: _config.metadata
if _config.service.annotations != _|_ {
metadata: annotations: _config.service.annotations
metadata: #config.metadata
if #config.service.annotations != _|_ {
metadata: annotations: #config.service.annotations
}
spec: corev1.#ServiceSpec & {
type: corev1.#ServiceTypeClusterIP
selector: _config.selector.labels
selector: #config.selector.labels
ports: [
{
port: _config.service.port
port: #config.service.port
protocol: "TCP"
name: "http"
targetPort: name
Expand Down
10 changes: 5 additions & 5 deletions examples/minimal/templates/config.cue
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ import (
config: #Config

objects: {
sa: #ServiceAccount & {_config: config}
svc: #Service & {_config: config}
cm: #ConfigMap & {_config: config}
sa: #ServiceAccount & {#config: config}
svc: #Service & {#config: config}
cm: #ConfigMap & {#config: config}

deploy: #Deployment & {
_config: config
#config: config
_cmName: objects.cm.metadata.name
}
}

tests: {
"test-svc": #TestJob & {_config: config}
"test-svc": #TestJob & {#config: config}
}
}
20 changes: 10 additions & 10 deletions examples/minimal/templates/configmap.cue
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
)

#ConfigMap: corev1.#ConfigMap & {
_config: #Config
#config: #Config
apiVersion: "v1"
kind: "ConfigMap"
metadata: {
name: "\(_config.metadata.name)-\(_checksum)"
namespace: _config.metadata.namespace
labels: _config.metadata.labels
if _config.metadata.annotations != _|_ {
annotations: _config.metadata.annotations
name: "\(#config.metadata.name)-\(_checksum)"
namespace: #config.metadata.namespace
labels: #config.metadata.labels
if #config.metadata.annotations != _|_ {
annotations: #config.metadata.annotations
}
}
immutable: true
Expand All @@ -26,7 +26,7 @@ import (
"nginx.default.conf": """
server {
listen 8080;
server_name \(_config.metadata.name);
server_name \(#config.metadata.name);
location / {
root /usr/share/nginx/html;
Expand All @@ -52,16 +52,16 @@ import (
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="10" />
<title>\(_config.metadata.name)</title>
<title>\(#config.metadata.name)</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1> \(_config.message) from \(_config.metadata.name)!</h1>
<p>If you see this page, the <b>\(_config.metadata.name)</b> instance is successfully deployed in the <b>\(_config.metadata.namespace)</b> namespace by Timoni.</p>
<h1> \(#config.message) from \(#config.metadata.name)!</h1>
<p>If you see this page, the <b>\(#config.metadata.name)</b> instance is successfully deployed in the <b>\(#config.metadata.namespace)</b> namespace by Timoni.</p>
</body>
</html>
"""
Expand Down
46 changes: 23 additions & 23 deletions examples/minimal/templates/deployment.cue
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ import (
)

#Deployment: appsv1.#Deployment & {
_config: #Config
#config: #Config
_cmName: string
apiVersion: "apps/v1"
kind: "Deployment"
metadata: _config.metadata
metadata: #config.metadata
spec: appsv1.#DeploymentSpec & {
replicas: _config.replicas
selector: matchLabels: _config.selector.labels
replicas: #config.replicas
selector: matchLabels: #config.selector.labels
template: {
metadata: {
labels: _config.selector.labels
if _config.podAnnotations != _|_ {
annotations: _config.podAnnotations
labels: #config.selector.labels
if #config.podAnnotations != _|_ {
annotations: #config.podAnnotations
}
}
spec: corev1.#PodSpec & {
serviceAccountName: _config.metadata.name
serviceAccountName: #config.metadata.name
containers: [
{
name: _config.metadata.name
image: _config.image.reference
imagePullPolicy: _config.image.pullPolicy
name: #config.metadata.name
image: #config.image.reference
imagePullPolicy: #config.image.pullPolicy
ports: [
{
name: "http"
Expand Down Expand Up @@ -57,8 +57,8 @@ import (
name: "html"
},
]
resources: _config.resources
securityContext: _config.securityContext
resources: #config.resources
securityContext: #config.securityContext
},
]
volumes: [
Expand All @@ -83,20 +83,20 @@ import (
}
},
]
if _config.podSecurityContext != _|_ {
securityContext: _config.podSecurityContext
if #config.podSecurityContext != _|_ {
securityContext: #config.podSecurityContext
}
if _config.topologySpreadConstraints != _|_ {
topologySpreadConstraints: _config.topologySpreadConstraints
if #config.topologySpreadConstraints != _|_ {
topologySpreadConstraints: #config.topologySpreadConstraints
}
if _config.affinity != _|_ {
affinity: _config.affinity
if #config.affinity != _|_ {
affinity: #config.affinity
}
if _config.tolerations != _|_ {
tolerations: _config.tolerations
if #config.tolerations != _|_ {
tolerations: #config.tolerations
}
if _config.imagePullSecrets != _|_ {
imagePullSecrets: _config.imagePullSecrets
if #config.imagePullSecrets != _|_ {
imagePullSecrets: #config.imagePullSecrets
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions examples/minimal/templates/job.cue
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,46 @@ import (
)

#TestJob: batchv1.#Job & {
_config: #Config
#config: #Config
apiVersion: "batch/v1"
kind: "Job"
metadata: timoniv1.#MetaComponent & {
#Meta: _config.metadata
#Meta: #config.metadata
#Component: "test"
}
metadata: annotations: timoniv1.Action.Force
spec: batchv1.#JobSpec & {
template: corev1.#PodTemplateSpec & {
let _checksum = uuid.SHA1(uuid.ns.DNS, yaml.Marshal(_config))
let _checksum = uuid.SHA1(uuid.ns.DNS, yaml.Marshal(#config))
metadata: annotations: "timoni.sh/checksum": "\(_checksum)"
spec: {
containers: [{
name: "curl"
image: _config.test.image.reference
imagePullPolicy: _config.test.image.pullPolicy
image: #config.test.image.reference
imagePullPolicy: #config.test.image.pullPolicy
command: [
"curl",
"-v",
"-m",
"5",
"\(_config.metadata.name):\(_config.service.port)",
"\(#config.metadata.name):\(#config.service.port)",
]
}]
restartPolicy: "Never"
if _config.podSecurityContext != _|_ {
securityContext: _config.podSecurityContext
if #config.podSecurityContext != _|_ {
securityContext: #config.podSecurityContext
}
if _config.topologySpreadConstraints != _|_ {
topologySpreadConstraints: _config.topologySpreadConstraints
if #config.topologySpreadConstraints != _|_ {
topologySpreadConstraints: #config.topologySpreadConstraints
}
if _config.affinity != _|_ {
affinity: _config.affinity
if #config.affinity != _|_ {
affinity: #config.affinity
}
if _config.tolerations != _|_ {
tolerations: _config.tolerations
if #config.tolerations != _|_ {
tolerations: #config.tolerations
}
if _config.imagePullSecrets != _|_ {
imagePullSecrets: _config.imagePullSecrets
if #config.imagePullSecrets != _|_ {
imagePullSecrets: #config.imagePullSecrets
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions examples/minimal/templates/service.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (
)

#Service: corev1.#Service & {
_config: #Config
#config: #Config
apiVersion: "v1"
kind: "Service"
metadata: _config.metadata
if _config.service.annotations != _|_ {
metadata: annotations: _config.service.annotations
metadata: #config.metadata
if #config.service.annotations != _|_ {
metadata: annotations: #config.service.annotations
}
spec: corev1.#ServiceSpec & {
type: corev1.#ServiceTypeClusterIP
selector: _config.selector.labels
selector: #config.selector.labels
ports: [
{
port: _config.service.port
port: #config.service.port
protocol: "TCP"
name: "http"
targetPort: name
Expand Down
4 changes: 2 additions & 2 deletions examples/minimal/templates/serviceaccount.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
)

#ServiceAccount: corev1.#ServiceAccount & {
_config: #Config
#config: #Config
apiVersion: "v1"
kind: "ServiceAccount"
metadata: _config.metadata
metadata: #config.metadata
}
Loading

0 comments on commit 27f445d

Please sign in to comment.