github.com/fabianvf/ocp-release-operator-sdk@v0.0.0-20190426141702-57620ee2f090/cmd/operator-sdk/scorecard/cmd.go (about)

     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  	"fmt"
    19  	"strings"
    20  
    21  	"github.com/operator-framework/operator-sdk/internal/pkg/scaffold"
    22  	"github.com/operator-framework/operator-sdk/version"
    23  
    24  	log "github.com/sirupsen/logrus"
    25  	"github.com/spf13/cobra"
    26  	"github.com/spf13/viper"
    27  )
    28  
    29  // scorecardConfig stores all scorecard config passed as flags
    30  type scorecardConfig struct {
    31  	namespace          string
    32  	kubeconfigPath     string
    33  	initTimeout        int
    34  	olmDeployed        bool
    35  	csvPath            string
    36  	basicTests         bool
    37  	olmTests           bool
    38  	tenantTests        bool
    39  	namespacedManifest string
    40  	globalManifest     string
    41  	crManifest         string
    42  	proxyImage         string
    43  	proxyPullPolicy    string
    44  	crdsDir            string
    45  	verbose            bool
    46  }
    47  
    48  var scConf scorecardConfig
    49  
    50  func NewCmd() *cobra.Command {
    51  	scorecardCmd := &cobra.Command{
    52  		Use:   "scorecard",
    53  		Short: "Run scorecard tests",
    54  		Long: `Runs blackbox scorecard tests on an operator
    55  `,
    56  		RunE: ScorecardTests,
    57  	}
    58  
    59  	scorecardCmd.Flags().StringVar(&ScorecardConf, ConfigOpt, "", "config file (default is <project_dir>/.osdk-yaml)")
    60  	scorecardCmd.Flags().StringVar(&scConf.namespace, NamespaceOpt, "", "Namespace of custom resource created in cluster")
    61  	scorecardCmd.Flags().StringVar(&scConf.kubeconfigPath, KubeconfigOpt, "", "Path to kubeconfig of custom resource created in cluster")
    62  	scorecardCmd.Flags().IntVar(&scConf.initTimeout, InitTimeoutOpt, 10, "Timeout for status block on CR to be created in seconds")
    63  	scorecardCmd.Flags().BoolVar(&scConf.olmDeployed, OlmDeployedOpt, false, "The OLM has deployed the operator. Use only the CSV for test data")
    64  	scorecardCmd.Flags().StringVar(&scConf.csvPath, CSVPathOpt, "", "Path to CSV being tested")
    65  	scorecardCmd.Flags().BoolVar(&scConf.basicTests, BasicTestsOpt, true, "Enable basic operator checks")
    66  	scorecardCmd.Flags().BoolVar(&scConf.olmTests, OLMTestsOpt, true, "Enable OLM integration checks")
    67  	scorecardCmd.Flags().BoolVar(&scConf.tenantTests, TenantTestsOpt, false, "Enable good tenant checks")
    68  	scorecardCmd.Flags().StringVar(&scConf.namespacedManifest, NamespacedManifestOpt, "", "Path to manifest for namespaced resources (e.g. RBAC and Operator manifest)")
    69  	scorecardCmd.Flags().StringVar(&scConf.globalManifest, GlobalManifestOpt, "", "Path to manifest for Global resources (e.g. CRD manifests)")
    70  	scorecardCmd.Flags().StringVar(&scConf.crManifest, CRManifestOpt, "", "Path to manifest for Custom Resource (required)")
    71  	scorecardCmd.Flags().StringVar(&scConf.proxyImage, ProxyImageOpt, fmt.Sprintf("quay.io/operator-framework/scorecard-proxy:%s", strings.TrimSuffix(version.Version, "+git")), "Image name for scorecard proxy")
    72  	scorecardCmd.Flags().StringVar(&scConf.proxyPullPolicy, ProxyPullPolicyOpt, "Always", "Pull policy for scorecard proxy image")
    73  	scorecardCmd.Flags().StringVar(&scConf.crdsDir, "crds-dir", scaffold.CRDsDir, "Directory containing CRDs (all CRD manifest filenames must have the suffix 'crd.yaml')")
    74  	scorecardCmd.Flags().BoolVar(&scConf.verbose, VerboseOpt, false, "Enable verbose logging")
    75  
    76  	if err := viper.BindPFlags(scorecardCmd.Flags()); err != nil {
    77  		log.Fatalf("Failed to bind scorecard flags to viper: %v", err)
    78  	}
    79  
    80  	return scorecardCmd
    81  }