Change configuration format.

This commit is contained in:
Michael Lipp 2023-08-18 11:23:17 +02:00
parent 417fc736d7
commit 823bcedf1e
9 changed files with 55 additions and 52 deletions

View file

@ -3,6 +3,7 @@
"/Manager": "/Manager":
"/Controller": "/Controller":
namespace: vmop-dev namespace: vmop-dev
"/Reconciler":
runnerData: runnerData:
storageClassName: null storageClassName: null
loadBalancerService: | loadBalancerService: |

View file

@ -32,6 +32,7 @@ patches:
config.yaml: | config.yaml: |
"/Manager": "/Manager":
"/Controller": "/Controller":
runnerData: "/Reconciler"
runnerDataPvc:
# Default is to use the default storage class # Default is to use the default storage class
storageClassName: local-path storageClassName: local-path

View file

@ -26,5 +26,6 @@ patches:
config.yaml: | config.yaml: |
"/Manager": "/Manager":
"/Controller": "/Controller":
"/Reconciler":
runnerData: runnerData:
storageClassName: rook-cephfs storageClassName: rook-cephfs

View file

@ -2,10 +2,10 @@
"/Manager": "/Manager":
"/Controller": "/Controller":
# Values used when creating the PVC for the runner's data # Explicitly specify the namespace to be managed (only for development).
runnerData: # namespace: vmop-dev
storageClassName: null
"/Reconciler":
# Amount by which the current cpu count is devided when generating # Amount by which the current cpu count is devided when generating
# the resource properties. # the resource properties.
cpuOvercommit: 2 cpuOvercommit: 2
@ -14,6 +14,10 @@
# the resource properties. # the resource properties.
ramOvercommit: 1.5 ramOvercommit: 1.5
# Values used when creating the PVC for the runner's data
runnerDataPvc:
storageClassName: null
# If defined, causes a load balancer service to be created. # If defined, causes a load balancer service to be created.
# May be a boolean or a string with nested yaml that # May be a boolean or a string with nested yaml that
# defines additional labels or annotations to be merged # defines additional labels or annotations to be merged
@ -22,5 +26,3 @@
# labels: {} # labels: {}
# annotations: {} # annotations: {}
# Explicitly specify the namespace to be managed (only for development).
# namespace: vmop-dev

View file

@ -96,15 +96,15 @@ spec:
requests: requests:
<#if cr.spec.vm.currentCpus?? > <#if cr.spec.vm.currentCpus?? >
<#assign factor = 2.0 /> <#assign factor = 2.0 />
<#if config.cpuOvercommit??> <#if reconciler.cpuOvercommit??>
<#assign factor = config.cpuOvercommit * 1.0 /> <#assign factor = reconciler.cpuOvercommit * 1.0 />
</#if> </#if>
cpu: ${ (cr.spec.vm.currentCpus.asInt / factor)?floor?c } cpu: ${ (cr.spec.vm.currentCpus.asInt / factor)?floor?c }
</#if> </#if>
<#if cr.spec.vm.currentRam?? > <#if cr.spec.vm.currentRam?? >
<#assign factor = 1.25 /> <#assign factor = 1.25 />
<#if config.ramOvercommit??> <#if reconciler.ramOvercommit??>
<#assign factor = config.ramOvercommit * 1.0 /> <#assign factor = reconciler.ramOvercommit * 1.0 />
</#if> </#if>
memory: ${ (parseMemory(cr.spec.vm.currentRam.asString) / factor)?floor?c } memory: ${ (parseMemory(cr.spec.vm.currentRam.asString) / factor)?floor?c }
</#if> </#if>
@ -151,8 +151,8 @@ spec:
spec: spec:
accessModes: accessModes:
- ReadWriteOnce - ReadWriteOnce
<#if config.runnerData?? && config.runnerData.storageClassName??> <#if reconciler.runnerDataPvc?? && reconciler.runnerDataPvc.storageClassName??>
storageClassName: ${ config.runnerData.storageClassName } storageClassName: ${ reconciler.runnerDataPvc.storageClassName }
</#if> </#if>
resources: resources:
requests: requests:

View file

