Skip to content
Open
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
19 changes: 17 additions & 2 deletions chart/templates/_rbac.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
{{- printf "vc-mn-%s-v-%s" .Release.Name .Release.Namespace | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Whether storage classes are synced from the host after resolving auto.
*/}}
{{- define "vcluster.syncFromHostStorageClasses" -}}
{{- if or
(eq (toString .Values.sync.fromHost.storageClasses.enabled) "true")
(and
(eq (toString .Values.sync.fromHost.storageClasses.enabled) "auto")
.Values.sync.toHost.persistentVolumeClaims.enabled
(not .Values.sync.toHost.storageClasses.enabled)
)
-}}
{{- true -}}
{{- end -}}
{{- end -}}

{{/*
Whether to create a cluster role or not
*/}}
Expand Down Expand Up @@ -33,7 +49,7 @@
.Values.sync.toHost.pods.hybridScheduling.enabled
.Values.sync.fromHost.ingressClasses.enabled
.Values.sync.fromHost.runtimeClasses.enabled
(eq (toString .Values.sync.fromHost.storageClasses.enabled) "true")
(include "vcluster.syncFromHostStorageClasses" .)
(eq (toString .Values.sync.fromHost.csiNodes.enabled) "true")
(eq (toString .Values.sync.fromHost.csiDrivers.enabled) "true")
(eq (toString .Values.sync.fromHost.csiStorageCapacities.enabled) "true")
Expand Down Expand Up @@ -255,4 +271,3 @@
{{- end }}
{{- end }}
{{- end }}

9 changes: 8 additions & 1 deletion chart/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ rules:
resources: ["storageclasses", "csinodes", "csidrivers", "csistoragecapacities"]
verbs: ["get", "watch", "list"]
{{- end }}
{{- if eq (toString .Values.sync.fromHost.storageClasses.enabled) "true" }}
{{- if and
(include "vcluster.syncFromHostStorageClasses" .)
(not (or
.Values.controlPlane.distro.k8s.scheduler.enabled
.Values.controlPlane.advanced.virtualScheduler.enabled
.Values.sync.toHost.pods.hybridScheduling.enabled
))
}}
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "watch", "list"]
Expand Down
114 changes: 94 additions & 20 deletions chart/tests/clusterrole_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 2
count: 3
- contains:
path: rules
content:
Expand All @@ -72,6 +72,80 @@ tests:
resources: [ "nodes" ]
verbs: [ "get" ]

- it: auto projects host storage classes for translated PVCs
set:
rbac:
enableVolumeSnapshotRules:
enabled: false
sync:
toHost:
persistentVolumeClaims:
enabled: true
persistentVolumes:
enabled: false
asserts:
- hasDocuments:
count: 1
- contains:
path: rules
content:
apiGroups: [ "storage.k8s.io" ]
resources: [ "storageclasses" ]
verbs: [ "get", "watch", "list" ]

- it: explicit false does not project host storage classes
set:
rbac:
enableVolumeSnapshotRules:
enabled: false
sync:
toHost:
persistentVolumeClaims:
enabled: true
persistentVolumes:
enabled: false
fromHost:
storageClasses:
enabled: false
asserts:
- hasDocuments:
count: 1
- notContains:
path: rules
content:
apiGroups: [ "storage.k8s.io" ]
resources: [ "storageclasses" ]
verbs: [ "get", "watch", "list" ]

- it: auto does not project host storage classes when guest classes sync to host
set:
rbac:
enableVolumeSnapshotRules:
enabled: false
sync:
toHost:
persistentVolumeClaims:
enabled: true
persistentVolumes:
enabled: false
storageClasses:
enabled: true
asserts:
- hasDocuments:
count: 1
- contains:
path: rules
content:
apiGroups: [ "storage.k8s.io" ]
resources: [ "storageclasses" ]
verbs: [ "create", "delete", "patch", "update", "get", "watch", "list" ]
- notContains:
path: rules
content:
apiGroups: [ "storage.k8s.io" ]
resources: [ "storageclasses" ]
verbs: [ "get", "watch", "list" ]

