Move automatic login request to CRD.

Undoes reorganize constants.
This commit is contained in:
Michael Lipp 2025-03-01 15:44:05 +01:00
parent 5366e24092
commit 5e282c4d2b
17 changed files with 103 additions and 126 deletions

View file

@ -27,47 +27,24 @@ public class Constants {
/** The Constant APP_NAME. */ /** The Constant APP_NAME. */
public static final String APP_NAME = "vm-runner"; public static final String APP_NAME = "vm-runner";
/** /** The Constant VM_OP_NAME. */
* Constants related to the CRD. public static final String VM_OP_NAME = "vm-operator";
*/
@SuppressWarnings("PMD.ShortClassName")
public static class Crd {
/** The Constant NAME. */ /** The Constant VM_OP_GROUP. */
public static final String NAME = "vm-operator"; public static final String VM_OP_GROUP = "vmoperator.jdrupes.org";
/** The Constant GROUP. */ /** The Constant VM_OP_KIND_VM. */
public static final String GROUP = "vmoperator.jdrupes.org"; public static final String VM_OP_KIND_VM = "VirtualMachine";
/** The Constant KIND_VM. */ /** The Constant VM_OP_KIND_VM_POOL. */
public static final String KIND_VM = "VirtualMachine"; public static final String VM_OP_KIND_VM_POOL = "VmPool";
/** The Constant KIND_VM_POOL. */ /** The Constant COMP_DISPLAY_SECRETS. */
public static final String KIND_VM_POOL = "VmPool"; public static final String COMP_DISPLAY_SECRET = "display-secret";
}
/** /** The Constant DATA_DISPLAY_PASSWORD. */
* Constants for the display secret. public static final String DATA_DISPLAY_PASSWORD = "display-password";
*/
public static class DisplaySecret {
/** The Constant NAME. */ /** The Constant DATA_PASSWORD_EXPIRY. */
public static final String NAME = "display-secret"; public static final String DATA_PASSWORD_EXPIRY = "password-expiry";
/** The Constant DISPLAY_PASSWORD. */
public static final String DISPLAY_PASSWORD = "display-password";
/** The Constant PASSWORD_EXPIRY. */
public static final String PASSWORD_EXPIRY = "password-expiry";
}
/**
* Constants for status fields.
*/
public static class Status {
/** The Constant LOGGED_IN_USER. */
public static final String LOGGED_IN_USER = "loggedInUser";
}
} }

View file

