Skip to content

Commit 1662516

Browse files
authored
Refactor, Modernize, and Document (#6)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a modular addon system for cluster management, enabling streamlined installation and configuration of components like cert-manager, Traefik, ClusterIssuer, Gitea, Prometheus, and Linkerd. - Added a new Traefik dashboard service for improved monitoring and access. - Enhanced test environment script with flexible multinode and teardown options. - **Bug Fixes** - Improved uninstall confirmation prompts for better user clarity. - **Documentation** - Expanded README with detailed instructions on adding new addons. - **Chores** - Updated license to reflect organizational ownership. - Simplified dependency management for improved maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 07ebe35 + 32a13de commit 1662516

36 files changed

Lines changed: 1313 additions & 2097 deletions

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 Yuuki Wesp, Aram Hayrapetyan, "Argon Inc. LLC". All rights reserved.
3+
Copyright (c) 2025 "Argon Inc. LLC". All rights reserved.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

bin/test_env.sh

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,61 @@
11
#!/usr/bin/env sh
22

3-
if ! command -v multipass &> /dev/null
4-
then
3+
# Usage:
4+
# ./test_env.sh [--multinode] [--teardown]
5+
#
6+
# If --multinode is set, launches node1 and node2. Otherwise, launches node1 only.
7+
# If --teardown is set, deletes all multipass nodes and exits.
8+
9+
set -e
10+
11+
if ! command -v multipass >/dev/null 2>&1; then
512
echo "Error: multipass could not be found. Please install multipass first."
613
exit 1
714
fi
815

9-
multipass launch --name node1 --cpus 2 --memory 2G --disk 20G
10-
multipass launch --name node2 --cpus 2 --memory 2G --disk 20G
16+
MULTINODE=0
17+
TEARDOWN=0
18+
for arg in "$@"
19+
do
20+
case "$arg" in
21+
--multinode) MULTINODE=1 ;;
22+
--teardown) TEARDOWN=1 ;;
23+
esac
24+
done
25+
26+
if [ "$TEARDOWN" -eq 1 ]; then
27+
echo "Deleting all multipass nodes..."
28+
NODES=$(multipass list --format csv | awk -F, 'NR>1 {print $1}')
29+
if [ -n "$NODES" ]; then
30+
multipass delete $NODES --purge
31+
else
32+
echo "No multipass nodes to delete."
33+
fi
34+
multipass list
35+
exit 0
36+
fi
37+
38+
if [ "$MULTINODE" -eq 1 ]; then
39+
NODES="node1 node2"
40+
else
41+
NODES="node1"
42+
fi
1143

12-
PASS=${MPS_PASSWORD:-password123}
13-
multipass exec node1 -- sudo bash -c "echo ubuntu:${PASS} | sudo chpasswd"
14-
multipass exec node2 -- sudo bash -c "echo ubuntu:${PASS} | sudo chpasswd"
1544

16-
for key in ~/.ssh/*.pub; do
17-
multipass exec node1 -- bash -c "echo '$(cat "$key")' >> ~/.ssh/authorized_keys"
18-
multipass exec node2 -- bash -c "echo '$(cat "$key")' >> ~/.ssh/authorized_keys"
45+
if [ "$MULTINODE" -eq 1 ]; then
46+
MEMORY=2G
47+
else
48+
MEMORY=4G
49+
fi
50+
51+
for NODE in $NODES; do
52+
multipass launch --name "$NODE" --cpus 2 --memory $MEMORY --disk 10G
53+
PASS=${MPS_PASSWORD:-password123}
54+
multipass exec "$NODE" -- sudo bash -c "echo ubuntu:${PASS} | sudo chpasswd"
55+
for key in ~/.ssh/*.pub; do
56+
multipass exec "$NODE" -- bash -c "echo '$(cat "$key")' >> ~/.ssh/authorized_keys"
57+
done
58+
echo "Node $NODE ready."
1959
done
2060

2161
multipass info | grep "IPv4"
22-

bin/test_teardown.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

cli/main.go

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// The main package for the k3sd CLI tool. Handles cluster creation, uninstallation, and logging.
21
package main
32

43
import (
@@ -9,66 +8,61 @@ import (
98
"os/exec"
109
"strings"
1110

12-
"github.com/argon-chat/k3sd/cluster"
13-
"github.com/argon-chat/k3sd/utils"
11+
. "github.com/argon-chat/k3sd/pkg/cluster"
12+
clusterstore "github.com/argon-chat/k3sd/pkg/clusterstore"
13+
. "github.com/argon-chat/k3sd/pkg/utils"
1414
)
1515

16-
// main is the entry point for the k3sd CLI tool.
17-
// It parses command-line flags, loads cluster configuration, and either creates or uninstalls clusters.
18-
// It also sets up logging and saves the updated cluster state.
1916
func main() {
20-
utils.ParseFlags()
17+
ParseFlags()
2118

22-
if utils.VersionFlag {
23-
fmt.Printf("K3SD version: %s\n", utils.Version)
19+
if VersionFlag {
20+
fmt.Printf("K3SD version: %s\n", Version)
2421
os.Exit(0)
2522
}
2623

27-
clusters, err := cluster.LoadClusters(utils.ConfigPath)
24+
clusters, err := clusterstore.LoadClusters(ConfigPath)
2825
if err != nil {
2926
log.Fatalf("failed to load clusters: %v", err)
3027
}
3128

32-
logger := utils.NewLogger("cli")
29+
logger := NewLogger("cli")
3330
go logger.LogWorker()
3431
go logger.LogWorkerErr()
3532
go logger.LogWorkerFile()
3633
go logger.LogWorkerCmd()
3734

3835
checkCommandExists()
3936

40-
if utils.Uninstall {
41-
// Prompt the user for confirmation before uninstalling clusters.
37+
if Uninstall {
4238
reader := bufio.NewReader(os.Stdin)
43-
fmt.Print("Are you sure you want to uninstall the clusters? (yes/no): ")
39+
fmt.Print("Are you sure you want to uninstall the clusters? (yes/y/no/n): ")
4440
response, _ := reader.ReadString('\n')
4541
response = strings.TrimSpace(strings.ToLower(response))
4642

47-
if response == "yes" {
48-
clusters, err = cluster.UninstallCluster(clusters, logger)
43+
if response == "yes" || response == "y" {
44+
clusters, err = UninstallCluster(clusters, logger)
4945
if err != nil {
5046
log.Fatalf("failed to uninstall clusters: %v", err)
5147
}
52-
} else {
48+
} else if response == "no" || response == "n" {
5349
fmt.Println("Uninstallation canceled.")
5450
return
51+
} else {
52+
log.Fatalf("And just what do you mean by %s?", response)
5553
}
5654
} else {
57-
// Create or update clusters as specified in the configuration.
58-
clusters, err = cluster.CreateCluster(clusters, logger, []string{})
55+
clusters, err = CreateCluster(clusters, logger, []string{})
5956
if err != nil {
6057
log.Fatalf("failed to create clusters: %v", err)
6158
}
6259
}
6360

64-
// Save the updated cluster state to the configuration file.
65-
if err := cluster.SaveClusters(utils.ConfigPath, clusters); err != nil {
61+
if err := clusterstore.SaveClusters(ConfigPath, clusters); err != nil {
6662
log.Fatalf("failed to save clusters: %v", err)
6763
}
6864
}
6965

70-
// checkCommandExists verifies that all required external commands are available in the system's PATH.
71-
// If any command is missing, the program will terminate with a fatal error.
7266
func checkCommandExists() {
7367
commands := []string{
7468
"linkerd",

0 commit comments

Comments
 (0)