Skip to content

Commit e877022

Browse files
refactor: use functional names for hook bash functions
Rename hook functions to describe their actions rather than when they run. Add documentation comments for clarity. No API changes. Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent 93a1e91 commit e877022

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

deployments/systemd/hooks-default.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ hooks:
33
apply-start:
44
- workdir: "/etc/nvidia-mig-manager"
55
command: "/bin/bash"
6-
args: ["-x", "-c", "source hooks.sh; apply-start ${MIG_PARTED_SELECTED_CONFIG}"]
6+
args: ["-x", "-c", "source hooks.sh; persist-config ${MIG_PARTED_SELECTED_CONFIG}"]
77
pre-apply-mode:
88
- workdir: "/etc/nvidia-mig-manager"
99
command: "/bin/bash"
10-
args: ["-x", "-c", "source hooks.sh; pre-apply-mode"]
10+
args: ["-x", "-c", "source hooks.sh; stop-services-for-mode"]
1111
pre-apply-config:
1212
- workdir: "/etc/nvidia-mig-manager"
1313
command: "/bin/bash"
14-
args: ["-x", "-c", "source hooks.sh; pre-apply-config"]
14+
args: ["-x", "-c", "source hooks.sh; stop-services-for-config"]
1515
apply-exit:
1616
- workdir: "/etc/nvidia-mig-manager"
1717
command: "/bin/bash"
18-
args: ["-x", "-c", "source hooks.sh; apply-exit"]
18+
args: ["-x", "-c", "source hooks.sh; start-services"]

deployments/systemd/hooks-minimal.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ hooks:
33
apply-start:
44
- workdir: "/etc/nvidia-mig-manager"
55
command: "/bin/bash"
6-
args: ["-x", "-c", "source hooks.sh; apply-start ${MIG_PARTED_SELECTED_CONFIG}"]
6+
args: ["-x", "-c", "source hooks.sh; persist-config ${MIG_PARTED_SELECTED_CONFIG}"]

deployments/systemd/hooks.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ k8s_pod_images=(
3535
dcgm-exporter
3636
)
3737

38-
function apply-start() {
38+
# persist-config saves the selected MIG configuration to ensure it is
39+
# automatically reapplied after a system reboot.
40+
function persist-config() {
3941
local selected_config="${1}"
4042
nvidia-mig-manager::service::persist_config_across_reboot ${selected_config}
4143
if [ "${?}" != "0" ]; then
@@ -44,7 +46,10 @@ function apply-start() {
4446
return 0
4547
}
4648

47-
function pre-apply-mode() {
49+
# stop-services-for-mode stops all GPU-dependent services (K8s workloads
50+
# and driver services) before applying MIG mode changes that require a
51+
# GPU reset.
52+
function stop-services-for-mode() {
4853
stop_k8s_services
4954
if [ "${?}" != "0" ]; then
5055
return 1
@@ -60,7 +65,9 @@ function pre-apply-mode() {
6065
return 0
6166
}
6267

63-
function pre-apply-config() {
68+
# stop-services-for-config stops Kubernetes services and pods before
69+
# applying MIG device configuration changes (no GPU reset required).
70+
function stop-services-for-config() {
6471
stop_k8s_services
6572
if [ "${?}" != "0" ]; then
6673
return 1
@@ -72,7 +79,9 @@ function pre-apply-config() {
7279
return 0
7380
}
7481

75-
function apply-exit() {
82+
# start-services restarts all previously stopped services (driver and K8s)
83+
# after MIG configuration changes have been successfully applied.
84+
function start-services() {
7685
start_driver_services
7786
if [ "${?}" != "0" ]; then
7887
return 1

0 commit comments

Comments
 (0)