builder: extra init error handling

* Return errors from creating the `NodeGroup`
* Ensure that `b.NodeGroup != nil` before reading from
  it during validation

Signed-off-by: Milas Bowman <milas.bowman@docker.com>
pull/1732/head
Milas Bowman 2 years ago
parent afcaa8df5f
commit 14f5d490ef

@ -108,7 +108,7 @@ func New(dockerCli command.Cli, opts ...Option) (_ *Builder, err error) {
// Validate validates builder context // Validate validates builder context
func (b *Builder) Validate() error { func (b *Builder) Validate() error {
if b.NodeGroup.DockerContext { if b.NodeGroup != nil && b.NodeGroup.DockerContext {
list, err := b.opts.dockerCli.ContextStore().List() list, err := b.opts.dockerCli.ContextStore().List()
if err != nil { if err != nil {
return err return err

@ -61,7 +61,10 @@ func GetCurrentInstance(txn *store.Txn, dockerCli command.Cli) (*store.NodeGroup
return nil, err return nil, err
} }
if ng == nil { if ng == nil {
ng, _ = GetNodeGroup(txn, dockerCli, dockerCli.CurrentContext()) ng, err = GetNodeGroup(txn, dockerCli, dockerCli.CurrentContext())
if err != nil {
return nil, err
}
} }
return ng, nil return ng, nil

Loading…
Cancel
Save