Installer: Handle VM uninstall before it has had a time to boot

Change-Id: I615bc949b5054b301899b1e0b7eae94a98126e61
diff --git a/core/installer/app_manager.go b/core/installer/app_manager.go
index 8bb072e..fbee783 100644
--- a/core/installer/app_manager.go
+++ b/core/installer/app_manager.go
@@ -83,7 +83,7 @@
 
 func (m *AppManager) GetAllInstances() ([]AppInstanceConfig, error) {
 	m.repo.Pull()
-	kust, err := soft.ReadKustomization(m.repo, filepath.Join(m.appDirRoot, "kustomization.yaml"))
+	kust, err := soft.ReadKustomization(m.repo, filepath.Join(m.appDirRoot, kustomizationFileName))
 	if err != nil {
 		if errors.Is(err, fs.ErrNotExist) {
 			return nil, nil
@@ -103,7 +103,7 @@
 }
 
 func (m *AppManager) GetAllAppInstances(name string) ([]AppInstanceConfig, error) {
-	kust, err := soft.ReadKustomization(m.repo, filepath.Join(m.appDirRoot, "kustomization.yaml"))
+	kust, err := soft.ReadKustomization(m.repo, filepath.Join(m.appDirRoot, kustomizationFileName))
 	if err != nil {
 		if errors.Is(err, fs.ErrNotExist) {
 			return nil, nil
@@ -269,7 +269,7 @@
 func createKustomizationChain(r soft.RepoFS, path string) error {
 	for p := filepath.Clean(path); p != "/"; {
 		parent, child := filepath.Split(p)
-		kustPath := filepath.Join(parent, "kustomization.yaml")
+		kustPath := filepath.Join(parent, kustomizationFileName)
 		kust, err := soft.ReadKustomization(r, kustPath)
 		if err != nil {
 			if errors.Is(err, fs.ErrNotExist) {
@@ -350,7 +350,7 @@
 				return err
 			}
 			for name, contents := range data {
-				if name == "config.json" || name == "kustomization.yaml" || name == "resources" {
+				if name == "config.json" || name == kustomizationFileName || name == "resources" {
 					return fmt.Errorf("%s is forbidden", name)
 				}
 				w, err := r.Writer(path.Join(appDir, name))
@@ -382,7 +382,7 @@
 					return err
 				}
 			}
-			if err := soft.WriteYaml(r, path.Join(resourcesDir, "kustomization.yaml"), appKust); err != nil {
+			if err := soft.WriteYaml(r, path.Join(resourcesDir, kustomizationFileName), appKust); err != nil {
 				return err
 			}
 			return nil
@@ -699,7 +699,7 @@
 				break
 			}
 			n := filepath.Base(curr)
-			kustPath := filepath.Join(p, "kustomization.yaml")
+			kustPath := filepath.Join(p, kustomizationFileName)
 			kust, err := soft.ReadKustomization(r, kustPath)
 			if err != nil {
 				return "", err
@@ -729,13 +729,14 @@
 	}
 	for vmName, vmCfg := range cfg.Out.VM {
 		if vmCfg.VPN.Enabled {
-			if err := m.vpnAPIClient.ExpireNode(vmCfg.Username, vmName); err != nil {
+			// Not found error is ignored as VM might have not had enough time to boot before uninstalling it.
+			if err := m.vpnAPIClient.ExpireNode(vmCfg.Username, vmName); err != nil && !errors.Is(err, ErrorNotFound) {
 				return err
 			}
 			if err := m.vpnAPIClient.ExpireKey(vmCfg.Username, vmCfg.VPN.AuthKey); err != nil {
 				return err
 			}
-			if err := m.vpnAPIClient.RemoveNode(vmCfg.Username, vmName); err != nil {
+			if err := m.vpnAPIClient.RemoveNode(vmCfg.Username, vmName); err != nil && !errors.Is(err, ErrorNotFound) {
 				return err
 			}
 		}
@@ -934,7 +935,7 @@
 }
 
 func (m *InfraAppManager) FindInstance(id string) (InfraAppInstanceConfig, error) {
-	kust, err := soft.ReadKustomization(m.repoIO, filepath.Join("/infrastructure", "kustomization.yaml"))
+	kust, err := soft.ReadKustomization(m.repoIO, filepath.Join("/infrastructure", kustomizationFileName))
 	if err != nil {
 		return InfraAppInstanceConfig{}, err
 	}