Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Local Volume #94

Merged
merged 2 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions v1/traits/traits.cue
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,14 @@ import (

// work around ambiguous disjunctions by disallowing fields
#VolumeSpec: {
local: string
local: {
name: string
storage: string
volumeMode: string | *"Filesystem"
accessModes: [string] | *["ReadWriteOnce"]
path: string
node: string
} | string
secret?: _|_
ephemeral?: _|_
persistent?: _|_
Expand All @@ -225,7 +232,14 @@ import (
$metadata: traits: Volume: null

volumes: [string]: #VolumeSpec & {
local: string
local: {
name: string
storage: string
volumeMode: string | *"Filesystem"
accessModes: [string] | *["ReadWriteOnce"]
path: string
node: string
} | string
secret?: _|_
ephemeral?: _|_
persistent?: _|_
Expand Down
89 changes: 88 additions & 1 deletion v1/transformers/kubernetes/transformers.cue
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,14 @@ _CreateContainers: {
}
}
}
if volume.local != _|_ {
{
name: volume.local.name
persistentVolumeClaim: {
claimName: "pvc-\(volume.local.name)"
}
}
}
},
]
"containers": [
Expand All @@ -398,6 +406,9 @@ _CreateContainers: {
if mount.volume.ephemeral != _|_ {
name: mount.volume.ephemeral
}
if mount.volume.local != _|_ {
name: mount.volume.local
}
if mount.volume.secret != _|_ {
name: mount.volume.secret.name
}
Expand All @@ -414,6 +425,82 @@ _CreateContainers: {
}
}

#AddWorkloadLocalVolumes: v1.#Transformer & {
v1.#Component
traits.#Volume

volumes: _

$resources: {
for _, volume in volumes {
if volume.local != _|_ {
"local-pv-\(volume.local.name)": {
_#KubernetesMeta
$metadata: labels: {
driver: "kubernetes"
type: "k8s.io/api/v1/PersistentVolume"
}
apiVersion: "v1"
kind: "PersistentVolume"
metadata: {
name: "local-pv-\(volume.local.name)"
}
spec: {
capacity: {
storage: volume.local.storage
}
accessModes: volume.local.accessModes
persistentVolumeReclaimPolicy: "Retain"
storageClassName: "local-storage"
local: {
path: volume.local.path
}
nodeAffinity: {
required: {
nodeSelectorTerms: [
{
matchExpressions: [
{
key: "kubernetes.io/hostname"
operator: "In"
values: [
volume.local.node,
]
},
]
},
]
}
}
}
}
"pvc-\(volume.local.name)": {
_#KubernetesMeta
$metadata: labels: {
driver: "kubernetes"
type: "k8s.io/api/v1/PersistentVolumeClaim"
}
apiVersion: "v1"
kind: "PersistentVolumeClaim"
metadata: {
name: "pvc-\(volume.local.name)"
}
spec: {
accessModes: volume.local.accessModes
storageClassName: "local-storage"
resources: {
requests: {
storage: volume.local.storage
}
}
volumeName: "local-pv-\(volume.local.name)"
}
}
}
}
}
}

#AddWorkloadProbes: v1.#Transformer & {
v1.#Component
traits.#Workload
Expand Down Expand Up @@ -466,7 +553,7 @@ _#IngressResource: {
}
spec: {
"ingressClassName": ingressClassName
let routeRules = [ for rule in http.rules {
let routeRules = [for rule in http.rules {
http: {
paths: [{
if strings.HasSuffix(rule.match.path, "*") {
Expand Down
Loading