@ -193,7 +193,7 @@ public class K8sGenericStub<O extends KubernetesObject,
} }
/** /**
* Updates the object's status. This method will not retry. * Updates the object's status.
* *
* @param object the current state of the object (passed to `status`) * @param object the current state of the object (passed to `status`)
* @param status function that returns the new status * @param status function that returns the new status
@ -231,7 +231,7 @@ public class K8sGenericStub<O extends KubernetesObject,
} }
/** /**
* Updates the status. In case of conflict, retries up to 16 times. * Updates the status.
* *
* @param status the status * @param status the status
* @return the kubernetes api response * @return the kubernetes api response

View file

@ -33,9 +33,9 @@ import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.Map; import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jdrupes.vmoperator.common.Constants.Crd;
import org.jdrupes.vmoperator.common.K8s; import org.jdrupes.vmoperator.common.K8s;
import static org.jdrupes.vmoperator.manager.Constants.APP_NAME; import static org.jdrupes.vmoperator.manager.Constants.APP_NAME;
import static org.jdrupes.vmoperator.manager.Constants.VM_OP_NAME;
import org.jdrupes.vmoperator.manager.events.VmChannel; import org.jdrupes.vmoperator.manager.events.VmChannel;
import org.jdrupes.vmoperator.util.DataPath; import org.jdrupes.vmoperator.util.DataPath;
import org.jdrupes.vmoperator.util.GsonPtr; import org.jdrupes.vmoperator.util.GsonPtr;
@ -121,7 +121,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
DynamicKubernetesObject newCm) { DynamicKubernetesObject newCm) {
ListOptions listOpts = new ListOptions(); ListOptions listOpts = new ListOptions();
listOpts.setLabelSelector( listOpts.setLabelSelector(
"app.kubernetes.io/managed-by=" + Crd.NAME + "," "app.kubernetes.io/managed-by=" + VM_OP_NAME + ","
+ "app.kubernetes.io/name=" + APP_NAME + "," + "app.kubernetes.io/name=" + APP_NAME + ","
+ "app.kubernetes.io/instance=" + newCm.getMetadata() + "app.kubernetes.io/instance=" + newCm.getMetadata()
.getLabels().get("app.kubernetes.io/instance")); .getLabels().get("app.kubernetes.io/instance"));

View file

@ -29,7 +29,8 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.time.Instant; import java.time.Instant;
import java.util.logging.Level; import java.util.logging.Level;
import org.jdrupes.vmoperator.common.Constants.Crd; import static org.jdrupes.vmoperator.common.Constants.VM_OP_GROUP;
import static org.jdrupes.vmoperator.common.Constants.VM_OP_KIND_VM;
import org.jdrupes.vmoperator.common.K8sClient; import org.jdrupes.vmoperator.common.K8sClient;
import org.jdrupes.vmoperator.common.K8sDynamicStub; import org.jdrupes.vmoperator.common.K8sDynamicStub;
import org.jdrupes.vmoperator.common.VmDefinitionStub; import org.jdrupes.vmoperator.common.VmDefinitionStub;
@ -193,7 +194,7 @@ public class Controller extends Component {
private void patchVmDef(K8sClient client, String name, String path, private void patchVmDef(K8sClient client, String name, String path,
Object value) throws ApiException, IOException { Object value) throws ApiException, IOException {
var vmStub = K8sDynamicStub.get(client, var vmStub = K8sDynamicStub.get(client,
new GroupVersionKind(Crd.GROUP, "", Crd.KIND_VM), namespace, new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM), namespace,
name); name);
// Patch running // Patch running
@ -226,7 +227,7 @@ public class Controller extends Component {
try { try {
var vmDef = channel.vmDefinition(); var vmDef = channel.vmDefinition();
var vmStub = VmDefinitionStub.get(channel.client(), var vmStub = VmDefinitionStub.get(channel.client(),
new GroupVersionKind(Crd.GROUP, "", Crd.KIND_VM), new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM),
vmDef.namespace(), vmDef.name()); vmDef.namespace(), vmDef.name());
if (vmStub.updateStatus(vmDef, from -> { if (vmStub.updateStatus(vmDef, from -> {
JsonObject status = from.statusJson(); JsonObject status = from.statusJson();

View file

@ -28,11 +28,11 @@ import io.kubernetes.client.util.generic.options.PatchOptions;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import static org.jdrupes.vmoperator.common.Constants.APP_NAME; import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
import org.jdrupes.vmoperator.common.Constants.Crd; import static org.jdrupes.vmoperator.common.Constants.VM_OP_NAME;
import org.jdrupes.vmoperator.common.Constants.DisplaySecret;
import org.jdrupes.vmoperator.common.K8sClient; import org.jdrupes.vmoperator.common.K8sClient;
import org.jdrupes.vmoperator.common.K8sV1PodStub; import org.jdrupes.vmoperator.common.K8sV1PodStub;
import org.jdrupes.vmoperator.common.K8sV1SecretStub; import org.jdrupes.vmoperator.common.K8sV1SecretStub;
import static org.jdrupes.vmoperator.manager.Constants.COMP_DISPLAY_SECRET;
import org.jdrupes.vmoperator.manager.events.ChannelDictionary; import org.jdrupes.vmoperator.manager.events.ChannelDictionary;
import org.jdrupes.vmoperator.manager.events.VmChannel; import org.jdrupes.vmoperator.manager.events.VmChannel;
import org.jgrapes.core.Channel; import org.jgrapes.core.Channel;
@ -61,7 +61,7 @@ public class DisplaySecretMonitor
context(K8sV1SecretStub.CONTEXT); context(K8sV1SecretStub.CONTEXT);
ListOptions options = new ListOptions(); ListOptions options = new ListOptions();
options.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + "," options.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + ","
+ "app.kubernetes.io/component=" + DisplaySecret.NAME); + "app.kubernetes.io/component=" + COMP_DISPLAY_SECRET);
options(options); options(options);
} }
@ -95,7 +95,7 @@ public class DisplaySecretMonitor
// Force update for pod // Force update for pod
ListOptions listOpts = new ListOptions(); ListOptions listOpts = new ListOptions();
listOpts.setLabelSelector( listOpts.setLabelSelector(
"app.kubernetes.io/managed-by=" + Crd.NAME + "," "app.kubernetes.io/managed-by=" + VM_OP_NAME + ","
+ "app.kubernetes.io/name=" + APP_NAME + "," + "app.kubernetes.io/name=" + APP_NAME + ","
+ "app.kubernetes.io/instance=" + change.object.getMetadata() + "app.kubernetes.io/instance=" + change.object.getMetadata()
.getLabels().get("app.kubernetes.io/instance")); .getLabels().get("app.kubernetes.io/instance"));

View file

@ -37,12 +37,14 @@ import java.util.Optional;
import java.util.Scanner; import java.util.Scanner;
import java.util.logging.Logger; import java.util.logging.Logger;
import static org.jdrupes.vmoperator.common.Constants.APP_NAME; import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
import org.jdrupes.vmoperator.common.Constants.Crd; import static org.jdrupes.vmoperator.common.Constants.COMP_DISPLAY_SECRET;
import org.jdrupes.vmoperator.common.Constants.DisplaySecret; import static org.jdrupes.vmoperator.common.Constants.VM_OP_GROUP;
import org.jdrupes.vmoperator.common.Constants.Status; import static org.jdrupes.vmoperator.common.Constants.VM_OP_KIND_VM;
import org.jdrupes.vmoperator.common.K8sV1SecretStub; import org.jdrupes.vmoperator.common.K8sV1SecretStub;
import org.jdrupes.vmoperator.common.VmDefinition; import org.jdrupes.vmoperator.common.VmDefinition;
import org.jdrupes.vmoperator.common.VmDefinitionStub; import org.jdrupes.vmoperator.common.VmDefinitionStub;
import static org.jdrupes.vmoperator.manager.Constants.DATA_DISPLAY_PASSWORD;
import static org.jdrupes.vmoperator.manager.Constants.DATA_PASSWORD_EXPIRY;
import org.jdrupes.vmoperator.manager.events.PrepareConsole; import org.jdrupes.vmoperator.manager.events.PrepareConsole;
import org.jdrupes.vmoperator.manager.events.VmChannel; import org.jdrupes.vmoperator.manager.events.VmChannel;
import org.jdrupes.vmoperator.manager.events.VmDefChanged; import org.jdrupes.vmoperator.manager.events.VmDefChanged;
@ -141,7 +143,7 @@ public class DisplaySecretReconciler extends Component {
var vmDef = event.vmDefinition(); var vmDef = event.vmDefinition();
ListOptions options = new ListOptions(); ListOptions options = new ListOptions();
options.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + "," options.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + ","
+ "app.kubernetes.io/component=" + DisplaySecret.NAME + "," + "app.kubernetes.io/component=" + COMP_DISPLAY_SECRET + ","
+ "app.kubernetes.io/instance=" + vmDef.name()); + "app.kubernetes.io/instance=" + vmDef.name());
var stubs = K8sV1SecretStub.list(channel.client(), vmDef.namespace(), var stubs = K8sV1SecretStub.list(channel.client(), vmDef.namespace(),
options); options);
@ -152,9 +154,9 @@ public class DisplaySecretReconciler extends Component {
// Create secret // Create secret
var secret = new V1Secret(); var secret = new V1Secret();
secret.setMetadata(new V1ObjectMeta().namespace(vmDef.namespace()) secret.setMetadata(new V1ObjectMeta().namespace(vmDef.namespace())
.name(vmDef.name() + "-" + DisplaySecret.NAME) .name(vmDef.name() + "-" + COMP_DISPLAY_SECRET)
.putLabelsItem("app.kubernetes.io/name", APP_NAME) .putLabelsItem("app.kubernetes.io/name", APP_NAME)
.putLabelsItem("app.kubernetes.io/component", DisplaySecret.NAME) .putLabelsItem("app.kubernetes.io/component", COMP_DISPLAY_SECRET)
.putLabelsItem("app.kubernetes.io/instance", vmDef.name())); .putLabelsItem("app.kubernetes.io/instance", vmDef.name()));
secret.setType("Opaque"); secret.setType("Opaque");
SecureRandom random = null; SecureRandom random = null;
@ -167,8 +169,8 @@ public class DisplaySecretReconciler extends Component {
byte[] bytes = new byte[16]; byte[] bytes = new byte[16];
random.nextBytes(bytes); random.nextBytes(bytes);
var password = Base64.encode(bytes); var password = Base64.encode(bytes);
secret.setStringData(Map.of(DisplaySecret.DISPLAY_PASSWORD, password, secret.setStringData(Map.of(DATA_DISPLAY_PASSWORD, password,
DisplaySecret.PASSWORD_EXPIRY, "now")); DATA_PASSWORD_EXPIRY, "now"));
K8sV1SecretStub.create(channel.client(), secret); K8sV1SecretStub.create(channel.client(), secret);
} }
@ -194,7 +196,7 @@ public class DisplaySecretReconciler extends Component {
// Check if access is possible // Check if access is possible
if (event.loginUser() if (event.loginUser()
? !vmDef.<String> fromStatus(Status.LOGGED_IN_USER) ? !vmDef.<String> fromStatus("loggedInUser")
.map(u -> u.equals(event.user())).orElse(false) .map(u -> u.equals(event.user())).orElse(false)
: !vmDef.conditionStatus("Running").orElse(false)) { : !vmDef.conditionStatus("Running").orElse(false)) {
return; return;
@ -227,7 +229,7 @@ public class DisplaySecretReconciler extends Component {
private VmDefinition updateConsoleUser(PrepareConsole event, private VmDefinition updateConsoleUser(PrepareConsole event,
VmChannel channel) throws ApiException { VmChannel channel) throws ApiException {
var vmStub = VmDefinitionStub.get(channel.client(), var vmStub = VmDefinitionStub.get(channel.client(),
new GroupVersionKind(Crd.GROUP, "", Crd.KIND_VM), new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM),
event.vmDefinition().namespace(), event.vmDefinition().name()); event.vmDefinition().namespace(), event.vmDefinition().name());
return vmStub.updateStatus(from -> { return vmStub.updateStatus(from -> {
JsonObject status = from.statusJson(); JsonObject status = from.statusJson();
@ -241,7 +243,7 @@ public class DisplaySecretReconciler extends Component {
// Look for secret // Look for secret
ListOptions options = new ListOptions(); ListOptions options = new ListOptions();
options.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + "," options.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + ","
+ "app.kubernetes.io/component=" + DisplaySecret.NAME + "," + "app.kubernetes.io/component=" + COMP_DISPLAY_SECRET + ","
+ "app.kubernetes.io/instance=" + vmDef.name()); + "app.kubernetes.io/instance=" + vmDef.name());
var stubs = K8sV1SecretStub.list(channel.client(), vmDef.namespace(), var stubs = K8sV1SecretStub.list(channel.client(), vmDef.namespace(),
options); options);
@ -255,14 +257,12 @@ public class DisplaySecretReconciler extends Component {
private boolean updatePassword(V1Secret secret, PrepareConsole event) { private boolean updatePassword(V1Secret secret, PrepareConsole event) {
var expiry = Optional.ofNullable(secret.getData() var expiry = Optional.ofNullable(secret.getData()
.get(DisplaySecret.PASSWORD_EXPIRY)).map(b -> new String(b)) .get(DATA_PASSWORD_EXPIRY)).map(b -> new String(b)).orElse(null);
.orElse(null); if (secret.getData().get(DATA_DISPLAY_PASSWORD) != null
if (secret.getData().get(DisplaySecret.DISPLAY_PASSWORD) != null
&& stillValid(expiry)) { && stillValid(expiry)) {
// Fixed secret, don't touch // Fixed secret, don't touch
event.setResult( event.setResult(
new String( new String(secret.getData().get(DATA_DISPLAY_PASSWORD)));
secret.getData().get(DisplaySecret.DISPLAY_PASSWORD)));
return false; return false;
} }
@ -277,8 +277,8 @@ public class DisplaySecretReconciler extends Component {
byte[] bytes = new byte[16]; byte[] bytes = new byte[16];
random.nextBytes(bytes); random.nextBytes(bytes);
var password = Base64.encode(bytes); var password = Base64.encode(bytes);
secret.setStringData(Map.of(DisplaySecret.DISPLAY_PASSWORD, password, secret.setStringData(Map.of(DATA_DISPLAY_PASSWORD, password,
DisplaySecret.PASSWORD_EXPIRY, DATA_PASSWORD_EXPIRY,
Long.toString(Instant.now().getEpochSecond() + passwordValidity))); Long.toString(Instant.now().getEpochSecond() + passwordValidity)));
event.setResult(password); event.setResult(password);
return true; return true;

View file

@ -40,7 +40,7 @@ import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option; import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
import org.jdrupes.vmoperator.common.Constants.Crd; import static org.jdrupes.vmoperator.manager.Constants.VM_OP_NAME;
import org.jdrupes.vmoperator.manager.events.Exit; import org.jdrupes.vmoperator.manager.events.Exit;
import org.jdrupes.vmoperator.util.FsdUtils; import org.jdrupes.vmoperator.util.FsdUtils;
import org.jgrapes.core.Channel; import org.jgrapes.core.Channel;
@ -108,7 +108,7 @@ public class Manager extends Component {
// Configuration store with file in /etc/opt (default) // Configuration store with file in /etc/opt (default)
File cfgFile = new File(cmdLine.getOptionValue('c', File cfgFile = new File(cmdLine.getOptionValue('c',
"/etc/opt/" + Crd.NAME.replace("-", "") + "/config.yaml")); "/etc/opt/" + VM_OP_NAME.replace("-", "") + "/config.yaml"));
logger.config(() -> "Using configuration from: " + cfgFile.getPath()); logger.config(() -> "Using configuration from: " + cfgFile.getPath());
// Don't rely on night config to produce a good exception // Don't rely on night config to produce a good exception
// for this simple case // for this simple case
@ -271,7 +271,7 @@ public class Manager extends Component {
try { try {
// Get logging properties from file and put them in effect // Get logging properties from file and put them in effect
InputStream props; InputStream props;
var path = FsdUtils.findConfigFile(Crd.NAME.replace("-", ""), var path = FsdUtils.findConfigFile(VM_OP_NAME.replace("-", ""),
"logging.properties"); "logging.properties");
if (path.isPresent()) { if (path.isPresent()) {
props = Files.newInputStream(path.get()); props = Files.newInputStream(path.get());

View file

@ -28,7 +28,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.jdrupes.vmoperator.common.Constants.Crd; import static org.jdrupes.vmoperator.common.Constants.VM_OP_GROUP;
import static org.jdrupes.vmoperator.common.Constants.VM_OP_KIND_VM;
import org.jdrupes.vmoperator.common.K8s; import org.jdrupes.vmoperator.common.K8s;
import org.jdrupes.vmoperator.common.K8sClient; import org.jdrupes.vmoperator.common.K8sClient;
import org.jdrupes.vmoperator.common.K8sDynamicModel; import org.jdrupes.vmoperator.common.K8sDynamicModel;
@ -37,6 +38,7 @@ import org.jdrupes.vmoperator.common.K8sDynamicStub;
import org.jdrupes.vmoperator.common.K8sObserver.ResponseType; import org.jdrupes.vmoperator.common.K8sObserver.ResponseType;
import org.jdrupes.vmoperator.common.VmDefinitionStub; import org.jdrupes.vmoperator.common.VmDefinitionStub;
import org.jdrupes.vmoperator.common.VmPool; import org.jdrupes.vmoperator.common.VmPool;
import static org.jdrupes.vmoperator.manager.Constants.VM_OP_KIND_VM_POOL;
import org.jdrupes.vmoperator.manager.events.GetPools; import org.jdrupes.vmoperator.manager.events.GetPools;
import org.jdrupes.vmoperator.manager.events.VmDefChanged; import org.jdrupes.vmoperator.manager.events.VmDefChanged;
import org.jdrupes.vmoperator.manager.events.VmPoolChanged; import org.jdrupes.vmoperator.manager.events.VmPoolChanged;
@ -86,7 +88,7 @@ public class PoolMonitor extends
client(new K8sClient()); client(new K8sClient());
// Get all our API versions // Get all our API versions
var ctx = K8s.context(client(), Crd.GROUP, "", Crd.KIND_VM_POOL); var ctx = K8s.context(client(), VM_OP_GROUP, "", VM_OP_KIND_VM_POOL);
if (ctx.isEmpty()) { if (ctx.isEmpty()) {
logger.severe(() -> "Cannot get CRD context."); logger.severe(() -> "Cannot get CRD context.");
return; return;
@ -182,7 +184,7 @@ public class PoolMonitor extends
return; return;
} }
var vmStub = VmDefinitionStub.get(client(), var vmStub = VmDefinitionStub.get(client(),
new GroupVersionKind(Crd.GROUP, "", Crd.KIND_VM), new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM),
vmDef.namespace(), vmDef.name()); vmDef.namespace(), vmDef.name());
vmStub.updateStatus(from -> { vmStub.updateStatus(from -> {
// TODO // TODO

View file

@ -36,7 +36,7 @@ import java.util.Set;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.jdrupes.vmoperator.common.Constants.APP_NAME; import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
import org.jdrupes.vmoperator.common.Constants.Crd; import static org.jdrupes.vmoperator.common.Constants.VM_OP_NAME;
import org.jdrupes.vmoperator.common.K8sV1PvcStub; import org.jdrupes.vmoperator.common.K8sV1PvcStub;
import org.jdrupes.vmoperator.manager.events.VmChannel; import org.jdrupes.vmoperator.manager.events.VmChannel;
import org.jdrupes.vmoperator.manager.events.VmDefChanged; import org.jdrupes.vmoperator.manager.events.VmDefChanged;
@ -83,7 +83,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
// Existing disks // Existing disks
ListOptions listOpts = new ListOptions(); ListOptions listOpts = new ListOptions();
listOpts.setLabelSelector( listOpts.setLabelSelector(
"app.kubernetes.io/managed-by=" + Crd.NAME + "," "app.kubernetes.io/managed-by=" + VM_OP_NAME + ","
+ "app.kubernetes.io/name=" + APP_NAME + "," + "app.kubernetes.io/name=" + APP_NAME + ","
+ "app.kubernetes.io/instance=" + vmDef.name()); + "app.kubernetes.io/instance=" + vmDef.name());
var knownDisks = K8sV1PvcStub.list(channel.client(), var knownDisks = K8sV1PvcStub.list(channel.client(),

View file

@ -46,12 +46,12 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import static org.jdrupes.vmoperator.common.Constants.APP_NAME; import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
import org.jdrupes.vmoperator.common.Constants.DisplaySecret;
import org.jdrupes.vmoperator.common.Convertions; import org.jdrupes.vmoperator.common.Convertions;
import org.jdrupes.vmoperator.common.K8sClient; import org.jdrupes.vmoperator.common.K8sClient;
import org.jdrupes.vmoperator.common.K8sObserver; import org.jdrupes.vmoperator.common.K8sObserver;
import org.jdrupes.vmoperator.common.K8sV1SecretStub; import org.jdrupes.vmoperator.common.K8sV1SecretStub;
import org.jdrupes.vmoperator.common.VmDefinition; import org.jdrupes.vmoperator.common.VmDefinition;
import static org.jdrupes.vmoperator.manager.Constants.COMP_DISPLAY_SECRET;
import org.jdrupes.vmoperator.manager.events.ResetVm; import org.jdrupes.vmoperator.manager.events.ResetVm;
import org.jdrupes.vmoperator.manager.events.VmChannel; import org.jdrupes.vmoperator.manager.events.VmChannel;
import org.jdrupes.vmoperator.manager.events.VmDefChanged; import org.jdrupes.vmoperator.manager.events.VmDefChanged;
@ -276,7 +276,7 @@ public class Reconciler extends Component {
// Check if we have a display secret // Check if we have a display secret
ListOptions options = new ListOptions(); ListOptions options = new ListOptions();
options.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + "," options.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + ","
+ "app.kubernetes.io/component=" + DisplaySecret.NAME + "," + "app.kubernetes.io/component=" + COMP_DISPLAY_SECRET + ","
+ "app.kubernetes.io/instance=" + vmDef.name()); + "app.kubernetes.io/instance=" + vmDef.name());
var dsStub = K8sV1SecretStub var dsStub = K8sV1SecretStub
.list(client, vmDef.namespace(), options) .list(client, vmDef.namespace(), options)

View file

@ -31,7 +31,8 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.jdrupes.vmoperator.common.Constants.Crd; import static org.jdrupes.vmoperator.common.Constants.VM_OP_GROUP;
import static org.jdrupes.vmoperator.common.Constants.VM_OP_KIND_VM;
import org.jdrupes.vmoperator.common.K8s; import org.jdrupes.vmoperator.common.K8s;
import org.jdrupes.vmoperator.common.K8sClient; import org.jdrupes.vmoperator.common.K8sClient;
import org.jdrupes.vmoperator.common.K8sDynamicStub; import org.jdrupes.vmoperator.common.K8sDynamicStub;
@ -45,6 +46,7 @@ import org.jdrupes.vmoperator.common.VmDefinitions;
import org.jdrupes.vmoperator.common.VmExtraData; import org.jdrupes.vmoperator.common.VmExtraData;
import org.jdrupes.vmoperator.common.VmPool; import org.jdrupes.vmoperator.common.VmPool;
import static org.jdrupes.vmoperator.manager.Constants.APP_NAME; import static org.jdrupes.vmoperator.manager.Constants.APP_NAME;
import static org.jdrupes.vmoperator.manager.Constants.VM_OP_NAME;
import org.jdrupes.vmoperator.manager.events.AssignVm; import org.jdrupes.vmoperator.manager.events.AssignVm;
import org.jdrupes.vmoperator.manager.events.ChannelManager; import org.jdrupes.vmoperator.manager.events.ChannelManager;
import org.jdrupes.vmoperator.manager.events.GetPools; import org.jdrupes.vmoperator.manager.events.GetPools;
@ -85,7 +87,7 @@ public class VmMonitor extends
client(new K8sClient()); client(new K8sClient());
// Get all our API versions // Get all our API versions
var ctx = K8s.context(client(), Crd.GROUP, "", Crd.KIND_VM); var ctx = K8s.context(client(), VM_OP_GROUP, "", VM_OP_KIND_VM);
if (ctx.isEmpty()) { if (ctx.isEmpty()) {
logger.severe(() -> "Cannot get CRD context."); logger.severe(() -> "Cannot get CRD context.");
return; return;
@ -103,7 +105,7 @@ public class VmMonitor extends
.stream().map(stub -> stub.name()).collect(Collectors.toSet()); .stream().map(stub -> stub.name()).collect(Collectors.toSet());
ListOptions opts = new ListOptions(); ListOptions opts = new ListOptions();
opts.setLabelSelector( opts.setLabelSelector(
"app.kubernetes.io/managed-by=" + Crd.NAME + "," "app.kubernetes.io/managed-by=" + VM_OP_NAME + ","
+ "app.kubernetes.io/name=" + APP_NAME); + "app.kubernetes.io/name=" + APP_NAME);
for (var context : Set.of(K8sV1StatefulSetStub.CONTEXT, for (var context : Set.of(K8sV1StatefulSetStub.CONTEXT,
K8sV1ConfigMapStub.CONTEXT)) { K8sV1ConfigMapStub.CONTEXT)) {

View file

@ -13,8 +13,10 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.jdrupes.vmoperator.common.Constants.APP_NAME; import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
import org.jdrupes.vmoperator.common.Constants.Crd; import static org.jdrupes.vmoperator.common.Constants.COMP_DISPLAY_SECRET;
import org.jdrupes.vmoperator.common.Constants.DisplaySecret; import static org.jdrupes.vmoperator.common.Constants.VM_OP_GROUP;
import static org.jdrupes.vmoperator.common.Constants.VM_OP_KIND_VM;
import static org.jdrupes.vmoperator.common.Constants.VM_OP_NAME;
import org.jdrupes.vmoperator.common.K8s; import org.jdrupes.vmoperator.common.K8s;
import org.jdrupes.vmoperator.common.K8sClient; import org.jdrupes.vmoperator.common.K8sClient;
import org.jdrupes.vmoperator.common.K8sDynamicStub; import org.jdrupes.vmoperator.common.K8sDynamicStub;
@ -58,7 +60,7 @@ class BasicTests {
waitForManager(); waitForManager();
// Context for working with our CR // Context for working with our CR
var apiRes = K8s.context(client, Crd.GROUP, null, Crd.KIND_VM); var apiRes = K8s.context(client, VM_OP_GROUP, null, VM_OP_KIND_VM);
assertTrue(apiRes.isPresent()); assertTrue(apiRes.isPresent());
vmsContext = apiRes.get(); vmsContext = apiRes.get();
@ -68,7 +70,7 @@ class BasicTests {
ListOptions listOpts = new ListOptions(); ListOptions listOpts = new ListOptions();
listOpts.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + "," listOpts.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + ","
+ "app.kubernetes.io/instance=" + VM_NAME + "," + "app.kubernetes.io/instance=" + VM_NAME + ","
+ "app.kubernetes.io/component=" + DisplaySecret.NAME); + "app.kubernetes.io/component=" + COMP_DISPLAY_SECRET);
var secrets = K8sV1SecretStub.list(client, "vmop-dev", listOpts); var secrets = K8sV1SecretStub.list(client, "vmop-dev", listOpts);
for (var secret : secrets) { for (var secret : secrets) {
secret.delete(); secret.delete();
@ -98,7 +100,7 @@ class BasicTests {
private static void deletePvcs() throws ApiException { private static void deletePvcs() throws ApiException {
ListOptions listOpts = new ListOptions(); ListOptions listOpts = new ListOptions();
listOpts.setLabelSelector( listOpts.setLabelSelector(
"app.kubernetes.io/managed-by=" + Crd.NAME + "," "app.kubernetes.io/managed-by=" + VM_OP_NAME + ","
+ "app.kubernetes.io/name=" + APP_NAME + "," + "app.kubernetes.io/name=" + APP_NAME + ","
+ "app.kubernetes.io/instance=" + VM_NAME); + "app.kubernetes.io/instance=" + VM_NAME);
var knownPvcs = K8sV1PvcStub.list(client, "vmop-dev", listOpts); var knownPvcs = K8sV1PvcStub.list(client, "vmop-dev", listOpts);
@ -137,11 +139,11 @@ class BasicTests {
List.of("labels", "app.kubernetes.io/name"), Constants.APP_NAME, List.of("labels", "app.kubernetes.io/name"), Constants.APP_NAME,
List.of("labels", "app.kubernetes.io/instance"), VM_NAME, List.of("labels", "app.kubernetes.io/instance"), VM_NAME,
List.of("labels", "app.kubernetes.io/managed-by"), List.of("labels", "app.kubernetes.io/managed-by"),
Crd.NAME, Constants.VM_OP_NAME,
List.of("annotations", "vmoperator.jdrupes.org/version"), EXISTS, List.of("annotations", "vmoperator.jdrupes.org/version"), EXISTS,
List.of("ownerReferences", 0, "apiVersion"), List.of("ownerReferences", 0, "apiVersion"),
vmsContext.getGroup() + "/" + vmsContext.getVersions().get(0), vmsContext.getGroup() + "/" + vmsContext.getVersions().get(0),
List.of("ownerReferences", 0, "kind"), Crd.KIND_VM, List.of("ownerReferences", 0, "kind"), Constants.VM_OP_KIND_VM,
List.of("ownerReferences", 0, "name"), VM_NAME, List.of("ownerReferences", 0, "name"), VM_NAME,
List.of("ownerReferences", 0, "uid"), EXISTS); List.of("ownerReferences", 0, "uid"), EXISTS);
checkProps(config.getMetadata(), toCheck); checkProps(config.getMetadata(), toCheck);
@ -187,7 +189,7 @@ class BasicTests {
ListOptions listOpts = new ListOptions(); ListOptions listOpts = new ListOptions();
listOpts.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + "," listOpts.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + ","
+ "app.kubernetes.io/instance=" + VM_NAME + "," + "app.kubernetes.io/instance=" + VM_NAME + ","
+ "app.kubernetes.io/component=" + DisplaySecret.NAME); + "app.kubernetes.io/component=" + COMP_DISPLAY_SECRET);
Collection<K8sV1SecretStub> secrets = null; Collection<K8sV1SecretStub> secrets = null;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
secrets = K8sV1SecretStub.list(client, "vmop-dev", listOpts); secrets = K8sV1SecretStub.list(client, "vmop-dev", listOpts);
@ -218,7 +220,7 @@ class BasicTests {
List.of("labels", "app.kubernetes.io/name"), Constants.APP_NAME, List.of("labels", "app.kubernetes.io/name"), Constants.APP_NAME,
List.of("labels", "app.kubernetes.io/instance"), VM_NAME, List.of("labels", "app.kubernetes.io/instance"), VM_NAME,
List.of("labels", "app.kubernetes.io/managed-by"), List.of("labels", "app.kubernetes.io/managed-by"),
Crd.NAME)); Constants.VM_OP_NAME));
checkProps(pvc.getSpec(), Map.of( checkProps(pvc.getSpec(), Map.of(
List.of("resources", "requests", "storage"), List.of("resources", "requests", "storage"),
Quantity.fromString("1Mi"))); Quantity.fromString("1Mi")));
@ -239,7 +241,7 @@ class BasicTests {
List.of("labels", "app.kubernetes.io/name"), Constants.APP_NAME, List.of("labels", "app.kubernetes.io/name"), Constants.APP_NAME,
List.of("labels", "app.kubernetes.io/instance"), VM_NAME, List.of("labels", "app.kubernetes.io/instance"), VM_NAME,
List.of("labels", "app.kubernetes.io/managed-by"), List.of("labels", "app.kubernetes.io/managed-by"),
Crd.NAME, Constants.VM_OP_NAME,
List.of("annotations", "use_as"), "system-disk")); List.of("annotations", "use_as"), "system-disk"));
checkProps(pvc.getSpec(), Map.of( checkProps(pvc.getSpec(), Map.of(
List.of("resources", "requests", "storage"), List.of("resources", "requests", "storage"),
@ -261,7 +263,7 @@ class BasicTests {
List.of("labels", "app.kubernetes.io/name"), Constants.APP_NAME, List.of("labels", "app.kubernetes.io/name"), Constants.APP_NAME,
List.of("labels", "app.kubernetes.io/instance"), VM_NAME, List.of("labels", "app.kubernetes.io/instance"), VM_NAME,
List.of("labels", "app.kubernetes.io/managed-by"), List.of("labels", "app.kubernetes.io/managed-by"),
Crd.NAME)); Constants.VM_OP_NAME));
checkProps(pvc.getSpec(), Map.of( checkProps(pvc.getSpec(), Map.of(
List.of("resources", "requests", "storage"), List.of("resources", "requests", "storage"),
Quantity.fromString("1Gi"))); Quantity.fromString("1Gi")));
@ -289,12 +291,12 @@ class BasicTests {
List.of("labels", "app.kubernetes.io/instance"), VM_NAME, List.of("labels", "app.kubernetes.io/instance"), VM_NAME,
List.of("labels", "app.kubernetes.io/component"), APP_NAME, List.of("labels", "app.kubernetes.io/component"), APP_NAME,
List.of("labels", "app.kubernetes.io/managed-by"), List.of("labels", "app.kubernetes.io/managed-by"),
Crd.NAME, Constants.VM_OP_NAME,
List.of("annotations", "vmrunner.jdrupes.org/cmVersion"), EXISTS, List.of("annotations", "vmrunner.jdrupes.org/cmVersion"), EXISTS,
List.of("annotations", "vmoperator.jdrupes.org/version"), EXISTS, List.of("annotations", "vmoperator.jdrupes.org/version"), EXISTS,
List.of("ownerReferences", 0, "apiVersion"), List.of("ownerReferences", 0, "apiVersion"),
vmsContext.getGroup() + "/" + vmsContext.getVersions().get(0), vmsContext.getGroup() + "/" + vmsContext.getVersions().get(0),
List.of("ownerReferences", 0, "kind"), Crd.KIND_VM, List.of("ownerReferences", 0, "kind"), Constants.VM_OP_KIND_VM,
List.of("ownerReferences", 0, "name"), VM_NAME, List.of("ownerReferences", 0, "name"), VM_NAME,
List.of("ownerReferences", 0, "uid"), EXISTS)); List.of("ownerReferences", 0, "uid"), EXISTS));
checkProps(pod.getSpec(), Map.of( checkProps(pod.getSpec(), Map.of(
@ -317,7 +319,7 @@ class BasicTests {
checkProps(svc.getMetadata(), Map.of( checkProps(svc.getMetadata(), Map.of(
List.of("labels", "app.kubernetes.io/name"), APP_NAME, List.of("labels", "app.kubernetes.io/name"), APP_NAME,
List.of("labels", "app.kubernetes.io/instance"), VM_NAME, List.of("labels", "app.kubernetes.io/instance"), VM_NAME,
List.of("labels", "app.kubernetes.io/managed-by"), Crd.NAME, List.of("labels", "app.kubernetes.io/managed-by"), VM_OP_NAME,
List.of("labels", "label1"), "label1", List.of("labels", "label1"), "label1",
List.of("labels", "label2"), "replaced", List.of("labels", "label2"), "replaced",
List.of("labels", "label3"), "added", List.of("labels", "label3"), "added",

View file

@ -19,8 +19,8 @@
handlers=java.util.logging.ConsoleHandler handlers=java.util.logging.ConsoleHandler
#org.jgrapes.level=FINE org.jgrapes.level=FINE
#org.jgrapes.core.handlerTracking.level=FINER org.jgrapes.core.handlerTracking.level=FINER
org.jdrupes.vmoperator.runner.qemu.level=FINE org.jdrupes.vmoperator.runner.qemu.level=FINE

View file

@ -25,7 +25,8 @@ import io.kubernetes.client.openapi.models.EventsV1Event;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import static org.jdrupes.vmoperator.common.Constants.APP_NAME; import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
import org.jdrupes.vmoperator.common.Constants.Crd; import static org.jdrupes.vmoperator.common.Constants.VM_OP_GROUP;
import static org.jdrupes.vmoperator.common.Constants.VM_OP_KIND_VM;
import org.jdrupes.vmoperator.common.K8s; import org.jdrupes.vmoperator.common.K8s;
import org.jdrupes.vmoperator.common.K8sClient; import org.jdrupes.vmoperator.common.K8sClient;
import org.jdrupes.vmoperator.common.VmDefinitionStub; import org.jdrupes.vmoperator.common.VmDefinitionStub;
@ -73,7 +74,7 @@ public class ConsoleTracker extends VmDefUpdater {
} }
try { try {
vmStub = VmDefinitionStub.get(apiClient, vmStub = VmDefinitionStub.get(apiClient,
new GroupVersionKind(Crd.GROUP, "", Crd.KIND_VM), new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM),
namespace, vmName); namespace, vmName);
} catch (ApiException e) { } catch (ApiException e) {
logger.log(Level.SEVERE, e, logger.log(Level.SEVERE, e,
@ -114,7 +115,7 @@ public class ConsoleTracker extends VmDefUpdater {
// Log event // Log event
var evt = new EventsV1Event() var evt = new EventsV1Event()
.reportingController(Crd.GROUP + "/" + APP_NAME) .reportingController(VM_OP_GROUP + "/" + APP_NAME)
.action("ConsoleConnectionUpdate") .action("ConsoleConnectionUpdate")
.reason("Connection from " + event.clientHost()); .reason("Connection from " + event.clientHost());
K8s.createEvent(apiClient, vmStub.model().get(), evt); K8s.createEvent(apiClient, vmStub.model().get(), evt);
@ -149,7 +150,7 @@ public class ConsoleTracker extends VmDefUpdater {
// Log event // Log event
var evt = new EventsV1Event() var evt = new EventsV1Event()
.reportingController(Crd.GROUP + "/" + APP_NAME) .reportingController(VM_OP_GROUP + "/" + APP_NAME)
.action("ConsoleConnectionUpdate") .action("ConsoleConnectionUpdate")
.reason("Disconnected from " + event.clientHost()); .reason("Disconnected from " + event.clientHost());
K8s.createEvent(apiClient, vmStub.model().get(), evt); K8s.createEvent(apiClient, vmStub.model().get(), evt);

View file

@ -24,7 +24,8 @@ import java.nio.file.Path;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.logging.Level; import java.util.logging.Level;
import org.jdrupes.vmoperator.common.Constants.DisplaySecret; import static org.jdrupes.vmoperator.common.Constants.DATA_DISPLAY_PASSWORD;
import static org.jdrupes.vmoperator.common.Constants.DATA_PASSWORD_EXPIRY;
import org.jdrupes.vmoperator.runner.qemu.commands.QmpSetDisplayPassword; import org.jdrupes.vmoperator.runner.qemu.commands.QmpSetDisplayPassword;
import org.jdrupes.vmoperator.runner.qemu.commands.QmpSetPasswordExpiry; import org.jdrupes.vmoperator.runner.qemu.commands.QmpSetPasswordExpiry;
import org.jdrupes.vmoperator.runner.qemu.events.ConfigureQemu; import org.jdrupes.vmoperator.runner.qemu.events.ConfigureQemu;
@ -63,7 +64,7 @@ public class DisplayController extends Component {
public DisplayController(Channel componentChannel, Path configDir) { public DisplayController(Channel componentChannel, Path configDir) {
super(componentChannel); super(componentChannel);
this.configDir = configDir; this.configDir = configDir;
fire(new WatchFile(configDir.resolve(DisplaySecret.DISPLAY_PASSWORD))); fire(new WatchFile(configDir.resolve(DATA_DISPLAY_PASSWORD)));
} }
/** /**
@ -114,8 +115,7 @@ public class DisplayController extends Component {
@Handler @Handler
@SuppressWarnings("PMD.EmptyCatchBlock") @SuppressWarnings("PMD.EmptyCatchBlock")
public void onFileChanged(FileChanged event) { public void onFileChanged(FileChanged event) {
if (event.path() if (event.path().equals(configDir.resolve(DATA_DISPLAY_PASSWORD))) {
.equals(configDir.resolve(DisplaySecret.DISPLAY_PASSWORD))) {
configurePassword(); configurePassword();
} }
} }
@ -130,7 +130,7 @@ public class DisplayController extends Component {
} }
private boolean setDisplayPassword() { private boolean setDisplayPassword() {
return readFromFile(DisplaySecret.DISPLAY_PASSWORD).map(password -> { return readFromFile(DATA_DISPLAY_PASSWORD).map(password -> {
if (Objects.equals(this.currentPassword, password)) { if (Objects.equals(this.currentPassword, password)) {
return true; return true;
} }
@ -143,7 +143,7 @@ public class DisplayController extends Component {
} }
private void setPasswordExpiry() { private void setPasswordExpiry() {
readFromFile(DisplaySecret.PASSWORD_EXPIRY).ifPresent(expiry -> { readFromFile(DATA_PASSWORD_EXPIRY).ifPresent(expiry -> {
logger.fine(() -> "Updating expiry time to " + expiry); logger.fine(() -> "Updating expiry time to " + expiry);
fire( fire(
new MonitorCommand(new QmpSetPasswordExpiry(protocol, expiry))); new MonitorCommand(new QmpSetPasswordExpiry(protocol, expiry)));

View file

@ -56,7 +56,7 @@ import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option; import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
import static org.jdrupes.vmoperator.common.Constants.APP_NAME; import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
import org.jdrupes.vmoperator.common.Constants.DisplaySecret; import static org.jdrupes.vmoperator.common.Constants.DATA_DISPLAY_PASSWORD;
import org.jdrupes.vmoperator.runner.qemu.commands.QmpCont; import org.jdrupes.vmoperator.runner.qemu.commands.QmpCont;
import org.jdrupes.vmoperator.runner.qemu.commands.QmpReset; import org.jdrupes.vmoperator.runner.qemu.commands.QmpReset;
import org.jdrupes.vmoperator.runner.qemu.events.ConfigureQemu; import org.jdrupes.vmoperator.runner.qemu.events.ConfigureQemu;
@ -312,7 +312,7 @@ public class Runner extends Component {
// Add some values from other sources to configuration // Add some values from other sources to configuration
newConf.asOf = Instant.ofEpochSecond(configFile.lastModified()); newConf.asOf = Instant.ofEpochSecond(configFile.lastModified());
Path dsPath = configDir.resolve(DisplaySecret.DISPLAY_PASSWORD); Path dsPath = configDir.resolve(DATA_DISPLAY_PASSWORD);
newConf.hasDisplayPassword = dsPath.toFile().canRead(); newConf.hasDisplayPassword = dsPath.toFile().canRead();
// Special actions for initial configuration (startup) // Special actions for initial configuration (startup)

View file

@ -33,8 +33,8 @@ import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.logging.Level; import java.util.logging.Level;
import static org.jdrupes.vmoperator.common.Constants.APP_NAME; import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
import org.jdrupes.vmoperator.common.Constants.Crd; import static org.jdrupes.vmoperator.common.Constants.VM_OP_GROUP;
import org.jdrupes.vmoperator.common.Constants.Status; import static org.jdrupes.vmoperator.common.Constants.VM_OP_KIND_VM;
import org.jdrupes.vmoperator.common.K8s; import org.jdrupes.vmoperator.common.K8s;
import org.jdrupes.vmoperator.common.VmDefinition; import org.jdrupes.vmoperator.common.VmDefinition;
import org.jdrupes.vmoperator.common.VmDefinitionStub; import org.jdrupes.vmoperator.common.VmDefinitionStub;
@ -112,17 +112,11 @@ public class StatusUpdater extends VmDefUpdater {
} }
try { try {
vmStub = VmDefinitionStub.get(apiClient, vmStub = VmDefinitionStub.get(apiClient,
new GroupVersionKind(Crd.GROUP, "", Crd.KIND_VM), new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM),
namespace, vmName); namespace, vmName);
var vmDef = vmStub.updateStatus(from -> { vmStub.model().ifPresent(model -> {
JsonObject status = from.statusJson(); observedGeneration = model.getMetadata().getGeneration();
status.remove(Status.LOGGED_IN_USER); });
return status;
}).orElse(null);
if (vmDef == null) {
return;
}
observedGeneration = vmDef.getMetadata().getGeneration();
} catch (ApiException e) { } catch (ApiException e) {
logger.log(Level.SEVERE, e, logger.log(Level.SEVERE, e,
() -> "Cannot access VM object, terminating."); () -> "Cannot access VM object, terminating.");
@ -160,7 +154,7 @@ public class StatusUpdater extends VmDefUpdater {
"displayPasswordSerial").getAsInt() == -1)) { "displayPasswordSerial").getAsInt() == -1)) {
return; return;
} }
vmStub.updateStatus(from -> { vmStub.updateStatus(vmDef.get(), from -> {
JsonObject status = from.statusJson(); JsonObject status = from.statusJson();
if (!event.configuration().hasDisplayPassword) { if (!event.configuration().hasDisplayPassword) {
status.addProperty("displayPasswordSerial", -1); status.addProperty("displayPasswordSerial", -1);
@ -189,7 +183,7 @@ public class StatusUpdater extends VmDefUpdater {
if (vmStub == null || (vmDef = vmStub.model().orElse(null)) == null) { if (vmStub == null || (vmDef = vmStub.model().orElse(null)) == null) {
return; return;
} }
vmStub.updateStatus(from -> { vmStub.updateStatus(vmDef, from -> {
JsonObject status = from.statusJson(); JsonObject status = from.statusJson();
boolean running = event.runState().vmRunning(); boolean running = event.runState().vmRunning();
updateCondition(vmDef, vmDef.statusJson(), "Running", running, updateCondition(vmDef, vmDef.statusJson(), "Running", running,
@ -204,7 +198,6 @@ public class StatusUpdater extends VmDefUpdater {
} else if (event.runState() == RunState.STOPPED) { } else if (event.runState() == RunState.STOPPED) {
status.addProperty("ram", "0"); status.addProperty("ram", "0");
status.addProperty("cpus", 0); status.addProperty("cpus", 0);
status.remove(Status.LOGGED_IN_USER);
} }
if (!running) { if (!running) {
@ -237,7 +230,7 @@ public class StatusUpdater extends VmDefUpdater {
// Log event // Log event
var evt = new EventsV1Event() var evt = new EventsV1Event()
.reportingController(Crd.GROUP + "/" + APP_NAME) .reportingController(VM_OP_GROUP + "/" + APP_NAME)
.action("StatusUpdate").reason(event.reason()) .action("StatusUpdate").reason(event.reason())
.note(event.message()); .note(event.message());
K8s.createEvent(apiClient, vmDef, evt); K8s.createEvent(apiClient, vmDef, evt);
@ -364,8 +357,7 @@ public class StatusUpdater extends VmDefUpdater {
throws ApiException { throws ApiException {
vmStub.updateStatus(from -> { vmStub.updateStatus(from -> {
JsonObject status = from.statusJson(); JsonObject status = from.statusJson();
status.addProperty(Status.LOGGED_IN_USER, status.addProperty("loggedInUser", event.triggering().user());
event.triggering().user());
return status; return status;
}); });
} }
@ -380,7 +372,7 @@ public class StatusUpdater extends VmDefUpdater {
throws ApiException { throws ApiException {
vmStub.updateStatus(from -> { vmStub.updateStatus(from -> {
JsonObject status = from.statusJson(); JsonObject status = from.statusJson();
status.remove(Status.LOGGED_IN_USER); status.remove("loggedInUser");
return status; return status;
}); });
} }