Skip to content

Commit 4fc0d21

Browse files
authored
Volume snapshots config and upstream controller and CRDs (#3192)
* Add volume snapshots enable switch * Deploy upstream snapshot-controller and CRDs * Add volumeSnapshotController config and remove volumeSnapshot.enabled * Add volumeSnapshotController config validation
1 parent 5660a50 commit 4fc0d21

File tree

10 files changed

+1397
-0
lines changed

10 files changed

+1397
-0
lines changed

chart/values.schema.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,10 @@
11091109
"metricsServer": {
11101110
"$ref": "#/$defs/DeployMetricsServer",
11111111
"description": "MetricsServer holds dedicated metrics server configuration."
1112+
},
1113+
"volumeSnapshotController": {
1114+
"$ref": "#/$defs/VolumeSnapshotController",
1115+
"description": "VolumeSnapshotController holds dedicated CSI snapshot-controller configuration."
11121116
}
11131117
},
11141118
"additionalProperties": false,
@@ -4714,6 +4718,17 @@
47144718
"additionalProperties": false,
47154719
"type": "object",
47164720
"description": "VolumeMount describes a mounting of a Volume within a container."
4721+
},
4722+
"VolumeSnapshotController": {
4723+
"properties": {
4724+
"enabled": {
4725+
"type": "boolean",
4726+
"description": "Enabled defines if the CSI volumes snapshot-controller should be enabled."
4727+
}
4728+
},
4729+
"additionalProperties": false,
4730+
"type": "object",
4731+
"description": "VolumeSnapshotController defines CSI volumes snapshot-controller configuration."
47174732
}
47184733
},
47194734
"properties": {

chart/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,11 @@ deploy:
885885
metricsServer:
886886
# Enabled defines if metrics server should be enabled.
887887
enabled: false
888+
889+
# VolumeSnapshotController holds dedicated CSI snapshot-controller configuration.
890+
volumeSnapshotController:
891+
# Enabled defines if the CSI volumes snapshot-controller should be enabled.
892+
enabled: false
888893

889894
# Integrations holds config for vCluster integrations with other operators or tools running on the host cluster
890895
integrations:

config/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,22 @@ type Deploy struct {
298298

299299
// MetricsServer holds dedicated metrics server configuration.
300300
MetricsServer DeployMetricsServer `json:"metricsServer,omitempty"`
301+
302+
// VolumeSnapshotController holds dedicated CSI snapshot-controller configuration.
303+
VolumeSnapshotController VolumeSnapshotController `json:"volumeSnapshotController,omitempty"`
301304
}
302305

303306
type DeployMetricsServer struct {
304307
// Enabled defines if metrics server should be enabled.
305308
Enabled bool `json:"enabled,omitempty"`
306309
}
307310

311+
// VolumeSnapshotController defines CSI volumes snapshot-controller configuration.
312+
type VolumeSnapshotController struct {
313+
// Enabled defines if the CSI volumes snapshot-controller should be enabled.
314+
Enabled bool `json:"enabled,omitempty"`
315+
}
316+
308317
type IngressNginx struct {
309318
// Enabled defines if ingress-nginx should be enabled.
310319
Enabled bool `json:"enabled,omitempty"`

config/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ deploy:
472472
defaultIngressClass: true
473473
metricsServer:
474474
enabled: false
475+
volumeSnapshotController:
476+
enabled: false
475477

476478
integrations:
477479
metricsServer:

pkg/cli/create_helm.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ func CreateHelm(ctx context.Context, options *CreateOptions, globalFlags *flags.
329329
return err
330330
}
331331

332+
err = pkgconfig.ValidateVolumeSnapshotController(vClusterConfig.Deploy.VolumeSnapshotController, vClusterConfig.PrivateNodes)
333+
if err != nil {
334+
return err
335+
}
336+
332337
warnings := pkgconfig.Lint(*vClusterConfig)
333338
for _, warning := range warnings {
334339
cmd.log.Warnf(warning)

pkg/config/validation.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ func ValidateConfigAndSetDefaults(vConfig *VirtualClusterConfig) error {
199199
return err
200200
}
201201

202+
// validate deploy.volumeSnapshotController
203+
err = ValidateVolumeSnapshotController(vConfig.Config.Deploy.VolumeSnapshotController, vConfig.PrivateNodes)
204+
if err != nil {
205+
return err
206+
}
207+
202208
return nil
203209
}
204210

@@ -790,6 +796,13 @@ func validatePrivatedNodesMode(vConfig *VirtualClusterConfig) error {
790796
return nil
791797
}
792798

799+
func ValidateVolumeSnapshotController(volumeSnapshotController config.VolumeSnapshotController, privateNodes config.PrivateNodes) error {
800+
if volumeSnapshotController.Enabled && !privateNodes.Enabled {
801+
return fmt.Errorf("volume snapshot-controller is only supported with private nodes")
802+
}
803+
return nil
804+
}
805+
793806
var allowedOperators = []string{"", "In", "NotIn", "Exists", "DoesNotExist", "Gt", "Lt"}
794807

795808
func validateRequirements(requirements []config.Requirement) error {

pkg/controllers/register.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/loft-sh/vcluster/pkg/controllers/k8sdefaultendpoint"
2222
"github.com/loft-sh/vcluster/pkg/controllers/podsecurity"
2323
"github.com/loft-sh/vcluster/pkg/snapshot"
24+
csiVolumeSnapshots "github.com/loft-sh/vcluster/pkg/snapshot/volumes/csi/deploy"
2425
"github.com/loft-sh/vcluster/pkg/util/loghelper"
2526
"github.com/pkg/errors"
2627
)
@@ -267,5 +268,13 @@ func registerSnapshotController(registerContext *synccontext.RegisterContext) er
267268
return fmt.Errorf("unable to register vcluster snapshot controller: %w", err)
268269
}
269270

271+
config := registerContext.Config
272+
if config.PrivateNodes.Enabled && config.Deploy.VolumeSnapshotController.Enabled {
273+
err = csiVolumeSnapshots.Deploy(registerContext)
274+
if err != nil {
275+
return fmt.Errorf("unable to deploy required CSI volume snapshot compoments: %w", err)
276+
}
277+
}
278+
270279
return nil
271280
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package deploy
2+
3+
import (
4+
_ "embed"
5+
"fmt"
6+
7+
"k8s.io/klog/v2"
8+
9+
"github.com/loft-sh/vcluster/pkg/syncer/synccontext"
10+
"github.com/loft-sh/vcluster/pkg/util/applier"
11+
)
12+
13+
var (
14+
//go:embed snapshot.storage.k8s.io-crds-v8.3.0.yaml
15+
snapshotCRDs string
16+
17+
//go:embed snapshot-controller-v8.3.0.yaml
18+
snapshotController string
19+
)
20+
21+
func Deploy(ctx *synccontext.RegisterContext) error {
22+
// apply the volume snapshot CustomResourceDefinition manifests
23+
klog.Infof("Applying volume snapshot CustomResourceDefinitions...")
24+
err := applier.ApplyManifest(ctx, ctx.VirtualManager.GetConfig(), []byte(snapshotCRDs))
25+
if err != nil {
26+
return fmt.Errorf("failed to apply volume snapshot CustomResourceDefinitions: %w", err)
27+
}
28+
29+
// apply the snapshot controller manifests
30+
klog.Infof("Applying snapshot controller...")
31+
err = applier.ApplyManifest(ctx, ctx.VirtualManager.GetConfig(), []byte(snapshotController))
32+
if err != nil {
33+
return fmt.Errorf("failed to apply snapshot controller: %w", err)
34+
}
35+
36+
return nil
37+
}
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: snapshot-controller
5+
namespace: kube-system
6+
---
7+
apiVersion: rbac.authorization.k8s.io/v1
8+
kind: Role
9+
metadata:
10+
name: snapshot-controller-leaderelection
11+
namespace: kube-system
12+
rules:
13+
- apiGroups:
14+
- coordination.k8s.io
15+
resources:
16+
- leases
17+
verbs:
18+
- get
19+
- watch
20+
- list
21+
- delete
22+
- update
23+
- create
24+
---
25+
apiVersion: rbac.authorization.k8s.io/v1
26+
kind: ClusterRole
27+
metadata:
28+
name: snapshot-controller-runner
29+
rules:
30+
- apiGroups:
31+
- ""
32+
resources:
33+
- persistentvolumes
34+
verbs:
35+
- get
36+
- list
37+
- watch
38+
- apiGroups:
39+
- ""
40+
resources:
41+
- persistentvolumeclaims
42+
verbs:
43+
- get
44+
- list
45+
- watch
46+
- update
47+
- apiGroups:
48+
- ""
49+
resources:
50+
- events
51+
verbs:
52+
- list
53+
- watch
54+
- create
55+
- update
56+
- patch
57+
- apiGroups:
58+
- snapshot.storage.k8s.io
59+
resources:
60+
- volumesnapshotclasses
61+
verbs:
62+
- get
63+
- list
64+
- watch
65+
- apiGroups:
66+
- snapshot.storage.k8s.io
67+
resources:
68+
- volumesnapshotcontents
69+
verbs:
70+
- create
71+
- get
72+
- list
73+
- watch
74+
- update
75+
- delete
76+
- patch
77+
- apiGroups:
78+
- snapshot.storage.k8s.io
79+
resources:
80+
- volumesnapshotcontents/status
81+
verbs:
82+
- patch
83+
- apiGroups:
84+
- snapshot.storage.k8s.io
85+
resources:
86+
- volumesnapshots
87+
verbs:
88+
- create
89+
- get
90+
- list
91+
- watch
92+
- update
93+
- patch
94+
- delete
95+
- apiGroups:
96+
- snapshot.storage.k8s.io
97+
resources:
98+
- volumesnapshots/status
99+
verbs:
100+
- update
101+
- patch
102+
- apiGroups:
103+
- groupsnapshot.storage.k8s.io
104+
resources:
105+
- volumegroupsnapshotclasses
106+
verbs:
107+
- get
108+
- list
109+
- watch
110+
- apiGroups:
111+
- groupsnapshot.storage.k8s.io
112+
resources:
113+
- volumegroupsnapshotcontents
114+
verbs:
115+
- create
116+
- get
117+
- list
118+
- watch
119+
- update
120+
- delete
121+
- patch
122+
- apiGroups:
123+
- groupsnapshot.storage.k8s.io
124+
resources:
125+
- volumegroupsnapshotcontents/status
126+
verbs:
127+
- patch
128+
- apiGroups:
129+
- groupsnapshot.storage.k8s.io
130+
resources:
131+
- volumegroupsnapshots
132+
verbs:
133+
- get
134+
- list
135+
- watch
136+
- update
137+
- patch
138+
- apiGroups:
139+
- groupsnapshot.storage.k8s.io
140+
resources:
141+
- volumegroupsnapshots/status
142+
verbs:
143+
- update
144+
- patch
145+
---
146+
apiVersion: rbac.authorization.k8s.io/v1
147+
kind: RoleBinding
148+
metadata:
149+
name: snapshot-controller-leaderelection
150+
namespace: kube-system
151+
roleRef:
152+
apiGroup: rbac.authorization.k8s.io
153+
kind: Role
154+
name: snapshot-controller-leaderelection
155+
subjects:
156+
- kind: ServiceAccount
157+
name: snapshot-controller
158+
---
159+
apiVersion: rbac.authorization.k8s.io/v1
160+
kind: ClusterRoleBinding
161+
metadata:
162+
name: snapshot-controller-role
163+
roleRef:
164+
apiGroup: rbac.authorization.k8s.io
165+
kind: ClusterRole
166+
name: snapshot-controller-runner
167+
subjects:
168+
- kind: ServiceAccount
169+
name: snapshot-controller
170+
namespace: kube-system
171+
---
172+
apiVersion: apps/v1
173+
kind: Deployment
174+
metadata:
175+
name: snapshot-controller
176+
namespace: kube-system
177+
spec:
178+
minReadySeconds: 35
179+
replicas: 2
180+
selector:
181+
matchLabels:
182+
app.kubernetes.io/name: snapshot-controller
183+
strategy:
184+
rollingUpdate:
185+
maxSurge: 0
186+
maxUnavailable: 1
187+
type: RollingUpdate
188+
template:
189+
metadata:
190+
labels:
191+
app.kubernetes.io/name: snapshot-controller
192+
spec:
193+
containers:
194+
- args:
195+
- --v=5
196+
- --leader-election=true
197+
image: registry.k8s.io/sig-storage/snapshot-controller:v8.3.0
198+
imagePullPolicy: IfNotPresent
199+
name: snapshot-controller
200+
serviceAccountName: snapshot-controller

0 commit comments

Comments
 (0)