Skip to content

Commit c460204

Browse files
sebrandon1praveenkumar
authored andcommitted
Issue #1194 Check machine instance directory on start
Validate that required SSH key files exist in ~/.crc/machines/crc/ before attempting to start an existing VM. Missing files now produce a clear error message instead of confusing SSH connection failures. Resolves #1194
1 parent 213b84f commit c460204

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pkg/crc/machine/start.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
282282
return nil, errors.Wrap(err, "Cannot determine if VM exists")
283283
}
284284

285+
if exists {
286+
if err := checkMachineInstanceDir(); err != nil {
287+
return nil, err
288+
}
289+
}
290+
285291
bundleNameFromURI, err := bundle.GetBundleNameFromURI(startConfig.BundlePath)
286292
if err != nil {
287293
return nil, errors.Wrap(err, "Error getting bundle name")
@@ -891,6 +897,19 @@ func startMicroshift(ctx context.Context, sshRunner *crcssh.Runner, ocConfig oc.
891897
return cluster.WaitForAPIServer(ctx, ocConfig)
892898
}
893899

900+
func checkMachineInstanceDir() error {
901+
requiredFiles := []string{
902+
constants.GetPrivateKeyPath(),
903+
constants.GetPublicKeyPath(),
904+
}
905+
for _, filePath := range requiredFiles {
906+
if !crcos.FileExists(filePath) {
907+
return fmt.Errorf("Required file %s is missing from the instance directory. Please delete the instance with 'crc delete' and recreate it with 'crc start'", filePath)
908+
}
909+
}
910+
return nil
911+
}
912+
894913
func ensurePullSecretPresentInVM(sshRunner *crcssh.Runner, pullSec cluster.PullSecretLoader) error {
895914
if pullSecret, _, err := sshRunner.RunPrivate("sudo", "cat", "/etc/crio/openshift-pull-secret"); err == nil {
896915
if err := validation.ImagePullSecret(pullSecret); err == nil {

0 commit comments

Comments
 (0)