<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Operator SDK – Scorecard</title>
    <link>/docs/testing-operators/scorecard/</link>
    <description>Recent content in Scorecard on Operator SDK</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    
	  <atom:link href="/docs/testing-operators/scorecard/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Docs: Writing Custom Scorecard Tests</title>
      <link>/docs/testing-operators/scorecard/custom-tests/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/docs/testing-operators/scorecard/custom-tests/</guid>
      <description>
        
        
        &lt;p&gt;This guide outlines the steps which can be followed to extend the existing scorecard tests and implement operator specific custom tests.&lt;/p&gt;
&lt;h2 id=&#34;run-scorecard-with-custom-tests&#34;&gt;Run scorecard with custom tests:&lt;/h2&gt;
&lt;h3 id=&#34;building-test-image&#34;&gt;Building test image:&lt;/h3&gt;
&lt;p&gt;The following steps explain creating of a custom test image which can be used with Scorecard to run operator specific tests. As an example, let us start by creating a sample go repository containing the test bundle data, custom scorecard tests and a Makefile to help us build a test image.&lt;/p&gt;
&lt;p&gt;The sample test image repository present &lt;a href=&#34;https://github.com/operator-framework/operator-sdk/tree/master/testdata/go/v4/memcached-operator&#34;&gt;here&lt;/a&gt; has the following project structure:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ tree .
.
...
├── config
|   ...
│   └── scorecard
│       ├── bases
│       │   └── config.yaml
│       ├── kustomization.yaml
│       └── patches
│           ├── basic.config.yaml
│           └── olm.config.yaml
├── Makefile
├── bundle
│   ├── manifests
│   │   ├── cache.example.com_memcached_crd.yaml
│   │   └── memcached-operator.clusterserviceversion.yaml
│   ├── metadata
│   │   └── annotations.yaml
│   └── tests
│       └── scorecard
│           └── config.yaml
├── go.mod
├── go.sum
├── images
│   └── custom-scorecard-tests
│       ├── Dockerfile
│       ├── bin
│       │   ├── entrypoint
│       │   └── user_setup
│       ├── cmd
│       │   └── test
│       │       └── main.go
│       └── custom-scorecard-tests
└── internal
    └── tests
        └── tests.go
&lt;/code&gt;&lt;/pre&gt;&lt;ol&gt;
&lt;li&gt;&lt;code&gt;config/scorecard&lt;/code&gt; - Contains a kustomization for generating a config from a base and set of overlays.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bundle/&lt;/code&gt; - Contains bundle manifests and metadata under test.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bundle/tests/scorecard/config.yaml&lt;/code&gt; - Configuration file generated by &lt;code&gt;make bundle&lt;/code&gt; from the &lt;code&gt;config/scorecard&lt;/code&gt; kustomization.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;images/custom-scorecard-tests/main.go&lt;/code&gt; - Scorecard test binary.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;internal/tests/tests.go&lt;/code&gt; -  Contains the implementation of custom tests specific to the operator.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;writing-custom-test-logic&#34;&gt;Writing custom test logic:&lt;/h4&gt;
&lt;p&gt;Scorecard currently implements a few &lt;a href=&#34;https://github.com/operator-framework/operator-sdk/blob/09c3aa14625965af9f22f513cd5c891471dbded2/internal/scorecard/tests/basic.go&#34;&gt;basic&lt;/a&gt; and &lt;a href=&#34;https://github.com/operator-framework/operator-sdk/blob/09c3aa14625965af9f22f513cd5c891471dbded2/internal/scorecard/tests/olm.go&#34;&gt;olm&lt;/a&gt; tests for the image bundle, custom resources and custom resource definitions. Additional tests specific to the operator can also be included in the test suite of scorecard.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;tests.go&lt;/code&gt; file is where the custom tests are implemented in the sample test image project. These tests use &lt;code&gt;scapiv1alpha3.TestResult&lt;/code&gt; struct to populate the result, which is then converted to json format for the output. For example, the format of a simple custom sample test can be as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-Go&#34; data-lang=&#34;Go&#34;&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;package&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;tests&lt;/span&gt;

