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

Make reason mandatory when interactive #336

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions pkg/workloads/console/runner/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@
}).Should(HaveLen(1), "only one console should be present")
})
})

Context("Unsuccessfully creates console", func() {
JustBeforeEach(func() {
var csl *workloadsv1alpha1.Console
createOptions := runner.Options{Cmd: cmd, Reason: ""}
csl, err = consoleRunner.CreateResource(namespace.Name, consoleTemplate, createOptions)
console = *csl
})

It("Fails to create a new console", func() {
By("Returning an error when reason not provided")
Expect(err).To(HaveOccurred(), "should have failed due to reason not being given for interactive console")
Expect(console).To(BeNil(), "no console should be created")
})
})

Describe("FindTemplateBySelector", func() {
Expand Down Expand Up @@ -497,4 +511,4 @@
})
})
})
})

Check failure on line 514 in pkg/workloads/console/runner/integration/integration_test.go

View workflow job for this annotation

GitHub Actions / vet

expected '}', found 'EOF'
9 changes: 9 additions & 0 deletions pkg/workloads/console/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ func (c *Runner) Create(ctx context.Context, opts CreateOptions) (*workloadsv1al
return nil, err
}

if !opts.Noninteractive && opts.Reason == "" {
return nil, errors.New("No reason given when creating interactive console session.")
}


opt := Options{Cmd: opts.Command, Timeout: int(opts.Timeout.Seconds()), Reason: opts.Reason, Noninteractive: opts.Noninteractive}
csl, err := c.CreateResource(tpl.Namespace, *tpl, opt)
if err != nil {
Expand Down Expand Up @@ -668,6 +673,10 @@ func (c *Runner) List(ctx context.Context, opts ListOptions) (ConsoleSlice, erro

// CreateResource builds a console according to the supplied options and submits it to the API
func (c *Runner) CreateResource(namespace string, template workloadsv1alpha1.ConsoleTemplate, opts Options) (*workloadsv1alpha1.Console, error) {
if !opts.Noninteractive && opts.Reason == "" {
return nil, errors.New("No reason given when creating interactive console session.")
}

csl := &workloadsv1alpha1.Console{
ObjectMeta: metav1.ObjectMeta{
// Let Kubernetes generate a unique name
Expand Down
Loading