Skip to content

Commit df5ef00

Browse files
alouriebenbromhead
authored andcommitted
Support user configs, user secrets and separate environments for cassandra and sidecar (#218)
* Initial work for clouds secrets and user-defined configmap Signed-off-by: Alex Lourie <[email protected]> * PR comments fixes Fixes #213 Fixes #208 * Fixed some comments from PR review * Added Env to CRD to allow specifying environment for containers (exists in java version) * Added userConfigMap handling (#213) * Restored PrivelegedSupported handling (#208) * Backup secret volume allows providing GOOGLE_APPLICATION_CREDENTIALS in a secret * Cloud providers creds can be set using Env field in CRD Signed-off-by: Alex Lourie <[email protected]> * Support TLS certificates for internal communication Signed-off-by: Alex Lourie <[email protected]> * PR comments, docs updates Signed-off-by: Alex Lourie <[email protected]> * Cleanups Signed-off-by: Alex Lourie <[email protected]> * Path naming update Signed-off-by: Alex Lourie <[email protected]> * Cleanups * go fmt Signed-off-by: Alex Lourie <[email protected]>
1 parent 2372b2e commit df5ef00

File tree

9 files changed

+215
-38
lines changed

9 files changed

+215
-38
lines changed

deploy/crds/cassandraoperator_v1alpha1_cassandradatacenter_crd.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ spec:
2929
type: object
3030
spec:
3131
properties:
32+
backupSecretVolumeSource:
33+
type: object
34+
cassandraEnv:
35+
items:
36+
type: object
37+
type: array
3238
cassandraImage:
3339
type: string
3440
cluster:
@@ -46,15 +52,25 @@ spec:
4652
nodes:
4753
format: int32
4854
type: integer
55+
privilegedSupported:
56+
type: boolean
4957
prometheusSupport:
5058
type: boolean
5159
resources:
5260
type: object
61+
sidecarEnv:
62+
items:
63+
type: object
64+
type: array
5365
serviceAccountName:
5466
description: ServiceAccount to assign to pods created by the operator
5567
type: string
5668
sidecarImage:
5769
type: string
70+
userConfigMapVolumeSource:
71+
type: object
72+
userSecretVolumeSource:
73+
type: object
5874
required:
5975
- nodes
6076
- cassandraImage

doc/backup_restore.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ You can inspect the secret created via `kubectl describe secrets/awsbackuptest`
2222
Create a `CassandraDataCenter` CRD that injects the secret as environment variables that matches the AWS client libraries expected env variables:
2323

2424
```yaml
25-
env:
25+
sidecarEnv:
2626
- name: AWS_ACCESS_KEY_ID
2727
valueFrom:
2828
secretKeyRef:
@@ -65,7 +65,7 @@ spec:
6565
resources:
6666
requests:
6767
storage: 100Mi
68-
env:
68+
sidecarEnv:
6969
- name: AWS_ACCESS_KEY_ID
7070
valueFrom:
7171
secretKeyRef:
@@ -85,6 +85,9 @@ spec:
8585
To create a cluster using this yaml file use `kubectl apply -f myBackupCluster.yaml`
8686

8787
## Configuring GCP Object Storage via environment variables
88+
The backup credentials will be added to the sidecar container at the `/tmp/backup-creds` location.
89+
Use this location to set GOOGLE_APPLICATION_CREDENTIALS environment variable to the key json file stored in the secret.
90+
8891
First create a secret in kubernetes to hold a Google service account token/file (assuming they are stored in files named access and secret respectively).
8992

9093
`kubectl create secret generic gcp-auth-reference --from-file=my_service_key.json`
@@ -118,14 +121,14 @@ spec:
118121
resources:
119122
requests:
120123
storage: 100Mi
121-
userSecretSource:
124+
backupSecretVolumeSource:
122125
name: gcp-auth-reference
123126
items:
124127
- key: my_service_key.json
125128
path: my_service_key.json
126-
env:
129+
sidecarEnv:
127130
- name: GOOGLE_APPLICATION_CREDENTIALS
128-
value: "/tmp/user-secret/my_service_key.json"
131+
value: "/tmp/backup-creds/my_service_key.json"
129132
- name: GOOGLE_CLOUD_PROJECT
130133
value: "cassandra-operator"
131134
- name: BUCKET_NAME

examples/go/example-datacenter.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,27 @@ spec:
1010
cassandraImage: "gcr.io/cassandra-operator/cassandra:3.11.3"
1111
sidecarImage: "gcr.io/cassandra-operator/cassandra-sidecar:latest"
1212
imagePullPolicy: IfNotPresent
13+
imagePullSecrets:
14+
- name: regcred
15+
backupSecretVolumeSource:
16+
# example from doc/backup_restore.md
17+
secretName: gcp-auth-reference
18+
# type is a workaround for https://github.com/kubernetes/kubernetes/issues/68466
19+
type: array
20+
items:
21+
- key: my-service-key.json
22+
path: my-service-key.json
23+
sidecarEnv:
24+
- name: GOOGLE_APPLICATION_CREDENTIALS
25+
value: "/tmp/backup-creds/my-service-key.json"
26+
userConfigMapVolumeSource:
27+
# example from doc/providers/pks.md
28+
# the name of the ConfigMap
29+
name: concurrent-data
30+
# ConfigMap keys -> file paths (relative to /etc/cassandra)
31+
items:
32+
- key: 100-concurrent-yaml
33+
path: cassandra.yaml.d/100-concurrent.yaml
1334
resources:
1435
limits:
1536
memory: 1Gi

pkg/apis/cassandraoperator/v1alpha1/cassandradatacenter_types.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ import (
1010
type CassandraDataCenterSpec struct {
1111
// Cluster is either a string or v1.LocalObjectReference
1212
//Cluster interface{} `json:"cluster,omitempty"`
13-
Cluster string `json:"cluster,omitempty"`
14-
Nodes int32 `json:"nodes"`
15-
CassandraImage string `json:"cassandraImage"`
16-
SidecarImage string `json:"sidecarImage"`
17-
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy"`
18-
ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
19-
20-
Resources v1.ResourceRequirements `json:"resources"`
21-
22-
DataVolumeClaimSpec v1.PersistentVolumeClaimSpec `json:"dataVolumeClaimSpec"`
23-
24-
PrometheusSupport bool `json:"prometheusSupport"`
25-
13+
Cluster string `json:"cluster,omitempty"`
14+
Nodes int32 `json:"nodes"`
15+
CassandraImage string `json:"cassandraImage"`
16+
SidecarImage string `json:"sidecarImage"`
17+
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy"`
18+
ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
19+
BackupSecretVolumeSource *v1.SecretVolumeSource `json:"backupSecretVolumeSource,omitempty"`
20+
UserSecretVolumeSource *v1.SecretVolumeSource `json:"userSecretVolumeSource,omitempty"`
21+
UserConfigMapVolumeSource *v1.ConfigMapVolumeSource `json:"userConfigMapVolumeSource,omitempty"`
22+
Resources v1.ResourceRequirements `json:"resources"`
23+
DataVolumeClaimSpec v1.PersistentVolumeClaimSpec `json:"dataVolumeClaimSpec"`
24+
PrivilegedSupported bool `json:"privilegedSupported,omitempty"`
25+
PrometheusSupport bool `json:"prometheusSupport"`
26+
SidecarEnv []v1.EnvVar `json:"sidecarEnv,omitempty"`
27+
CassandraEnv []v1.EnvVar `json:"cassandraEnv,omitempty"`
2628
// ServiceAccount to assign to pods created by the operator
2729
ServiceAccountName string `json:"serviceAccountName,omitempty"`
2830
}

