Skip to content

Commit a666957

Browse files
committed
OSDOCS-12976: updates greenboot scripts MicroShift
1 parent 21a925a commit a666957

13 files changed

+120
-144
lines changed

microshift_running_apps/microshift-greenboot-workload-scripts.adoc

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ include::modules/microshift-greenboot-how-workload-health-check-scripts-work.ado
1414

1515
include::modules/microshift-greenboot-included-health-checks.adoc[leveloffset=+1]
1616

17-
include::modules/microshift-greenboot-create-health-check-script.adoc[leveloffset=+1]
17+
include::modules/microshift-greenboot-app-health-check-script.adoc[leveloffset=+1]
18+
19+
include::modules/microshift-greenboot-workload-health-script-ex.adoc[leveloffset=+2]
1820

1921
include::modules/microshift-greenboot-testing-workload-script.adoc[leveloffset=+1]
2022

21-
[id="additional-resources_microshift-greenboot-workload-scripts_{context}"]
2223
[role="_additional-resources"]
2324
== Additional resources
25+
2426
* xref:../microshift_install_get_ready/microshift-greenboot.adoc#microshift-greenboot[The greenboot health check]
27+
2528
* xref:../microshift_running_apps/microshift-applications.adoc#microshift-applying-manifests-example_applications-microshift[Auto applying manifests]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//Module included in the following assemblies:
2+
//
3+
//* microshift_running_apps/microshift-greenboot-workload-scripts.adoc
4+
5+
:_mod-docs-content-type: CONCEPT
6+
[id="microshift-greenboot-app-health-check-script_{context}"]
7+
= How to create a health check script for your application
8+
9+
You can create workload or application health check scripts in the text editor of your choice using the example in this documentation. Save the scripts in the `/etc/greenboot/check/required.d` directory. When a script in the `/etc/greenboot/check/required.d` directory exits with an error, greenboot triggers a reboot in an attempt to heal the system.
10+
11+
[NOTE]
12+
====
13+
Any script in the `/etc/greenboot/check/required.d` directory triggers a reboot if it exits with an error.
14+
====
15+
16+
If your health check logic requires any post-check steps, you can also create additional scripts and save them in the relevant greenboot directories. For example:
17+
18+
* You can also place shell scripts you want to run after a boot has been declared successful in `/etc/greenboot/green.d`.
19+
* You can place shell scripts you want to run after a boot has been declared failed in `/etc/greenboot/red.d`. For example, if you have steps to heal the system before restarting, you can create scripts for your use case and place them in the `/etc/greenboot/red.d` directory.

modules/microshift-greenboot-check-status.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ $ systemctl show --property=ExecMainStatus --value greenboot-healthcheck.service
3434
----
3535
$ cat /run/motd.d/boot-status
3636
----
37+
38+
//Q: is all of this still true?

modules/microshift-greenboot-check-update.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ $ sudo grub2-editenv - list | grep ^boot_success
2323
boot_success=1
2424
----
2525

26-
If your command returns `boot_success=0`, either the greenboot health check is still running, or the update is a failure.
26+
If your command returns `boot_success=0`, either the greenboot health check is still running, or the update is a failure.

modules/microshift-greenboot-create-health-check-script.adoc

-113
This file was deleted.

