Skip to content

Added ability to mount external PVCs to cdap deployments and statefulsets #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions api/v1alpha1/cdapmaster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ type CDAPMasterSpec struct {
// Key is the secret object name. Value is the mount path.
// This adds Secret data to the directory specified by the volume mount path.
SecretVolumes map[string]string `json:"secretVolumes,omitempty"`
// PVCVolumes defines a map from Persistent Volume Claim names to volume mount path.
// Key is the PVC object name. Value is the mount path.
// This mounts PVC to the directory specified by the volume mount path.
PVCVolumes map[string]string `json:"pvcVolumes,omitempty"`
// SystemAppConfigs specifies configs used by CDAP to run system apps
// dynamically. Each entry is of format <filename, json app config> which will
// create a separate system config file with entry value as file content.
Expand Down Expand Up @@ -117,6 +121,10 @@ type CDAPServiceSpec struct {
// Key is the secret object name. Value is the mount path.
// This adds Secret data to the directory specified by the volume mount path.
SecretVolumes map[string]string `json:"secretVolumes,omitempty"`
// PVCVolumes defines a map from Persistent Volume Claim names to volume mount path.
// Key is the PVC object name. Value is the mount path.
// This mounts PVC to the directory specified by the volume mount path.
PVCVolumes map[string]string `json:"pvcVolumes,omitempty"`
// SecurityContext overrides the security context for the service pods.
SecurityContext *SecurityContext `json:"securityContext,omitempty"`
}
Expand Down
88 changes: 88 additions & 0 deletions config/crd/bases/cdap.cdap.io_cdapmasters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ spec:
is the mount path. This adds Secret data to the directory specified
by the volume mount path.
type: object
pvcVolumes:
additionalProperties:
type: string
description: PVCVolumes defines a map from Persistent Volume Claim
names to volume mount path. Key is the PVC object name. Value is the
mount path. This mounts PVC to the directory specified by the volume
mount path.
type: object
securityContext:
description: SecurityContext overrides the security context for
the service pods.
Expand Down Expand Up @@ -421,6 +429,14 @@ spec:
is the mount path. This adds Secret data to the directory specified
by the volume mount path.
type: object
pvcVolumes:
additionalProperties:
type: string
description: PVCVolumes defines a map from Persistent Volume Claim
names to volume mount path. Key is the PVC object name. Value is the
mount path. This mounts PVC to the directory specified by the volume
mount path.
type: object
securityContext:
description: SecurityContext overrides the security context for
the service pods.
Expand Down Expand Up @@ -656,6 +672,14 @@ spec:
is the mount path. This adds Secret data to the directory specified
by the volume mount path.
type: object
pvcVolumes:
additionalProperties:
type: string
description: PVCVolumes defines a map from Persistent Volume Claim
names to volume mount path. Key is the PVC object name. Value is the
mount path. This mounts PVC to the directory specified by the volume
mount path.
type: object
securityContext:
description: SecurityContext overrides the security context for
the service pods.
Expand Down Expand Up @@ -870,6 +894,14 @@ spec:
is the mount path. This adds Secret data to the directory specified
by the volume mount path.
type: object
pvcVolumes:
additionalProperties:
type: string
description: PVCVolumes defines a map from Persistent Volume Claim
names to volume mount path. Key is the PVC object name. Value is the
mount path. This mounts PVC to the directory specified by the volume
mount path.
type: object
securityContext:
description: SecurityContext overrides the security context for
the service pods.
Expand Down Expand Up @@ -1088,6 +1120,14 @@ spec:
is the mount path. This adds Secret data to the directory specified
by the volume mount path.
type: object
pvcVolumes:
additionalProperties:
type: string
description: PVCVolumes defines a map from Persistent Volume Claim
names to volume mount path. Key is the PVC object name. Value is the
mount path. This mounts PVC to the directory specified by the volume
mount path.
type: object
securityContext:
description: SecurityContext overrides the security context for
the service pods.
Expand Down Expand Up @@ -1294,6 +1334,14 @@ spec:
is the mount path. This adds Secret data to the directory specified
by the volume mount path.
type: object
pvcVolumes:
additionalProperties:
type: string
description: PVCVolumes defines a map from Persistent Volume Claim
names to volume mount path. Key is the PVC object name. Value is the
mount path. This mounts PVC to the directory specified by the volume
mount path.
type: object
securityContext:
description: SecurityContext overrides the security context for
the service pods.
Expand Down Expand Up @@ -1508,6 +1556,14 @@ spec:
is the mount path. This adds Secret data to the directory specified
by the volume mount path.
type: object
pvcVolumes:
additionalProperties:
type: string
description: PVCVolumes defines a map from Persistent Volume Claim
names to volume mount path. Key is the PVC object name. Value is the
mount path. This mounts PVC to the directory specified by the volume
mount path.
type: object
securityContext:
description: SecurityContext overrides the security context for
the service pods.
Expand Down Expand Up @@ -1726,6 +1782,14 @@ spec:
is the mount path. This adds Secret data to the directory specified
by the volume mount path.
type: object
pvcVolumes:
additionalProperties:
type: string
description: PVCVolumes defines a map from Persistent Volume Claim
names to volume mount path. Key is the PVC object name. Value is the
mount path. This mounts PVC to the directory specified by the volume
mount path.
type: object
securityContext:
description: SecurityContext overrides the security context for
the service pods.
Expand Down Expand Up @@ -1944,6 +2008,14 @@ spec:
is the mount path. This adds Secret data to the directory specified
by the volume mount path.
type: object
pvcVolumes:
additionalProperties:
type: string
description: PVCVolumes defines a map from Persistent Volume Claim
names to volume mount path. Key is the PVC object name. Value is the
mount path. This mounts PVC to the directory specified by the volume
mount path.
type: object
securityContext:
description: SecurityContext overrides the security context for
the service pods.
Expand Down Expand Up @@ -2007,6 +2079,14 @@ spec:
This adds Secret data to the directory specified by the volume mount
path.
type: object
pvcVolumes:
additionalProperties:
type: string
description: PVCVolumes defines a map from Persistent Volume Claim
names to volume mount path. Key is the PVC object name. Value is the
mount path. This mounts PVC to the directory specified by the volume
mount path.
type: object
securityContext:
description: SecurityContext defines the security context for all pods
for all services.
Expand Down Expand Up @@ -2226,6 +2306,14 @@ spec:
is the mount path. This adds Secret data to the directory specified
by the volume mount path.
type: object
pvcVolumes:
additionalProperties:
type: string
description: PVCVolumes defines a map from Persistent Volume Claim
names to volume mount path. Key is the PVC object name. Value is the
mount path. This mounts PVC to the directory specified by the volume
mount path.
type: object
securityContext:
description: SecurityContext overrides the security context for
the service pods.
Expand Down
6 changes: 6 additions & 0 deletions controllers/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ func buildStatefulSets(master *v1alpha1.CDAPMaster, name string, services Servic
if _, err := spec.addSecretVolumes(ss.SecretVolumes); err != nil {
return nil, err
}
if _, err := spec.addPVCVolumes(ss.PVCVolumes); err != nil {
return nil, err
}
}

