Skip to content

Commit

Permalink
Adding check for no reason, w/ test
Browse files Browse the repository at this point in the history
  • Loading branch information
doomholderz committed Nov 7, 2024
1 parent d9787b4 commit 5127d23
Showing 1 changed file with 9 additions and 0 deletions.
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

0 comments on commit 5127d23

Please sign in to comment.