@@ -12,21 +12,32 @@ import (
12
12
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
13
"k8s.io/apimachinery/pkg/labels"
14
14
"k8s.io/apimachinery/pkg/runtime"
15
+ "path"
15
16
"sigs.k8s.io/controller-runtime/pkg/client"
16
17
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
17
18
"strings"
18
19
"sync"
19
20
)
20
21
21
- const DataVolumeMountPath = "/var/lib/cassandra"
22
+ const (
23
+ DataVolumeMountPath = "/var/lib/cassandra"
24
+ OperatorConfigVolumeMountPath = "/tmp/operator-config"
25
+ UserConfigVolumeMountPath = "/tmp/user-config"
26
+ )
22
27
23
28
const SidecarApiPort = 4567
24
29
30
+ const GOOGLE_APPLICATION_CREDENTIALS = "GOOGLE_APPLICATION_CREDENTIALS"
31
+
25
32
var sidecarClientOptions = sidecar.ClientOptions {
26
33
Port : SidecarApiPort ,
27
34
Secure : false ,
28
35
}
29
36
37
+ func boolRef (b bool ) * bool {
38
+ return & b
39
+ }
40
+
30
41
func createOrUpdateStatefulSet (rctx * reconciliationRequestContext , configVolume * corev1.Volume ) (* v1beta2.StatefulSet , error ) {
31
42
statefulSet := & v1beta2.StatefulSet {ObjectMeta : DataCenterResourceMetadata (rctx .cdc )}
32
43
@@ -40,9 +51,11 @@ func createOrUpdateStatefulSet(rctx *reconciliationRequestContext, configVolume
40
51
41
52
dataVolumeClaim := newDataVolumeClaim (& rctx .cdc .Spec .DataVolumeClaimSpec )
42
53
podInfoVolume := newPodInfoVolume ()
54
+ backupSecretVolume := newBackupSecretVolume (rctx )
55
+ userConfigVolume := newUserConfigVolume (rctx )
43
56
44
- cassandraContainer := newCassandraContainer (rctx .cdc , dataVolumeClaim , configVolume )
45
- sidecarContainer := newSidecarContainer (rctx .cdc , dataVolumeClaim , podInfoVolume )
57
+ cassandraContainer := newCassandraContainer (rctx .cdc , dataVolumeClaim , configVolume , userConfigVolume )
58
+ sidecarContainer := newSidecarContainer (rctx .cdc , dataVolumeClaim , podInfoVolume , backupSecretVolume )
46
59
47
60
sysctlLimitsContainer := newSysctlLimitsContainer (rctx .cdc )
48
61
@@ -51,6 +64,14 @@ func createOrUpdateStatefulSet(rctx *reconciliationRequestContext, configVolume
51
64
[]corev1.Container {* cassandraContainer , * sidecarContainer },
52
65
[]corev1.Container {* sysctlLimitsContainer })
53
66
67
+ if backupSecretVolume != nil {
68
+ podSpec .Volumes = append (podSpec .Volumes , * backupSecretVolume )
69
+ }
70
+
71
+ if userConfigVolume != nil {
72
+ podSpec .Volumes = append (podSpec .Volumes , * userConfigVolume )
73
+ }
74
+
54
75
statefulSetSpec := newStatefulSetSpec (rctx .cdc , podSpec , dataVolumeClaim )
55
76
56
77
if statefulSet .CreationTimestamp .IsZero () {
@@ -99,17 +120,12 @@ func newPodSpec(cdc *cassandraoperatorv1alpha1.CassandraDataCenter, volumes []co
99
120
return podSpec
100
121
}
101
122
102
- func newCassandraContainer (cdc * cassandraoperatorv1alpha1.CassandraDataCenter , dataVolumeClaim * corev1.PersistentVolumeClaim , configVolume * corev1.Volume ) * corev1.Container {
103
- const (
104
- OperatorConfigVolumeMountPath = "/tmp/operator-config"
105
- UserConfigVolumePath = "/etc/cassandra/cassandra.yaml.d/003-user-overrides.yaml"
106
- )
107
-
123
+ func newCassandraContainer (cdc * cassandraoperatorv1alpha1.CassandraDataCenter , dataVolumeClaim * corev1.PersistentVolumeClaim , configVolume * corev1.Volume , userConfigVolume * corev1.Volume ) * corev1.Container {
108
124
container := & corev1.Container {
109
125
Name : "cassandra" ,
110
126
Image : cdc .Spec .CassandraImage ,
111
127
ImagePullPolicy : cdc .Spec .ImagePullPolicy ,
112
- Args : []string {OperatorConfigVolumeMountPath , UserConfigVolumePath },
128
+ Args : []string {OperatorConfigVolumeMountPath },
113
129
Ports : []corev1.ContainerPort {
114
130
{Name : "internode" , ContainerPort : 7000 },
115
131
{Name : "cql" , ContainerPort : 9042 },
@@ -139,8 +155,9 @@ func newCassandraContainer(cdc *cassandraoperatorv1alpha1.CassandraDataCenter, d
139
155
},
140
156
}
141
157
142
- if cdc .Spec .UserConfigMap .Size () != 0 {
143
- container .VolumeMounts = append (container .VolumeMounts , corev1.VolumeMount {Name : cdc .Spec .UserConfigMap .Name , MountPath : UserConfigVolumePath })
158
+ if userConfigVolume != nil {
159
+ container .Args = append (container .Args , UserConfigVolumeMountPath )
160
+ container .VolumeMounts = append (container .VolumeMounts , corev1.VolumeMount {Name : userConfigVolume .Name , MountPath : UserConfigVolumeMountPath })
144
161
}
145
162
146
163
if cdc .Spec .PrometheusSupport == true {
@@ -150,7 +167,7 @@ func newCassandraContainer(cdc *cassandraoperatorv1alpha1.CassandraDataCenter, d
150
167
return container
151
168
}
152
169
153
- func newSidecarContainer (cdc * cassandraoperatorv1alpha1.CassandraDataCenter , dataVolumeClaim * corev1.PersistentVolumeClaim , podInfoVolume * corev1.Volume ) * corev1.Container {
170
+ func newSidecarContainer (cdc * cassandraoperatorv1alpha1.CassandraDataCenter , dataVolumeClaim * corev1.PersistentVolumeClaim , podInfoVolume * corev1.Volume , backupSecretVolume * corev1. Volume ) * corev1.Container {
154
171
container := & corev1.Container {
155
172
Name : "sidecar" ,
156
173
Image : cdc .Spec .SidecarImage ,
@@ -164,10 +181,26 @@ func newSidecarContainer(cdc *cassandraoperatorv1alpha1.CassandraDataCenter, dat
164
181
},
165
182
}
166
183
167
- if len (cdc .Spec .BackupSecrets ) != 0 {
168
- container .EnvFrom = []corev1.EnvFromSource {
169
- {SecretRef : & corev1.SecretEnvSource {LocalObjectReference : corev1.LocalObjectReference {Name : cdc .Spec .BackupSecrets }}},
184
+ if len (cdc .Spec .Env ) > 0 {
185
+ container .Env = cdc .Spec .Env
186
+ }
187
+
188
+ if backupSecretVolume != nil {
189
+ // find GOOGLE_APPLICATION_CREDENTIALS in env:
190
+ google_creds_path := "/etc/gcp"
191
+ for _ , env := range cdc .Spec .Env {
192
+ if env .Name == GOOGLE_APPLICATION_CREDENTIALS {
193
+ google_creds_path = path .Dir (env .Value )
194
+ }
195
+ }
196
+
197
+ if google_creds_path == "/etc/gcp" {
198
+ // environment not set, log it, but it may be not an issue
199
+ log .Info ("Warning: backupSecretVolume is set, but GOOGLE_APPLICATION_CREDENTIALS env is missing" )
170
200
}
201
+
202
+ // Use it for the mount
203
+ container .VolumeMounts = append (container .VolumeMounts , corev1.VolumeMount {Name : backupSecretVolume .Name , MountPath : google_creds_path })
171
204
}
172
205
173
206
return container
@@ -179,7 +212,7 @@ func newSysctlLimitsContainer(cdc *cassandraoperatorv1alpha1.CassandraDataCenter
179
212
Image : cdc .Spec .CassandraImage ,
180
213
ImagePullPolicy : cdc .Spec .ImagePullPolicy ,
181
214
SecurityContext : & corev1.SecurityContext {
182
- Privileged : func () * bool { b := true ; return & b }( ),
215
+ Privileged : boolRef ( cdc . Spec . PrivilegedSupported ),
183
216
},
184
217
Command : []string {"bash" , "-xuec" },
185
218
Args : []string {
@@ -188,6 +221,32 @@ func newSysctlLimitsContainer(cdc *cassandraoperatorv1alpha1.CassandraDataCenter
188
221
}
189
222
}
190
223
224
+ func newUserConfigVolume (rctx * reconciliationRequestContext ) * corev1.Volume {
225
+
226
+ // check if set
227
+ if len (rctx .cdc .Spec .UserConfigMapVolumeSource .Name ) == 0 {
228
+ return nil
229
+ }
230
+
231
+ return & corev1.Volume {
232
+ Name : rctx .cdc .Spec .UserConfigMapVolumeSource .Name ,
233
+ VolumeSource : corev1.VolumeSource {ConfigMap : & rctx .cdc .Spec .UserConfigMapVolumeSource },
234
+ }
235
+ }
236
+
237
+ func newBackupSecretVolume (rctx * reconciliationRequestContext ) * corev1.Volume {
238
+
239
+ // check if set
240
+ if len (rctx .cdc .Spec .BackupSecretVolume .SecretName ) == 0 {
241
+ return nil
242
+ }
243
+
244
+ return & corev1.Volume {
245
+ Name : rctx .cdc .Spec .BackupSecretVolume .SecretName ,
246
+ VolumeSource : corev1.VolumeSource {Secret : & rctx .cdc .Spec .BackupSecretVolume },
247
+ }
248
+ }
249
+
191
250
func newPodInfoVolume () * corev1.Volume {
192
251
return & corev1.Volume {
193
252
Name : "pod-info" ,
0 commit comments