Skip to content

Commit

Permalink
refactor: rename sync.customResourceDefinitions -> customResources
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKramm committed Oct 1, 2024
1 parent 9c97197 commit 10dd062
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 30 deletions.
16 changes: 8 additions & 8 deletions chart/templates/_rbac.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
(eq (toString .Values.sync.fromHost.csiDrivers.enabled) "true")
(eq (toString .Values.sync.fromHost.csiStorageCapacities.enabled) "true")
.Values.sync.fromHost.nodes.enabled
.Values.sync.toHost.customResourceDefinitions
.Values.sync.fromHost.customResourceDefinitions
.Values.sync.toHost.customResources
.Values.sync.fromHost.customResources
.Values.integrations.kubeVirt.enabled
.Values.integrations.externalSecrets.enabled
(and .Values.integrations.metricsServer.enabled .Values.integrations.metricsServer.nodes)
Expand Down Expand Up @@ -128,9 +128,9 @@
{{/*
Role rules defined in generic syncer
*/}}
{{- define "vcluster.customResourceDefinitions.roleExtraRules" -}}
{{- if .Values.sync.toHost.customResourceDefinitions }}
{{- range $crdName, $rule := .Values.sync.toHost.customResourceDefinitions }}
{{- define "vcluster.customResources.roleExtraRules" -}}
{{- if .Values.sync.toHost.customResources }}
{{- range $crdName, $rule := .Values.sync.toHost.customResources }}
{{- if $rule.enabled }}
- resources: [ "{{ (splitn "." 2 $crdName)._0 }}" ]
apiGroups: [ "{{ (splitn "." 2 $crdName)._1 }}" ]
Expand All @@ -143,9 +143,9 @@
{{/*
Cluster role rules defined in generic syncer
*/}}
{{- define "vcluster.customResourceDefinitions.clusterRoleExtraRules" -}}
{{- if .Values.sync.fromHost.customResourceDefinitions }}
{{- range $crdName, $rule := .Values.sync.fromHost.customResourceDefinitions }}
{{- define "vcluster.customResources.clusterRoleExtraRules" -}}
{{- if .Values.sync.fromHost.customResources }}
{{- range $crdName, $rule := .Values.sync.fromHost.customResources }}
{{- if $rule.enabled }}
- resources: [ "{{ (splitn "." 2 $crdName)._0 }}" ]
apiGroups: [ "{{ (splitn "." 2 $crdName)._1 }}" ]
Expand Down
4 changes: 2 additions & 2 deletions chart/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ rules:
resources: ["validatingwebhookconfigurations", "mutatingwebhookconfigurations"]
verbs: ["get", "list", "watch"]
{{- end }}
{{- if or .Values.integrations.kubeVirt.enabled .Values.integrations.externalSecrets.enabled .Values.sync.toHost.customResourceDefinitions .Values.sync.fromHost.customResourceDefinitions }}
{{- if or .Values.integrations.kubeVirt.enabled .Values.integrations.externalSecrets.enabled .Values.sync.toHost.customResources .Values.sync.fromHost.customResources }}
- apiGroups: ["apiextensions.k8s.io"]
resources: ["customresourcedefinitions"]
verbs: ["get", "list", "watch"]
Expand All @@ -127,7 +127,7 @@ rules:
resources: ["clustersecretstores"]
verbs: ["get", "list", "watch"]
{{- end }}
{{- include "vcluster.customResourceDefinitions.clusterRoleExtraRules" . | indent 2 }}
{{- include "vcluster.customResources.clusterRoleExtraRules" . | indent 2 }}
{{- include "vcluster.plugin.clusterRoleExtraRules" . | indent 2 }}
{{- include "vcluster.generic.clusterRoleExtraRules" . | indent 2 }}
{{- include "vcluster.rbac.clusterRoleExtraRules" . | indent 2 }}
Expand Down
2 changes: 1 addition & 1 deletion chart/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ rules:
verbs: ["create", "delete", "patch", "update", "get", "list", "watch"]
{{- end }}
{{- end }}
{{- include "vcluster.customResourceDefinitions.roleExtraRules" . | indent 2 }}
{{- include "vcluster.customResources.roleExtraRules" . | indent 2 }}
{{- include "vcluster.plugin.roleExtraRules" . | indent 2 }}
{{- include "vcluster.generic.roleExtraRules" . | indent 2 }}
{{- include "vcluster.rbac.roleExtraRules" . | indent 2 }}
Expand Down
4 changes: 2 additions & 2 deletions chart/tests/clusterrole_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ tests:
set:
sync:
toHost:
customResourceDefinitions:
customResources:
test.test-group:
enabled: true
release:
Expand All @@ -373,7 +373,7 @@ tests:
set:
sync:
fromHost:
customResourceDefinitions:
customResources:
test.test-group:
enabled: true
release:
Expand Down
6 changes: 3 additions & 3 deletions chart/tests/role_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ tests:
set:
sync:
toHost:
customResourceDefinitions:
customResources:
test.my-group:
enabled: false
test.my-group-2:
Expand Down Expand Up @@ -302,7 +302,7 @@ tests:
set:
sync:
toHost:
customResourceDefinitions:
customResources:
test.my-group-2:
enabled: true
translate:
Expand All @@ -319,7 +319,7 @@ tests:
set:
sync:
toHost:
customResourceDefinitions:
customResources:
test.my-group-2:
enabled: true
translate:
Expand Down
16 changes: 8 additions & 8 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2959,18 +2959,18 @@
"$ref": "#/$defs/EnableAutoSwitch",
"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."
},
"customResourceDefinitions": {
"customResources": {
"additionalProperties": {
"$ref": "#/$defs/SyncFromHostCustomResourceDefinition"
"$ref": "#/$defs/SyncFromHostCustomResources"
},
"type": "object",
"description": "CustomResourceDefinitions defines what custom resource definitions should get synced read-only to the virtual cluster from the host cluster."
"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."
}
},
"additionalProperties": false,
"type": "object"
},
"SyncFromHostCustomResourceDefinition": {
"SyncFromHostCustomResources": {
"properties": {
"enabled": {
"type": "boolean",
Expand Down Expand Up @@ -3144,18 +3144,18 @@
"$ref": "#/$defs/EnableSwitch",
"description": "PriorityClasses defines if priority classes created within the virtual cluster should get synced to the host cluster."
},
"customResourceDefinitions": {
"customResources": {
"additionalProperties": {
"$ref": "#/$defs/SyncToHostCustomResourceDefinition"
"$ref": "#/$defs/SyncToHostCustomResources"
},
"type": "object",
"description": "CustomResourceDefinitions defines what custom resource definitions should get synced from the virtual cluster to the host cluster."
"description": "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.\nvCluster will also automatically add any required RBAC permissions to the vCluster role for this to work."
}
},
"additionalProperties": false,
"type": "object"
},
"SyncToHostCustomResourceDefinition": {
"SyncToHostCustomResources": {
"properties": {
"enabled": {
"type": "boolean",
Expand Down
13 changes: 7 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,9 @@ type SyncToHost struct {
// PriorityClasses defines if priority classes created within the virtual cluster should get synced to the host cluster.
PriorityClasses EnableSwitch `json:"priorityClasses,omitempty"`

// CustomResourceDefinitions defines what custom resource definitions should get synced from the virtual cluster to the host cluster.
CustomResourceDefinitions map[string]SyncToHostCustomResourceDefinition `json:"customResourceDefinitions,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.
CustomResources map[string]SyncToHostCustomResources `json:"customResources,omitempty"`
}

type EnableSwitchWithTranslate struct {
Expand Down Expand Up @@ -485,11 +486,11 @@ type SyncFromHost struct {
// 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"`

// CustomResourceDefinitions defines what custom resource definitions should get synced read-only to the virtual cluster from the host cluster.
CustomResourceDefinitions map[string]SyncFromHostCustomResourceDefinition `json:"customResourceDefinitions,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]SyncFromHostCustomResources `json:"customResources,omitempty"`
}

type SyncToHostCustomResourceDefinition struct {
type SyncToHostCustomResources struct {
// Enabled defines if this option should be enabled.
Enabled bool `json:"enabled,omitempty"`

Expand Down Expand Up @@ -544,7 +545,7 @@ type TranslatePatchExpression struct {
FromHost string `json:"fromHost,omitempty" jsonschema:"oneof_required=fromHost"`
}

type SyncFromHostCustomResourceDefinition struct {
type SyncFromHostCustomResources struct {
// Enabled defines if this option should be enabled.
Enabled bool `json:"enabled,omitempty"`
}
Expand Down

0 comments on commit 10dd062

Please sign in to comment.