Skip to content

Commit e6babd6

Browse files
committed
Revert "fix inconsistency error in limactl create command intance name exists"
This reverts commit d6a6d7f. Signed-off-by: Jan Dubois <[email protected]>
1 parent cce27c4 commit e6babd6

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

cmd/limactl/start.go

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,28 @@ 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+
}
167189
if arg != "" && arg != DefaultInstanceName {
168190
logrus.Infof("Creating an instance %q from template://default (Not from template://%s)", tmpl.Name, tmpl.Name)
169191
logrus.Warnf("This form is deprecated. Use `limactl create --name=%s template://default` instead", tmpl.Name)
@@ -175,29 +197,6 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string, createOnly bool) (*
175197
}
176198
}
177199

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-
201200
yqExprs, err := editflags.YQExpressions(flags, true)
202201
if err != nil {
203202
return nil, err

0 commit comments

Comments
 (0)