@ -40,7 +40,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
* Delegee for reconciling the config map * Delegee for reconciling the config map
*/ */
@SuppressWarnings("PMD.DataflowAnomalyAnalysis") @SuppressWarnings("PMD.DataflowAnomalyAnalysis")
/* default */ class CmReconciler { /* default */ class ConfigMapReconciler {
protected final Logger logger = Logger.getLogger(getClass().getName()); protected final Logger logger = Logger.getLogger(getClass().getName());
private final Configuration fmConfig; private final Configuration fmConfig;
@ -50,7 +50,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
* *
* @param fmConfig the fm config * @param fmConfig the fm config
*/ */
public CmReconciler(Configuration fmConfig) { public ConfigMapReconciler(Configuration fmConfig) {
this.fmConfig = fmConfig; this.fmConfig = fmConfig;
} }

View file

@ -77,7 +77,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
// Check if to be generated // Check if to be generated
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
var lbs = Optional.of(model) var lbs = Optional.of(model)
.map(m -> (Map<String, Object>) m.get("config")) .map(m -> (Map<String, Object>) m.get("reconciler"))
.map(c -> c.get(LOAD_BALANCER_SERVICE)).orElse(Boolean.FALSE); .map(c -> c.get(LOAD_BALANCER_SERVICE)).orElse(Boolean.FALSE);
if (lbs instanceof Boolean isOn && !isOn) { if (lbs instanceof Boolean isOn && !isOn) {
return; return;

View file

@ -45,7 +45,6 @@ import org.jdrupes.vmoperator.util.ExtendedObjectWrapper;
import org.jdrupes.vmoperator.util.ParseUtils; import org.jdrupes.vmoperator.util.ParseUtils;
import org.jgrapes.core.Channel; import org.jgrapes.core.Channel;
import org.jgrapes.core.Component; import org.jgrapes.core.Component;
import org.jgrapes.core.Components;
import org.jgrapes.core.annotation.Handler; import org.jgrapes.core.annotation.Handler;
import org.jgrapes.util.events.ConfigurationUpdate; import org.jgrapes.util.events.ConfigurationUpdate;
@ -58,8 +57,8 @@ public class Reconciler extends Component {
@SuppressWarnings("PMD.SingularField") @SuppressWarnings("PMD.SingularField")
private final Configuration fmConfig; private final Configuration fmConfig;
private final CmReconciler cmReconciler; private final ConfigMapReconciler cmReconciler;
private final StsReconciler stsReconciler; private final StatefuleSetReconciler stsReconciler;
private final LoadBalancerReconciler lbReconciler; private final LoadBalancerReconciler lbReconciler;
@SuppressWarnings("PMD.UseConcurrentHashMap") @SuppressWarnings("PMD.UseConcurrentHashMap")
private final Map<String, Object> config = new HashMap<>(); private final Map<String, Object> config = new HashMap<>();
@ -82,8 +81,8 @@ public class Reconciler extends Component {
fmConfig.setLogTemplateExceptions(false); fmConfig.setLogTemplateExceptions(false);
fmConfig.setClassForTemplateLoading(Reconciler.class, ""); fmConfig.setClassForTemplateLoading(Reconciler.class, "");
cmReconciler = new CmReconciler(fmConfig); cmReconciler = new ConfigMapReconciler(fmConfig);
stsReconciler = new StsReconciler(fmConfig); stsReconciler = new StatefuleSetReconciler(fmConfig);
lbReconciler = new LoadBalancerReconciler(fmConfig); lbReconciler = new LoadBalancerReconciler(fmConfig);
} }
@ -94,8 +93,7 @@ public class Reconciler extends Component {
*/ */
@Handler @Handler
public void onConfigurationUpdate(ConfigurationUpdate event) { public void onConfigurationUpdate(ConfigurationUpdate event) {
event.structured(Components.manager(parent()).componentPath()) event.structured(componentPath()).ifPresent(c -> {
.ifPresent(c -> {
config.putAll(c); config.putAll(c);
}); });
} }
@ -153,7 +151,7 @@ public class Reconciler extends Component {
Configuration.VERSION_2_3_32) Configuration.VERSION_2_3_32)
.build().getStaticModels() .build().getStaticModels()
.get(Constants.class.getName())); .get(Constants.class.getName()));
model.put("config", config); model.put("reconciler", config);
// Methods // Methods
model.put("parseMemory", new TemplateMethodModelEx() { model.put("parseMemory", new TemplateMethodModelEx() {

View file

@ -37,7 +37,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
* Delegee for reconciling the stateful set (effectively the pod). * Delegee for reconciling the stateful set (effectively the pod).
*/ */
@SuppressWarnings("PMD.DataflowAnomalyAnalysis") @SuppressWarnings("PMD.DataflowAnomalyAnalysis")
/* default */ class StsReconciler { /* default */ class StatefuleSetReconciler {
protected final Logger logger = Logger.getLogger(getClass().getName()); protected final Logger logger = Logger.getLogger(getClass().getName());
private final Configuration fmConfig; private final Configuration fmConfig;
@ -47,7 +47,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
* *
* @param fmConfig the fm config * @param fmConfig the fm config
*/ */
public StsReconciler(Configuration fmConfig) { public StatefuleSetReconciler(Configuration fmConfig) {
this.fmConfig = fmConfig; this.fmConfig = fmConfig;
} }