Skip to content

Commit

Permalink
fix #4 and update init
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Anni committed Jan 18, 2025
1 parent 71b7b6d commit 654bfcf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions assets/playbooks/k3s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
- name: Install K3s agent
ansible.builtin.shell: /tmp/k3s_install.sh
environment:
K3S_URL: "https://{{ hostvars[groups['control_plane'][0]]['ansible_host'] }}:6443"
K3S_URL: "https://{{ hostvars[groups['control_plane'][0]]['inventory_hostname'] }}:6443"
K3S_TOKEN: "{{ hostvars[groups['control_plane'][0]]['node_token']['stdout'] }}"

- name: Configure kubectl on control plane
Expand Down Expand Up @@ -108,7 +108,7 @@
kubernetes.core.k8s_taint:
kubeconfig: "{{ kubeconfig }}"
state: present
name: "{{ hostvars[groups['control_plane'][0]]['ansible_host'] }}"
name: "{{ hostvars[groups['control_plane'][0]]['inventory_hostname'] }}"
taints:
- key: "node-role.kubernetes.io/control-plane"
effect: "NoSchedule"
16 changes: 13 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func createTemplates(overwrite bool) error {
if err != nil {
return fmt.Errorf("error creating templates directory: %w", err)
}
fmt.Printf("Templates directory created at %s\n", templatesDir)
} else {
fmt.Printf("Templates directory already exists at %s\n", templatesDir)
}
return initializeFiles(assets.TemplateFiles, "templates", templatesDir, overwrite)
}
Expand All @@ -132,6 +135,9 @@ func createPlaybooks(overwrite bool) error {
if err != nil {
return fmt.Errorf("error creating playbooks directory: %w", err)
}
fmt.Printf("Playbooks directory created at %s\n", playbooksDir)
} else {
fmt.Printf("Playbooks directory already exists at %s\n", playbooksDir)
}
return initializeFiles(assets.PlaybookFiles, "playbooks", playbooksDir, overwrite)
}
Expand All @@ -154,8 +160,10 @@ func createDefaultKeysDir() error {
if err != nil {
return fmt.Errorf("error creating default keys directory: %w", err)
}
fmt.Printf("Default keys directory created at %s\n", defaultKeysDir)
} else {
fmt.Printf("Default keys directory already exists at %s\n", defaultKeysDir)
}
fmt.Printf("Default keys directory created at %s\n", defaultKeysDir)
return nil
}

Expand All @@ -177,8 +185,10 @@ func createDefaultLabStorage() error {
if err != nil {
return fmt.Errorf("error writing default lab storage file: %w", err)
}
fmt.Printf("Default lab storage file created at %s\n", labStorageFile)
} else {
fmt.Printf("Default lab storage file already exists at %s\n", labStorageFile)
}
fmt.Printf("Default lab storage file created at %s\n", labStorageFile)
return nil
}

Expand All @@ -203,7 +213,6 @@ func initializeFiles(sourceFS embed.FS, sourceDir, targetDir string, overwrite b

relPath := path[len(sourceDir+"/"):]
targetPath := filepath.Join(targetDir, relPath)
fmt.Printf("Extracting %s to %s\n", path, targetPath)

// Ensure subdirectories exist
if err := os.MkdirAll(filepath.Dir(targetPath), 0755); err != nil {
Expand All @@ -216,6 +225,7 @@ func initializeFiles(sourceFS embed.FS, sourceDir, targetDir string, overwrite b
return nil // Skip if file exists and overwrite is false
}
}
fmt.Printf("Extracting %s to %s\n", path, targetPath)
return os.WriteFile(targetPath, content, 0644)
})
}
4 changes: 4 additions & 0 deletions internal/lab/lab.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ func (m *ManagerSvc) Delete(labName string, force bool) error {
if err != nil {
return err
}
// Check if the lab is ready for deletion
if !lab.Status.DeleteAfter.Before(time.Now().UTC()) && !force {
return fmt.Errorf("lab %s is not ready for deletion", labName)
}
// delete volumes first
for _, volume := range lab.Status.Volumes {
m.Logger.Debug("deleting volume", "volume", volume.ObjectMeta.Name)
Expand Down

0 comments on commit 654bfcf

Please sign in to comment.