Add some logging messages and enhance logging configurability.

This commit is contained in:
Michael Lipp 2024-11-12 19:29:46 +00:00
parent b8aa925a49
commit 12d6745d75
6 changed files with 67 additions and 5 deletions

View file

@ -18,6 +18,7 @@
package org.jdrupes.vmoperator.manager;
import com.google.gson.JsonObject;
import freemarker.template.Configuration;
import freemarker.template.TemplateException;
import io.kubernetes.client.custom.V1Patch;
@ -36,6 +37,8 @@ import org.jdrupes.vmoperator.common.K8s;
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.util.DataPath;
import org.jdrupes.vmoperator.util.GsonPtr;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
@ -71,10 +74,6 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
public Map<String, Object> reconcile(Map<String, Object> model,
VmChannel channel)
throws IOException, TemplateException, ApiException {
// Get API
DynamicKubernetesApi cmApi = new DynamicKubernetesApi("", "v1",
"configmaps", channel.client());
// Combine template and data and parse result
var fmTemplate = fmConfig.getTemplate("runnerConfig.ftl.yaml");
StringWriter out = new StringWriter();
@ -84,8 +83,26 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
var mapDef = Dynamics.newFromYaml(
new Yaml(new SafeConstructor(new LoaderOptions())), out.toString());
// Maybe override logging.properties from reconciler configuration.
DataPath.<String> get(model, "reconciler", "loggingProperties")
.ifPresent(props -> {
GsonPtr.to(mapDef.getRaw()).get(JsonObject.class, "data")
.get().addProperty("logging.properties", props);
});
// Maybe override logging.properties from VM definition.
DataPath.<String> get(model, "cr", "spec", "loggingProperties")
.ifPresent(props -> {
GsonPtr.to(mapDef.getRaw()).get(JsonObject.class, "data")
.get().addProperty("logging.properties", props);
});
// Get API
DynamicKubernetesApi cmApi = new DynamicKubernetesApi("", "v1",
"configmaps", channel.client());
// Apply and maybe force pod update
var newState = K8s.apply(cmApi, mapDef, out.toString());
var newState = K8s.apply(cmApi, mapDef, mapDef.getRaw().toString());
maybeForceUpdate(channel.client(), newState);
@SuppressWarnings("unchecked")
var res = (Map<String, Object>) channel.client().getJSON().getGson()

View file

@ -132,6 +132,11 @@ import org.jgrapes.util.events.ConfigurationUpdate;
* ```
* This makes all VM consoles available at IP address 192.168.168.1
* with the port numbers from the VM definitions.
*
* * `loggingProperties`: If defined, specifies the default logging
* properties to be used by the runners managed by the controller.
* This property is a string that holds the content of
* a logging.properties file.
*/
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis",
"PMD.AvoidDuplicateLiterals" })