&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;(&lt;/span&gt;
  &lt;span style=&#34;color:#000&#34;&gt;apimanifests&lt;/span&gt; &lt;span style=&#34;color:#4e9a06&#34;&gt;&amp;#34;github.com/operator-framework/api/pkg/manifests&amp;#34;&lt;/span&gt;
  &lt;span style=&#34;color:#000&#34;&gt;scapiv1alpha3&lt;/span&gt; &lt;span style=&#34;color:#4e9a06&#34;&gt;&amp;#34;github.com/operator-framework/api/pkg/apis/scorecard/v1alpha3&amp;#34;&lt;/span&gt;
&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;)&lt;/span&gt;

&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;const&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;(&lt;/span&gt;
  &lt;span style=&#34;color:#000&#34;&gt;CustomTest1Name&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#4e9a06&#34;&gt;&amp;#34;customtest1&amp;#34;&lt;/span&gt;
&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;)&lt;/span&gt;

&lt;span style=&#34;color:#8f5902;font-style:italic&#34;&gt;// CustomTest1
&lt;/span&gt;&lt;span style=&#34;color:#8f5902;font-style:italic&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;CustomTest1&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;bundle&lt;/span&gt; &lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;*&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;apimanifests&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;Bundle&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;scapiv1alpha3&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;TestStatus&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;{&lt;/span&gt;
  &lt;span style=&#34;color:#000&#34;&gt;r&lt;/span&gt; &lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;:=&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;scapiv1alpha3&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;TestResult&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;{}&lt;/span&gt;
  &lt;span style=&#34;color:#000&#34;&gt;r&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;Name&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;CustomTest1Name&lt;/span&gt;
  &lt;span style=&#34;color:#000&#34;&gt;r&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;State&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;scapiv1alpha3&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;PassState&lt;/span&gt;
  &lt;span style=&#34;color:#000&#34;&gt;r&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;Errors&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#204a87&#34;&gt;make&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;([]&lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;string&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#0000cf;font-weight:bold&#34;&gt;0&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;)&lt;/span&gt;
  &lt;span style=&#34;color:#000&#34;&gt;r&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;Suggestions&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#204a87&#34;&gt;make&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;([]&lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;string&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#0000cf;font-weight:bold&#34;&gt;0&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;)&lt;/span&gt;

  &lt;span style=&#34;color:#8f5902;font-style:italic&#34;&gt;// Implement relevant custom test logic here
&lt;/span&gt;&lt;span style=&#34;color:#8f5902;font-style:italic&#34;&gt;&lt;/span&gt;
  &lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;wrapResult&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;r&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;)&lt;/span&gt;
&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;scorecard-configuration-file&#34;&gt;Scorecard Configuration file:&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&#34;https://github.com/operator-framework/operator-sdk/blob/09c3aa14625965af9f22f513cd5c891471dbded2/internal/scorecard/testdata/bundle/tests/scorecard/config.yaml&#34;&gt;configuration file&lt;/a&gt; includes test definitions and metadata to run the test.
This file is constructed using a kustomization under &lt;code&gt;config/scorecard&lt;/code&gt;, with overlays for test sets.&lt;/p&gt;
&lt;p&gt;For the example &lt;code&gt;CustomTest1&lt;/code&gt; function, add the following to &lt;code&gt;config/scorecard/patches/customtest1.config.yaml&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;- &lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;op&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;add&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;  &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;path&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;/stages/&lt;span style=&#34;color:#0000cf;font-weight:bold&#34;&gt;0&lt;/span&gt;/tests/&lt;span style=&#34;color:#8f5902;font-style:italic&#34;&gt;-
&lt;/span&gt;&lt;span style=&#34;color:#8f5902;font-style:italic&#34;&gt;  value:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;    &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;image&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;quay.io/&amp;lt;username&amp;gt;/custom-scorecard-tests&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;latest&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;    &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;entrypoint&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;    &lt;/span&gt;- custom-scorecard-tests&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;    &lt;/span&gt;- customtest1&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;    &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;labels&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;      &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;suite&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;custom&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;      &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;test&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;customtest1&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The important fields to note here are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;image&lt;/code&gt; - name and tag of the test image which was specified in the Makefile.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;labels&lt;/code&gt; - the name of the &lt;code&gt;test&lt;/code&gt; and &lt;code&gt;suite&lt;/code&gt; the test function belongs to.
This can be specified in the &lt;code&gt;operator-sdk scorecard&lt;/code&gt; command to run the desired test.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Next, add a &lt;a href=&#34;https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/patchesjson6902/&#34;&gt;JSON 6902 patch&lt;/a&gt; to your &lt;code&gt;config/scorecard/kustomization.yaml&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;patchesJson6902&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;...&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;- &lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;path&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;patches/customtest1.config.yaml&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;  &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;target&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;    &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;group&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;scorecard.operatorframework.io&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;    &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;version&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;v1alpha3&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;    &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;kind&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;Configuration&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;    &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;name&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;config&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Once you run &lt;code&gt;make bundle&lt;/code&gt;, the &lt;code&gt;bundle/tests/scorecard/config.yaml&lt;/code&gt; will be (re)generated with your custom test.&lt;/p&gt;
&lt;p&gt;If generating a config file outside of the on-disk bundle, you can run:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-console&#34; data-lang=&#34;console&#34;&gt;$ kustomize build config/scorecard &amp;gt; path/to/config.yaml
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The default location of &lt;code&gt;config.yaml&lt;/code&gt; inside the bundle is &lt;code&gt;&amp;lt;bundle directory&amp;gt;/tests/scorecard/config.yaml&lt;/code&gt;. It can be overridden using the &lt;code&gt;--config&lt;/code&gt; flag. For more details regarding the configuration file refer to &lt;a href=&#34;/docs/testing-operators/scorecard/&#34;&gt;user docs&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;scorecard-binary&#34;&gt;Scorecard binary:&lt;/h3&gt;
&lt;p&gt;The scorecard test image implementation requires the bundle under test to be present in the test image. The &lt;code&gt;apimanifests.GetBundleFromDir()&lt;/code&gt; function reads the pod&amp;rsquo;s bundle to fetch the manifests and scorecard configuration from desired path.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-Go&#34; data-lang=&#34;Go&#34;&gt;&lt;span style=&#34;color:#000&#34;&gt;cfg&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;err&lt;/span&gt; &lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;:=&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;apimanifests&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;GetBundleFromDir&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;scorecard&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;PodBundleRoot&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;)&lt;/span&gt;
&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;err&lt;/span&gt; &lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;!=&lt;/span&gt; &lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;{&lt;/span&gt;
  &lt;span style=&#34;color:#000&#34;&gt;log&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;Fatal&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;err&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;Error&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;())&lt;/span&gt;
&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The scorecard binary uses &lt;code&gt;config.yaml&lt;/code&gt; file to locate tests and execute the them as Pods which scorecard creates. Custom test images are included into Pods that scorecard creates, passing in the bundle contents on a shared mount point to the test image container. The specific custom test that is executed is driven by the config.yaml&amp;rsquo;s entry-point command and arguments.&lt;/p&gt;
&lt;p&gt;An example custom scorecard test implementation is present &lt;a href=&#34;https://github.com/operator-framework/operator-sdk/blob/09c3aa14625965af9f22f513cd5c891471dbded2/images/custom-scorecard-tests/main.go&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The names with which the tests are identified in &lt;code&gt;config.yaml&lt;/code&gt; and would be passed in the &lt;code&gt;scorecard&lt;/code&gt; command, are to be specified here.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-Go&#34; data-lang=&#34;Go&#34;&gt;&lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;...&lt;/span&gt;
&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;switch&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;entrypoint&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;[&lt;/span&gt;&lt;span style=&#34;color:#0000cf;font-weight:bold&#34;&gt;0&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;]&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;{&lt;/span&gt;
&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;tests&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;CustomTest1Name&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;
  &lt;span style=&#34;color:#000&#34;&gt;result&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;tests&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;CustomTest1&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;cfg&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;)&lt;/span&gt;
  &lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;...&lt;/span&gt;
&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;}&lt;/span&gt;
&lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The result of the custom tests which is in &lt;code&gt;scapiv1alpha3.TestResult&lt;/code&gt; format, is converted to json for output.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-Go&#34; data-lang=&#34;Go&#34;&gt;&lt;span style=&#34;color:#000&#34;&gt;prettyJSON&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;err&lt;/span&gt; &lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;:=&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;json&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;MarshalIndent&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;result&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#4e9a06&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#4e9a06&#34;&gt;&amp;#34;    &amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;)&lt;/span&gt;
&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;err&lt;/span&gt; &lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;!=&lt;/span&gt; &lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;{&lt;/span&gt;
  &lt;span style=&#34;color:#000&#34;&gt;log&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;Fatal&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#4e9a06&#34;&gt;&amp;#34;Failed to generate json&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;err&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;)&lt;/span&gt;
&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;}&lt;/span&gt;
&lt;span style=&#34;color:#000&#34;&gt;fmt&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;Printf&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#4e9a06&#34;&gt;&amp;#34;%s\n&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#204a87&#34;&gt;string&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;prettyJSON&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The names of the custom tests are also included in &lt;code&gt;printValidTests()&lt;/code&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-Go&#34; data-lang=&#34;Go&#34;&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;printValidTests&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;()&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;result&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;scapiv1alpha3&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;TestStatus&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;{&lt;/span&gt;
  &lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;...&lt;/span&gt;
  &lt;span style=&#34;color:#000&#34;&gt;str&lt;/span&gt; &lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;:=&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;fmt&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;Sprintf&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#4e9a06&#34;&gt;&amp;#34;Valid tests for this image include: %s&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;tests&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;CustomTest1Name&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;)&lt;/span&gt;
  &lt;span style=&#34;color:#000&#34;&gt;result&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;Errors&lt;/span&gt; &lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#204a87&#34;&gt;append&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;result&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;Errors&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;str&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;)&lt;/span&gt;
  &lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;...&lt;/span&gt;
&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;building-the-project&#34;&gt;Building the project&lt;/h3&gt;
&lt;p&gt;The SDK project makefile contains targets to build the sample custom test image.  The current makefile is found &lt;a href=&#34;https://github.com/operator-framework/operator-sdk/blob/09c3aa14625965af9f22f513cd5c891471dbded2/Makefile&#34;&gt;here&lt;/a&gt;.  You can use this makefile as a reference for your own custom test image makefile.&lt;/p&gt;
&lt;p&gt;To build the sample custom test image, run:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;make image/custom-scorecard-tests
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;running-scorecard-command&#34;&gt;Running scorecard command&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;operator-sdk scorecard&lt;/code&gt; command is used to execute the scorecard tests by specifying the location of test bundle in the command. The name or suite of the tests which are to be executed can be specified with the &lt;code&gt;--selector&lt;/code&gt; flag. The command will create scorecard pods with the image specified in &lt;code&gt;config.yaml&lt;/code&gt; for the respective test. For example, the &lt;code&gt;CustomTest1Name&lt;/code&gt; test provides the following json output.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-console&#34; data-lang=&#34;console&#34;&gt;$ operator-sdk scorecard &amp;lt;bundle_dir_or_image&amp;gt; --selector=suite=custom -o json --wait-time=32s --skip-cleanup=false
{
  &amp;quot;kind&amp;quot;: &amp;quot;TestList&amp;quot;,
  &amp;quot;apiVersion&amp;quot;: &amp;quot;scorecard.operatorframework.io/v1alpha3&amp;quot;,
  &amp;quot;items&amp;quot;: [
    {
      &amp;quot;kind&amp;quot;: &amp;quot;Test&amp;quot;,
      &amp;quot;apiVersion&amp;quot;: &amp;quot;scorecard.operatorframework.io/v1alpha3&amp;quot;,
      &amp;quot;spec&amp;quot;: {
        &amp;quot;image&amp;quot;: &amp;quot;quay.io/operator-framework/scorecard-test:latest&amp;quot;,
        &amp;quot;entrypoint&amp;quot;: [
          &amp;quot;custom-scorecard-tests&amp;quot;,
          &amp;quot;customtest1&amp;quot;
        ],
        &amp;quot;labels&amp;quot;: {
          &amp;quot;suite&amp;quot;: &amp;quot;custom&amp;quot;,
          &amp;quot;test&amp;quot;: &amp;quot;customtest1&amp;quot;
        }
      },
      &amp;quot;status&amp;quot;: {
        &amp;quot;results&amp;quot;: [
          {
            &amp;quot;name&amp;quot;: &amp;quot;customtest1&amp;quot;,
            &amp;quot;log&amp;quot;: &amp;quot;an ISV custom test&amp;quot;,
            &amp;quot;state&amp;quot;: &amp;quot;pass&amp;quot;
          }
        ]
      }
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: More details on the usage of &lt;code&gt;operator-sdk scorecard&lt;/code&gt; command and its flags can be found in the &lt;a href=&#34;/docs/testing-operators/scorecard/&#34;&gt;scorecard user documentation&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;debugging-scorecard-custom-tests&#34;&gt;Debugging scorecard custom tests&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;--skip-cleanup&lt;/code&gt; flag can be used when executing the &lt;code&gt;operator-sdk scorecard&lt;/code&gt; command to cause the scorecard created test pods to be unremoved.
This is useful when debugging or writing new tests so that you can view
the test logs or the pod manifests.&lt;/p&gt;
&lt;h3 id=&#34;storing-scorecard-test-output&#34;&gt;Storing scorecard test output&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;--test-output&lt;/code&gt; flag can be used when executing the &lt;code&gt;operator-sdk scorecard&lt;/code&gt; command with a config specifying &lt;a href=&#34;https://pkg.go.dev/github.com/operator-framework/api@v0.10.4/pkg/apis/scorecard/v1alpha3#Storage&#34;&gt;output persistence&lt;/a&gt; to store the output of the scorecard tests in a specific directory. Any persistent volume data will be stored in the specified local directory upon completion of the scorecard tests.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-console&#34; data-lang=&#34;console&#34;&gt;$ operator-sdk scorecard ./bundle --test-output=/mytestoutput
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: By default, the gathered test output will be stored in &lt;code&gt;$(pwd)/test-output&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;overwrite-storage-and-untar-images-to-prevent-downloading-the-images-from-external-registries&#34;&gt;Overwrite storage and untar images to prevent downloading the images from external registries&lt;/h3&gt;
&lt;p&gt;The following options are useful to prevent downloading the images from external registries during scorecard job execution.
That could be a case of disconnected environments or to prevent an impact of the external registry&amp;rsquo;s pull limits.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;--storage-image&lt;/code&gt; flag can be used when executing the &lt;code&gt;operator-sdk scorecard&lt;/code&gt; command to overwrite the default &lt;code&gt;busybox&lt;/code&gt; image used by the Scorecard pod.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;--untar-image&lt;/code&gt; flag can be used when executing the &lt;code&gt;operator-sdk scorecard&lt;/code&gt; command to overwrite the default untar image used by the Scorecard pod.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;scorecard-initcontainer&#34;&gt;Scorecard initContainer&lt;/h3&gt;
&lt;p&gt;The scorecard inserts an &lt;code&gt;initContainer&lt;/code&gt; into the test pods it creates. The
&lt;code&gt;initContainer&lt;/code&gt; serves the purpose of uncompressing the operator bundle
contents, mounting them into a shared mount point accessible by test
images.  The operator bundle contents are stored within a ConfigMap, uniquely
built for each scorecard test execution.  Upon scorecard completion,
the ConfigMap is removed as part of normal cleanup, along with the test
pods created by scorecard.&lt;/p&gt;
&lt;h3 id=&#34;using-custom-service-accounts&#34;&gt;Using Custom Service Accounts&lt;/h3&gt;
&lt;p&gt;Scorecard does not deploy service accounts, RBAC resources, or
namespaces for your test but instead considers these resources
to be outside its scope. You can however specify whichever service account
your tests require, like &lt;code&gt;config/rbac/service_account.yaml&lt;/code&gt; in
Go operator projects, and then specify that service account
from the command line:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-console&#34; data-lang=&#34;console&#34;&gt;$ operator-sdk scorecard &amp;lt;bundle_dir_or_image&amp;gt; --service-account=my-project-controller-manager
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Also, you can specify a non-default namespace that scorecard will run in:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-console&#34; data-lang=&#34;console&#34;&gt;$ operator-sdk scorecard &amp;lt;bundle_dir_or_image&amp;gt; --namespace=my-project-system
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you do not specify either of these flags, the default namespace
and service account will be used by the scorecard to run test pods.&lt;/p&gt;
&lt;h3 id=&#34;returning-multiple-test-results&#34;&gt;Returning Multiple Test Results&lt;/h3&gt;
&lt;p&gt;Some custom tests might require or be better implemented to return
more than a single test result. For this case, scorecard&amp;rsquo;s output
API allows &lt;a href=&#34;https://github.com/operator-framework/api/blob/333d064/pkg/apis/scorecard/v1alpha3/test_types.go#L35&#34;&gt;multiple test results&lt;/a&gt; to be defined for a single test.&lt;/p&gt;
&lt;h3 id=&#34;accessing-the-kube-api&#34;&gt;Accessing the Kube API&lt;/h3&gt;
&lt;p&gt;Within your custom tests you might require connecting to the Kube API.
In golang, you could use the &lt;a href=&#34;https://github.com/kubernetes/client-go&#34;&gt;client-go&lt;/a&gt; API for example to
check Kube resources within your tests, or even create custom resources. Your
custom test image is being executed within a Pod, so you can use an in-cluster
connection to invoke the Kube API.&lt;/p&gt;
&lt;!-- TODO: this file shouldn&#39;t refer to the top-level operator-sdk repo as a reference, but a sample (in testdata?) --&gt;

      </description>
    </item>
    
    <item>
      <title>Docs: Writing Kuttl Scorecard Tests</title>
      <link>/docs/testing-operators/scorecard/kuttl-tests/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/docs/testing-operators/scorecard/kuttl-tests/</guid>
      <description>
        
        
        &lt;p&gt;This guide outlines the steps which can be followed to implement scorecard
tests using the &lt;a href=&#34;https://github.com/kudobuilder/kuttl/&#34;&gt;kuttl&lt;/a&gt; project and specifically the scorecard
kuttl test image.&lt;/p&gt;
&lt;h2 id=&#34;defining-kuttl-tests-in-scorecard&#34;&gt;Defining kuttl Tests in Scorecard&lt;/h2&gt;
&lt;p&gt;Scorecard users can include kuttl tests within their operator
bundles as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ tree ./bundle
./bundle
├── manifests
│   ├── cache.example.com_memcacheds_crd.yaml
│   └── memcached-operator.clusterserviceversion.yaml
├── metadata
│   └── annotations.yaml
└── tests
    └── scorecard
        ├── config.yaml
        └── kuttl
            ├── kuttl-test.yaml
            └── list-pods
                ├── 00-assert.yaml
                └── 00-pod.yaml
            └── list-other
                ├── 00-assert.yaml
                └── 00-pod.yaml
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;bundle/&lt;/code&gt; - Contains bundle manifests and metadata under test.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bundle/tests/scorecard/config.yaml&lt;/code&gt; - Configuration yaml to define and run scorecard tests.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bundle/tests/scorecard/kuttl&lt;/code&gt; - Contains tests written for kuttl to execute&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bundle/tests/scorecard/kuttl/kuttl-test.yaml&lt;/code&gt; - Contains the kuttl configuration, it is here that you would add any kuttl specific configuration settings that you might require.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bundle/tests/scorecard/kuttl/list-pods&lt;/code&gt; - Contains a kuttl test case&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bundle/tests/scorecard/kuttl/list-pods/00-assert.yaml&lt;/code&gt; - Contains a kuttl test case assert&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bundle/tests/scorecard/kuttl/list-pods/00-pod.yaml&lt;/code&gt; - Contains a kuttl test case step&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bundle/tests/scorecard/kuttl/list-other&lt;/code&gt; - Contains another kuttl test case&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When the scorecard kuttl binary is executed, it will process all the test
cases under the scorecard/kuttl directory within the bundle contents.&lt;/p&gt;
&lt;h2 id=&#34;configuring-kuttl-tests-in-the-scorecard-configuration&#34;&gt;Configuring kuttl Tests in the Scorecard Configuration&lt;/h2&gt;
&lt;p&gt;In the scorecard configuration file, you might have the following
definition of what the selector &lt;code&gt;suite=kuttlsuite&lt;/code&gt; will translate to:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;stages&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;- &lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;tests&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;  &lt;/span&gt;- &lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;image&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;quay.io/operator-framework/scorecard-test-kuttl&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;v2&lt;span style=&#34;color:#0000cf;font-weight:bold&#34;&gt;.0.0&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;    &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;labels&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;      &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;suite&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;kuttlsuite&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;      &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;test&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;kuttltest1&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This test configuration will execute the scorecard-test-kuttl
image which executes kuttl.  The kuttl output is translated
into scorecard compliant output which is displayed back to the
end user along with any other test results.&lt;/p&gt;
&lt;p&gt;With the above kuttl test configuration, you can execute that
kuttl test using scorecard as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;operator-sdk scorecard &amp;lt;bundle_dir_or_image&amp;gt; --selector&lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;suite&lt;/span&gt;&lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;=&lt;/span&gt;kuttlsuite
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;defining-kuttl-specific-configuration-options&#34;&gt;Defining kuttl Specific Configuration Options&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&#34;https://github.com/kudobuilder/kuttl/blob/main/docs/cli.md#examples&#34;&gt;kuttl configuration file&lt;/a&gt; is documented within the
kuttl project.&lt;/p&gt;
&lt;p&gt;An example of the kuttl configuration file is as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;apiVersion&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;kudo.dev/v1beta1&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;kind&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;TestSuite&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;parallel&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#0000cf;font-weight:bold&#34;&gt;4&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;timeout&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#0000cf;font-weight:bold&#34;&gt;120&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;startControlPlane&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;false&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The important fields to note here are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;startControlPlane&lt;/code&gt; - Set to false since scorecard assumes it is running
within a control plane already.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Other kuttl configurations settings are available for more advanced kuttl
use cases.  See &lt;a href=&#34;https://github.com/kudobuilder/kuttl/blob/main/docs/testing/reference.md#testsuite&#34;&gt;kuttl configuration&lt;/a&gt; for more details on kuttl configuration.&lt;/p&gt;
&lt;h3 id=&#34;kuttl-tests-explained&#34;&gt;kuttl Tests Explained&lt;/h3&gt;
&lt;p&gt;The kuttl test tool looks for tests to execute within the bundle
following a naming convention as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;        └── kuttl
            ├── kuttl-test.yaml
            └── list-pods
                ├── 00-assert.yaml
                └── 00-pod.yaml
            └── list-other
                ├── 00-assert.yaml
                └── 00-pod.yaml
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The important fields to note here are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;kuttl-test.yaml&lt;/code&gt; - The name required for your kuttl configuration file.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;list-pods, list-other&lt;/code&gt; - The names given by you for these test cases.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;00-assert.yaml&lt;/code&gt; - The assert file is executed to test whether or
not the test was successful, this assertion determines whether or not
the test passed or failed.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;00-pod.yaml&lt;/code&gt; - The pod file is used to define what the test will
create, in this case a pod will be created based on the manifest within
00-pod.yaml.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The number in front of the assert and pod manifests is used to determine
the order in which kuttl will execute the files.&lt;/p&gt;
&lt;p&gt;See &lt;a href=&#34;https://github.com/kudobuilder/kuttl/blob/main/docs/kuttl-test-harness.md#writing-your-first-test&#34;&gt;kuttl tests&lt;/a&gt; for a detailed description of how
kuttl tests are named and executed.&lt;/p&gt;
&lt;h3 id=&#34;kuttl-test-privileges&#34;&gt;kuttl Test Privileges&lt;/h3&gt;
&lt;p&gt;The kuttl tests a user might write can vary widely in functionality
and in particular require special Kubernetes RBAC privileges outside
of what the default service account for a namespace might have.
It is therefore very likely you will be required to run scorecard
in a custom service account that holds the required RBAC permissions,
like &lt;code&gt;config/rbac/service_account.yaml&lt;/code&gt; in Go operator projects.
You can specify a custom service account in scorecard as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-console&#34; data-lang=&#34;console&#34;&gt;$ operator-sdk scorecard &amp;lt;bundle_dir_or_image&amp;gt; --service-account=my-project-controller-manager
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Also, you can specify a non-default namespace that scorecard will run in:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-console&#34; data-lang=&#34;console&#34;&gt;$ operator-sdk scorecard &amp;lt;bundle_dir_or_image&amp;gt; --namespace=my-project-system
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you do not specify either of these flags, the default namespace
and service account will be used by the scorecard to run test pods.&lt;/p&gt;
&lt;p&gt;It is worth noting that scorecard-test-kuttl specifies a namespace
to the kubectl-kuttl command which causes kuttl to not create a
namespace for each test.  This might impact your kuttl tests in
that you might need to perform resource cleanup in your tests
instead of depending upon namespace deletion to perform that cleanup.&lt;/p&gt;
&lt;p&gt;Also of note is that in our example &lt;a href=&#34;https://github.com/kudobuilder/kuttl/blob/main/docs/testing/reference.md#testsuite&#34;&gt;kuttl configuration&lt;/a&gt;
file, we add the &lt;code&gt;suppressLog: events&lt;/code&gt; setting which means that
kuttl will not log kubernetes events and thereby means you do not
have to provide RBAC access for reading kubernetes events to the
service account used to run kuttl tests.&lt;/p&gt;

      </description>
    </item>
    
  </channel>
</rss>
