diff --git a/pkg/topology/run.go b/pkg/topology/run.go index 6c75ee282..67622c10c 100644 --- a/pkg/topology/run.go +++ b/pkg/topology/run.go @@ -15,6 +15,7 @@ import ( "github.com/flanksource/duty/job" "github.com/flanksource/duty/models" "github.com/flanksource/duty/query" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "github.com/flanksource/duty/types" "github.com/google/uuid" @@ -31,30 +32,37 @@ func mergeComponentLookup(ctx *ComponentContext, component *v1.ComponentSpec, sp if err != nil { return nil, errors.Wrapf(err, "component lookup failed: %s", component) } + if len(results) == 1 { - if err := json.Unmarshal([]byte(results[0].(string)), &components); err != nil { - return nil, errors.Wrapf(err, "component lookup returned invalid json: %s", component) - } - } else { - // the property returned a list of new properties - for _, result := range results { - var p pkg.Component - data, err := json.Marshal(result) - if err != nil { - return nil, fmt.Errorf("error marshaling result to json: %w", err) - } - if err := json.Unmarshal(data, &p); err != nil { - return nil, fmt.Errorf("error unmarshaling data from json: %w", err) + switch v := results[0].(type) { + case string: + if err := json.Unmarshal([]byte(v), &components); err != nil { + return nil, fmt.Errorf("error unmarshaling data from pkg.Components: %w", err) } + results = nil + } + } - components = append(components, &p) + // the property returned a list of new properties + for _, result := range results { + var p pkg.Component + data, err := json.Marshal(result) + if err != nil { + return nil, fmt.Errorf("error marshaling result to json: %w", err) } + if err := json.Unmarshal(data, &p); err != nil { + return nil, fmt.Errorf("error unmarshaling data from json: %w", err) + } + + components = append(components, &p) } + for _, _c := range components { if err = forEachComponent(ctx, component, _c); err != nil { return nil, err } } + return components, nil } @@ -199,9 +207,19 @@ func lookup(ctx *ComponentContext, name string, spec v1.CanarySpec) ([]interface if result.Message != "" { results = append(results, result.Message) } else if result.Detail != nil { - switch result.Detail.(type) { + switch v := result.Detail.(type) { case []any: results = append(results, result.Detail.([]interface{})...) + case checks.ExecDetails: + results = append(results, v.Stdout) + case checks.ConfigDBQueryResult: + for _, item := range v.Results { + results = append(results, any(item)) + } + case []unstructured.Unstructured: + for _, item := range v { + results = append(results, any(item)) + } case any: results = append(results, result.Detail) default: @@ -211,6 +229,7 @@ func lookup(ctx *ComponentContext, name string, spec v1.CanarySpec) ([]interface results = append(results, "") } } + return results, nil }