- it: force enable
set:
rbac:
Expand Down Expand Up @@ -196,7 +270,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 6
count: 7
- contains:
path: rules
content:
Expand Down Expand Up @@ -246,7 +320,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 7
count: 8
- contains:
path: rules
content:
Expand Down Expand Up @@ -277,7 +351,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 7
count: 8
- contains:
path: rules
content:
Expand All @@ -303,7 +377,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 6
count: 7
- contains:
path: rules
content:
Expand All @@ -322,7 +396,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 6
count: 7
- contains:
path: rules
content:
Expand Down Expand Up @@ -352,7 +426,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 5
count: 6
- contains:
path: rules
content:
Expand Down Expand Up @@ -393,7 +467,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 7
count: 8
- contains:
path: rules
content:
Expand Down Expand Up @@ -453,7 +527,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 6
count: 7
- contains:
path: rules
content:
Expand All @@ -473,7 +547,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 7
count: 8
- contains:
path: rules
content:
Expand All @@ -499,7 +573,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 7
count: 8
- contains:
path: rules
content:
Expand All @@ -521,7 +595,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 6
count: 7
- contains:
path: rules
content:
Expand All @@ -548,7 +622,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 8
count: 9
- contains:
path: rules
content:
Expand Down Expand Up @@ -622,7 +696,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 8
count: 9
- contains:
path: rules
content:
Expand Down Expand Up @@ -658,7 +732,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 8
count: 9
- contains:
path: rules
content:
Expand Down Expand Up @@ -694,7 +768,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 8
count: 9
- contains:
path: rules
content:
Expand Down Expand Up @@ -741,7 +815,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 8
count: 9
- contains:
path: rules
content:
Expand Down Expand Up @@ -777,7 +851,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 8
count: 9
- contains:
path: rules
content:
Expand Down Expand Up @@ -813,7 +887,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 8
count: 9
- contains:
path: rules
content:
Expand Down Expand Up @@ -847,7 +921,7 @@ tests:
count: 1
- lengthEqual:
path: rules
count: 6
count: 7
- contains:
path: rules
content:
Expand Down
4 changes: 2 additions & 2 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5091,7 +5091,7 @@
},
"storageClasses": {
"$ref": "#/$defs/EnableAutoSwitchWithPatchesAndSelector",
"description": "StorageClasses defines if storage classes should get synced from the host cluster to the virtual cluster, but not back. If auto, is automatically enabled when the virtual scheduler is enabled."
"description": "StorageClasses defines if storage classes should get synced from the host cluster to the virtual cluster, but not back. If auto, is automatically enabled when persistent volume claims are synced to the host and storage classes are not synced to the host."
},
"csiNodes": {
"$ref": "#/$defs/EnableAutoSwitchWithPatches",
Expand Down Expand Up @@ -5903,4 +5903,4 @@
"additionalProperties": false,
"type": "object",
"description": "Config is the vCluster config."
}
}
2 changes: 1 addition & 1 deletion chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ sync:
csiStorageCapacities:
# Enabled defines if this option should be enabled.
enabled: auto
# StorageClasses defines if storage classes should get synced from the host cluster to the virtual cluster, but not back. If auto, is automatically enabled when the virtual scheduler is enabled.
# StorageClasses defines if storage classes should get synced from the host cluster to the virtual cluster, but not back. If auto, is automatically enabled when persistent volume claims are synced to the host and storage classes are not synced to the host.
storageClasses:
# Enabled defines if this option should be enabled.
enabled: auto
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ type SyncFromHost struct {
// PriorityClasses defines if priority classes classes should get synced from the host cluster to the virtual cluster, but not back.
PriorityClasses EnableSwitchWithPatchesAndSelector `json:"priorityClasses,omitempty"`

// StorageClasses defines if storage classes should get synced from the host cluster to the virtual cluster, but not back. If auto, is automatically enabled when the virtual scheduler is enabled.
// StorageClasses defines if storage classes should get synced from the host cluster to the virtual cluster, but not back. If auto, is automatically enabled when persistent volume claims are synced to the host and storage classes are not synced to the host.
StorageClasses EnableAutoSwitchWithPatchesAndSelector `json:"storageClasses,omitempty"`

// CSINodes defines if csi nodes should get synced from the host cluster to the virtual cluster, but not back. If auto, is automatically enabled when the virtual scheduler is enabled.
Expand Down
11 changes: 8 additions & 3 deletions pkg/config/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ func ValidateConfigAndSetDefaults(vConfig *VirtualClusterConfig) error {
vConfig.Sync.FromHost.Nodes.Selector.All = true
}

// Keep the guest's effective storage classes aligned with the host whenever
// guest PVCs are translated to the host.
if vConfig.Sync.ToHost.PersistentVolumeClaims.Enabled &&
vConfig.Sync.FromHost.StorageClasses.Enabled == "auto" &&
!vConfig.Sync.ToHost.StorageClasses.Enabled {
vConfig.Sync.FromHost.StorageClasses.Enabled = "true"
}

// enable additional controllers required for scheduling with storage
if vConfig.SchedulingInVirtualClusterEnabled() && vConfig.Sync.ToHost.PersistentVolumeClaims.Enabled {
if vConfig.Sync.FromHost.CSINodes.Enabled == "auto" {
Expand All @@ -71,9 +79,6 @@ func ValidateConfigAndSetDefaults(vConfig *VirtualClusterConfig) error {
if vConfig.Sync.FromHost.CSIDrivers.Enabled == "auto" {
vConfig.Sync.FromHost.CSIDrivers.Enabled = "true"
}
if vConfig.Sync.FromHost.StorageClasses.Enabled == "auto" && !vConfig.Sync.ToHost.StorageClasses.Enabled {
vConfig.Sync.FromHost.StorageClasses.Enabled = "true"
}
}

// check if embedded database and multiple replicas
Expand Down
Loading