Skip to content

WIP: Introduce arch flag for launching clusters #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/lima/lima.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ func ExecLimaVM(vmName string, command string, quiet bool) {
}
}

func SpawnLimaVM(vmName string, tmpl string, yqExpression string, wg *sync.WaitGroup, errCh chan<- error) {
func SpawnLimaVM(vmName string, arch string, tmpl string, yqExpression string, wg *sync.WaitGroup, errCh chan<- error) {
defer wg.Done()

// Define the command to spawn a Lima VM
limaCmd := fmt.Sprintf("limactl start --name %s %s --tty=false --set '%s'", vmName, tmpl, yqExpression)
limaCmd := fmt.Sprintf("limactl start --name %s %s --arch %s --tty=false --set '%s'", vmName, tmpl, arch, yqExpression)
cmd := exec.Command("/bin/sh", "-c", limaCmd)

// Set the output to os.Stdout and os.Stderr
Expand Down
1 change: 1 addition & 0 deletions app/lima/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Image struct {

type LimaVM struct {
Name string `json:"name"`
Arch string `json:"arch"`
Status string `json:"status"`
Dir string `json:"dir"`
Memory uint64 `json:"memory"`
Expand Down
2 changes: 1 addition & 1 deletion app/shikari/shikari.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (c ShikariCluster) CreateCluster(scale bool) {
wg.Add(1)
yqExpr := fmt.Sprintf(`%s | .env.SHIKARI_VM_MODE="%s"`, yqExpression, c.getInstanceMode(vmName))

go lima.SpawnLimaVM(vmName, tmpl, yqExpr, &wg, errCh)
go lima.SpawnLimaVM(vmName, c.Arch, tmpl, yqExpr, &wg, errCh)
yqExpr = ""

}
Expand Down
1 change: 1 addition & 0 deletions app/shikari/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package shikari

type ShikariCluster struct {
Name string
Arch string
NumServers uint8
NumClients uint8
Template string
Expand Down
1 change: 1 addition & 0 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func init() {
createCmd.Flags().Uint8VarP(&cluster.NumServers, "servers", "s", 1, "number of servers")
createCmd.Flags().Uint8VarP(&cluster.NumClients, "clients", "c", 0, "number of clients")
createCmd.Flags().StringVarP(&cluster.Name, "name", "n", "", "name of the cluster")
createCmd.Flags().StringVarP(&cluster.Arch, "arch", "a", "aarch64", "the architecture of the VM (supported by Lima). Eg: aarch64, s390x")
createCmd.Flags().StringVarP(&cluster.Template, "template", "t", "./hashibox.yaml", "name of lima template for the VMs")
createCmd.Flags().StringSliceVarP(&cluster.EnvVars, "env", "e", []string{}, "provide environment vars in the for key=value (can be used multiple times)")
createCmd.Flags().StringVarP(&cluster.ImgPath, "image", "i", "", "path to the cqow2 images to be used for the VMs, overriding the one in the template")
Expand Down
26 changes: 12 additions & 14 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"os"
"regexp"
"runtime"
"strings"
"text/tabwriter"

Expand Down Expand Up @@ -40,7 +39,7 @@ func listInstances(clusterName string) {
w := tabwriter.NewWriter(os.Stdout, 4, 8, 4, byte(' '), 0)

if !noheader {
fmt.Fprintln(w, "CLUSTER\tVM NAME\tIP(lima0)\tSTATUS\tSCENARIO\tDISK(GB)\tMEMORY(GB)\tCPUS\tIMAGE")
fmt.Fprintln(w, "CLUSTER\tVM NAME\tARCH\tIP(lima0)\tSTATUS\tSCENARIO\tDISK(GB)\tMEMORY(GB)\tCPUS\tIMAGE")
}

for _, vm := range vms {
Expand All @@ -51,26 +50,25 @@ func listInstances(clusterName string) {
continue //skip printing the
}
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%s\n", getClusterNameFromInstanceName(vm.Name), vm.Name, vm.GetIPAddress(), vm.Status, vm.GetScenarioNameFromEnv(), bytesToGiB(vm.Disk), bytesToGiB(vm.Memory), vm.Cpus, getImageLocation(vm.Config.Images))
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%s\n", getClusterNameFromInstanceName(vm.Name),
vm.Name, vm.Arch, vm.GetIPAddress(),
vm.Status, vm.GetScenarioNameFromEnv(),
bytesToGiB(vm.Disk), bytesToGiB(vm.Memory),
vm.Cpus,
getImageLocation(vm),
)
}
}
w.Flush()
}

func getImageLocation(images []lima.Image) string {
func getImageLocation(vm lima.LimaVM) string {

var arch, location string
var location string

switch runtime.GOARCH {
case "arm64":
arch = "aarch64"
case "amd64":
arch = "x86_64"
}

for _, image := range images {
for _, image := range vm.Config.Images {

if image.Arch == arch {
if image.Arch == vm.Arch {
location = image.Location
}
}
Expand Down