Skip to content

Commit

Permalink
Support all data types in summary annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
khrm authored and tekton-robot committed Mar 5, 2024
1 parent d7f4d16 commit cf31c50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions pkg/watcher/results/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,14 @@ func (c *Client) ensureResult(ctx context.Context, o Object, opts ...grpc.CallOp

// parseAnnotations attempts to return the provided value as a map of strings.
func parseAnnotations(annotationKey, value string) (map[string]string, error) {
var annotations map[string]string
if err := json.Unmarshal([]byte(value), &annotations); err != nil {
var data map[string]interface{}
if err := json.Unmarshal([]byte(value), &data); err != nil {
return nil, controller.NewPermanentError(fmt.Errorf("error parsing annotation %s: %w", annotationKey, err))
}
annotations := map[string]string{}
for i, v := range data {
annotations[i] = fmt.Sprint(v)
}
return annotations, nil
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/watcher/results/results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ func TestAnnotations(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Annotations: map[string]string{
annotation.ResultAnnotations: `{"x": "y"}`,
annotation.RecordSummaryAnnotations: `{"foo":"bar"}`,
annotation.ResultAnnotations: `{"x": "y", "i": 7}`,
annotation.RecordSummaryAnnotations: `{"foo":"bar", "test": 1}`,
},
UID: types.UID("1"),
},
Expand All @@ -366,13 +366,13 @@ func TestAnnotations(t *testing.T) {
}

if diff := cmp.Diff(map[string]string{
"x": "y",
"x": "y", "i": "7",
}, result.Annotations); diff != "" {
t.Errorf("Result.Annotations: mismatch (-want +got):\n%s", diff)
}

if diff := cmp.Diff(map[string]string{
"foo": "bar",
"foo": "bar", "test": "1",
}, result.Summary.Annotations); diff != "" {
t.Errorf("Result.Summary.Annotations: mismatch (-want +got):\n%s", diff)
}
Expand Down

0 comments on commit cf31c50

Please sign in to comment.