pkg/apis/cassandraoperator/v1alpha1/zz_generated.deepcopy.go

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/cassandraoperator/v1alpha1/zz_generated.openapi.go

+46-1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,21 @@ func schema_pkg_apis_cassandraoperator_v1alpha1_CassandraDataCenterSpec(ref comm
309309
},
310310
},
311311
},
312+
"backupSecretVolumeSource": {
313+
SchemaProps: spec.SchemaProps{
314+
Ref: ref("k8s.io/api/core/v1.SecretVolumeSource"),
315+
},
316+
},
317+
"userSecretVolumeSource": {
318+
SchemaProps: spec.SchemaProps{
319+
Ref: ref("k8s.io/api/core/v1.SecretVolumeSource"),
320+
},
321+
},
322+
"userConfigMapVolumeSource": {
323+
SchemaProps: spec.SchemaProps{
324+
Ref: ref("k8s.io/api/core/v1.ConfigMapVolumeSource"),
325+
},
326+
},
312327
"resources": {
313328
SchemaProps: spec.SchemaProps{
314329
Ref: ref("k8s.io/api/core/v1.ResourceRequirements"),
@@ -319,12 +334,42 @@ func schema_pkg_apis_cassandraoperator_v1alpha1_CassandraDataCenterSpec(ref comm
319334
Ref: ref("k8s.io/api/core/v1.PersistentVolumeClaimSpec"),
320335
},
321336
},
337+
"privilegedSupported": {
338+
SchemaProps: spec.SchemaProps{
339+
Type: []string{"boolean"},
340+
Format: "",
341+
},
342+
},
322343
"prometheusSupport": {
323344
SchemaProps: spec.SchemaProps{
324345
Type: []string{"boolean"},
325346
Format: "",
326347
},
327348
},
349+
"sidecarEnv": {
350+
SchemaProps: spec.SchemaProps{
351+
Type: []string{"array"},
352+
Items: &spec.SchemaOrArray{
353+
Schema: &spec.Schema{
354+
SchemaProps: spec.SchemaProps{
355+
Ref: ref("k8s.io/api/core/v1.EnvVar"),
356+
},
357+
},
358+
},
359+
},
360+
},
361+
"cassandraEnv": {
362+
SchemaProps: spec.SchemaProps{
363+
Type: []string{"array"},
364+
Items: &spec.SchemaOrArray{
365+
Schema: &spec.Schema{
366+
SchemaProps: spec.SchemaProps{
367+
Ref: ref("k8s.io/api/core/v1.EnvVar"),
368+
},
369+
},
370+
},
371+
},
372+
},
328373
"serviceAccountName": {
329374
SchemaProps: spec.SchemaProps{
330375
Description: "ServiceAccount to assign to pods created by the operator",
@@ -337,7 +382,7 @@ func schema_pkg_apis_cassandraoperator_v1alpha1_CassandraDataCenterSpec(ref comm
337382
},
338383
},
339384
Dependencies: []string{
340-
"k8s.io/api/core/v1.LocalObjectReference", "k8s.io/api/core/v1.PersistentVolumeClaimSpec", "k8s.io/api/core/v1.ResourceRequirements"},
385+
"k8s.io/api/core/v1.ConfigMapVolumeSource", "k8s.io/api/core/v1.EnvVar", "k8s.io/api/core/v1.LocalObjectReference", "k8s.io/api/core/v1.PersistentVolumeClaimSpec", "k8s.io/api/core/v1.ResourceRequirements", "k8s.io/api/core/v1.SecretVolumeSource"},
341386
}
342387
}
343388

pkg/controller/cassandradatacenter/configmap.go

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func createOrUpdateOperatorConfigMap(rctx *reconciliationRequestContext, seedNod
3838

3939
addPrometheusSupport(rctx.cdc, addFileFn)
4040

41+
4142
if err := controllerutil.SetControllerReference(rctx.cdc, configMap, rctx.scheme); err != nil {
4243
return err
4344
}

0 commit comments

Comments
 (0)