Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 8593b80

Browse files
committed
chore: meaningful message in case key is not found in properties type hierarcy
1 parent 75e7d56 commit 8593b80

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pkg/resources.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"io/ioutil"
66
"strings"
77

8+
"github.com/flanksource/commons/logger"
9+
810
"github.com/flanksource/kommons/kustomize"
911
"github.com/hairyhenderson/gomplate/v3/base64"
1012
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -77,11 +79,16 @@ func (r Resource) GetPropertiesMap() map[string]string {
7779
func (r Resource) GeneratePropertesMapFromProperties() map[string]string {
7880
var propertiesMap = make(map[string]string)
7981
var prop string
82+
value := r.Item.Object["data"].(map[string]interface{})[r.Hierarchy.Key]
83+
if value == nil {
84+
logger.Debugf("can not find the given key: %v in the %v: %v", r.Hierarchy.Key, r.Item.GetKind(), r.Item.GetName())
85+
return nil
86+
}
8087
if r.Item.GetKind() == "Secret" {
81-
val, _ := base64.Decode(r.Item.Object["data"].(map[string]interface{})[r.Hierarchy.Key].(string))
88+
val, _ := base64.Decode(value.(string))
8289
prop = string(val)
8390
} else {
84-
prop = r.Item.Object["data"].(map[string]interface{})[r.Hierarchy.Key].(string)
91+
prop = value.(string)
8592
}
8693
for _, keyValue := range strings.Split(prop, "\n") {
8794
propKeyValue := strings.Split(keyValue, "=")

0 commit comments

Comments
 (0)