@@ -203,13 +203,24 @@ func updatePluginConfigMap(cm *corev1.ConfigMap, value []byte, key string, depre
203
203
}
204
204
205
205
// TODO: temporary solution that is used to migrate to a new naming scheme, can be deprecated later
206
- _ , ok := cm .BinaryData [deprecatedKey ]
207
- if ok {
206
+ if _ , ok := cm .BinaryData [deprecatedKey ]; ok {
208
207
delete (cm .BinaryData , deprecatedKey )
209
208
210
209
isUpdated = true
211
210
}
212
211
212
+ // Delete the key if no plugins left
213
+ if len (value ) == 0 {
214
+ if _ , ok := cm .BinaryData [key ]; ok {
215
+ {
216
+ delete (cm .BinaryData , key )
217
+ isUpdated = true // nolint:wsl_v5
218
+
219
+ return
220
+ }
221
+ }
222
+ }
223
+
213
224
if ! bytes .Equal (value , cm .BinaryData [key ]) {
214
225
cm .BinaryData [key ] = value
215
226
isUpdated = true
@@ -235,9 +246,15 @@ func ReconcilePlugins(ctx context.Context, k8sClient client.Client, scheme *runt
235
246
// when we fetch the actual contents of the ConfigMap using k8sClient, so we need to set it here again
236
247
controllerutil .SetControllerReference (grafana , cm , scheme ) //nolint:errcheck
237
248
238
- val , err := json .Marshal (plugins .Sanitize ())
239
- if err != nil {
240
- return err
249
+ val := []byte {}
250
+
251
+ // Just in case we have some broken plugins, better to assess length of the sanitized list, not the original one
252
+ sanitized := plugins .Sanitize ()
253
+ if len (sanitized ) > 0 {
254
+ val , err = json .Marshal (sanitized )
255
+ if err != nil {
256
+ return err
257
+ }
241
258
}
242
259
243
260
isUpdated := updatePluginConfigMap (cm , val , cmKey , cmDeprecatedKey )
0 commit comments