-
Notifications
You must be signed in to change notification settings - Fork 1.8k
V1alpha2 api - scorecard output changes for v1alpha2 version #1995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
17841d3
50feda0
dd0bf33
6c30748
6c4731f
3e5ab12
b391538
477b53f
8e420e1
f6cd0f7
3a8ae98
146fa90
54b8f50
68ac6d3
8f20945
fba804e
178e17e
5c0d199
456d337
394ab82
3ba185a
ee143ad
cf74e91
6767e66
b61eca7
5740698
2830cc2
b961f88
83b27d2
f09d64d
7ce3a9d
611375f
d31e808
9903139
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2019 The Operator-SDK Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package scorecard | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
schelpers "github.com/operator-framework/operator-sdk/internal/pkg/scorecard/helpers" | ||
scapi "github.com/operator-framework/operator-sdk/pkg/apis/scorecard" | ||
scapiv1alpha1 "github.com/operator-framework/operator-sdk/pkg/apis/scorecard/v1alpha1" | ||
"io/ioutil" | ||
) | ||
|
||
func printPluginOutputs(version string, pluginOutputs []scapiv1alpha1.ScorecardOutput) error { | ||
|
||
var list scapi.ScorecardFormatter | ||
var err error | ||
list, err = combinePluginOutput(pluginOutputs) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if schelpers.IsV1alpha2(version) { | ||
list = scapi.ConvertScorecardOutputV1ToV2(list.(scapiv1alpha1.ScorecardOutput)) | ||
} | ||
|
||
// produce text output | ||
if scViper.GetString(OutputFormatOpt) == TextOutputFormat { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This is out of scope for this PR, but I'm not a huge fan of the global variables used throughout scorecard (e.g. In a follow-on, I think it would be worth it to refactor things so that viper is used only in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, I could write up a new Jira story for refactoring that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://jira.coreos.com/browse/OSDK-587 |
||
output, err := list.MarshalText() | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("%s\n", output) | ||
|
||
return nil | ||
} | ||
|
||
// produce json output | ||
if scViper.GetString(OutputFormatOpt) == JSONOutputFormat { | ||
bytes, err := json.MarshalIndent(list, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("%s\n", string(bytes)) | ||
return nil | ||
|
||
} | ||
|
||
return nil | ||
} | ||
|
||
func combinePluginOutput(pluginOutputs []scapiv1alpha1.ScorecardOutput) (scapiv1alpha1.ScorecardOutput, error) { | ||
output := scapiv1alpha1.ScorecardOutput{} | ||
output.Results = make([]scapiv1alpha1.ScorecardSuiteResult, 0) | ||
for _, v := range pluginOutputs { | ||
for _, r := range v.Results { | ||
output.Results = append(output.Results, r) | ||
} | ||
} | ||
|
||
if scViper.GetString(OutputFormatOpt) == JSONOutputFormat { | ||
log, err := ioutil.ReadAll(logReadWriter) | ||
if err != nil { | ||
return output, fmt.Errorf("failed to read log buffer: %v", err) | ||
} | ||
output.Log = string(log) | ||
} | ||
|
||
return output, nil | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked that k8s uses the nomenclature
--experimental-x
for this kind of impl. WDYT about we adopted the same? As for example--experimental-version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's meant more for enabling or configuring experimental features. In this case, this will control core features of the scorecard (output formats, support for external plugins, exit code handling, label selection, etc.).
So I think we should leave
--version
as the flag name.