modules/microshift-greenboot-dir-structure.adoc

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ If you customize the values of any environment variable in the `/etc/greenboot/g
4646
4747
* To retain customizations when building system images with {microshift-short}, add the `greenboot.conf` file to a blueprint.
4848
* To retain customizations when using an RPM installation, apply changes to the `greenboot.conf` file after you install {microshift-short} and greenboot RPMs.
49-
====
49+
====
50+
51+
//Q: all still true?

modules/microshift-greenboot-health-check-log.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ Waiting 300s for MicroShift service to be active and not failed
3434
FAILURE
3535
...
3636
...
37-
----
37+
----

modules/microshift-greenboot-how-workload-health-check-scripts-work.adoc

+24-6
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,37 @@
66
[id="microshift-greenboot-how-workload-health-check-scripts-work_{context}"]
77
= How workload health check scripts work
88

9-
The workload or application health check script described in this tutorial uses the {microshift-short} health check functions that are available in the `/usr/share/microshift/functions/greenboot.sh` file. This enables you to reuse procedures already implemented for the {microshift-short} core services.
9+
The workload or application health check script described in this tutorial uses the {microshift-short} health check functions already implemented for the {microshift-short} core services. This enables you to reuse those procedures as a convenience for checking your own workloads.
1010

1111
The script starts by running checks that the basic functions of the workload are operating as expected. To run the script successfully:
1212

1313
* Execute the script from a root user account.
1414
* Enable the {microshift-short} service.
1515
16-
The health check performs the following actions:
16+
The `microshift healthcheck` command checks whether a workload of the provided type exists and verifies its
17+
status for the specified timeout duration. The number of ready replicas, that is, pods, must match the expected amount.
1718

18-
* Gets a wait timeout of the current boot cycle for the `wait_for` function.
19-
* Calls the `namespace_images_downloaded` function to wait until pod images are available.
20-
* Calls the `namespace_pods_ready` function to wait until pods are ready.
21-
* Calls the `namespace_pods_not_restarting` function to verify pods are not restarting.
19+
You can add the following actions to the `microshift healthcheck` command:
20+
21+
* `-v=2` to increase verbosity of the output
22+
* `--timeout="${WAIT_TIMEOUT_SECS}s"` to override default 300s timeout value
23+
* `--namespace busybox` to specify the Namespace of the workloads
24+
* `--deployments busybox-deployment` to specify Deployment to check the readiness of
25+
26+
The `microshift healthcheck` command also accepts the following additional parameters to specify other kinds
27+
of workloads:
28+
29+
*`--daemonsets`
30+
* `--statefulsets`
31+
32+
These options take a comma-delimited list of resources, for example, `--daemonsets ovnkube-master,ovnkube-node`.
33+
34+
Alternatively, a `--custom` option can be used with a `JSON` string, for example:
35+
+
36+
[source,terminal]
37+
----
38+
$ microshift healthcheck --custom '{"openshift-storage":{"deployments": ["lvms-operator"], "daemonsets": ["vg-manager"]}, "openshift-ovn-kubernetes":{"daemonsets": ["ovnkube-master", "ovnkube-node"]}}'
39+
----
2240
2341
[NOTE]
2442
====

modules/microshift-greenboot-microshift-health-script.adoc

+2-17
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,14 @@ The `40_microshift_running_check.sh` health check script only performs validatio
3030
|Next
3131
|`exit 1`
3232

33-
|Wait for Kubernetes API health endpoints to be working and receiving traffic
33+
|For each core namespace, wait for readiness of the workload
3434
|Next
3535
|`exit 1`
36-
37-
|Wait for any pod to start
38-
|Next
39-
|`exit 1`
40-
41-
|For each core namespace, wait for images to be pulled
42-
|Next
43-
|`exit 1`
44-
45-
|For each core namespace, wait for pods to be ready
46-
|Next
47-
|`exit 1`
48-
49-
|For each core namespace, check if pods are not restarting
50-
|`exit 0`
51-
|`exit 1`
5236
|===
5337

5438
[id="validation-wait-period_{context}"]
5539
== Validation wait period
40+
5641
The wait period in each validation is five minutes by default. After the wait period, if the validation has not succeeded, it is declared a failure. This wait period is incrementally increased by the base wait period after each boot in the verification loop.
5742

5843
* You can override the base-time wait period by setting the `MICROSHIFT_WAIT_TIMEOUT_SEC` environment variable in the `/etc/greenboot/greenboot.conf` configuration file. For example, you can change the wait time to three minutes by resetting the value to 180 seconds, such as `MICROSHIFT_WAIT_TIMEOUT_SEC=180`.

modules/microshift-greenboot-prerollback-log.adoc

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[id="microshift-greenboot-access-prerollback-check_{context}"]
88
= Accessing prerollback health check output in the system log
99

10-
You can access the output of health check scripts in the system log. For example, check the results of a prerollback script using the following procedure.
10+
You can access the output of health check scripts in the system log. For example, check the results of a pre-rollback script using the following procedure.
1111

1212
.Procedure
1313

@@ -47,3 +47,8 @@ Script '40_microshift_pre_rollback.sh' SUCCESS
4747
FINISHED
4848
redboot-task-runner.service: Deactivated successfully.
4949
----
50+
+
51+
[NOTE]
52+
====
53+
In case of a rollback, the pre-rollback script runs the `sudo microshift-cleanup-data --ovn` command to prepare the system for a potential software downgrade.
54+
====

modules/microshift-greenboot-updates-workloads.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Health check scripts for updates are installed into the `/etc/greenboot/check/re
1313
[IMPORTANT]
1414
====
1515
Wait until after an update is declared valid before starting third-party workloads. If a rollback is performed after workloads start, you can lose data. Some third-party workloads create or update data on a device before an update is complete. Upon rollback, the file system reverts to its state before the update.
16-
====
16+
====
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/Module included in the following assemblies:
2+
//
3+
//* microshift_running_apps/microshift-greenboot-workload-scripts.adoc
4+
5+
:_mod-docs-content-type: REFERENCE
6+
[id="microshift-greenboot-workload-health-check-script-ex_{context}"]
7+
= Workload health check script example
8+
9+
The following example uses the {microshift-short} health check script as a template. You can use this example with the provided libraries as a guide for creating basic health check scripts for your applications.
10+
11+
[id="microshift-greenboot-app-health-check-basic-prereqs_{context}"]
12+
== Basic prerequisites for creating a health check script
13+
14+
* The workload must be installed.
15+
* You must have root access.
16+
17+
[id="microshift-greenboot-app-health-check-ex_{context}"]
18+
== Example and functional requirements
19+
20+
You can start with the following example health check script. Modify it for your use case. In your workload health check script, you must complete the following minimum steps:
21+
22+
* Set the environment variables.
23+
* Define the user workload namespaces.
24+
* List the expected pod count.
25+
26+
[IMPORTANT]
27+
====
28+
Choose a name prefix for your application that ensures it runs after the `40_microshift_running_check.sh` script, which implements the {microshift-short} health check procedure for its core services.
29+
====
30+
31+
.Example workload health check script
32+
[source, bash]
33+
----
34+
# #!/bin/bash
35+
set -e
36+
37+
SCRIPT_NAME=$(basename $0)
38+
39+
# Set greenboot to read and execute the workload health check functions library.
40+
source /usr/share/microshift/functions/greenboot.sh
41+
#Q: should this still be in the script if we deprecated it? see https://github.com/openshift/microshift/pull/4437/files#diff-01887b3e92e76300a404b954081c1b6c06f7417e7d74b8bdac0d16a071a56c5dR7
42+
43+
# Set the system to automatically stop the script if the user running it is not 'root'.
44+
if [ $(id -u) -ne 0 ] ; then
45+
echo "The '${SCRIPT_NAME}' script must be run with the 'root' user privileges"
46+
exit 1
47+
fi
48+
49+
echo "STARTED"
50+
51+
# Set the wait timeout for the current check based on the boot counter
52+
WAIT_TIMEOUT_SECS=$(get_wait_timeout)
53+
54+
/usr/bin/microshift healthcheck -v=2 --timeout="${WAIT_TIMEOUT_SECS}s" --namespace busybox --deployments busybox-deployment
55+
----

modules/microshift-greenboot-workloads-validation.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ $ sudo grub2-editenv - list | grep ^boot_success
2121
[source,terminal]
2222
----
2323
boot_success=1
24-
----
24+
----

0 commit comments

Comments
 (0)