MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / buildInitDBFlags

Function buildInitDBFlags

pkg/specs/jobs.go:114–174  ·  view source on GitHub ↗
(cluster apiv1.Cluster)

Source from the content-addressed store, hash-verified

112}
113
114func buildInitDBFlags(cluster apiv1.Cluster) (initCommand []string) {
115 config := cluster.Spec.Bootstrap.InitDB
116 var options []string
117 // Kept for backward compatibility.
118 // If set we will ignore all the explicit parameters.
119 if len(config.Options) > 0 { //nolint:staticcheck
120 log.Warning("initdb.options is deprecated, consider migrating to initdb explicit configuration. "+
121 "Ignoring explicit configurations if present",
122 "cluster", cluster.Name,
123 "namespace", cluster.Namespace)
124
125 //nolint:staticcheck // still in use for backward compatibility
126 options = append(options, config.Options...)
127 initCommand = append(
128 initCommand,
129 "--initdb-flags",
130 shellquote.Join(options...))
131 return initCommand
132 }
133 if config.DataChecksums != nil &&
134 *config.DataChecksums {
135 options = append(options, "-k")
136 }
137 if logLevel := cluster.Spec.LogLevel; log.DebugLevelString == logLevel ||
138 log.TraceLevelString == logLevel {
139 options = append(options, "-d")
140 }
141 if encoding := config.Encoding; encoding != "" {
142 options = append(options, fmt.Sprintf("--encoding=%s", encoding))
143 }
144 if localeCollate := config.LocaleCollate; localeCollate != "" {
145 options = append(options, fmt.Sprintf("--lc-collate=%s", localeCollate))
146 }
147 if localeCType := config.LocaleCType; localeCType != "" {
148 options = append(options, fmt.Sprintf("--lc-ctype=%s", localeCType))
149 }
150 if locale := config.Locale; locale != "" {
151 options = append(options, fmt.Sprintf("--locale=%s", locale))
152 }
153 if localeProvider := config.LocaleProvider; localeProvider != "" {
154 options = append(options, fmt.Sprintf("--locale-provider=%s", localeProvider))
155 }
156 if icuLocale := config.IcuLocale; icuLocale != "" {
157 options = append(options, fmt.Sprintf("--icu-locale=%s", icuLocale))
158 }
159 if icuRules := config.IcuRules; icuRules != "" {
160 options = append(options, fmt.Sprintf("--icu-rules=%s", icuRules))
161 }
162 if builtinLocale := config.BuiltinLocale; builtinLocale != "" {
163 options = append(options, fmt.Sprintf("--builtin-locale=%s", builtinLocale))
164 }
165 if walSegmentSize := config.WalSegmentSize; walSegmentSize != 0 && utils.IsPowerOfTwo(walSegmentSize) {
166 options = append(options, fmt.Sprintf("--wal-segsize=%v", walSegmentSize))
167 }
168 initCommand = append(
169 initCommand,
170 "--initdb-flags",
171 shellquote.Join(options...))

Callers 1

Calls 3

IsPowerOfTwoFunction · 0.92
WarningMethod · 0.80
JoinMethod · 0.80

Tested by

no test coverage detected