defaultMonitoringQueries adds the default monitoring queries configMap if not already present in CustomQueriesConfigMap
(config *configuration.Data)
| 182 | // defaultMonitoringQueries adds the default monitoring queries configMap |
| 183 | // if not already present in CustomQueriesConfigMap |
| 184 | func (r *Cluster) defaultMonitoringQueries(config *configuration.Data) { |
| 185 | if r.Spec.Monitoring == nil { |
| 186 | r.Spec.Monitoring = &MonitoringConfiguration{} |
| 187 | } |
| 188 | |
| 189 | if config.MonitoringQueriesConfigmap != "" { |
| 190 | var defaultConfigMapQueriesAlreadyPresent bool |
| 191 | // We check if the default queries are already inserted in the monitoring configuration |
| 192 | for _, monitoringConfigMap := range r.Spec.Monitoring.CustomQueriesConfigMap { |
| 193 | if monitoringConfigMap.Name == DefaultMonitoringConfigMapName { |
| 194 | defaultConfigMapQueriesAlreadyPresent = true |
| 195 | break |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // If the default queries are already present there is no need to re-add them. |
| 200 | // Please note that in this case that the default configMap could overwrite user existing queries |
| 201 | // depending on the order. This is an accepted behavior because the user willingly defined the order of his array |
| 202 | if !defaultConfigMapQueriesAlreadyPresent { |
| 203 | r.Spec.Monitoring.CustomQueriesConfigMap = append([]ConfigMapKeySelector{ |
| 204 | { |
| 205 | LocalObjectReference: LocalObjectReference{Name: DefaultMonitoringConfigMapName}, |
| 206 | Key: DefaultMonitoringKey, |
| 207 | }, |
| 208 | }, r.Spec.Monitoring.CustomQueriesConfigMap...) |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | if config.MonitoringQueriesSecret != "" { |
| 213 | var defaultSecretQueriesAlreadyPresent bool |
| 214 | // we check if the default queries are already inserted in the monitoring configuration |
| 215 | for _, monitoringSecret := range r.Spec.Monitoring.CustomQueriesSecret { |
| 216 | if monitoringSecret.Name == DefaultMonitoringSecretName { |
| 217 | defaultSecretQueriesAlreadyPresent = true |
| 218 | break |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | if !defaultSecretQueriesAlreadyPresent { |
| 223 | r.Spec.Monitoring.CustomQueriesSecret = append([]SecretKeySelector{ |
| 224 | { |
| 225 | LocalObjectReference: LocalObjectReference{Name: DefaultMonitoringSecretName}, |
| 226 | Key: DefaultMonitoringKey, |
| 227 | }, |
| 228 | }, r.Spec.Monitoring.CustomQueriesSecret...) |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // defaultInitDB enriches the initDB with defaults if not all the required arguments were passed |
| 234 | func (r *Cluster) defaultInitDB() { |
no outgoing calls
no test coverage detected