Make result of guest shutdown configurable.
This commit is contained in:
parent
bbe2d6efbc
commit
fb4a0206f1
5 changed files with 22 additions and 1 deletions
|
|
@ -41,6 +41,11 @@
|
|||
# config file's modification timestamp. .userData and .networkConfig
|
||||
# are optional.
|
||||
|
||||
# Whether a guest initiated shutdown event patches the state
|
||||
# property in the CRD.
|
||||
# "guestShutdownStops":
|
||||
# false
|
||||
|
||||
# Define the VM (required)
|
||||
"vm":
|
||||
# The VM's name (required)
|
||||
|
|
|
|||
|
|
@ -76,6 +76,9 @@ public class Configuration implements Dto {
|
|||
/** Optional cloud-init data. */
|
||||
public CloudInit cloudInit;
|
||||
|
||||
/** If guest shutdown changes CRD .vm.state to "Stopped". */
|
||||
public boolean guestShutdownStops;
|
||||
|
||||
/** The vm. */
|
||||
@SuppressWarnings("PMD.ShortVariable")
|
||||
public Vm vm;
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ public class StatusUpdater extends Component {
|
|||
private DynamicKubernetesApi vmCrApi;
|
||||
private EventsV1Api evtsApi;
|
||||
private long observedGeneration;
|
||||
private boolean guestShutdownStops;
|
||||
private boolean shutdownByGuest;
|
||||
|
||||
/**
|
||||
|
|
@ -217,6 +218,9 @@ public class StatusUpdater extends Component {
|
|||
@Handler
|
||||
public void onRunnerConfigurationUpdate(RunnerConfigurationUpdate event)
|
||||
throws ApiException {
|
||||
guestShutdownStops = event.configuration().guestShutdownStops;
|
||||
|
||||
// Remainder applies only if we have a connection to k8s.
|
||||
if (vmCrApi == null) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -274,7 +278,8 @@ public class StatusUpdater extends Component {
|
|||
|
||||
// Maybe stop VM
|
||||
if (event.state() == State.TERMINATING && !event.failed()
|
||||
&& shutdownByGuest) {
|
||||
&& guestShutdownStops && shutdownByGuest) {
|
||||
logger.info(() -> "Stopping VM because of shutdown by guest.");
|
||||
PatchOptions patchOpts = new PatchOptions();
|
||||
patchOpts.setFieldManager("kubernetes-java-kubectl-apply");
|
||||
var res = vmCrApi.patch(namespace, vmName,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue