@@ -26,6 +26,7 @@ import (
2626 "k8s.io/apimachinery/pkg/labels"
2727 "k8s.io/apimachinery/pkg/util/wait"
2828 "k8s.io/client-go/kubernetes"
29+ "k8s.io/client-go/rest"
2930
3031 registryutil "github.com/operator-framework/operator-sdk/internal/registry"
3132)
@@ -47,8 +48,10 @@ type PodTestRunner struct {
4748 Namespace string
4849 ServiceAccount string
4950 BundlePath string
51+ TestOutput string
5052 BundleMetadata registryutil.Labels
5153 Client kubernetes.Interface
54+ RESTConfig * rest.Config
5255
5356 configMapName string
5457}
@@ -75,6 +78,7 @@ func (o Scorecard) Run(ctx context.Context) (testOutput v1alpha3.TestList, err e
7578 if len (tests ) == 0 {
7679 continue
7780 }
81+ tests = o .setTestDefaults (tests )
7882
7983 output := make (chan v1alpha3.Test , len (tests ))
8084 if stage .Parallel {
@@ -107,6 +111,15 @@ func (o Scorecard) Run(ctx context.Context) (testOutput v1alpha3.TestList, err e
107111 return testOutput , err
108112}
109113
114+ func (o Scorecard ) setTestDefaults (tests []v1alpha3.TestConfiguration ) []v1alpha3.TestConfiguration {
115+ for i := range tests {
116+ if len (tests [i ].Storage .Spec .MountPath .Path ) == 0 {
117+ tests [i ].Storage .Spec .MountPath .Path = o .Config .Storage .Spec .MountPath .Path
118+ }
119+ }
120+ return tests
121+ }
122+
110123func (o Scorecard ) runStageParallel (ctx context.Context , tests []v1alpha3.TestConfiguration , results chan <- v1alpha3.Test ) {
111124 var wg sync.WaitGroup
112125 for _ , t := range tests {
@@ -172,6 +185,7 @@ func (r *PodTestRunner) Initialize(ctx context.Context) error {
172185 if err != nil {
173186 return fmt .Errorf ("error creating ConfigMap %w" , err )
174187 }
188+
175189 return nil
176190
177191}
@@ -187,6 +201,7 @@ func (r FakeTestRunner) Cleanup(ctx context.Context) error {
187201
188202// Cleanup deletes pods and configmap resources from this test run
189203func (r PodTestRunner ) Cleanup (ctx context.Context ) (err error ) {
204+
190205 err = r .deletePods (ctx , r .configMapName )
191206 if err != nil {
192207 return err
@@ -195,13 +210,20 @@ func (r PodTestRunner) Cleanup(ctx context.Context) (err error) {
195210 if err != nil {
196211 return err
197212 }
213+
198214 return nil
199215}
200216
201217// RunTest executes a single test
202218func (r PodTestRunner ) RunTest (ctx context.Context , test v1alpha3.TestConfiguration ) (* v1alpha3.TestStatus , error ) {
219+
203220 // Create a Pod to run the test
204221 podDef := getPodDefinition (r .configMapName , test , r )
222+
223+ if test .Storage .Spec .MountPath .Path != "" {
224+ addStorageToPod (podDef , test .Storage .Spec .MountPath .Path )
225+ }
226+
205227 pod , err := r .Client .CoreV1 ().Pods (r .Namespace ).Create (ctx , podDef , metav1.CreateOptions {})
206228 if err != nil {
207229 return nil , err
@@ -212,6 +234,14 @@ func (r PodTestRunner) RunTest(ctx context.Context, test v1alpha3.TestConfigurat
212234 return nil , err
213235 }
214236
237+ // gather test output if necessary
238+ if test .Storage .Spec .MountPath .Path != "" {
239+ err := gatherTestOutput (r , test .Labels ["suite" ], test .Labels ["test" ], pod .Name , test .Storage .Spec .MountPath .Path )
240+ if err != nil {
241+ return nil , err
242+ }
243+ }
244+
215245 return r .getTestStatus (ctx , pod ), nil
216246}
217247
@@ -239,9 +269,14 @@ func (r PodTestRunner) waitForTestToComplete(ctx context.Context, p *v1.Pod) (er
239269 if err != nil {
240270 return true , fmt .Errorf ("error getting pod %s %w" , p .Name , err )
241271 }
242- if tmp .Status .Phase == v1 .PodSucceeded || tmp .Status .Phase == v1 .PodFailed {
243- return true , nil
272+ for _ , s := range tmp .Status .ContainerStatuses {
273+ if s .Name == "scorecard-test" {
274+ if s .State .Terminated != nil {
275+ return true , nil
276+ }
277+ }
244278 }
279+
245280 return false , nil
246281 })
247282
0 commit comments