Skip to content

Commit 6d50a2b

Browse files
committed
refactor db construction
1 parent 3aa8315 commit 6d50a2b

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

controllers/operator/construct/database_construction.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ type DatabaseStatefulSetOptions struct {
108108
// InitDatabaseImage is the image used for the init container as well as for the static binary holder
109109
InitDatabaseImage string
110110
DatabaseNonStaticImage string
111-
MongodbImage string
112-
AgentImage string
111+
MongodbImage string
112+
AgentImage string
113113

114114
Annotations map[string]string
115115
VaultConfig vault.VaultConfiguration
@@ -414,8 +414,6 @@ func buildDatabaseStatefulSetConfigurationFunction(mdb databaseStatefulSetSource
414414
PodAntiAffinityLabelKey: opts.Name,
415415
}
416416

417-
configurePodSpecSecurityContext, _ := podtemplatespec.WithDefaultSecurityContextsModifications()
418-
419417
configureImagePullSecrets := podtemplatespec.NOOP()
420418
name, found := env.Read(util.ImagePullSecrets) // nolint:forbidigo
421419
if found {
@@ -469,8 +467,6 @@ func buildDatabaseStatefulSetConfigurationFunction(mdb databaseStatefulSetSource
469467
}
470468

471469
shareProcessNs := statefulset.NOOP()
472-
secondContainerModification := podtemplatespec.NOOP()
473-
474470
if architectures.IsRunningStaticArchitecture(mdb.GetAnnotations()) {
475471
shareProcessNs = func(sts *appsv1.StatefulSet) {
476472
sts.Spec.Template.Spec.ShareProcessNamespace = ptr.To(true)
@@ -493,9 +489,7 @@ func buildDatabaseStatefulSetConfigurationFunction(mdb databaseStatefulSetSource
493489
podtemplatespec.WithAffinity(podAffinity, PodAntiAffinityLabelKey, 100),
494490
podtemplatespec.WithTerminationGracePeriodSeconds(util.DefaultPodTerminationPeriodSeconds),
495491
podtemplatespec.WithPodLabels(podLabels),
496-
secondContainerModification,
497492
volumesFunc,
498-
configurePodSpecSecurityContext,
499493
configureImagePullSecrets,
500494
podTemplateSpecFunc,
501495
)),
@@ -664,21 +658,16 @@ func getVolumesAndVolumeMounts(mdb databaseStatefulSetSource, databaseOpts Datab
664658
// buildMongoDBPodTemplateSpec constructs the podTemplateSpec for the MongoDB resource
665659
func buildMongoDBPodTemplateSpec(opts DatabaseStatefulSetOptions, mdb databaseStatefulSetSource, log *zap.SugaredLogger) podtemplatespec.Modification {
666660
serviceAccountName := getServiceAccountName(opts)
661+
configurePodSpecSecurityContext, _ := podtemplatespec.WithDefaultSecurityContextsModifications()
667662

668663
// scripts volume is shared by the init container and the AppDB, so the startup
669664
// script can be copied over
670665
scriptsVolume := statefulset.CreateVolumeFromEmptyDir("database-scripts")
671-
672666
volumes := []corev1.Volume{scriptsVolume}
667+
673668
secretsToInject := buildVaultDatabaseSecretsToInject(mdb, opts)
674669
_, volumeMounts, _ := getVolumesAndPVCs(mdb, opts, secretsToInject, log)
675670

676-
// Add hostname override volume if specified
677-
if opts.HostNameOverrideConfigmapName != "" {
678-
volumes = append(volumes, statefulset.CreateVolumeFromConfigMap(opts.HostNameOverrideConfigmapName, opts.HostNameOverrideConfigmapName))
679-
}
680-
681-
configurePodSpecSecurityContext, _ := podtemplatespec.WithDefaultSecurityContextsModifications()
682671
pullSecretsConfigurationFunc := podtemplatespec.NOOP()
683672
if pullSecrets, ok := env.Read(util.ImagePullSecrets); ok { // nolint:forbidigo
684673
pullSecretsConfigurationFunc = podtemplatespec.WithImagePullSecrets(pullSecrets)
@@ -798,12 +787,15 @@ func createDatabaseInitContainer(opts DatabaseStatefulSetOptions) corev1.Contain
798787

799788
// createDatabaseContainer creates the database container for non-static architecture
800789
func createDatabaseContainer(opts DatabaseStatefulSetOptions, volumeMounts []corev1.VolumeMount) corev1.Container {
790+
// scripts volume is shared by the init container and the AppDB, so the startup
791+
// script can be copied over
792+
801793
c := corev1.Container{
802794
Name: util.DatabaseContainerName,
803795
Image: opts.DatabaseNonStaticImage,
804796
Command: []string{"/opt/scripts/agent-launcher.sh"},
805797
Env: databaseEnvVars(opts),
806-
VolumeMounts: volumeMounts,
798+
VolumeMounts: append(volumeMounts, databaseScriptsVolumeMount(true)),
807799
Resources: buildRequirementsFromPodSpec(*opts.PodSpec),
808800
Ports: []corev1.ContainerPort{{ContainerPort: opts.ServicePort}},
809801
ImagePullPolicy: corev1.PullPolicy(env.ReadOrPanic(util.AutomationAgentImagePullPolicy)),
@@ -818,7 +810,7 @@ func createDatabaseContainer(opts DatabaseStatefulSetOptions, volumeMounts []cor
818810

819811
_, containerSecurityContext := podtemplatespec.WithDefaultSecurityContextsModifications()
820812

821-
sharedDatabaseContainerFunc( opts.DatabaseNonStaticImage, *opts.PodSpec, volumeMounts, containerSecurityContext, opts.ServicePort)(&c)
813+
sharedDatabaseContainerFunc(opts.DatabaseNonStaticImage, *opts.PodSpec, volumeMounts, containerSecurityContext, opts.ServicePort)(&c)
822814

823815
return c
824816
}

0 commit comments

Comments
 (0)