Skip to content

Commit b964dd6

Browse files
author
Jeff McCormick
authored
V1alpha2 api - scorecard output changes for v1alpha2 version (#1995)
* initial set of v1alpha2 api files and output formatting * add simple v1alpha2 scorecard test that can be run on demand * add v1alpha2 version docs updates * update CHANGELOG to mention new version flag added * adjust json output for v1alpha2 rendering to show failed required tests * refactor a bit of basic_tests * tweak output for text v1alpha2 * remove erroneous v1alpha2 reference in v1alpha1 test * initial set of v1alpha2 api files and output formatting * add simple v1alpha2 scorecard test that can be run on demand * add v1alpha2 version docs updates * update CHANGELOG to mention new version flag added * adjust json output for v1alpha2 rendering to show failed required tests * refactor a bit of basic_tests * tweak output for text v1alpha2 * remove erroneous v1alpha2 reference in v1alpha1 test * add code changes per PR review comments * fix merge * refactor api output formatting implementation to use an interface * change interface function name for json output to avoid conflict found by go vet * make v1alpha2 the default scorecard version * refactor * updates * fix ci scorecard test * minor tweaks per review comments * add labels field to v1alpha2 ScorecardTestResult type * remove Suite from the v1alpha2 API, adjust text output to print suite label * removed required test status, add omitempty to v1alpha2 types
1 parent 99021fa commit b964dd6

22 files changed

+622
-95
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- Ansible based operators now gather and serve metrics about each custom resource on port 8686 of the metrics service. ([#1723](https://github.com/operator-framework/operator-sdk/pull/1723))
2323
- Added the Go version, OS, and architecture to the output of `operator-sdk version` ([#1863](https://github.com/operator-framework/operator-sdk/pull/1863))
2424
- Added support for `ppc64le-linux` for the `operator-sdk` binary and the Helm operator base image. ([#1533](https://github.com/operator-framework/operator-sdk/pull/1533))
25+
- Added new `--version` flag to the `operator-sdk scorecard` command to support a new output format for the scorecard. ([#1916](https://github.com/operator-framework/operator-sdk/pull/1916)
2526

2627
### Changed
2728

@@ -65,6 +66,7 @@
6566
- [`pkg/test.FrameworkClient`](https://github.com/operator-framework/operator-sdk/blob/master/pkg/test/client.go#L33) methods `List()` and `Delete()` have new signatures corresponding to the homonymous methods of `sigs.k8s.io/controller-runtime/pkg/client.Client`. ([#1876](https://github.com/operator-framework/operator-sdk/pull/1876))
6667
- CRD file names were previously of the form `<group>_<version>_<kind>_crd.yaml`. Now that CRD manifest `spec.version` is deprecated in favor of `spec.versions`, i.e. multiple versions can be specified in one CRD, CRD file names have the form `<full group>_<resource>_crd.yaml`. `<full group>` is the full group name of your CRD while `<group>` is the last subdomain of `<full group>`, ex. `foo.bar.com` vs `foo`. `<resource>` is the plural lower-case CRD Kind found at `spec.names.plural`. ([#1876](https://github.com/operator-framework/operator-sdk/pull/1876))
6768
- Upgrade Python version from `2.7` to `3.6`, Ansible version from `2.8.0` to `~=2.8` and ansible-runner from `1.2` to `1.3.4` in the Ansible based images. ([#1947](https://github.com/operator-framework/operator-sdk/pull/1947))
69+
- Made the default scorecard version `v1alpha2` which is new for this release and could break users that were parsing the older scorecard output (`v1alpha1`). Users can still specify version `v1alpha1` on the scorecard configuration to use the older style for some period of time until `v1alpha1` is removed.
6870
- Replaced `pkg/kube-metrics.NewCollectors()` with `pkg/kube-metrics.NewMetricsStores()` and changed exported function signature for `pkg/kube-metrics.ServeMetrics()` due to a [breaking change in kube-state-metrics](https://github.com/kubernetes/kube-state-metrics/pull/786). ([#1943](https://github.com/operator-framework/operator-sdk/pull/1943))
6971

7072
### Deprecated

ci/tests/subcommand-scorecard.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ trap_add 'cp $ROOTDIR/backup2.yaml $CONFIG_PATH && rm $ROOTDIR/backup2.yaml' EXI
2424
sed 's|REPLACE_IMAGE|'$IMAGE'|g' -i $CONFIG_PATH
2525

2626
# basic test with specified config location
27-
commandoutput="$(operator-sdk scorecard --config "$CONFIG_PATH" 2>&1)"
27+
commandoutput="$(operator-sdk scorecard --version v1alpha1 --config "$CONFIG_PATH" 2>&1)"
2828
echo $commandoutput | grep "Total Score: 67%"
2929

3030
# test json output and default config path
31-
commandoutput2="$(operator-sdk scorecard 2>&1)"
31+
commandoutput2="$(operator-sdk scorecard --version v1alpha1 2>&1)"
3232
# check basic suite
3333
echo $commandoutput2 | grep '^.*"error": 0,[[:space:]]"pass": 3,[[:space:]]"partialPass": 0,[[:space:]]"fail": 0,[[:space:]]"totalTests": 3,[[:space:]]"totalScorePercent": 100,.*$'
3434
# check olm suite
@@ -43,7 +43,7 @@ echo $commandoutput2 | grep '^.*"name": "Flags",[[:space:]]"description": "Test
4343
echo $commandoutput2 | grep '^.*"name": "Environment",[[:space:]]"description": "Test plugin with kubeconfig set via env var",[[:space:]]"earnedPoints": 2,[[:space:]]"maximumPoints": 5,.*$'
4444

4545
# test kubeconfig flag (kubeconfig shouldn't exist so internal plugins should instantly fail)
46-
commandoutput3="$(operator-sdk scorecard --kubeconfig=/kubeconfig 2>&1)"
46+
commandoutput3="$(operator-sdk scorecard --version v1alpha1 --kubeconfig=/kubeconfig 2>&1)"
4747
# check basic suite
4848
echo $commandoutput3 | grep '^.*"name": "Basic Tests",[[:space:]]"description": "",[[:space:]]"error": 1,.*$'
4949
# check olm suite
@@ -58,6 +58,6 @@ echo $commandoutput3 | grep '^.*"name": "Different Env and flag",[[:space:]]"des
5858
echo $commandoutput3 | grep '^.*"name": "Environment",[[:space:]]"description": "Test plugin with kubeconfig set via env var",[[:space:]]"earnedPoints": 2,[[:space:]]"maximumPoints": 5,.*$'
5959

6060
# Test invalid config
61-
operator-sdk scorecard --config "$CONFIG_PATH_INVALID" |& grep '^.*invalid keys.*$'
61+
operator-sdk scorecard --version v1alpha1 --config "$CONFIG_PATH_INVALID" |& grep '^.*invalid keys.*$'
6262

6363
popd

doc/sdk-cli-reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ Run scorecard tests on an operator
449449
* `proxy-image` string - Image name for scorecard proxy (default "quay.io/operator-framework/scorecard-proxy")
450450
* `proxy-pull-policy` string - Pull policy for scorecard proxy image (default "Always")
451451
* `-h, --help` - help for scorecard
452+
* `version` string - The scorecard version to run (default v1alpha1), the tech preview version is v1alpha2.
452453

453454
### Example
454455

doc/test-framework/scorecard.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ While most configuration is done via a config file, there are a few important ar
106106
| `--config` | string | Path to config file (default `<project_dir>/.osdk-scorecard`; file type and extension can be any of `.yaml`, `.json`, or `.toml`). If a config file is not provided and a config file is not found at the default location, the scorecard will exit with an error. |
107107
| `--output`, `-o` | string | Output format. Valid options are: `text` and `json`. The default format is `text`, which is designed to be a simpler human readable format. The `json` format uses the JSON schema output format used for plugins defined later in this document. |
108108
| `--kubeconfig`, `-o` | string | path to kubeconfig. It sets the kubeconfig internally for internal plugins and sets the `KUBECONFIG` env var to the provided value for external plugins. If an external plugin specifically sets the `KUBECONFIG` env var, the kubeconfig from the specified env var will be used for that plugin instead. |
109+
| `--version` | string | The version of scorecard to run, v1alpha1 is the default, whereas v1alpha2 is the tech preview. |
109110

110111
### Config File Options
111112

@@ -405,4 +406,4 @@ Running with a CSV alone requires both the `--csv-path=<CSV manifest path>` and
405406
[olm-csv-alm-examples]:https://github.com/operator-framework/operator-lifecycle-manager/blob/master/doc/design/building-your-csv.md#crd-templates
406407
[olm]:https://github.com/operator-framework/operator-lifecycle-manager
407408
[olm-deploy-operator]:https://github.com/operator-framework/community-operators/blob/master/docs/testing-operators.md
408-
[okd]:https://www.okd.io/
409+
[okd]:https://www.okd.io/

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ require (
4141
github.com/markbates/inflect v1.0.4
4242
github.com/martinlindhe/base36 v0.0.0-20180729042928-5cda0030da17
4343
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a
44+
github.com/mattn/go-isatty v0.0.8
4445
github.com/mitchellh/go-homedir v1.1.0
4546
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
4647
github.com/mitchellh/mapstructure v1.1.2

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ github.com/martinlindhe/base36 v0.0.0-20180729042928-5cda0030da17/go.mod h1:+AtE
289289
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a h1:+J2gw7Bw77w/fbK7wnNJJDKmw1IbWft2Ul5BzrG1Qm8=
290290
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a/go.mod h1:M1qoD/MqPgTZIk0EWKB38wE28ACRfVcn+cU08jyArI0=
291291
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
292+
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
292293
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
293294
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
294295
github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=

hack/tests/subcommand-scorecard.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
DEST_IMAGE="quay.io/example/scorecard-proxy"
44
CONFIG_PATH=".test-osdk-scorecard.yaml"
5+
CONFIG_PATH_V1ALPHA1=".test-osdk-scorecard-v1alpha1.yaml"
56
CONFIG_PATH_DISABLE=".osdk-scorecard-disable.yaml"
67
CONFIG_PATH_INVALID=".osdk-scorecard-invalid.yaml"
78

@@ -12,11 +13,26 @@ set -ex
1213

1314
# the test framework directory has all the manifests needed to run the cluster
1415
pushd test/test-framework
15-
commandoutput="$(operator-sdk scorecard --config "$CONFIG_PATH" 2>&1)"
16+
17+
# test to see if v1alpha2 is used from the command line
18+
commandoutput="$(operator-sdk scorecard --version v1alpha2 --config "$CONFIG_PATH" 2>&1)"
19+
failCount=`echo $commandoutput | grep -o ": fail" | wc -l`
20+
expectedFailCount=7
21+
if [ $failCount -ne $expectedFailCount ]
22+
then
23+
echo "expected fail count $expectedFailCount, got $failCount"
24+
exit 1
25+
fi
26+
27+
# test to see if version in config file allows v1alpha1 to be specified
28+
commandoutput="$(operator-sdk scorecard --config "$CONFIG_PATH_V1ALPHA1" 2>&1)"
29+
echo $commandoutput | grep "Total Score: 67%"
30+
31+
commandoutput="$(operator-sdk scorecard --version v1alpha1 --config "$CONFIG_PATH" 2>&1)"
1632
echo $commandoutput | grep "Total Score: 67%"
1733

1834
# test json output and default config path
19-
commandoutput2="$(operator-sdk scorecard 2>&1)"
35+
commandoutput2="$(operator-sdk scorecard --version v1alpha1 2>&1)"
2036
# check basic suite
2137
echo $commandoutput2 | grep '^.*"error": 0,[[:space:]]"pass": 3,[[:space:]]"partialPass": 0,[[:space:]]"fail": 0,[[:space:]]"totalTests": 3,[[:space:]]"totalScorePercent": 100,.*$'
2238
# check olm suite
@@ -31,7 +47,7 @@ echo $commandoutput2 | grep '^.*"name": "Flags",[[:space:]]"description": "Test
3147
echo $commandoutput2 | grep '^.*"name": "Environment",[[:space:]]"description": "Test plugin with kubeconfig set via env var",[[:space:]]"earnedPoints": 2,[[:space:]]"maximumPoints": 5,.*$'
3248

3349
# test kubeconfig flag (kubeconfig shouldn't exist so internal plugins should instantly fail)
34-
commandoutput3="$(operator-sdk scorecard --kubeconfig=/kubeconfig 2>&1)"
50+
commandoutput3="$(operator-sdk scorecard --version v1alpha1 --kubeconfig=/kubeconfig 2>&1)"
3551
# check basic suite
3652
echo $commandoutput3 | grep '^.*"name": "Basic Tests",[[:space:]]"description": "",[[:space:]]"error": 1,.*$'
3753
# check olm suite
@@ -46,6 +62,7 @@ echo $commandoutput3 | grep '^.*"name": "Different Env and flag",[[:space:]]"des
4662
echo $commandoutput3 | grep '^.*"name": "Environment",[[:space:]]"description": "Test plugin with kubeconfig set via env var",[[:space:]]"earnedPoints": 2,[[:space:]]"maximumPoints": 5,.*$'
4763

4864
# Test invalid config
49-
operator-sdk scorecard --config "$CONFIG_PATH_INVALID" |& grep '^.*invalid keys.*$'
65+
operator-sdk scorecard --version v1alpha1 --config "$CONFIG_PATH_INVALID" |& grep '^.*invalid keys.*$'
66+
5067

5168
popd

internal/pkg/scorecard/helpers/helpers.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func UpdateState(res scapiv1alpha1.ScorecardTestResult) scapiv1alpha1.ScorecardT
139139
if res.State == scapiv1alpha1.ErrorState {
140140
return res
141141
}
142+
142143
if res.EarnedPoints == 0 {
143144
res.State = scapiv1alpha1.FailState
144145
} else if res.EarnedPoints < res.MaximumPoints {
@@ -177,13 +178,3 @@ func UpdateSuiteStates(suite scapiv1alpha1.ScorecardSuiteResult) scapiv1alpha1.S
177178
}
178179
return suite
179180
}
180-
181-
func CombineScorecardOutput(outputs []scapiv1alpha1.ScorecardOutput, log string) scapiv1alpha1.ScorecardOutput {
182-
output := scapiv1alpha1.ScorecardOutput{
183-
Log: log,
184-
}
185-
for _, item := range outputs {
186-
output.Results = append(output.Results, item.Results...)
187-
}
188-
return output
189-
}

internal/pkg/scorecard/helpers/versions.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ package schelpers
1616

1717
import (
1818
"fmt"
19-
"github.com/spf13/viper"
2019
"strings"
2120
)
2221

2322
const v1alpha1 = "v1alpha1"
2423
const v1alpha2 = "v1alpha2"
25-
const DefaultScorecardVersion = v1alpha1
24+
25+
const DefaultScorecardVersion = v1alpha2
2626
const LatestScorecardVersion = v1alpha2
2727
const VersionOpt = "version"
2828

29-
var ScorecardVersions = []string{DefaultScorecardVersion, LatestScorecardVersion}
29+
var ScorecardVersions = []string{v1alpha1, v1alpha2}
3030

3131
func ValidateVersion(version string) error {
3232
for _, a := range ScorecardVersions {
@@ -38,16 +38,6 @@ func ValidateVersion(version string) error {
3838

3939
}
4040

41-
func IsV1alpha2() bool {
42-
if viper.Sub("scorecard").GetString(VersionOpt) == v1alpha2 {
43-
return true
44-
}
45-
return false
46-
}
47-
48-
func IsLatestVersion() bool {
49-
if viper.Sub("scorecard").GetString(VersionOpt) == LatestScorecardVersion {
50-
return true
51-
}
52-
return false
41+
func IsV1alpha2(version string) bool {
42+
return version == v1alpha2
5343
}

internal/pkg/scorecard/plugins/basic_tests.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ func (t *CheckSpecTest) Run(ctx context.Context) *schelpers.TestResult {
114114
res.Errors = append(res.Errors, fmt.Errorf("error getting custom resource: %v", err))
115115
return res
116116
}
117-
if t.CR.Object["spec"] != nil {
118-
res.EarnedPoints++
119-
}
120-
if res.EarnedPoints != 1 {
117+
118+
if t.CR.Object["spec"] == nil {
121119
res.Suggestions = append(res.Suggestions, "Add a 'spec' field to your Custom Resource")
120+
return res
122121
}
122+
res.EarnedPoints++
123123
return res
124124
}
125125

@@ -131,12 +131,11 @@ func (t *CheckStatusTest) Run(ctx context.Context) *schelpers.TestResult {
131131
res.Errors = append(res.Errors, fmt.Errorf("error getting custom resource: %v", err))
132132
return res
133133
}
134-
if t.CR.Object["status"] != nil {
135-
res.EarnedPoints++
136-
}
137-
if res.EarnedPoints != 1 {
134+
if t.CR.Object["status"] == nil {
138135
res.Suggestions = append(res.Suggestions, "Add a 'status' field to your Custom Resource")
136+
return res
139137
}
138+
res.EarnedPoints++
140139
return res
141140
}
142141

internal/pkg/scorecard/scorecard.go

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ package scorecard
1616

1717
import (
1818
"bytes"
19-
"encoding/json"
2019
"fmt"
2120
"io"
22-
"io/ioutil"
2321
"os"
2422
"strings"
2523

@@ -116,64 +114,18 @@ func ScorecardTests(cmd *cobra.Command, args []string) error {
116114
for _, plugin := range plugins {
117115
pluginOutputs = append(pluginOutputs, plugin.Run())
118116
}
119-
totalScore := 0.0
117+
120118
// Update the state for the tests
121119
for _, suite := range pluginOutputs {
122120
for idx, res := range suite.Results {
123121
suite.Results[idx] = schelpers.UpdateSuiteStates(res)
124122
}
125123
}
126-
if scViper.GetString(OutputFormatOpt) == TextOutputFormat {
127-
numSuites := 0
128-
for _, plugin := range pluginOutputs {
129-
for _, suite := range plugin.Results {
130-
fmt.Printf("%s:\n", suite.Name)
131-
for _, result := range suite.Tests {
132-
fmt.Printf("\t%s: %d/%d\n", result.Name, result.EarnedPoints, result.MaximumPoints)
133-
}
134-
totalScore += float64(suite.TotalScore)
135-
numSuites++
136-
}
137-
}
138-
totalScore = totalScore / float64(numSuites)
139-
fmt.Printf("\nTotal Score: %.0f%%\n", totalScore)
140-
// TODO: We can probably use some helper functions to clean up these quadruple nested loops
141-
// Print suggestions
142-
for _, plugin := range pluginOutputs {
143-
for _, suite := range plugin.Results {
144-
for _, result := range suite.Tests {
145-
for _, suggestion := range result.Suggestions {
146-
// 33 is yellow (specifically, the same shade of yellow that logrus uses for warnings)
147-
fmt.Printf("\x1b[%dmSUGGESTION:\x1b[0m %s\n", 33, suggestion)
148-
}
149-
}
150-
}
151-
}
152-
// Print errors
153-
for _, plugin := range pluginOutputs {
154-
for _, suite := range plugin.Results {
155-
for _, result := range suite.Tests {
156-
for _, err := range result.Errors {
157-
// 31 is red (specifically, the same shade of red that logrus uses for errors)
158-
fmt.Printf("\x1b[%dmERROR:\x1b[0m %s\n", 31, err)
159-
}
160-
}
161-
}
162-
}
163-
}
164-
if scViper.GetString(OutputFormatOpt) == JSONOutputFormat {
165-
log, err := ioutil.ReadAll(logReadWriter)
166-
if err != nil {
167-
return fmt.Errorf("failed to read log buffer: %v", err)
168-
}
169-
scTest := schelpers.CombineScorecardOutput(pluginOutputs, string(log))
170-
// Pretty print so users can also read the json output
171-
bytes, err := json.MarshalIndent(scTest, "", " ")
172-
if err != nil {
173-
return err
174-
}
175-
fmt.Printf("%s\n", string(bytes))
124+
125+
if err := printPluginOutputs(scViper.GetString(schelpers.VersionOpt), pluginOutputs); err != nil {
126+
return err
176127
}
128+
177129
return nil
178130
}
179131

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright 2019 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package scorecard
16+
17+
import (
18+
"encoding/json"
19+
"fmt"
20+
schelpers "github.com/operator-framework/operator-sdk/internal/pkg/scorecard/helpers"
21+
scapi "github.com/operator-framework/operator-sdk/pkg/apis/scorecard"
22+
scapiv1alpha1 "github.com/operator-framework/operator-sdk/pkg/apis/scorecard/v1alpha1"
23+
"io/ioutil"
24+
)
25+
26+
func printPluginOutputs(version string, pluginOutputs []scapiv1alpha1.ScorecardOutput) error {
27+
28+
var list scapi.ScorecardFormatter
29+
var err error
30+
list, err = combinePluginOutput(pluginOutputs)
31+
if err != nil {
32+
return err
33+
}
34+
35+
if schelpers.IsV1alpha2(version) {
36+
list = scapi.ConvertScorecardOutputV1ToV2(list.(scapiv1alpha1.ScorecardOutput))
37+
}
38+
39+
// produce text output
40+
if scViper.GetString(OutputFormatOpt) == TextOutputFormat {
41+
output, err := list.MarshalText()
42+
if err != nil {
43+
return err
44+
}
45+
fmt.Printf("%s\n", output)
46+
47+
return nil
48+
}
49+
50+
// produce json output
51+
if scViper.GetString(OutputFormatOpt) == JSONOutputFormat {
52+
bytes, err := json.MarshalIndent(list, "", " ")
53+
if err != nil {
54+
return err
55+
}
56+
fmt.Printf("%s\n", string(bytes))
57+
return nil
58+
59+
}
60+
61+
return nil
62+
}
63+
64+
func combinePluginOutput(pluginOutputs []scapiv1alpha1.ScorecardOutput) (scapiv1alpha1.ScorecardOutput, error) {
65+
output := scapiv1alpha1.ScorecardOutput{}
66+
output.Results = make([]scapiv1alpha1.ScorecardSuiteResult, 0)
67+
for _, v := range pluginOutputs {
68+
for _, r := range v.Results {
69+
output.Results = append(output.Results, r)
70+
}
71+
}
72+
73+
if scViper.GetString(OutputFormatOpt) == JSONOutputFormat {
74+
log, err := ioutil.ReadAll(logReadWriter)
75+
if err != nil {
76+
return output, fmt.Errorf("failed to read log buffer: %v", err)
77+
}
78+
output.Log = string(log)
79+
}
80+
81+
return output, nil
82+
}

0 commit comments

Comments
 (0)