From 0419136a59c32a4ef1416630e417965d5acd66ac Mon Sep 17 00:00:00 2001 From: "Michael N. Lipp" Date: Fri, 1 Sep 2023 22:25:38 +0200 Subject: [PATCH] Use embedded YAML for load balancer configuration. --- .../vmoperator/manager/LoadBalancerReconciler.java | 11 +++++------ .../org/jdrupes/vmoperator/manager/Reconciler.java | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/LoadBalancerReconciler.java b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/LoadBalancerReconciler.java index 8cf8f63..a9c0d2b 100644 --- a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/LoadBalancerReconciler.java +++ b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/LoadBalancerReconciler.java @@ -75,16 +75,16 @@ import org.yaml.snakeyaml.constructor.SafeConstructor; Map model, VmChannel channel) throws IOException, TemplateException, ApiException { // Check if to be generated - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "PMD.AvoidDuplicateLiterals" }) var lbs = Optional.of(model) .map(m -> (Map) m.get("reconciler")) .map(c -> c.get(LOAD_BALANCER_SERVICE)).orElse(Boolean.FALSE); if (lbs instanceof Boolean isOn && !isOn) { return; } - if (!(lbs instanceof String)) { + if (!(lbs instanceof Map)) { logger.warning(() -> "\"" + LOAD_BALANCER_SERVICE - + "\" in configuration must be boolean or string but is " + + "\" in configuration must be boolean or mapping but is " + lbs.getClass() + "."); return; } @@ -110,9 +110,8 @@ import org.yaml.snakeyaml.constructor.SafeConstructor; Object lbsConfig, VmChannel channel) { // Get metadata from config Map asmData = Collections.emptyMap(); - if (lbsConfig instanceof String config) { - asmData = (Map) new Yaml( - new SafeConstructor(new LoaderOptions())).load(config); + if (lbsConfig instanceof Map config) { + asmData = (Map) config; } var json = channel.client().getJSON(); JsonObject cfgMeta diff --git a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/Reconciler.java b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/Reconciler.java index 7815864..9777af1 100644 --- a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/Reconciler.java +++ b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/Reconciler.java @@ -106,12 +106,12 @@ import org.jgrapes.util.events.ConfigurationUpdate; * properties for the VM (defaults to 1.25). * * * `loadBalancerService`: If defined, causes a load balancer service - * to be created. This property may be a boolean or a string with nested + * to be created. This property may be a boolean or * YAML that defines additional labels or annotations to be merged * into the service defintion. Here's an example for using * [MetalLb](https://metallb.universe.tf/) as "internal load balancer": * ```yaml - * loadBalancerService: | + * loadBalancerService: * annotations: * metallb.universe.tf/loadBalancerIPs: 192.168.168.1 * metallb.universe.tf/ip-allocated-from-pool: single-common