Skip to content

Commit

Permalink
Fix error when decoding null values using manifest_decode() (#2461)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhouston authored Apr 9, 2024
1 parent c055be2 commit 6f05a99
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/2461.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
`manifest_decode()`: fix handling of manifests containing null values
```
2 changes: 2 additions & 0 deletions internal/framework/provider/functions/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func decodeSequence(ctx context.Context, s []any) (attr.Value, diag.Diagnostics)

func decodeScalar(ctx context.Context, m any) (value attr.Value, diags diag.Diagnostics) {
switch v := m.(type) {
case nil:
value = types.DynamicNull()
case float64:
value = types.NumberValue(big.NewFloat(float64(v)))
case bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ func TestManifestDecodeMulti(t *testing.T) {
}),
"kind": knownvalue.StringExact("ConfigMap"),
"metadata": knownvalue.ObjectExact(map[string]knownvalue.Check{
"annotations": knownvalue.Null(),
"labels": knownvalue.ObjectExact(map[string]knownvalue.Check{
"test": knownvalue.StringExact("test---label"),
}),
"name": knownvalue.StringExact("test-configmap"),
}),
"status": knownvalue.Null(),
}),
})),
},
Expand Down
2 changes: 2 additions & 0 deletions internal/framework/provider/functions/manifest_decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ func TestManifestDecode(t *testing.T) {
}),
"kind": knownvalue.StringExact("ConfigMap"),
"metadata": knownvalue.ObjectExact(map[string]knownvalue.Check{
"annotations": knownvalue.Null(),
"labels": knownvalue.ObjectExact(map[string]knownvalue.Check{
"test": knownvalue.StringExact("test---label"),
}),
"name": knownvalue.StringExact("test-configmap"),
}),
"status": knownvalue.Null(),
})),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: test-configmap
annotations: null
labels:
test: "test---label"
data:
configfile: |
---
test: document
status:

0 comments on commit 6f05a99

Please sign in to comment.