Skip to content

Commit 26500cd

Browse files
authored
Merge pull request #29 from jay7x/start_jobs
Make start VM jobs configurable
2 parents e628e78 + 2902784 commit 26500cd

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

plans/cluster/start.pp

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# @summary Start the cluster of Lima VMs
22
# @param name
33
# Cluster name
4+
# @param jobs
5+
# How much VMs to start in parallel
46
# @param clusters
57
# Hash of all defined clusters. Populated from Hiera usually.
68
# @param target
79
# The host to run the limactl on
810
plan lima::cluster::start (
911
String[1] $name,
12+
Integer[0] $jobs = 0,
1013
Optional[Hash] $clusters = undef,
1114
TargetSpec $target = 'localhost',
1215
) {
@@ -36,22 +39,24 @@
3639
fail_plan("Some nodes are missing: ${missing_nodes}", 'lima/missing-nodes', missing_nodes => $missing_nodes)
3740
}
3841

39-
# Collect and set the target's facts
40-
if empty(facts($tgt)) {
41-
without_default_logging() || {
42-
run_plan('facts', $tgt, _catch_errors => true)
42+
$start_jobs = if $jobs > 0 {
43+
$jobs
44+
} else {
45+
if $tgt.facts.length < 1 {
46+
without_default_logging() || {
47+
run_plan('facts', $tgt, _catch_errors => true)
48+
}
4349
}
50+
$cpus = $tgt.facts.get('processors.count', 1)
51+
if $cpus < 4 { 1 } else { $cpus / 2 } # Assume every VM can consume up to 200% of a CPU core on start
4452
}
45-
$cpus = facts($tgt).get('processors.count', 1)
46-
# FIXME: make start_threads configurable
47-
$start_threads = if $cpus < 4 { 1 } else { $cpus / 2 } # Assume every VM can consume up to 200% of a CPU core on start
4853

4954
# Start stopped nodes
5055
$stopped_nodes = $lima_list.filter |$x| { $x['status'] == 'Stopped' }.map |$x| { $x['name'] }
51-
out::verbose("Nodes to start (${start_threads} nodes per batch): ${stopped_nodes}")
56+
out::verbose("Nodes to start (${start_jobs} nodes per batch): ${stopped_nodes}")
5257

53-
# Run in batches of $start_threads VMs in parallel
54-
$start_res = $stopped_nodes.slice($start_threads).map |$batch| {
58+
# Run in batches of $start_jobs VMs in parallel
59+
$start_res = $stopped_nodes.slice($start_jobs).map |$batch| {
5560
$batch.parallelize |$node| {
5661
run_task('lima::start', $tgt, name => $node)
5762
}

spec/plans/cluster/start_spec.rb

+25-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
}
4444
end
4545
let(:nodes_to_start) { [nodes[0], nodes[1], nodes[3], nodes[4]] }
46-
let(:plan_params) { { 'name' => cluster_name, 'clusters' => clusters } }
46+
let(:jobs) { nil }
47+
let(:plan_params) { { 'name' => cluster_name, 'clusters' => clusters, 'jobs' => jobs } }
4748
let(:facts) { { 'processors': { 'count': 1 } } }
4849

4950
context 'with non-existent cluster' do
@@ -81,14 +82,32 @@
8182
expect_task('lima::start').be_called_times(1).with_params('name' => node).always_return(start: true)
8283
end
8384
expect_out_verbose.with_params("Defined nodes: [#{nodes.join(', ')}]")
84-
expect_out_verbose.with_params("Nodes to start (1 nodes per batch): [#{nodes_to_start.join(', ')}]")
8585
end
8686

87-
it 'starts all stopped nodes in the cluster' do
88-
result = run_plan(plan, plan_params)
87+
context 'with no jobs specified' do
88+
it 'starts all stopped nodes in the cluster' do
89+
expect_task('facts').be_called_times(1)
90+
expect_out_verbose.with_params("Nodes to start (1 nodes per batch): [#{nodes_to_start.join(', ')}]")
91+
92+
result = run_plan(plan, plan_params)
93+
94+
expect(result.ok?).to be(true)
95+
expect(result.value.count).to eq(nodes_to_start.length)
96+
end
97+
end
8998

90-
expect(result.ok?).to be(true)
91-
expect(result.value.count).to eq(nodes_to_start.length)
99+
context 'with jobs=>2' do
100+
let(:jobs) { 2 }
101+
102+
it 'starts all stopped nodes in the cluster' do
103+
expect_task('facts').be_called_times(0)
104+
expect_out_verbose.with_params("Nodes to start (#{jobs} nodes per batch): [#{nodes_to_start.join(', ')}]")
105+
106+
result = run_plan(plan, plan_params)
107+
108+
expect(result.ok?).to be(true)
109+
expect(result.value.count).to eq(nodes_to_start.length / jobs)
110+
end
92111
end
93112
end
94113
end

0 commit comments

Comments
 (0)