// All services are optional services and are disabled in CR.
Expand Down Expand Up @@ -283,6 +286,9 @@ func buildDeployment(master *v1alpha1.CDAPMaster, name string, services ServiceG
if _, err := spec.addSecretVolumes(ss.SecretVolumes); err != nil {
return nil, err
}
if _, err := spec.addPVCVolumes(ss.PVCVolumes); err != nil {
return nil, err
}
}
// All services are optional services and are disabled in CR.
// Return nil to indicate no deployment is built.
Expand Down
23 changes: 23 additions & 0 deletions controllers/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ type BaseSpec struct {
SysAppConf string `json:"sysAppConf,omitempty"`
ConfigMapVolumes map[string]string `json:"configMapVolumes,omitempty"`
SecretVolumes map[string]string `json:"secretVolumes,omitempty"`
PVCVolumes map[string]string `json:"pvcVolumes,omitempty"`
SecurityContext *v1alpha1.SecurityContext `json:"securityContext,omitempty"`
}

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

return s
}
Expand Down Expand Up @@ -205,6 +207,13 @@ func (s *BaseSpec) addSecretVolumes(volumes map[string]string) (*BaseSpec, error
return s, nil
}

func (s *BaseSpec) addPVCVolumes(volumes map[string]string) (*BaseSpec, error) {
if err := addVolumes(s.PVCVolumes, volumes, "Persistent Volume Claim"); err != nil {
return nil, err
}
return s, nil
}

