Skip to content

Commit

Permalink
Skip requirement of kubeconfig for e2e & gen (vmware-tanzu#438)
Browse files Browse the repository at this point in the history
* Skip requirement of kubeconfig for e2e & gen

Earlier `kubeconfig` was needed to use the sub-commands `e2e` and `gen`
which is unnecessary since using these sub-commands does not require
communication to Kubernetes server.

This commit removes that necessity.

Signed-off-by: Suraj Deshmukh <[email protected]>

* With `e2e` subcommand, kubeconfig needed

The special case/flag of `e2e` `--rerun-failed` needs kubeconfig, this
commit adds a check to see if this is enabled then it creates the
sonobuoy client with config, otherwise without it.

Signed-off-by: Suraj Deshmukh <[email protected]>

Signed-off-by: Jesse Hamilton [email protected]

Signed-off-by: Jesse Hamilton [email protected]
  • Loading branch information
surajssd authored and chuckha committed Jun 8, 2018
1 parent 3fbd9df commit d5e59bf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
20 changes: 15 additions & 5 deletions cmd/sonobuoy/app/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/client-go/rest"
)

type e2eFlags struct {
Expand Down Expand Up @@ -75,11 +76,17 @@ func e2es(cmd *cobra.Command, args []string) {
os.Exit(1)
}
defer gzr.Close()
restConfig, err := e2eflags.kubecfg.Get()
if err != nil {
errlog.LogError(errors.Wrap(err, "couldn't get REST client"))
os.Exit(1)

var restConfig *rest.Config
// If we are doing a rerun, only then, we need kubeconfig
if e2eflags.rerun {
restConfig, err = e2eflags.kubecfg.Get()
if err != nil {
errlog.LogError(errors.Wrap(err, "couldn't get REST client"))
os.Exit(1)
}
}

sonobuoy, err := client.NewSonobuoyClient(restConfig)
if err != nil {
errlog.LogError(errors.Wrap(err, "could not create sonobuoy client"))
Expand All @@ -105,7 +112,10 @@ func e2es(cmd *cobra.Command, args []string) {
}

if !e2eflags.skipPreflight {
if errs := sonobuoy.PreflightChecks(&client.PreflightConfig{e2eflags.namespace}); len(errs) > 0 {
errs := sonobuoy.PreflightChecks(&client.PreflightConfig{
Namespace: e2eflags.namespace,
})
if len(errs) > 0 {
errlog.LogError(errors.New("Preflight checks failed"))
for _, err := range errs {
errlog.LogError(err)
Expand Down
9 changes: 3 additions & 6 deletions cmd/sonobuoy/app/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,9 @@ func genManifest(cmd *cobra.Command, args []string) {
errlog.LogError(err)
os.Exit(1)
}
kubeCfg, err := genflags.kubecfg.Get()
if err != nil {
errlog.LogError(errors.Wrap(err, "couldn't get kubernetes config"))
os.Exit(1)
}
sbc, err := client.NewSonobuoyClient(kubeCfg)
// Passing in `nil` and no `kubeconfig` because it is not required by the method
// for generating any manifests
sbc, err := client.NewSonobuoyClient(nil)
if err != nil {
errlog.LogError(errors.Wrap(err, "could not create sonobuoy client"))
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

// GetTests extracts the junit results from a sonobuoy archive and returns the requested tests.
func (c *SonobuoyClient) GetTests(reader io.Reader, show string) ([]reporters.JUnitTestCase, error) {
func (*SonobuoyClient) GetTests(reader io.Reader, show string) ([]reporters.JUnitTestCase, error) {
read := results.NewReaderWithVersion(reader, "irrelevant")
junitResults := reporters.JUnitTestSuite{}
err := read.WalkFiles(func(path string, info os.FileInfo, err error) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type templateValues struct {
}

// GenerateManifest fills in a template with a Sonobuoy config
func (c *SonobuoyClient) GenerateManifest(cfg *GenConfig) ([]byte, error) {
func (*SonobuoyClient) GenerateManifest(cfg *GenConfig) ([]byte, error) {
marshalledConfig, err := json.Marshal(cfg.Config)
if err != nil {
return nil, errors.Wrap(err, "couldn't marshall selector")
Expand Down

0 comments on commit d5e59bf

Please sign in to comment.