Skip to content

Commit

Permalink
chore(results): use results command from sonobuoy. simply retrieve co…
Browse files Browse the repository at this point in the history
…mmand to write to target directory
  • Loading branch information
bostrt committed Jun 30, 2022
1 parent e1dfd12 commit 77950e5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 136 deletions.
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/openshift/provider-certification-tool/pkg"
"github.com/openshift/provider-certification-tool/pkg/destroy"
"github.com/openshift/provider-certification-tool/pkg/results"
"github.com/openshift/provider-certification-tool/pkg/retrieve"
"github.com/openshift/provider-certification-tool/pkg/run"
"github.com/openshift/provider-certification-tool/pkg/status"
Expand Down Expand Up @@ -86,13 +85,14 @@ func init() {

// Link in child commands
rootCmd.AddCommand(destroy.NewCmdDestroy(config))
rootCmd.AddCommand(results.NewCmdResults(config))
rootCmd.AddCommand(retrieve.NewCmdRetrieve(config))
rootCmd.AddCommand(run.NewCmdRun(config))
rootCmd.AddCommand(status.NewCmdStatus(config))
rootCmd.AddCommand(version.NewCmdVersion())

// Link in child commands direct from Sonobuoy
rootCmd.AddCommand(app.NewSonobuoyCommand())
rootCmd.AddCommand(app.NewCmdResults())
}

// initConfig reads in config file and ENV variables if set.
Expand Down
102 changes: 0 additions & 102 deletions pkg/results/results.go

This file was deleted.

37 changes: 23 additions & 14 deletions pkg/retrieve/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package retrieve

import (
"io"
"os"
"time"

"github.com/pkg/errors"
Expand All @@ -12,26 +13,39 @@ import (
"golang.org/x/sync/errgroup"

"github.com/openshift/provider-certification-tool/pkg"
results2 "github.com/openshift/provider-certification-tool/pkg/results"
"github.com/openshift/provider-certification-tool/pkg/status"
)

func NewCmdRetrieve(config *pkg.Config) *cobra.Command {
return &cobra.Command{
Use: "retrieve",
Args: cobra.MaximumNArgs(1),
Short: "Collect results from certification environment",
Long: `Downloads the results archive from the certification environment`,
Run: func(cmd *cobra.Command, args []string) {
destinationDirectory, err := os.Getwd()
if err != nil {
log.Error(err)
return
}
if len(args) == 1 {
destinationDirectory = args[0]
if _, err := os.Stat(destinationDirectory); err != nil {
log.Error(err)
return
}
}

s := status.NewStatusOptions(config)
err := s.PreRunCheck()
err = s.PreRunCheck()
if err != nil {
log.Error(err)
return
}

log.Info("Collecting results...")

if err := retrieveResultsRetry(config); err != nil {
if err := retrieveResultsRetry(config, destinationDirectory); err != nil {
log.Error(err)
return
}
Expand All @@ -41,13 +55,13 @@ func NewCmdRetrieve(config *pkg.Config) *cobra.Command {
}
}

func retrieveResultsRetry(config *pkg.Config) error {
func retrieveResultsRetry(config *pkg.Config, destinationDirectory string) error {
var err error
limit := 10 // Retry retrieve 10 times
pause := time.Second * 2
retries := 1
for retries <= limit {
err = retrieveResults(config)
err = retrieveResults(config, destinationDirectory)
if err != nil {
log.Warn(err)
if retries+1 < limit {
Expand All @@ -63,7 +77,7 @@ func retrieveResultsRetry(config *pkg.Config) error {
return errors.New("Retrieval retry limit reached")
}

func retrieveResults(config *pkg.Config) error {
func retrieveResults(config *pkg.Config, destinationDirectory string) error {
// Get a reader that contains the tar output of the results directory.
reader, ec, err := config.SonobuoyClient.RetrieveResults(&client.RetrieveConfig{
Namespace: pkg.CertificationNamespace,
Expand All @@ -73,22 +87,17 @@ func retrieveResults(config *pkg.Config) error {
return errors.Wrap(err, "error retrieving results from sonobuoy")
}

// Download results into cache directory
err, results := writeResultsToDirectory(pkg.ResultsDirectory, reader, ec)
// Download results into target directory
err, results := writeResultsToDirectory(destinationDirectory, reader, ec)
if err != nil {
return errors.Wrap(err, "error retrieving certification results from sonobyuoy")
}

// Log the new files to stdout and save them to a cache for results and upload commands
// Log the new files to stdout
for _, result := range results {
log.Infof("Results saved to %s", result)
}

err = results2.SaveToResultsFile(results)
if err != nil {
return errors.Wrap(err, "error saving results to cache file")
}

return nil
}

Expand Down
18 changes: 0 additions & 18 deletions pkg/types.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package pkg

import (
"os"

"github.com/adrg/xdg"
log "github.com/sirupsen/logrus"
"github.com/vmware-tanzu/sonobuoy/pkg/client"
"k8s.io/client-go/kubernetes"
)
Expand All @@ -13,22 +9,8 @@ const (
AnyUIDClusterRoleBinding = "opct-anyuid"
PrivilegedClusterRoleBinding = "opct-privileged"
CertificationNamespace = "openshift-provider-certification"
ResultsFileName = "results-latest.txt"
)

var (
ResultsDirectory string
)

func init() {
var err error
ResultsDirectory, err = xdg.CacheFile("opct")
if err != nil {
log.Error(err)
os.Exit(1)
}
}

type Config struct {
Kubeconfig string
Clientset kubernetes.Interface
Expand Down

0 comments on commit 77950e5

Please sign in to comment.