func addVolumes(volumes, newVolumes map[string]string, typeName string) error {
for k, v := range newVolumes {
if val, exists := volumes[k]; exists {
Expand Down Expand Up @@ -306,6 +315,13 @@ func (s *DeploymentSpec) addSecretVolumes(volumes map[string]string) (*Deploymen
return s, nil
}

func (s *DeploymentSpec) addPVCVolumes(volumes map[string]string) (*DeploymentSpec, error) {
if _, err := s.Base.addPVCVolumes(volumes); err != nil {
return nil, err
}
return s, nil
}

func (s *DeploymentSpec) setSecurityContext(securityContext *v1alpha1.SecurityContext) *DeploymentSpec {
s.Base.setSecurityContext(securityContext)
return s
Expand Down Expand Up @@ -397,6 +413,13 @@ func (s *StatefulSpec) addSecretVolumes(volumes map[string]string) (*StatefulSpe
return s, nil
}

func (s *StatefulSpec) addPVCVolumes(volumes map[string]string) (*StatefulSpec, error) {
if _, err := s.Base.addPVCVolumes(volumes); err != nil {
return nil, err
}
return s, nil
}

func (s *StatefulSpec) setSecurityContext(securityContext *v1alpha1.SecurityContext) *StatefulSpec {
s.Base.setSecurityContext(securityContext)
return s
Expand Down
28 changes: 28 additions & 0 deletions controllers/testdata/appfabric.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@
{
"mountPath": "/my/secret/1",
"name": "cdap-se-vol-my-secret-1"
},
{
"mountPath": "/my/pvc/0",
"name": "cdap-vol-my-pvc-0"
},
{
"mountPath": "/my/pvc/1",
"name": "cdap-vol-my-pvc-1"
}
]
}
Expand Down Expand Up @@ -189,6 +197,14 @@
{
"mountPath": "/my/secret/1",
"name": "cdap-se-vol-my-secret-1"
},
{
"mountPath": "/my/pvc/0",
"name": "cdap-vol-my-pvc-0"
},
{
"mountPath": "/my/pvc/1",
"name": "cdap-vol-my-pvc-1"
}
]
}
Expand Down Expand Up @@ -283,6 +299,18 @@
"defaultMode": 420,
"secretName": "my-secret-1"
}
},
{
"name": "cdap-vol-my-pvc-0",
"persistentVolumeClaim": {
"claimName": "my-pvc-0"
}
},
{
"name": "cdap-vol-my-pvc-1",
"persistentVolumeClaim": {
"claimName": "my-pvc-1"
}
}
]
}
Expand Down
10 changes: 10 additions & 0 deletions controllers/testdata/authentication.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@
{
"mountPath": "/my/secret/key",
"name": "cdap-se-vol-secret-key"
},
{
"mountPath": "/my/pvc/0",
"name": "cdap-vol-my-pvc-0"
}
]
}
Expand Down Expand Up @@ -233,6 +237,12 @@
"secret": {
"secretName": "secret-key"
}
},
{
"name": "cdap-vol-my-pvc-0",
"persistentVolumeClaim": {
"claimName": "my-pvc-0"
}
}
]
}
Expand Down
6 changes: 6 additions & 0 deletions controllers/testdata/cdap_master_cr.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
"runAsGroup": 3000,
"fsGroup": 4000,
"runAsNonRoot": false
},
"pvcVolumes": {
"my-pvc-1": "/my/pvc/1"
}
},
"authentication": {
Expand Down Expand Up @@ -81,6 +84,9 @@
"secretVolumes": {
"my-secret-1": "/my/secret/1"
},
"pvcVolumes": {
"my-pvc-0": "/my/pvc/0"
},
"image": "gcr.io/cloud-data-fusion-images/cloud-data-fusion:6.1.0.5",
"locationURI": "hdfs://hadoop:9000",
"logs": {
Expand Down
14 changes: 14 additions & 0 deletions controllers/testdata/logs.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@
{
"mountPath": "/my/secret/1",
"name": "cdap-se-vol-my-secret-1"
},
{
"mountPath": "/my/pvc/0",
"name": "cdap-vol-my-pvc-0"
}
]
}
Expand Down Expand Up @@ -182,6 +186,10 @@
{
"mountPath": "/my/secret/1",
"name": "cdap-se-vol-my-secret-1"
},
{
"mountPath": "/my/pvc/0",
"name": "cdap-vol-my-pvc-0"
}
]
}
Expand Down Expand Up @@ -275,6 +283,12 @@
"defaultMode": 420,
"secretName": "my-secret-1"
}
},
{
"name": "cdap-vol-my-pvc-0",
"persistentVolumeClaim": {
"claimName": "my-pvc-0"
}
}
]
}
Expand Down
Loading