Files
ubicloud/prog/install_dnsmasq.rb
Jeremy Evans 15b91ff0c4 Absorb leaf into reap
Reviewing leaf usage in progs, it always occurs right after reap.
Combining leaf and reap methods avoids a redundant query for the
strand's children.

It's typical for nap or donate to be called after the leaf check
after reap.  Also build this into reap, by calling donate by default,
or nap if a nap keyword argument is given.

There are a few cases where reap was called without leaf/donate.
Add a fallthrough keyword argument to support this, so if there are
no children, it does not call either nap or donate

Vm::HostNexus#wait_prep and Kubernetes::UpgradeKubernetesNode#wait_new_node
both need the return value of the reapable child(ren). Add a reaper
keyword argument for this, which is called once for each child.

The most common pattern for using reap/leaf/donate was:

```ruby
reap
hop_download_lb_cert if leaf?
donate
```

This turns into:

```ruby
reap(:download_lb_cert)
```

The second most common pattern was:

```ruby
reap
donate unless leaf?
pop "upgrade cancelled" # or other code
```

This turns into:

```ruby
reap { pop "upgrade cancelled" }
```

In a few places, I changed operations on strand.children to
strand.children_dataset.  Now that we are no longer using
cached children by default, it's better to do these checks
in the database intead of in Ruby.  These places deserve careful
review:

* Prog::Minio::MinioServerNexus#unavailable
* Prog::Postgres::PostgresResourceNexus#wait
* Prog::Postgres::PostgresServerNexus#unavailable

For Prog::Vnet::LoadBalancerNexus#wait_update_vm_load_balancers,
I removed a check on the children completely. It was checking
for an exitval using children_dataset directly after reap,
which should only be true if there was still an active lease
for the child.  This also deserves careful review.

This broke many mocked tests.  This fixes the mocked tests
to use database-backed objects, ensuring that we are testing
observable behavior and not implementation details.
2025-06-26 03:49:53 +09:00

40 lines
1.1 KiB
Ruby

# frozen_string_literal: true
class Prog::InstallDnsmasq < Prog::Base
subject_is :sshable
label def start
# Handle some short, non-dependent steps concurrently, keeping
# overall code compact by self-budding and starting at a different
# label.
bud self.class, frame, :install_build_dependencies
bud self.class, frame, :git_clone_dnsmasq
hop_wait_downloads
end
label def wait_downloads
reap(:compile_and_install)
end
label def compile_and_install
sshable.cmd("(cd dnsmasq && make -sj$(nproc) && sudo make install)")
pop "compiled and installed dnsmasq"
end
label def install_build_dependencies
sshable.cmd("sudo apt-get -y install make gcc")
pop "installed build dependencies"
end
label def git_clone_dnsmasq
q_commit = "b6769234bca9b0eabfe4768832b88d2cdb187092".shellescape
sshable.cmd("git init dnsmasq && " \
"(cd dnsmasq && " \
" git fetch https://github.com/ubicloud/dnsmasq.git #{q_commit} --depth=1 &&" \
" git checkout #{q_commit} &&" \
" git fsck --full)")
pop "downloaded and verified dnsmasq successfully"
end
end