diff --git a/pkg/resources/fluentd/outputsecret.go b/pkg/resources/fluentd/outputsecret.go index 0cd97f858..f50497024 100644 --- a/pkg/resources/fluentd/outputsecret.go +++ b/pkg/resources/fluentd/outputsecret.go @@ -28,6 +28,10 @@ import ( ) func (r *Reconciler) markSecrets(secrets *secret.MountSecrets) ([]runtime.Object, reconciler.DesiredState, error) { + if secrets == nil { + return nil, reconciler.StateAbsent, nil + } + var loggingRef string if r.Logging.Spec.LoggingRef != "" { loggingRef = r.Logging.Spec.LoggingRef @@ -36,6 +40,7 @@ func (r *Reconciler) markSecrets(secrets *secret.MountSecrets) ([]runtime.Object } annotationKey := fmt.Sprintf("logging.banzaicloud.io/%s", loggingRef) var markedSecrets []runtime.Object + for _, secret := range *secrets { secretItem := &corev1.Secret{} err := r.Client.Get(context.TODO(), types.NamespacedName{ @@ -51,6 +56,7 @@ func (r *Reconciler) markSecrets(secrets *secret.MountSecrets) ([]runtime.Object secretItem.ObjectMeta.Annotations[annotationKey] = "watched" markedSecrets = append(markedSecrets, secretItem) } + return markedSecrets, reconciler.StatePresent, nil } @@ -65,8 +71,12 @@ func (r *Reconciler) outputSecret(secrets *secret.MountSecrets, mountPath string if fluentOutputSecret.Data == nil { fluentOutputSecret.Data = make(map[string][]byte) } - for _, secret := range *secrets { - fluentOutputSecret.Data[secret.MappedKey] = secret.Value + + if secrets != nil { + for _, secret := range *secrets { + fluentOutputSecret.Data[secret.MappedKey] = secret.Value + } } + return fluentOutputSecret, reconciler.StatePresent, nil }