Skip to content

Commit

Permalink
fix: nil ptr panic on empty secrets slice during cfg-check
Browse files Browse the repository at this point in the history
Signed-off-by: Bence Csati <[email protected]>
  • Loading branch information
csatib02 committed Nov 28, 2024
1 parent eae0264 commit 2273e6a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/resources/fluentd/outputsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{
Expand All @@ -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
}

Expand All @@ -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
}

0 comments on commit 2273e6a

Please sign in to comment.