(preserveUserSettings bool)
| 59 | } |
| 60 | |
| 61 | func (r *Cluster) setDefaults(preserveUserSettings bool) { |
| 62 | // Defaulting the image name if not specified |
| 63 | if r.Spec.ImageName == "" && r.Spec.ImageCatalogRef == nil { |
| 64 | r.Spec.ImageName = configuration.Current.PostgresImageName |
| 65 | } |
| 66 | |
| 67 | // Defaulting the bootstrap method if not specified |
| 68 | if r.Spec.Bootstrap == nil { |
| 69 | r.Spec.Bootstrap = &BootstrapConfiguration{} |
| 70 | } |
| 71 | |
| 72 | // Defaulting initDB if no other bootstrap method was passed |
| 73 | switch { |
| 74 | case r.Spec.Bootstrap.Recovery != nil: |
| 75 | r.defaultRecovery() |
| 76 | case r.Spec.Bootstrap.PgBaseBackup != nil: |
| 77 | r.defaultPgBaseBackup() |
| 78 | default: |
| 79 | r.defaultInitDB() |
| 80 | } |
| 81 | |
| 82 | // Defaulting the pod anti-affinity type if podAntiAffinity |
| 83 | if (r.Spec.Affinity.EnablePodAntiAffinity == nil || *r.Spec.Affinity.EnablePodAntiAffinity) && |
| 84 | r.Spec.Affinity.PodAntiAffinityType == "" { |
| 85 | r.Spec.Affinity.PodAntiAffinityType = PodAntiAffinityTypePreferred |
| 86 | } |
| 87 | |
| 88 | if r.Spec.Backup != nil && r.Spec.Backup.Target == "" { |
| 89 | r.Spec.Backup.Target = DefaultBackupTarget |
| 90 | } |
| 91 | |
| 92 | psqlVersion, err := r.GetPostgresqlMajorVersion() |
| 93 | if err == nil { |
| 94 | // The validation error will be already raised by the |
| 95 | // validateImageName function |
| 96 | info := postgres.ConfigurationInfo{ |
| 97 | Settings: postgres.CnpgConfigurationSettings, |
| 98 | MajorVersion: psqlVersion, |
| 99 | UserSettings: r.Spec.PostgresConfiguration.Parameters, |
| 100 | IsReplicaCluster: r.IsReplica(), |
| 101 | PreserveFixedSettingsFromUser: preserveUserSettings, |
| 102 | IsWalArchivingDisabled: utils.IsWalArchivingDisabled(&r.ObjectMeta), |
| 103 | IsAlterSystemEnabled: r.Spec.PostgresConfiguration.EnableAlterSystem, |
| 104 | } |
| 105 | sanitizedParameters := postgres.CreatePostgresqlConfiguration(info).GetConfigurationParameters() |
| 106 | r.Spec.PostgresConfiguration.Parameters = sanitizedParameters |
| 107 | } |
| 108 | |
| 109 | if r.Spec.LogLevel == "" { |
| 110 | r.Spec.LogLevel = log.InfoLevelString |
| 111 | } |
| 112 | |
| 113 | // we inject the defaultMonitoringQueries if the MonitoringQueriesConfigmap parameter is not empty |
| 114 | // and defaultQueries not disabled on cluster crd |
| 115 | if !r.Spec.Monitoring.AreDefaultQueriesDisabled() { |
| 116 | r.defaultMonitoringQueries(configuration.Current) |
| 117 | } |
| 118 |
no test coverage detected