Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip requirement of kubeconfig for e2e & gen #438

Merged
merged 2 commits into from
Jun 8, 2018
Merged
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
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a slightly deeper change than I originally expected. Since e2e does many things (oops) it will need the config later on. Would you be able to move this down below if !e2eflags.rerun { this line?

There is a flag, which needs rethinking, --rerun which allows users to rerun the failed tests if an error is detected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, rather than moving it down I have added a check.

Moving down was causing the initiation of client twice, so added a check rather.

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