-
Notifications
You must be signed in to change notification settings - Fork 1.8k
scorecard: make config a componentconfig, scaffold config kustomization on init
#3490
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
Merged
estroz
merged 7 commits into
operator-framework:master
from
estroz:feature/scorecard-componentconfig
Jul 23, 2020
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e57e5ae
This commit modifies the scorecard config to be a componentconfig
estroz ff1c2b0
move config/scorecard scaffold to 'init' plugins
estroz 3187148
add changelog fragment
estroz 22883b9
updates to config spec
estroz 76c9817
update scorecard docs
estroz 3d7fdb5
update test bundle
estroz 75b2dfc
updates based on PR comments
estroz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
This commit modifies the scorecard config to be a componentconfig
versioned with other scorecard APIs in `pkg/apis/scorecard/v1alpha3`. It also adds the `generate kustomize scorecard` subcommand, which scaffolds componentconfig bases and patches in `config/scorecard`. `generate kustomize manifests` will add the scorecard kustomize path to the manifests kustomization.yaml, and `generate bundle` will write the scorecard config to `bundle/tests/scorecard/config.yaml` cmd/operator-sdk/generate: add `kustomize scorecard` subcommand and modify `kustomize manifests` subcommand pkg/apis/scorecard/v1alpha3: add ScorecardConfiguration types that map to the original Config's types internal/scorecard: replace Config type with v1alpha3.ScorecardConfiguration and related types
- Loading branch information
commit e57e5ae92f0e2d19ae019bd2f42601c0c0185a55
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| // Copyright 2020 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 ( | ||
| "fmt" | ||
| "path/filepath" | ||
|
|
||
| log "github.com/sirupsen/logrus" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/pflag" | ||
| "sigs.k8s.io/kubebuilder/pkg/model/config" | ||
|
|
||
| kbutil "github.com/operator-framework/operator-sdk/internal/util/kubebuilder" | ||
| ) | ||
|
|
||
| const scorecardLongHelp = ` | ||
| Running 'generate kustomize scorecard' will (re)generate scorecard configuration kustomize bases, | ||
| default test patches, and a kustomization.yaml in 'config/scorecard'. | ||
| ` | ||
|
|
||
| const scorecardExamples = ` | ||
| $ operator-sdk generate kustomize scorecard | ||
| Generating kustomize files in config/scorecard | ||
| Kustomize files generated successfully | ||
| $ tree ./config/scorecard | ||
| ./config/scorecard/ | ||
| ├── bases | ||
| │ └── config.yaml | ||
| ├── kustomization.yaml | ||
| └── patches | ||
| ├── basic.config.yaml | ||
| └── olm.config.yaml | ||
| ` | ||
|
|
||
| // defaultTestImageTag points to the latest-released image. | ||
| // TODO: change the tag to "latest" once config scaffolding is in a release, | ||
| // as the new config spec won't work with the current latest image. | ||
| const defaultTestImageTag = "quay.io/operator-framework/scorecard-test:master" | ||
|
|
||
| type scorecardCmd struct { | ||
| operatorName string | ||
| outputDir string | ||
| testImageTag string | ||
| quiet bool | ||
| } | ||
|
|
||
| // NewCmd returns the `scorecard` subcommand. | ||
| func NewCmd() *cobra.Command { | ||
| c := &scorecardCmd{} | ||
| cmd := &cobra.Command{ | ||
| Use: "scorecard", | ||
| Short: "Generates scorecard configuration files", | ||
| Long: scorecardLongHelp, | ||
| Example: scorecardExamples, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if len(args) != 0 { | ||
| return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath()) | ||
| } | ||
|
|
||
| cfg, err := kbutil.ReadConfig() | ||
| if err != nil { | ||
| return fmt.Errorf("error reading configuration: %v", err) | ||
| } | ||
| c.setDefaults(cfg) | ||
|
|
||
| // Run command logic. | ||
| if err = c.run(); err != nil { | ||
| log.Fatalf("Error generating kustomize files: %v", err) | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| c.addFlagsTo(cmd.Flags()) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *scorecardCmd) addFlagsTo(fs *pflag.FlagSet) { | ||
| fs.StringVar(&c.operatorName, "operator-name", "", "Name of the operator") | ||
| fs.StringVar(&c.outputDir, "output-dir", "", "Directory to write kustomize files") | ||
| fs.StringVar(&c.testImageTag, "image", defaultTestImageTag, | ||
| "Image to use for default tests; this image must contain the `/scorecard-test` binary") | ||
| fs.BoolVarP(&c.quiet, "quiet", "q", false, "Run in quiet mode") | ||
| // NB(estroz): might be nice to have an --overwrite flag to explicitly turn on overwrite behavior (the current default). | ||
| } | ||
|
|
||
| // defaultDir is the default directory in which to generate kustomize bases and the kustomization.yaml. | ||
| var defaultDir = filepath.Join("config", "scorecard") | ||
|
|
||
| // setDefaults sets command defaults. | ||
| func (c *scorecardCmd) setDefaults(cfg *config.Config) { | ||
| if c.operatorName == "" { | ||
| c.operatorName = filepath.Base(cfg.Repo) | ||
| } | ||
|
|
||
| if c.outputDir == "" { | ||
| c.outputDir = defaultDir | ||
| } | ||
| } | ||
|
|
||
| // run scaffolds kustomize files for kustomizing a scorecard componentconfig. | ||
| func (c scorecardCmd) run() error { | ||
|
|
||
| if !c.quiet { | ||
| fmt.Println("Generating kustomize files in", c.outputDir) | ||
| } | ||
|
|
||
| err := generate(c.operatorName, c.testImageTag, c.outputDir) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if !c.quiet { | ||
| fmt.Println("Kustomize files generated successfully") | ||
| } | ||
|
|
||
| return nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.