Skip to content

Commit d6a6d7f

Browse files
committed
fix inconsistency error in limactl create command intance name exists
Signed-off-by: olalekan odukoya <[email protected]>
1 parent c08b326 commit d6a6d7f

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

cmd/limactl/start.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -164,28 +164,6 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string, createOnly bool) (*
164164
if err := identifiers.Validate(tmpl.Name); err != nil {
165165
return nil, fmt.Errorf("argument must be either an instance name, a YAML file path, or a URL, got %q: %w", tmpl.Name, err)
166166
}
167-
inst, err := store.Inspect(tmpl.Name)
168-
if err == nil {
169-
if createOnly {
170-
return nil, fmt.Errorf("instance %q already exists", tmpl.Name)
171-
}
172-
logrus.Infof("Using the existing instance %q", tmpl.Name)
173-
yqExprs, err := editflags.YQExpressions(flags, false)
174-
if err != nil {
175-
return nil, err
176-
}
177-
if len(yqExprs) > 0 {
178-
yq := yqutil.Join(yqExprs)
179-
inst, err = applyYQExpressionToExistingInstance(inst, yq)
180-
if err != nil {
181-
return nil, fmt.Errorf("failed to apply yq expression %q to instance %q: %w", yq, tmpl.Name, err)
182-
}
183-
}
184-
return inst, nil
185-
}
186-
if !errors.Is(err, os.ErrNotExist) {
187-
return nil, err
188-
}
189167
if arg != "" && arg != DefaultInstanceName {
190168
logrus.Infof("Creating an instance %q from template://default (Not from template://%s)", tmpl.Name, tmpl.Name)
191169
logrus.Warnf("This form is deprecated. Use `limactl create --name=%s template://default` instead", tmpl.Name)
@@ -197,6 +175,29 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string, createOnly bool) (*
197175
}
198176
}
199177

178+
inst, err := store.Inspect(tmpl.Name)
179+
if err == nil {
180+
if createOnly {
181+
return nil, fmt.Errorf("instance %q already exists", tmpl.Name)
182+
}
183+
logrus.Infof("Using the existing instance %q", tmpl.Name)
184+
yqExprs, err := editflags.YQExpressions(flags, false)
185+
if err != nil {
186+
return nil, err
187+
}
188+
if len(yqExprs) > 0 {
189+
yq := yqutil.Join(yqExprs)
190+
inst, err = applyYQExpressionToExistingInstance(inst, yq)
191+
if err != nil {
192+
return nil, fmt.Errorf("failed to apply yq expression %q to instance %q: %w", yq, tmpl.Name, err)
193+
}
194+
}
195+
return inst, nil
196+
}
197+
if !errors.Is(err, os.ErrNotExist) {
198+
return nil, err
199+
}
200+
200201
yqExprs, err := editflags.YQExpressions(flags, true)
201202
if err != nil {
202203
return nil, err

0 commit comments

Comments
 (0)