@@ -14,9 +14,11 @@ import (
1414 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1515 "sigs.k8s.io/controller-runtime/pkg/client"
1616
17+ "github.com/crunchydata/postgres-operator/internal/controller/runtime"
1718 "github.com/crunchydata/postgres-operator/internal/initialize"
1819 "github.com/crunchydata/postgres-operator/internal/naming"
1920 "github.com/crunchydata/postgres-operator/internal/testing/cmp"
21+ "github.com/crunchydata/postgres-operator/internal/testing/events"
2022 "github.com/crunchydata/postgres-operator/internal/testing/require"
2123 "github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
2224)
@@ -219,4 +221,78 @@ tolerations:
219221
220222 assert .Assert (t , cmp .MarshalMatches (template .Spec , compare ))
221223 })
224+
225+ t .Run ("verify additional volumes" , func (t * testing.T ) {
226+ recorder := events .NewRecorder (t , runtime .Scheme )
227+ reconciler .Recorder = recorder
228+
229+ custompgadmin := new (v1beta1.PGAdmin )
230+
231+ // add pod level customizations
232+ custompgadmin .Name = "custom-volumes"
233+ custompgadmin .Namespace = ns .Name
234+
235+ require .UnmarshalInto (t , & custompgadmin .Spec , `{
236+ dataVolumeClaimSpec: {
237+ accessModes: [ReadWriteOnce],
238+ resources: { requests: { storage: 1Gi } },
239+ },
240+ }` )
241+ require .UnmarshalInto (t , & custompgadmin .Spec , `{
242+ volumes: {
243+ additional: [
244+ {
245+ "name": "required",
246+ "claimName": "required-1"
247+ }
248+ ],
249+ },
250+ }` )
251+
252+ assert .NilError (t , cc .Create (ctx , custompgadmin ))
253+ t .Cleanup (func () { assert .Check (t , cc .Delete (ctx , custompgadmin )) })
254+
255+ err := reconciler .reconcilePGAdminStatefulSet (ctx , custompgadmin , configmap , pvc )
256+ assert .NilError (t , err )
257+
258+ selector , err := naming .AsSelector (metav1.LabelSelector {
259+ MatchLabels : map [string ]string {
260+ naming .LabelStandalonePGAdmin : custompgadmin .Name ,
261+ },
262+ })
263+ assert .NilError (t , err )
264+
265+ list := appsv1.StatefulSetList {}
266+ assert .NilError (t , cc .List (ctx , & list , client .InNamespace (custompgadmin .Namespace ),
267+ client.MatchingLabelsSelector {Selector : selector }))
268+ assert .Equal (t , len (list .Items ), 1 )
269+
270+ template := list .Items [0 ].Spec .Template .DeepCopy ()
271+
272+ for _ , container := range template .Spec .Containers {
273+ assert .Assert (t , cmp .MarshalContains (container .VolumeMounts ,
274+ `- mountPath: /etc/pgadmin/conf.d
275+ name: pgadmin-config
276+ readOnly: true
277+ - mountPath: /var/lib/pgadmin
278+ name: pgadmin-data
279+ - mountPath: /etc/pgadmin
280+ name: pgadmin-config-system
281+ readOnly: true
282+ - mountPath: /tmp
283+ name: tmp
284+ - mountPath: /volumes/required
285+ name: volumes-required` ))
286+ }
287+
288+ assert .Assert (t , cmp .MarshalContains (template .Spec .Volumes ,
289+ `
290+ - name: volumes-required
291+ persistentVolumeClaim:
292+ claimName: required-1` ))
293+
294+ // No events created
295+ assert .Equal (t , len (recorder .Events ), 0 )
296+
297+ })
222298}
0 commit comments