Skip to content

Commit 24755d2

Browse files
committed
fix: nil pointer for additionalMetadata
Signed-off-by: Hristo Hristov <[email protected]>
1 parent f5c7cff commit 24755d2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

controllers/resources/processor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"errors"
99
"fmt"
10+
"github.com/projectcapsule/capsule/controllers/utils"
1011
"sync"
1112

1213
"github.com/valyala/fasttemplate"
@@ -118,8 +119,8 @@ func (r *Processor) HandleSection(ctx context.Context, tnt capsulev1beta2.Tenant
118119
objAnnotations, objLabels := map[string]string{}, map[string]string{}
119120

120121
if spec.AdditionalMetadata != nil {
121-
objAnnotations = spec.AdditionalMetadata.Annotations
122-
objLabels = spec.AdditionalMetadata.Labels
122+
objAnnotations = utils.PrepareAdditionalMetadata(spec.AdditionalMetadata.Annotations)
123+
objLabels = utils.PrepareAdditionalMetadata(spec.AdditionalMetadata.Labels)
123124
}
124125

125126
objAnnotations[tenantLabel] = tnt.GetName()

controllers/utils/safe_mapping.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package utils
2+
3+
func PrepareAdditionalMetadata(m map[string]string) map[string]string {
4+
if m == nil {
5+
return make(map[string]string)
6+
}
7+
return m
8+
}

0 commit comments

Comments
 (0)