Move automatic login request to CRD.
Undoes reorganize constants.
This commit is contained in:
parent
5366e24092
commit
5e282c4d2b
17 changed files with 103 additions and 126 deletions
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
handlers=java.util.logging.ConsoleHandler
|
||||
|
||||
#org.jgrapes.level=FINE
|
||||
#org.jgrapes.core.handlerTracking.level=FINER
|
||||
org.jgrapes.level=FINE
|
||||
org.jgrapes.core.handlerTracking.level=FINER
|
||||
|
||||
org.jdrupes.vmoperator.runner.qemu.level=FINE
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ import io.kubernetes.client.openapi.models.EventsV1Event;
|
|||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
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.K8sClient;
|
||||
import org.jdrupes.vmoperator.common.VmDefinitionStub;
|
||||
|
|
@ -73,7 +74,7 @@ public class ConsoleTracker extends VmDefUpdater {
|
|||
}
|
||||
try {
|
||||
vmStub = VmDefinitionStub.get(apiClient,
|
||||
new GroupVersionKind(Crd.GROUP, "", Crd.KIND_VM),
|
||||
new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM),
|
||||
namespace, vmName);
|
||||
} catch (ApiException e) {
|
||||
logger.log(Level.SEVERE, e,
|
||||
|
|
@ -114,7 +115,7 @@ public class ConsoleTracker extends VmDefUpdater {
|
|||
|
||||
// Log event
|
||||
var evt = new EventsV1Event()
|
||||
.reportingController(Crd.GROUP + "/" + APP_NAME)
|
||||
.reportingController(VM_OP_GROUP + "/" + APP_NAME)
|
||||
.action("ConsoleConnectionUpdate")
|
||||
.reason("Connection from " + event.clientHost());
|
||||
K8s.createEvent(apiClient, vmStub.model().get(), evt);
|
||||
|
|
@ -149,7 +150,7 @@ public class ConsoleTracker extends VmDefUpdater {
|
|||
|
||||
// Log event
|
||||
var evt = new EventsV1Event()
|
||||
.reportingController(Crd.GROUP + "/" + APP_NAME)
|
||||
.reportingController(VM_OP_GROUP + "/" + APP_NAME)
|
||||
.action("ConsoleConnectionUpdate")
|
||||
.reason("Disconnected from " + event.clientHost());
|
||||
K8s.createEvent(apiClient, vmStub.model().get(), evt);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ import java.nio.file.Path;
|
|||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
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.QmpSetPasswordExpiry;
|
||||
import org.jdrupes.vmoperator.runner.qemu.events.ConfigureQemu;
|
||||
|
|
@ -63,7 +64,7 @@ public class DisplayController extends Component {
|
|||
public DisplayController(Channel componentChannel, Path configDir) {
|
||||
super(componentChannel);
|
||||
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
|
||||
@SuppressWarnings("PMD.EmptyCatchBlock")
|
||||
public void onFileChanged(FileChanged event) {
|
||||
if (event.path()
|
||||
.equals(configDir.resolve(DisplaySecret.DISPLAY_PASSWORD))) {
|
||||
if (event.path().equals(configDir.resolve(DATA_DISPLAY_PASSWORD))) {
|
||||
configurePassword();
|
||||
}
|
||||
}
|
||||
|
|
@ -130,7 +130,7 @@ public class DisplayController extends Component {
|
|||
}
|
||||
|
||||
private boolean setDisplayPassword() {
|
||||
return readFromFile(DisplaySecret.DISPLAY_PASSWORD).map(password -> {
|
||||
return readFromFile(DATA_DISPLAY_PASSWORD).map(password -> {
|
||||
if (Objects.equals(this.currentPassword, password)) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -143,7 +143,7 @@ public class DisplayController extends Component {
|
|||
}
|
||||
|
||||
private void setPasswordExpiry() {
|
||||
readFromFile(DisplaySecret.PASSWORD_EXPIRY).ifPresent(expiry -> {
|
||||
readFromFile(DATA_PASSWORD_EXPIRY).ifPresent(expiry -> {
|
||||
logger.fine(() -> "Updating expiry time to " + expiry);
|
||||
fire(
|
||||
new MonitorCommand(new QmpSetPasswordExpiry(protocol, expiry)));
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ import org.apache.commons.cli.DefaultParser;
|
|||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.Options;
|
||||
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.QmpReset;
|
||||
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
|
||||
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();
|
||||
|
||||
// Special actions for initial configuration (startup)
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ import java.io.IOException;
|
|||
import java.math.BigDecimal;
|
||||
import java.util.logging.Level;
|
||||
import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
|
||||
import org.jdrupes.vmoperator.common.Constants.Crd;
|
||||
import org.jdrupes.vmoperator.common.Constants.Status;
|
||||
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.VmDefinition;
|
||||
import org.jdrupes.vmoperator.common.VmDefinitionStub;
|
||||
|
|
@ -112,17 +112,11 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
}
|
||||
try {
|
||||
vmStub = VmDefinitionStub.get(apiClient,
|
||||
new GroupVersionKind(Crd.GROUP, "", Crd.KIND_VM),
|
||||
new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM),
|
||||
namespace, vmName);
|
||||
var vmDef = vmStub.updateStatus(from -> {
|
||||
JsonObject status = from.statusJson();
|
||||
status.remove(Status.LOGGED_IN_USER);
|
||||
return status;
|
||||
}).orElse(null);
|
||||
if (vmDef == null) {
|
||||
return;
|
||||
}
|
||||
observedGeneration = vmDef.getMetadata().getGeneration();
|
||||
vmStub.model().ifPresent(model -> {
|
||||
observedGeneration = model.getMetadata().getGeneration();
|
||||
});
|
||||
} catch (ApiException e) {
|
||||
logger.log(Level.SEVERE, e,
|
||||
() -> "Cannot access VM object, terminating.");
|
||||
|
|
@ -160,7 +154,7 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
"displayPasswordSerial").getAsInt() == -1)) {
|
||||
return;
|
||||
}
|
||||
vmStub.updateStatus(from -> {
|
||||
vmStub.updateStatus(vmDef.get(), from -> {
|
||||
JsonObject status = from.statusJson();
|
||||
if (!event.configuration().hasDisplayPassword) {
|
||||
status.addProperty("displayPasswordSerial", -1);
|
||||
|
|
@ -189,7 +183,7 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
if (vmStub == null || (vmDef = vmStub.model().orElse(null)) == null) {
|
||||
return;
|
||||
}
|
||||
vmStub.updateStatus(from -> {
|
||||
vmStub.updateStatus(vmDef, from -> {
|
||||
JsonObject status = from.statusJson();
|
||||
boolean running = event.runState().vmRunning();
|
||||
updateCondition(vmDef, vmDef.statusJson(), "Running", running,
|
||||
|
|
@ -204,7 +198,6 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
} else if (event.runState() == RunState.STOPPED) {
|
||||
status.addProperty("ram", "0");
|
||||
status.addProperty("cpus", 0);
|
||||
status.remove(Status.LOGGED_IN_USER);
|
||||
}
|
||||
|
||||
if (!running) {
|
||||
|
|
@ -237,7 +230,7 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
|
||||
// Log event
|
||||
var evt = new EventsV1Event()
|
||||
.reportingController(Crd.GROUP + "/" + APP_NAME)
|
||||
.reportingController(VM_OP_GROUP + "/" + APP_NAME)
|
||||
.action("StatusUpdate").reason(event.reason())
|
||||
.note(event.message());
|
||||
K8s.createEvent(apiClient, vmDef, evt);
|
||||
|
|
@ -364,8 +357,7 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
throws ApiException {
|
||||
vmStub.updateStatus(from -> {
|
||||
JsonObject status = from.statusJson();
|
||||
status.addProperty(Status.LOGGED_IN_USER,
|
||||
event.triggering().user());
|
||||
status.addProperty("loggedInUser", event.triggering().user());
|
||||
return status;
|
||||
});
|
||||
}
|
||||
|
|
@ -380,7 +372,7 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
throws ApiException {
|
||||
vmStub.updateStatus(from -> {
|
||||
JsonObject status = from.statusJson();
|
||||
status.remove(Status.LOGGED_IN_USER);
|
||||
status.remove("loggedInUser");
|
||||
return status;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue