Skip to content

Commit

Permalink
feat: support pointers (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored Jul 24, 2023
1 parent 765b014 commit 01f9c63
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func GetUnstructured(in interface{}) *unstructured.Unstructured {
case types.Bytes:
err = yaml.Unmarshal(v, &obj)
case map[string]interface{}:
obj = v
if val, ok := v["Object"].(map[string]any); ok {
obj = val
} else {
obj = v
}
case unstructured.Unstructured:
obj = v.Object
default:
Expand Down
4 changes: 4 additions & 0 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func serialize(in map[string]any) (map[string]any, error) {
var err error

vt := reflect.TypeOf(v)
if vt.Kind() == reflect.Ptr {
vt = vt.Elem()
}

switch vt.Kind() {
case reflect.Struct:
var result map[string]any
Expand Down
13 changes: 13 additions & 0 deletions template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,19 @@ func Test_serialize(t *testing.T) {
},
wantErr: false,
},
{
name: "pointers",
in: map[string]any{
"r": &Address{
City: "Bhaktapur",
},
},
want: map[string]any{
"r": map[string]any{
"city_name": "Bhaktapur",
},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 01f9c63

Please sign in to comment.