Provide more context information.
Some checks failed
Java CI with Gradle / build (push) Has been cancelled

This commit is contained in:
Michael Lipp 2023-11-05 15:08:51 +01:00
parent 203ea00c7b
commit 03dfa7a4d8
6 changed files with 79 additions and 12 deletions

View file

@ -1,6 +1,8 @@
# Used for running manager outside Kubernetes. # Used for running manager outside Kubernetes.
# Keep in sync with kustomize.yaml # Keep in sync with kustomize.yaml
"/Manager": "/Manager":
# If provided, is shown at top left before namespace
# clusterName: "test"
# The controller manages the VM # The controller manages the VM
"/Controller": "/Controller":
namespace: vmop-dev namespace: vmop-dev

View file

@ -29,6 +29,7 @@ patches:
# Keep in sync with config.yaml # Keep in sync with config.yaml
config.yaml: | config.yaml: |
"/Manager": "/Manager":
# clusterName: "test"
"/Controller": "/Controller":
namespace: vmop-dev namespace: vmop-dev
"/Reconciler": "/Reconciler":

View file

@ -1,2 +1,5 @@
<a class="navbar-brand" href="#"><img style="height: 1.25em; padding-right: 0.25em;" <a class="navbar-brand" href="#"><img style="height: 1.25em; padding-right: 0.25em;"
src="${renderSupport.consoleResource('VM-Operator.svg')}"><span>${_("consoleTitle")}<span></a> src="${renderSupport.consoleResource('VM-Operator.svg')}"
><span title="${ version }">${_("consoleTitle")}</span>&nbsp;
<span style="font-weight: normal;"
>(<#if clusterName()??>${clusterName() + "/"}</#if>${ namespace() })</span></a>

View file

@ -138,6 +138,8 @@ public class Controller extends Component {
.of("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); .of("/var/run/secrets/kubernetes.io/serviceaccount/namespace");
if (Files.isReadable(path)) { if (Files.isReadable(path)) {
namespace = Files.lines(path).findFirst().orElse(null); namespace = Files.lines(path).findFirst().orElse(null);
fire(new ConfigurationUpdate().add(componentPath(), "namespace",
namespace));
} }
} }
if (namespace == null) { if (namespace == null) {

View file

@ -18,6 +18,8 @@
package org.jdrupes.vmoperator.manager; package org.jdrupes.vmoperator.manager;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -27,6 +29,9 @@ import java.net.URISyntaxException;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogManager; import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -54,6 +59,7 @@ import org.jgrapes.net.SocketServer;
import org.jgrapes.util.ComponentCollector; import org.jgrapes.util.ComponentCollector;
import org.jgrapes.util.FileSystemWatcher; import org.jgrapes.util.FileSystemWatcher;
import org.jgrapes.util.YamlConfigurationStore; import org.jgrapes.util.YamlConfigurationStore;
import org.jgrapes.util.events.ConfigurationUpdate;
import org.jgrapes.util.events.WatchFile; import org.jgrapes.util.events.WatchFile;
import org.jgrapes.webconlet.locallogin.LoginConlet; import org.jgrapes.webconlet.locallogin.LoginConlet;
import org.jgrapes.webconsole.base.BrowserLocalBackedKVStore; import org.jgrapes.webconsole.base.BrowserLocalBackedKVStore;
@ -69,9 +75,13 @@ import org.jgrapes.webconsole.vuejs.VueJsConsoleWeblet;
/** /**
* The application class. * The application class.
*/ */
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.ExcessiveImports" })
public class Manager extends Component { public class Manager extends Component {
private static String version;
private static Manager app; private static Manager app;
private String clusterName;
private String namespace = "unknown";
/** /**
* Instantiates a new manager. * Instantiates a new manager.
@ -79,26 +89,26 @@ public class Manager extends Component {
* *
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
@SuppressWarnings("PMD.TooFewBranchesForASwitchStatement") @SuppressWarnings({ "PMD.TooFewBranchesForASwitchStatement",
"PMD.NcssCount" })
public Manager(CommandLine cmdLine) throws IOException { public Manager(CommandLine cmdLine) throws IOException {
super(new NamedChannel("manager"));
// Prepare component tree // Prepare component tree
attach(new NioDispatcher()); attach(new NioDispatcher());
Channel mgrChannel = new NamedChannel("manager"); attach(new FileSystemWatcher(channel()));
attach(new FileSystemWatcher(mgrChannel)); attach(new Controller(channel()));
attach(new Controller(mgrChannel));
// 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/" + VM_OP_NAME.replace("-", "") + "/config.yaml")) "/etc/opt/" + VM_OP_NAME.replace("-", "") + "/config.yaml"));
.getCanonicalFile();
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
if (!Files.isReadable(cfgFile.toPath())) { if (!Files.isReadable(cfgFile.toPath())) {
throw new IOException("Cannot read configuration file " + cfgFile); throw new IOException("Cannot read configuration file " + cfgFile);
} }
attach(new YamlConfigurationStore(mgrChannel, cfgFile, false)); attach(new YamlConfigurationStore(channel(), cfgFile, false));
fire(new WatchFile(cfgFile.toPath())); fire(new WatchFile(cfgFile.toPath()), channel());
// Prepare GUI // Prepare GUI
Channel httpTransport = new NamedChannel("guiTransport"); Channel httpTransport = new NamedChannel("guiTransport");
@ -126,7 +136,12 @@ public class Manager extends Component {
return; return;
} }
ConsoleWeblet consoleWeblet = guiHttpServer ConsoleWeblet consoleWeblet = guiHttpServer
.attach(new VueJsConsoleWeblet(httpChannel, Channel.SELF, rootUri)) .attach(new VueJsConsoleWeblet(httpChannel, Channel.SELF, rootUri) {
@Override
protected Map<String, Object> createConsoleBaseModel() {
return augmentBaseModel(super.createConsoleBaseModel());
}
})
.prependClassTemplateLoader(getClass()) .prependClassTemplateLoader(getClass())
.prependResourceBundleProvider(getClass()) .prependResourceBundleProvider(getClass())
.prependConsoleResourceProvider(getClass()); .prependConsoleResourceProvider(getClass());
@ -154,6 +169,47 @@ public class Manager extends Component {
})); }));
} }
private Map<String, Object> augmentBaseModel(Map<String, Object> base) {
base.put("version", version);
base.put("clusterName", new TemplateMethodModelEx() {
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments)
throws TemplateModelException {
return clusterName;
}
});
base.put("namespace", new TemplateMethodModelEx() {
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments)
throws TemplateModelException {
return namespace;
}
});
return base;
}
/**
* Configure the component.
*
* @param event the event
*/
@Handler
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
public void onConfigurationUpdate(ConfigurationUpdate event) {
event.structured(componentPath()).ifPresent(c -> {
if (c.containsKey("clusterName")) {
clusterName = (String) c.get("clusterName");
} else {
clusterName = null;
}
});
event.structured(componentPath() + "/Controller").ifPresent(c -> {
if (c.containsKey("namespace")) {
namespace = (String) c.get("namespace");
}
});
}
/** /**
* Log the exception when a handling error is reported. * Log the exception when a handling error is reported.
* *
@ -207,8 +263,10 @@ public class Manager extends Component {
try { try {
// Instance logger is not available yet. // Instance logger is not available yet.
var logger = Logger.getLogger(Manager.class.getName()); var logger = Logger.getLogger(Manager.class.getName());
logger.config(() -> "Version: " version = Optional.ofNullable(
+ Manager.class.getPackage().getImplementationVersion()); Manager.class.getPackage().getImplementationVersion())
.orElse("unknown");
logger.config(() -> "Version: " + version);
logger.config(() -> "running on " logger.config(() -> "running on "
+ System.getProperty("java.vm.name") + System.getProperty("java.vm.name")
+ " (" + System.getProperty("java.vm.version") + ")" + " (" + System.getProperty("java.vm.version") + ")"

View file

@ -140,6 +140,7 @@
* mgr .left. [FileSystemWatcher] * mgr .left. [FileSystemWatcher]
* mgr .right. [YamlConfigurationStore] * mgr .right. [YamlConfigurationStore]
* mgr .. [Controller] * mgr .. [Controller]
* mgr .up. [Manager]
* mgr .up. [VmWatcher] * mgr .up. [VmWatcher]
* mgr .. [Reconciler] * mgr .. [Reconciler]
* *