Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package executor
package TestJobRunner

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package executor
package TestJobRunner

import (
"archive/tar"
Expand Down Expand Up @@ -44,14 +44,14 @@ type Config struct {
RestConfig *rest.Config
}

type Executor struct {
type TestJobRunner struct {
oc *openshift.Client
cfg *Config
logger logr.Logger
}

// New sets up a new executor to run a given test suite image
func New(logger logr.Logger, cfg *Config) (*Executor, error) {
func New(logger logr.Logger, cfg *Config) (*TestJobRunner, error) {
var oc *openshift.Client
var err error
if cfg.RestConfig != nil {
Expand All @@ -62,10 +62,10 @@ func New(logger logr.Logger, cfg *Config) (*Executor, error) {
if err != nil {
return nil, fmt.Errorf("openshift client creation: %w", err)
}
return &Executor{oc: oc, cfg: cfg, logger: logger.WithName("executor")}, nil
return &TestJobRunner{oc: oc, cfg: cfg, logger: logger.WithName("executor")}, nil
}

func (e *Executor) Execute(ctx context.Context, image string) (*testResults, error) {
func (e *TestJobRunner) Execute(ctx context.Context, image string) (*testResults, error) {
if err := os.MkdirAll(e.cfg.OutputDir, os.ModePerm); err != nil {
return nil, fmt.Errorf("creating output directory: %w", err)
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func (e *Executor) Execute(ctx context.Context, image string) (*testResults, err
return results, nil
}

func (e *Executor) setupProject(ctx context.Context) (*projectv1.Project, error) {
func (e *TestJobRunner) setupProject(ctx context.Context) (*projectv1.Project, error) {
// TODO: why does GenerateName not work?
project := &projectv1.Project{ObjectMeta: metav1.ObjectMeta{Name: "osde2e-executor-" + util.RandomStr(5)}}
if err := e.oc.Create(ctx, project); err != nil {
Expand Down Expand Up @@ -151,7 +151,7 @@ func (e *Executor) setupProject(ctx context.Context) (*projectv1.Project, error)
return project, nil
}

func (e *Executor) createJob(ctx context.Context, namespace string, image string) (*batchv1.Job, error) {
func (e *TestJobRunner) createJob(ctx context.Context, namespace string, image string) (*batchv1.Job, error) {
job := e.buildJobSpec(namespace, image)

if len(e.cfg.PassthruSecrets) > 0 {
Expand Down Expand Up @@ -182,7 +182,7 @@ func (e *Executor) createJob(ctx context.Context, namespace string, image string
return job, nil
}

func (e *Executor) buildJobSpec(namespace string, image string) *batchv1.Job {
func (e *TestJobRunner) buildJobSpec(namespace string, image string) *batchv1.Job {
return &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "executor-",
Expand Down Expand Up @@ -264,7 +264,7 @@ func (e *Executor) buildJobSpec(namespace string, image string) *batchv1.Job {

// Wait for the e2e-suite container to complete (succeed/fail/stop)
// We can't wait for the job because the pause container keeps it running for artifact collection
func (e *Executor) waitForSuite(ctx context.Context, name, namespace, image string) error {
func (e *TestJobRunner) waitForSuite(ctx context.Context, name, namespace, image string) error {
return wait.PollUntilContextTimeout(ctx, 10*time.Second, e.cfg.Timeout, false, func(ctx context.Context) (bool, error) {
pod, err := e.findJobPod(ctx, name, namespace)
if err != nil {
Expand Down Expand Up @@ -294,7 +294,7 @@ func (e *Executor) waitForSuite(ctx context.Context, name, namespace, image stri
})
}

func (e *Executor) fetchArtifacts(ctx context.Context, name, namespace string) error {
func (e *TestJobRunner) fetchArtifacts(ctx context.Context, name, namespace string) error {
clientSet, err := kubernetes.NewForConfig(e.oc.GetConfig())
if err != nil {
return fmt.Errorf("creating clientset: %w", err)
Expand All @@ -316,7 +316,7 @@ func (e *Executor) fetchArtifacts(ctx context.Context, name, namespace string) e
return nil
}

func (e *Executor) findJobPod(ctx context.Context, jobName, namespace string) (*corev1.Pod, error) {
func (e *TestJobRunner) findJobPod(ctx context.Context, jobName, namespace string) (*corev1.Pod, error) {
pods := new(corev1.PodList)
if err := e.oc.WithNamespace(namespace).List(ctx, pods, resources.WithLabelSelector(labels.FormatLabels(map[string]string{"job-name": jobName}))); err != nil {
return nil, fmt.Errorf("listing pods for job: %w", err)
Expand All @@ -329,7 +329,7 @@ func (e *Executor) findJobPod(ctx context.Context, jobName, namespace string) (*
return &pods.Items[0], nil
}

func (e *Executor) fetchPodLogs(ctx context.Context, clientSet *kubernetes.Clientset, pod *corev1.Pod, jobName string) error {
func (e *TestJobRunner) fetchPodLogs(ctx context.Context, clientSet *kubernetes.Clientset, pod *corev1.Pod, jobName string) error {
var logs strings.Builder

req := clientSet.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &corev1.PodLogOptions{Container: "e2e-suite"})
Expand All @@ -354,7 +354,7 @@ func (e *Executor) fetchPodLogs(ctx context.Context, clientSet *kubernetes.Clien
return nil
}

func (e *Executor) fetchArtifactFiles(ctx context.Context, clientSet *kubernetes.Clientset, pod *corev1.Pod) error {
func (e *TestJobRunner) fetchArtifactFiles(ctx context.Context, clientSet *kubernetes.Clientset, pod *corev1.Pod) error {
execRequest := clientSet.CoreV1().RESTClient().
Post().
Resource("pods").
Expand Down
4 changes: 2 additions & 2 deletions pkg/common/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"github.com/openshift/osde2e-common/pkg/clients/openshift"
viper "github.com/openshift/osde2e/pkg/common/concurrentviper"
"github.com/openshift/osde2e/pkg/common/config"
"github.com/openshift/osde2e/pkg/common/mainjobrunner"
"github.com/openshift/osde2e/pkg/common/providers/ocmprovider"
"github.com/openshift/osde2e/pkg/common/runner"
"github.com/openshift/osde2e/pkg/common/templates"
"github.com/openshift/osde2e/pkg/common/util"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -480,7 +480,7 @@ func (h *H) GetRunnerCommandString(templatePath string, timeout int, latestImage
JobName: jobName,
Timeout: timeout,
Image: adHocTestImage,
OutputDir: runner.DefaultRunner.OutputDir,
OutputDir: mainjobrunner.DefaultMainJobRunner.OutputDir,
ServiceAccount: serviceAccountNamespacedName,
PushResultsContainer: latestImageStream,
Suffix: suffix,
Expand Down
4 changes: 2 additions & 2 deletions pkg/common/helper/olm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"context"
"fmt"

"github.com/openshift/osde2e/pkg/common/runner"
"github.com/openshift/osde2e/pkg/common/mainjobrunner"
)

// InspectOLM inspects the OLM state of the cluster and saves the state to disk for later debugging
func (h *H) InspectOLM(ctx context.Context) error {
inspectTimeoutInSeconds := 200
h.SetServiceAccount(ctx, "system:serviceaccount:%s:cluster-admin")
r := h.Runner(fmt.Sprintf("oc adm inspect --dest-dir=%v -A olm", runner.DefaultRunner.OutputDir))
r := h.Runner(fmt.Sprintf("oc adm inspect --dest-dir=%v -A olm", mainjobrunner.DefaultMainJobRunner.OutputDir))
r.Name = "olm-inspect"
r.Tarball = true
stopCh := make(chan struct{})
Expand Down
4 changes: 2 additions & 2 deletions pkg/common/helper/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/openshift/osde2e/pkg/common/runner"
"github.com/openshift/osde2e/pkg/common/mainjobrunner"

projectv1 "github.com/openshift/api/project/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -63,7 +63,7 @@ func (h *H) inspect(ctx context.Context, projects []string) error {
}

projectsArg := strings.Join(inspectProjects, " ")
r := h.Runner(fmt.Sprintf("oc adm inspect %v --dest-dir=%v", projectsArg, runner.DefaultRunner.OutputDir))
r := h.Runner(fmt.Sprintf("oc adm inspect %v --dest-dir=%v", projectsArg, mainjobrunner.DefaultMainJobRunner.OutputDir))
r.Name = "must-gather-additional-projects"
r.Tarball = true
stopCh := make(chan struct{})
Expand Down
12 changes: 6 additions & 6 deletions pkg/common/helper/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
viper "github.com/openshift/osde2e/pkg/common/concurrentviper"

"github.com/openshift/osde2e/pkg/common/config"
"github.com/openshift/osde2e/pkg/common/runner"
"github.com/openshift/osde2e/pkg/common/mainjobrunner"
)

// RunnerWithNoCommand creates an extended test suite runner and configure RBAC for it.
func (h *H) RunnerWithNoCommand() *runner.Runner {
r := runner.DefaultRunner.DeepCopy()
func (h *H) RunnerWithNoCommand() *mainjobrunner.MainJobRunner {
r := mainjobrunner.DefaultMainJobRunner.DeepCopy()

// setup clients
r.Kube = h.Kube()
Expand All @@ -28,19 +28,19 @@ func (h *H) RunnerWithNoCommand() *runner.Runner {
}

// SetRunnerProject sets namespace for runner pod
func (h *H) SetRunnerProject(project string, r *runner.Runner) *runner.Runner {
func (h *H) SetRunnerProject(project string, r *mainjobrunner.MainJobRunner) *mainjobrunner.MainJobRunner {
r.Namespace = project
return r
}

// SetRunnerCommand sets given command to a pod runner
func (h *H) SetRunnerCommand(cmd string, r *runner.Runner) *runner.Runner {
func (h *H) SetRunnerCommand(cmd string, r *mainjobrunner.MainJobRunner) *mainjobrunner.MainJobRunner {
r.Cmd = cmd
return r
}

// Runner creates an extended test suite runner and configure RBAC for it and runs cmd in it.
func (h *H) Runner(cmd string) *runner.Runner {
func (h *H) Runner(cmd string) *mainjobrunner.MainJobRunner {
r := h.RunnerWithNoCommand()
r.PodSpec.ServiceAccountName = h.GetNamespacedServiceAccount()
r.Cmd = cmd
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package runner
package mainjobrunner

import (
"bytes"
Expand Down Expand Up @@ -45,7 +45,7 @@ cd {{$outDir}} && echo "Starting server" && python -m "${MODULE}"
var cmdTemplate = template.Must(template.New("testCmd").Parse(testCmd))

// Command generates the templated command.
func (r *Runner) Command() ([]byte, error) {
func (r *MainJobRunner) Command() ([]byte, error) {
var cmd bytes.Buffer
if err := cmdTemplate.Execute(&cmd, r); err != nil {
return []byte{}, fmt.Errorf("failed templating command: %v", err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package runner
package mainjobrunner

import "testing"

func TestCommand(t *testing.T) {
// copy default runner
def := *DefaultRunner
def := *DefaultMainJobRunner
r := &def

_, err := r.Command()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package runner
package mainjobrunner

import (
kubev1 "k8s.io/api/core/v1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package runner
package mainjobrunner

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package runner
package mainjobrunner

import (
"context"
Expand All @@ -17,12 +17,12 @@ const (
)

// GetLatestImageStreamTag returns the From name of the latest ImageStream tag.
func (r *Runner) GetLatestImageStreamTag() (string, error) {
func (r *MainJobRunner) GetLatestImageStreamTag() (string, error) {
return r.getImageStreamTag("latest")
}

// getImageStreamTag returns the From name of the given ImageStream tag.
func (r *Runner) getImageStreamTag(tag string) (string, error) {
func (r *MainJobRunner) getImageStreamTag(tag string) (string, error) {
if r.Image == nil {
return "", errors.New("client for Image must be set")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package runner
package mainjobrunner

import (
"testing"
Expand All @@ -14,7 +14,7 @@ func TestGetLatestImageStreamTag(t *testing.T) {
expectedFromName := "quay.io/run/tests"

// copy default runner
def := *DefaultRunner
def := *DefaultMainJobRunner
r := &def

// create example ImageStream
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package runner provides a wrapper for the OpenShift extended test suite image.
package runner
package mainjobrunner

import (
"context"
Expand All @@ -15,14 +15,14 @@ import (
)

const (
// name used in Runner resources
// name used in MainJobRunner resources
defaultName = "osde2e-runner"
// directory containing service account credentials
serviceAccountDir = "/var/run/secrets/kubernetes.io/serviceaccount"
)

// DefaultRunner is a runner with the most commonly desired settings.
var DefaultRunner = &Runner{
// DefaultMainJobRunner is a runner with the most commonly desired settings.
var DefaultMainJobRunner = &MainJobRunner{
Name: defaultName,
ImageStreamName: testImageStreamName,
ImageStreamNamespace: testImageStreamNamespace,
Expand All @@ -39,8 +39,8 @@ var DefaultRunner = &Runner{
Logger: ginkgo.GinkgoLogr,
}

// Runner runs the OpenShift extended test suite within a cluster.
type Runner struct {
// MainJobRunner runs the OpenShift extended test suite within a cluster.
type MainJobRunner struct {
// Kube client used to run test in-cluster.
Kube kube.Interface

Expand Down Expand Up @@ -99,7 +99,7 @@ type Runner struct {
}

// Run deploys the suite into a cluster, waits for it to finish, and gathers the results.
func (r *Runner) Run(timeoutInSeconds int, stopCh <-chan struct{}) (err error) {
func (r *MainJobRunner) Run(timeoutInSeconds int, stopCh <-chan struct{}) (err error) {
// TODO: pass this in
ctx := context.TODO()

Expand Down Expand Up @@ -153,13 +153,13 @@ func (r *Runner) Run(timeoutInSeconds int, stopCh <-chan struct{}) (err error) {
}

// Status returns the current state of the runner.
func (r *Runner) Status() Status {
func (r *MainJobRunner) Status() Status {
return r.status
}

// DeepCopy returns a deep copy of a runner.
func (r *Runner) DeepCopy() *Runner {
newRunner := *DefaultRunner
func (r *MainJobRunner) DeepCopy() *MainJobRunner {
newRunner := *DefaultMainJobRunner

// copy repos & PodSpec
newRunner.Repos = make(Repos, len(r.Repos))
Expand All @@ -169,8 +169,8 @@ func (r *Runner) DeepCopy() *Runner {
return &newRunner
}

// meta returns the ObjectMeta used for Runner resources.
func (r *Runner) meta() metav1.ObjectMeta {
// meta returns the ObjectMeta used for MainJobRunner resources.
func (r *MainJobRunner) meta() metav1.ObjectMeta {
return metav1.ObjectMeta{
Name: fmt.Sprintf("%s-%s", r.Name, util.RandomStr(5)),
Labels: map[string]string{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package runner
package mainjobrunner

import (
"fmt"
Expand Down Expand Up @@ -58,8 +58,8 @@ func TestRunner(t *testing.T) {
}
}

func setupRunner(t *testing.T) *Runner {
r := DefaultRunner.DeepCopy()
func setupRunner(t *testing.T) *MainJobRunner {
r := DefaultMainJobRunner.DeepCopy()
if filename := viper.GetString(config.Kubeconfig.Path); len(filename) == 0 {
t.Skipf("TEST_KUBECONFIG must be set to test against a cluster.")
} else if restConfig, err := clientcmd.BuildConfigFromFlags("", filename); err != nil {
Expand Down
Loading
Loading