Skip to content

Commit 3cc3a2f

Browse files
committed
Added ability to mount external PVCs to cdap deployments and statefulsets.
1 parent f4ba48a commit 3cc3a2f

File tree

6 files changed

+143
-0
lines changed

6 files changed

+143
-0
lines changed

api/v1alpha1/cdapmaster_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ type CDAPMasterSpec struct {
5454
// Key is the secret object name. Value is the mount path.
5555
// This adds Secret data to the directory specified by the volume mount path.
5656
SecretVolumes map[string]string `json:"secretVolumes,omitempty"`
57+
// PVCVolumes defines a map from Persistent Volume Claim names to volume mount path.
58+
// Key is the PVC object name. Value is the mount path.
59+
// This mounts PVC to the directory specified by the volume mount path.
60+
PVCVolumes map[string]string `json:"pvcVolumes,omitempty"`
5761
// SystemAppConfigs specifies configs used by CDAP to run system apps
5862
// dynamically. Each entry is of format <filename, json app config> which will
5963
// create a separate system config file with entry value as file content.
@@ -117,6 +121,10 @@ type CDAPServiceSpec struct {
117121
// Key is the secret object name. Value is the mount path.
118122
// This adds Secret data to the directory specified by the volume mount path.
119123
SecretVolumes map[string]string `json:"secretVolumes,omitempty"`
124+
// PVCVolumes defines a map from Persistent Volume Claim names to volume mount path.
125+
// Key is the PVC object name. Value is the mount path.
126+
// This mounts PVC to the directory specified by the volume mount path.
127+
PVCVolumes map[string]string `json:"pvcVolumes,omitempty"`
120128
// SecurityContext overrides the security context for the service pods.
121129
SecurityContext *SecurityContext `json:"securityContext,omitempty"`
122130
}

config/crd/bases/cdap.cdap.io_cdapmasters.yaml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ spec:
199199
is the mount path. This adds Secret data to the directory specified
200200
by the volume mount path.
201201
type: object
202+
pvcVolumes:
203+
additionalProperties:
204+
type: string
205+
description: PVCVolumes defines a map from Persistent Volume Claim
206+
names to volume mount path. Key is the PVC object name. Value is the
207+
mount path. This mounts PVC to the directory specified by the volume
208+
mount path.
209+
type: object
202210
securityContext:
203211
description: SecurityContext overrides the security context for
204212
the service pods.
@@ -421,6 +429,14 @@ spec:
421429
is the mount path. This adds Secret data to the directory specified
422430
by the volume mount path.
423431
type: object
432+
pvcVolumes:
433+
additionalProperties:
434+
type: string
435+
description: PVCVolumes defines a map from Persistent Volume Claim
436+
names to volume mount path. Key is the PVC object name. Value is the
437+
mount path. This mounts PVC to the directory specified by the volume
438+
mount path.
439+
type: object
424440
securityContext:
425441
description: SecurityContext overrides the security context for
426442
the service pods.
@@ -656,6 +672,14 @@ spec:
656672
is the mount path. This adds Secret data to the directory specified
657673
by the volume mount path.
658674
type: object
675+
pvcVolumes:
676+
additionalProperties:
677+
type: string
678+
description: PVCVolumes defines a map from Persistent Volume Claim
679+
names to volume mount path. Key is the PVC object name. Value is the
680+
mount path. This mounts PVC to the directory specified by the volume
681+
mount path.
682+
type: object
659683
securityContext:
660684
description: SecurityContext overrides the security context for
661685
the service pods.
@@ -870,6 +894,14 @@ spec:
870894
is the mount path. This adds Secret data to the directory specified
871895
by the volume mount path.
872896
type: object
897+
pvcVolumes:
898+
additionalProperties:
899+
type: string
900+
description: PVCVolumes defines a map from Persistent Volume Claim
901+
names to volume mount path. Key is the PVC object name. Value is the
902+
mount path. This mounts PVC to the directory specified by the volume
903+
mount path.
904+
type: object
873905
securityContext:
874906
description: SecurityContext overrides the security context for
875907
the service pods.
@@ -1088,6 +1120,14 @@ spec:
10881120
is the mount path. This adds Secret data to the directory specified
10891121
by the volume mount path.
10901122
type: object
1123+
pvcVolumes:
1124+
additionalProperties:
1125+
type: string
1126+
description: PVCVolumes defines a map from Persistent Volume Claim
1127+
names to volume mount path. Key is the PVC object name. Value is the
1128+
mount path. This mounts PVC to the directory specified by the volume
1129+
mount path.
1130+
type: object
10911131
securityContext:
10921132
description: SecurityContext overrides the security context for
10931133
the service pods.
@@ -1294,6 +1334,14 @@ spec:
12941334
is the mount path. This adds Secret data to the directory specified
12951335
by the volume mount path.
12961336
type: object
1337+
pvcVolumes:
1338+
additionalProperties:
1339+
type: string
1340+
description: PVCVolumes defines a map from Persistent Volume Claim
1341+
names to volume mount path. Key is the PVC object name. Value is the
1342+
mount path. This mounts PVC to the directory specified by the volume
1343+
mount path.
1344+
type: object
12971345
securityContext:
12981346
description: SecurityContext overrides the security context for
12991347
the service pods.
@@ -1508,6 +1556,14 @@ spec:
15081556
is the mount path. This adds Secret data to the directory specified
15091557
by the volume mount path.
15101558
type: object
1559+
pvcVolumes:
1560+
additionalProperties:
1561+
type: string
1562+
description: PVCVolumes defines a map from Persistent Volume Claim
1563+
names to volume mount path. Key is the PVC object name. Value is the
1564+
mount path. This mounts PVC to the directory specified by the volume
1565+
mount path.
1566+
type: object
15111567
securityContext:
15121568
description: SecurityContext overrides the security context for
15131569
the service pods.
@@ -1726,6 +1782,14 @@ spec:
17261782
is the mount path. This adds Secret data to the directory specified
17271783
by the volume mount path.
17281784
type: object
1785+
pvcVolumes:
1786+
additionalProperties:
1787+
type: string
1788+
description: PVCVolumes defines a map from Persistent Volume Claim
1789+
names to volume mount path. Key is the PVC object name. Value is the
1790+
mount path. This mounts PVC to the directory specified by the volume
1791+
mount path.
1792+
type: object
17291793
securityContext:
17301794
description: SecurityContext overrides the security context for
17311795
the service pods.
@@ -1944,6 +2008,14 @@ spec:
19442008
is the mount path. This adds Secret data to the directory specified
19452009
by the volume mount path.
19462010
type: object
2011+
pvcVolumes:
2012+
additionalProperties:
2013+
type: string
2014+
description: PVCVolumes defines a map from Persistent Volume Claim
2015+
names to volume mount path. Key is the PVC object name. Value is the
2016+
mount path. This mounts PVC to the directory specified by the volume
2017+
mount path.
2018+
type: object
19472019
securityContext:
19482020
description: SecurityContext overrides the security context for
19492021
the service pods.
@@ -2007,6 +2079,14 @@ spec:
20072079
This adds Secret data to the directory specified by the volume mount
20082080
path.
20092081
type: object
2082+
pvcVolumes:
2083+
additionalProperties:
2084+
type: string
2085+
description: PVCVolumes defines a map from Persistent Volume Claim
2086+
names to volume mount path. Key is the PVC object name. Value is the
2087+
mount path. This mounts PVC to the directory specified by the volume
2088+
mount path.
2089+
type: object
20102090
securityContext:
20112091
description: SecurityContext defines the security context for all pods
20122092
for all services.
@@ -2226,6 +2306,14 @@ spec:
22262306
is the mount path. This adds Secret data to the directory specified
22272307
by the volume mount path.
22282308
type: object
2309+
pvcVolumes:
2310+
additionalProperties:
2311+
type: string
2312+
description: PVCVolumes defines a map from Persistent Volume Claim
2313+
names to volume mount path. Key is the PVC object name. Value is the
2314+
mount path. This mounts PVC to the directory specified by the volume
2315+
mount path.
2316+
type: object
22292317
securityContext:
22302318
description: SecurityContext overrides the security context for
22312319
the service pods.

controllers/deployment.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ func buildStatefulSets(master *v1alpha1.CDAPMaster, name string, services Servic
198198
if _, err := spec.addSecretVolumes(ss.SecretVolumes); err != nil {
199199
return nil, err
200200
}
201+
if _, err := spec.addPVCVolumes(ss.PVCVolumes); err != nil {
202+
return nil, err
203+
}
201204
}
202205

203206
// All services are optional services and are disabled in CR.
@@ -283,6 +286,9 @@ func buildDeployment(master *v1alpha1.CDAPMaster, name string, services ServiceG
283286
if _, err := spec.addSecretVolumes(ss.SecretVolumes); err != nil {
284287
return nil, err
285288
}
289+
if _, err := spec.addPVCVolumes(ss.PVCVolumes); err != nil {
290+
return nil, err
291+
}
286292
}
287293
// All services are optional services and are disabled in CR.
288294
// Return nil to indicate no deployment is built.

controllers/spec.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ type BaseSpec struct {
137137
SysAppConf string `json:"sysAppConf,omitempty"`
138138
ConfigMapVolumes map[string]string `json:"configMapVolumes,omitempty"`
139139
SecretVolumes map[string]string `json:"secretVolumes,omitempty"`
140+
PVCVolumes map[string]string `json:"pvcVolumes,omitempty"`
140141
SecurityContext *v1alpha1.SecurityContext `json:"securityContext,omitempty"`
141142
}
142143

@@ -156,6 +157,7 @@ func newBaseSpec(master *v1alpha1.CDAPMaster, name string, labels map[string]str
156157
s.SysAppConf = sysappconf
157158
s.ConfigMapVolumes = cloneMap(master.Spec.ConfigMapVolumes)
158159
s.SecretVolumes = cloneMap(master.Spec.SecretVolumes)
160+
s.PVCVolumes = cloneMap(master.Spec.PVCVolumes)
159161

160162
return s
161163
}
@@ -205,6 +207,13 @@ func (s *BaseSpec) addSecretVolumes(volumes map[string]string) (*BaseSpec, error
205207
return s, nil
206208
}
207209

210+
func (s *BaseSpec) addPVCVolumes(volumes map[string]string) (*BaseSpec, error) {
211+
if err := addVolumes(s.PVCVolumes, volumes, "Persistent Volume Claim"); err != nil {
212+
return nil, err
213+
}
214+
return s, nil
215+
}
216+
208217
func addVolumes(volumes, newVolumes map[string]string, typeName string) error {
209218
for k, v := range newVolumes {
210219
if val, exists := volumes[k]; exists {
@@ -306,6 +315,13 @@ func (s *DeploymentSpec) addSecretVolumes(volumes map[string]string) (*Deploymen
306315
return s, nil
307316
}
308317

318+
func (s *DeploymentSpec) addPVCVolumes(volumes map[string]string) (*DeploymentSpec, error) {
319+
if _, err := s.Base.addPVCVolumes(volumes); err != nil {
320+
return nil, err
321+
}
322+
return s, nil
323+
}
324+
309325
func (s *DeploymentSpec) setSecurityContext(securityContext *v1alpha1.SecurityContext) *DeploymentSpec {
310326
s.Base.setSecurityContext(securityContext)
311327
return s
@@ -397,6 +413,13 @@ func (s *StatefulSpec) addSecretVolumes(volumes map[string]string) (*StatefulSpe
397413
return s, nil
398414
}
399415

416+
func (s *StatefulSpec) addPVCVolumes(volumes map[string]string) (*StatefulSpec, error) {
417+
if _, err := s.Base.addPVCVolumes(volumes); err != nil {
418+
return nil, err
419+
}
420+
return s, nil
421+
}
422+
400423
func (s *StatefulSpec) setSecurityContext(securityContext *v1alpha1.SecurityContext) *StatefulSpec {
401424
s.Base.setSecurityContext(securityContext)
402425
return s

templates/cdap-deployment.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ spec:
132132
- name: cdap-se-vol-{{$k}}
133133
mountPath: {{$v}}
134134
{{end}}
135+
{{range $k,$v := $.Base.PVCVolumes}}
136+
- name: cdap-vol-{{$k}}
137+
mountPath: {{$v}}
138+
{{end}}
135139
{{end}}
136140
volumes:
137141
- name: podinfo
@@ -170,3 +174,8 @@ spec:
170174
secret:
171175
secretName: {{$k}}
172176
{{end}}
177+
{{range $k,$v := $.Base.PVCVolumes}}
178+
- name: cdap-vol-{{$k}}
179+
persistentVolumeClaim:
180+
claimName: {{$k}}
181+
{{end}}

templates/cdap-sts.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ spec:
172172
- name: cdap-se-vol-{{$k}}
173173
mountPath: {{$v}}
174174
{{end}}
175+
{{range $k,$v := $.Base.PVCVolumes}}
176+
- name: cdap-vol-{{$k}}
177+
mountPath: {{$v}}
178+
{{end}}
175179
{{end}}
176180
volumes:
177181
- name: podinfo
@@ -210,6 +214,11 @@ spec:
210214
secret:
211215
secretName: {{$k}}
212216
{{end}}
217+
{{range $k,$v := $.Base.PVCVolumes}}
218+
- name: cdap-vol-{{$k}}
219+
persistentVolumeClaim:
220+
claimName: {{$k}}
221+
{{end}}
213222
volumeClaimTemplates:
214223
- metadata:
215224
name: {{.Base.Name}}-data

0 commit comments

Comments
 (0)