Skip to content

Commit

Permalink
feat: Added patches to more core resources
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Kosiewski <[email protected]>
  • Loading branch information
ThomasK33 committed Oct 8, 2024
1 parent 2e05a4c commit 32cbda2
Show file tree
Hide file tree
Showing 35 changed files with 328 additions and 115 deletions.
3 changes: 2 additions & 1 deletion chart/templates/_rbac.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
.Values.sync.toHost.persistentVolumes.enabled
.Values.sync.toHost.priorityClasses.enabled
.Values.sync.fromHost.priorityClasses.enabled
.Values.sync.toHost.volumeSnapshots.enabled
.Values.sync.toHost.volumeSnapshotContents.enabled
.Values.sync.fromHost.volumeSnapshotClasses.enabled
.Values.controlPlane.advanced.virtualScheduler.enabled
.Values.sync.fromHost.ingressClasses.enabled
.Values.sync.fromHost.runtimeClasses.enabled
Expand Down
4 changes: 3 additions & 1 deletion chart/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ rules:
resources: ["priorityclasses"]
verbs: ["create", "delete", "patch", "update", "get", "list", "watch"]
{{- end }}
{{- if .Values.sync.toHost.volumeSnapshots.enabled }}
{{- if .Values.sync.fromHost.volumeSnapshotClasses.enabled }}
- apiGroups: ["snapshot.storage.k8s.io"]
resources: ["volumesnapshotclasses"]
verbs: ["get", "list", "watch"]
{{- end }}
{{- if .Values.sync.toHost.volumeSnapshotContents.enabled }}
- apiGroups: ["snapshot.storage.k8s.io"]
resources: ["volumesnapshotcontents"]
verbs: ["create", "delete", "patch", "update", "get", "list", "watch"]
Expand Down
56 changes: 39 additions & 17 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@
"additionalProperties": false,
"type": "object"
},
"EnableAutoSwitch": {
"EnableAutoSwitchWithPatches": {
"properties": {
"enabled": {
"oneOf": [
Expand All @@ -1001,6 +1001,13 @@
}
],
"description": "Enabled defines if this option should be enabled."
},
"patches": {
"items": {
"$ref": "#/$defs/TranslatePatch"
},
"type": "array",
"description": "Patches patch the resource according to the provided specification."
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -2936,35 +2943,35 @@
"description": "Nodes defines if nodes should get synced from the host cluster to the virtual cluster, but not back."
},
"events": {
"$ref": "#/$defs/EnableSwitch",
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "Events defines if events should get synced from the host cluster to the virtual cluster, but not back."
},
"ingressClasses": {
"$ref": "#/$defs/EnableSwitch",
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "IngressClasses defines if ingress classes should get synced from the host cluster to the virtual cluster, but not back."
},
"runtimeClasses": {
"$ref": "#/$defs/EnableSwitch",
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "RuntimeClasses defines if runtime classes should get synced from the host cluster to the virtual cluster, but not back."
},
"priorityClasses": {
"$ref": "#/$defs/EnableSwitch",
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "PriorityClasses defines if priority classes classes should get synced from the host cluster to the virtual cluster, but not back."
},
"storageClasses": {
"$ref": "#/$defs/EnableAutoSwitch",
"$ref": "#/$defs/EnableAutoSwitchWithPatches",
"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."
},
"csiNodes": {
"$ref": "#/$defs/EnableAutoSwitch",
"$ref": "#/$defs/EnableAutoSwitchWithPatches",
"description": "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."
},
"csiDrivers": {
"$ref": "#/$defs/EnableAutoSwitch",
"$ref": "#/$defs/EnableAutoSwitchWithPatches",
"description": "CSIDrivers defines if csi drivers 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."
},
"csiStorageCapacities": {
"$ref": "#/$defs/EnableAutoSwitch",
"$ref": "#/$defs/EnableAutoSwitchWithPatches",
"description": "CSIStorageCapacities defines if csi storage capacities 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."
},
"customResources": {
Expand All @@ -2973,6 +2980,10 @@
},
"type": "object",
"description": "CustomResources defines what custom resources should get synced read-only to the virtual cluster from the host cluster. vCluster will automatically add any required RBAC to the vCluster cluster role."
},
"volumeSnapshotClasses": {
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "VolumeSnapshotClasses defines if volume snapshot classes created within the virtual cluster should get synced to the host cluster."
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -3029,6 +3040,13 @@
"selector": {
"$ref": "#/$defs/SyncNodeSelector",
"description": "Selector can be used to define more granular what nodes should get synced from the host cluster to the virtual cluster."
},
"patches": {
"items": {
"$ref": "#/$defs/TranslatePatch"
},
"type": "array",
"description": "Patches patch the resource according to the provided specification."
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -3124,39 +3142,43 @@
"description": "Services defines if services created within the virtual cluster should get synced to the host cluster."
},
"endpoints": {
"$ref": "#/$defs/EnableSwitch",
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "Endpoints defines if endpoints created within the virtual cluster should get synced to the host cluster."
},
"networkPolicies": {
"$ref": "#/$defs/EnableSwitch",
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "NetworkPolicies defines if network policies created within the virtual cluster should get synced to the host cluster."
},
"persistentVolumeClaims": {
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "PersistentVolumeClaims defines if persistent volume claims created within the virtual cluster should get synced to the host cluster."
},
"persistentVolumes": {
"$ref": "#/$defs/EnableSwitch",
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "PersistentVolumes defines if persistent volumes created within the virtual cluster should get synced to the host cluster."
},
"volumeSnapshots": {
"$ref": "#/$defs/EnableSwitch",
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "VolumeSnapshots defines if volume snapshots created within the virtual cluster should get synced to the host cluster."
},
"volumeSnapshotContents": {
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "VolumeSnapshotContents defines if volume snapshot contents created within the virtual cluster should get synced to the host cluster."
},
"storageClasses": {
"$ref": "#/$defs/EnableSwitch",
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "StorageClasses defines if storage classes created within the virtual cluster should get synced to the host cluster."
},
"serviceAccounts": {
"$ref": "#/$defs/EnableSwitch",
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "ServiceAccounts defines if service accounts created within the virtual cluster should get synced to the host cluster."
},
"podDisruptionBudgets": {
"$ref": "#/$defs/EnableSwitch",
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "PodDisruptionBudgets defines if pod disruption budgets created within the virtual cluster should get synced to the host cluster."
},
"priorityClasses": {
"$ref": "#/$defs/EnableSwitch",
"$ref": "#/$defs/EnableSwitchWithPatches",
"description": "PriorityClasses defines if priority classes created within the virtual cluster should get synced to the host cluster."
},
"customResources": {
Expand Down
20 changes: 20 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ sync:
enabled: true
# Endpoints defines if endpoints created within the virtual cluster should get synced to the host cluster.
endpoints:
# Enabled defines if this option should be enabled.
enabled: true
# PersistentVolumeClaims defines if persistent volume claims created within the virtual cluster should get synced to the host cluster.
persistentVolumeClaims:
Expand Down Expand Up @@ -61,30 +62,42 @@ sync:
enabled: false
# PriorityClasses defines if priority classes created within the virtual cluster should get synced to the host cluster.
priorityClasses:
# Enabled defines if this option should be enabled.
enabled: false
# NetworkPolicies defines if network policies created within the virtual cluster should get synced to the host cluster.
networkPolicies:
# Enabled defines if this option should be enabled.
enabled: false
# VolumeSnapshots defines if volume snapshots created within the virtual cluster should get synced to the host cluster.
volumeSnapshots:
# Enabled defines if this option should be enabled.
enabled: false
# VolumeSnapshotContents defines if volume snapshot contents created within the virtual cluster should get synced to the host cluster.
volumeSnapshotContents:
# Enabled defines if this option should be enabled.
enabled: false
# PodDisruptionBudgets defines if pod disruption budgets created within the virtual cluster should get synced to the host cluster.
podDisruptionBudgets:
# Enabled defines if this option should be enabled.
enabled: false
# ServiceAccounts defines if service accounts created within the virtual cluster should get synced to the host cluster.
serviceAccounts:
# Enabled defines if this option should be enabled.
enabled: false
# StorageClasses defines if storage classes created within the virtual cluster should get synced to the host cluster.
storageClasses:
# Enabled defines if this option should be enabled.
enabled: false
# PersistentVolumes defines if persistent volumes created within the virtual cluster should get synced to the host cluster.
persistentVolumes:
# Enabled defines if this option should be enabled.
enabled: false

# Configure what resources vCluster should sync from the host cluster to the virtual cluster.
fromHost:
# Events defines if events should get synced from the host cluster to the virtual cluster, but not back.
events:
# Enabled defines if this option should be enabled.
enabled: true
# CSIDrivers defines if csi drivers 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.
csiDrivers:
Expand All @@ -104,12 +117,15 @@ sync:
enabled: auto
# IngressClasses defines if ingress classes should get synced from the host cluster to the virtual cluster, but not back.
ingressClasses:
# Enabled defines if this option should be enabled.
enabled: false
# RuntimeClasses defines if runtime classes should get synced from the host cluster to the virtual cluster, but not back.
runtimeClasses:
# Enabled defines if this option should be enabled.
enabled: false
# PriorityClasses defines if priority classes classes should get synced from the host cluster to the virtual cluster, but not back.
priorityClasses:
# Enabled defines if this option should be enabled.
enabled: false
# Nodes defines if nodes should get synced from the host cluster to the virtual cluster, but not back.
nodes:
Expand All @@ -124,6 +140,10 @@ sync:
# All specifies if all nodes should get synced by vCluster from the host to the virtual cluster or only the ones where pods are assigned to.
all: false
labels: {}
# VolumeSnapshotClasses defines if volume snapshot classes created within the virtual cluster should get synced to the host cluster.
volumeSnapshotClasses:
# Enabled defines if this option should be enabled.
enabled: false

# Configure vCluster's control plane components and deployment.
controlPlane:
Expand Down
49 changes: 33 additions & 16 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,31 +419,34 @@ type SyncToHost struct {
Services EnableSwitchWithPatches `json:"services,omitempty"`

// Endpoints defines if endpoints created within the virtual cluster should get synced to the host cluster.
Endpoints EnableSwitch `json:"endpoints,omitempty"`
Endpoints EnableSwitchWithPatches `json:"endpoints,omitempty"`

// NetworkPolicies defines if network policies created within the virtual cluster should get synced to the host cluster.
NetworkPolicies EnableSwitch `json:"networkPolicies,omitempty"`
NetworkPolicies EnableSwitchWithPatches `json:"networkPolicies,omitempty"`

// PersistentVolumeClaims defines if persistent volume claims created within the virtual cluster should get synced to the host cluster.
PersistentVolumeClaims EnableSwitchWithPatches `json:"persistentVolumeClaims,omitempty"`

// PersistentVolumes defines if persistent volumes created within the virtual cluster should get synced to the host cluster.
PersistentVolumes EnableSwitch `json:"persistentVolumes,omitempty"`
PersistentVolumes EnableSwitchWithPatches `json:"persistentVolumes,omitempty"`

// VolumeSnapshots defines if volume snapshots created within the virtual cluster should get synced to the host cluster.
VolumeSnapshots EnableSwitch `json:"volumeSnapshots,omitempty"`
VolumeSnapshots EnableSwitchWithPatches `json:"volumeSnapshots,omitempty"`

// VolumeSnapshotContents defines if volume snapshot contents created within the virtual cluster should get synced to the host cluster.
VolumeSnapshotContents EnableSwitchWithPatches `json:"volumeSnapshotContents,omitempty"`

// StorageClasses defines if storage classes created within the virtual cluster should get synced to the host cluster.
StorageClasses EnableSwitch `json:"storageClasses,omitempty"`
StorageClasses EnableSwitchWithPatches `json:"storageClasses,omitempty"`

// ServiceAccounts defines if service accounts created within the virtual cluster should get synced to the host cluster.
ServiceAccounts EnableSwitch `json:"serviceAccounts,omitempty"`
ServiceAccounts EnableSwitchWithPatches `json:"serviceAccounts,omitempty"`

// PodDisruptionBudgets defines if pod disruption budgets created within the virtual cluster should get synced to the host cluster.
PodDisruptionBudgets EnableSwitch `json:"podDisruptionBudgets,omitempty"`
PodDisruptionBudgets EnableSwitchWithPatches `json:"podDisruptionBudgets,omitempty"`

// PriorityClasses defines if priority classes created within the virtual cluster should get synced to the host cluster.
PriorityClasses EnableSwitch `json:"priorityClasses,omitempty"`
PriorityClasses EnableSwitchWithPatches `json:"priorityClasses,omitempty"`

// CustomResources defines what custom resources should get synced from the virtual cluster to the host cluster. vCluster will copy the definition automatically from host cluster to virtual cluster on startup.
// vCluster will also automatically add any required RBAC permissions to the vCluster role for this to work.
Expand All @@ -463,31 +466,34 @@ type SyncFromHost struct {
Nodes SyncNodes `json:"nodes,omitempty"`

// Events defines if events should get synced from the host cluster to the virtual cluster, but not back.
Events EnableSwitch `json:"events,omitempty"`
Events EnableSwitchWithPatches `json:"events,omitempty"`

// IngressClasses defines if ingress classes should get synced from the host cluster to the virtual cluster, but not back.
IngressClasses EnableSwitch `json:"ingressClasses,omitempty"`
IngressClasses EnableSwitchWithPatches `json:"ingressClasses,omitempty"`

// RuntimeClasses defines if runtime classes should get synced from the host cluster to the virtual cluster, but not back.
RuntimeClasses EnableSwitch `json:"runtimeClasses,omitempty"`
RuntimeClasses EnableSwitchWithPatches `json:"runtimeClasses,omitempty"`

// PriorityClasses defines if priority classes classes should get synced from the host cluster to the virtual cluster, but not back.
PriorityClasses EnableSwitch `json:"priorityClasses,omitempty"`
PriorityClasses EnableSwitchWithPatches `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 EnableAutoSwitch `json:"storageClasses,omitempty"`
StorageClasses EnableAutoSwitchWithPatches `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.
CSINodes EnableAutoSwitch `json:"csiNodes,omitempty"`
CSINodes EnableAutoSwitchWithPatches `json:"csiNodes,omitempty"`

// CSIDrivers defines if csi drivers 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.
CSIDrivers EnableAutoSwitch `json:"csiDrivers,omitempty"`
CSIDrivers EnableAutoSwitchWithPatches `json:"csiDrivers,omitempty"`

// CSIStorageCapacities defines if csi storage capacities 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.
CSIStorageCapacities EnableAutoSwitch `json:"csiStorageCapacities,omitempty"`
CSIStorageCapacities EnableAutoSwitchWithPatches `json:"csiStorageCapacities,omitempty"`

// CustomResources defines what custom resources should get synced read-only to the virtual cluster from the host cluster. vCluster will automatically add any required RBAC to the vCluster cluster role.
CustomResources map[string]SyncFromHostCustomResource `json:"customResources,omitempty"`

// VolumeSnapshotClasses defines if volume snapshot classes created within the virtual cluster should get synced to the host cluster.
VolumeSnapshotClasses EnableSwitchWithPatches `json:"volumeSnapshotClasses,omitempty"`
}

type SyncToHostCustomResource struct {
Expand Down Expand Up @@ -561,6 +567,14 @@ type EnableAutoSwitch struct {
Enabled StrBool `json:"enabled,omitempty" jsonschema:"oneof_type=string;boolean"`
}

type EnableAutoSwitchWithPatches struct {
// Enabled defines if this option should be enabled.
Enabled StrBool `json:"enabled,omitempty" jsonschema:"oneof_type=string;boolean"`

// Patches patch the resource according to the provided specification.
Patches []TranslatePatch `json:"patches,omitempty"`
}

type EnableSwitch struct {
// Enabled defines if this option should be enabled.
Enabled bool `json:"enabled,omitempty"`
Expand Down Expand Up @@ -629,6 +643,9 @@ type SyncNodes struct {

// Selector can be used to define more granular what nodes should get synced from the host cluster to the virtual cluster.
Selector SyncNodeSelector `json:"selector,omitempty"`

// Patches patch the resource according to the provided specification.
Patches []TranslatePatch `json:"patches,omitempty"`
}

type SyncNodeSelector struct {
Expand Down
Loading

0 comments on commit 32cbda2

Please sign in to comment.