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,9 +3,10 @@
"/Manager":
"/Controller":
namespace: vmop-dev
runnerData:
storageClassName: null
loadBalancerService: |
labels:
test1: info
test2: toBeDeleted
"/Reconciler":
runnerData:
storageClassName: null
loadBalancerService: |
labels:
test1: info
test2: toBeDeleted

View file

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

View file

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

View file

@ -2,25 +2,27 @@
"/Manager":
"/Controller":
# Values used when creating the PVC for the runner's data
runnerData:
storageClassName: null
# Amount by which the current cpu count is devided when generating
# the resource properties.
cpuOvercommit: 2
# Amount by which the current ram size is devided when generating
# the resource properties.
ramOvercommit: 1.5
# If defined, causes a load balancer service to be created.
# May be a boolean or a string with nested yaml that
# defines additional labels or annotations to be merged
# into the service.
# loadBalancerService: |
# labels: {}
# annotations: {}
# Explicitly specify the namespace to be managed (only for development).
# namespace: vmop-dev
"/Reconciler":
# Amount by which the current cpu count is devided when generating
# the resource properties.
cpuOvercommit: 2
# Amount by which the current ram size is devided when generating
# the resource properties.
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.
# May be a boolean or a string with nested yaml that
# defines additional labels or annotations to be merged
# into the service.
# loadBalancerService: |
# labels: {}
# annotations: {}

View file

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

View file

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

View file

@ -77,7 +77,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
// Check if to be generated
@SuppressWarnings("unchecked")
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);
if (lbs instanceof Boolean isOn && !isOn) {
return;

View file

@ -45,7 +45,6 @@ import org.jdrupes.vmoperator.util.ExtendedObjectWrapper;
import org.jdrupes.vmoperator.util.ParseUtils;
import org.jgrapes.core.Channel;
import org.jgrapes.core.Component;
import org.jgrapes.core.Components;
import org.jgrapes.core.annotation.Handler;
import org.jgrapes.util.events.ConfigurationUpdate;
@ -58,8 +57,8 @@ public class Reconciler extends Component {
@SuppressWarnings("PMD.SingularField")
private final Configuration fmConfig;
private final CmReconciler cmReconciler;
private final StsReconciler stsReconciler;
private final ConfigMapReconciler cmReconciler;
private final StatefuleSetReconciler stsReconciler;
private final LoadBalancerReconciler lbReconciler;
@SuppressWarnings("PMD.UseConcurrentHashMap")
private final Map<String, Object> config = new HashMap<>();
@ -82,8 +81,8 @@ public class Reconciler extends Component {
fmConfig.setLogTemplateExceptions(false);
fmConfig.setClassForTemplateLoading(Reconciler.class, "");
cmReconciler = new CmReconciler(fmConfig);
stsReconciler = new StsReconciler(fmConfig);
cmReconciler = new ConfigMapReconciler(fmConfig);
stsReconciler = new StatefuleSetReconciler(fmConfig);
lbReconciler = new LoadBalancerReconciler(fmConfig);
}
@ -94,10 +93,9 @@ public class Reconciler extends Component {
*/
@Handler
public void onConfigurationUpdate(ConfigurationUpdate event) {
event.structured(Components.manager(parent()).componentPath())
.ifPresent(c -> {
config.putAll(c);
});
event.structured(componentPath()).ifPresent(c -> {
config.putAll(c);
});
}
/**
@ -153,7 +151,7 @@ public class Reconciler extends Component {
Configuration.VERSION_2_3_32)
.build().getStaticModels()
.get(Constants.class.getName()));
model.put("config", config);
model.put("reconciler", config);
// Methods
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).
*/
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
/* default */ class StsReconciler {
/* default */ class StatefuleSetReconciler {
protected final Logger logger = Logger.getLogger(getClass().getName());
private final Configuration fmConfig;
@ -47,7 +47,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
*
* @param fmConfig the fm config
*/
public StsReconciler(Configuration fmConfig) {
public StatefuleSetReconciler(Configuration fmConfig) {
this.fmConfig = fmConfig;
}