Skip to content

Commit 7d7e652

Browse files
committed
Improve resource condition retrieval to handle status without 'resource' wrapper
Signed-off-by: Olve S. Hansen <olvesh@gmail.com>
1 parent 4a9b8d7 commit 7d7e652

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

function_maps.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ func fromYaml(val string) (any, error) {
8080
func getResourceCondition(ct string, res map[string]any) xpv1.Condition {
8181
var conditioned xpv1.ConditionedStatus
8282
if err := fieldpath.Pave(res).GetValueInto("resource.status", &conditioned); err != nil {
83-
conditioned = xpv1.ConditionedStatus{}
83+
if err := fieldpath.Pave(res).GetValueInto("status", &conditioned); err != nil {
84+
conditioned = xpv1.ConditionedStatus{}
85+
}
8486
}
8587

8688
// Return either found condition or empty one with "Unknown" status

function_maps_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func Test_fromYaml(t *testing.T) {
3232
complexDictionary:
3333
scalar1: true
3434
list:
35-
- abc
35+
- abc
3636
- def`,
3737
},
3838
want: want{
@@ -164,6 +164,28 @@ func Test_getResourceCondition(t *testing.T) {
164164
},
165165
},
166166
},
167+
"GetConditionObservedResource": {
168+
reason: "Should return condition, even if not wrapped in 'resource'",
169+
args: args{
170+
ct: "Ready",
171+
res: map[string]any{
172+
"status": map[string]any{
173+
"conditions": []any{
174+
map[string]any{
175+
"type": "Ready",
176+
"status": "True",
177+
},
178+
},
179+
},
180+
},
181+
},
182+
want: want{
183+
rsp: v1.Condition{
184+
Type: "Ready",
185+
Status: "True",
186+
},
187+
},
188+
},
167189
"GetConditionUnknown": {
168190
reason: "Should return an Unknown status",
169191
args: args{

0 commit comments

Comments
 (0)