Avoid unnecessary processing.
This commit is contained in:
parent
9baf9b7673
commit
dbc89e6e09
2 changed files with 22 additions and 19 deletions
|
|
@ -76,13 +76,24 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||||
*
|
*
|
||||||
* @param model the model
|
* @param model the model
|
||||||
* @param channel the channel
|
* @param channel the channel
|
||||||
|
* @param modelChanged the model has changed
|
||||||
* @throws IOException Signals that an I/O exception has occurred.
|
* @throws IOException Signals that an I/O exception has occurred.
|
||||||
* @throws TemplateException the template exception
|
* @throws TemplateException the template exception
|
||||||
* @throws ApiException the api exception
|
* @throws ApiException the API exception
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
||||||
public void reconcile(Map<String, Object> model, VmChannel channel)
|
public void reconcile(Map<String, Object> model, VmChannel channel,
|
||||||
|
boolean modelChanged)
|
||||||
throws IOException, TemplateException, ApiException {
|
throws IOException, TemplateException, ApiException {
|
||||||
|
// Check if an update is needed
|
||||||
|
Object prevInputs
|
||||||
|
= channel.associated(PrevData.class, Object.class).orElse(null);
|
||||||
|
Object newInputs = model.get("loginRequestedFor");
|
||||||
|
if (!modelChanged && Objects.equals(prevInputs, newInputs)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
channel.setAssociated(PrevData.class, newInputs);
|
||||||
|
|
||||||
// Combine template and data and parse result
|
// Combine template and data and parse result
|
||||||
model.put("adjustCloudInitMeta", adjustCloudInitMetaModel);
|
model.put("adjustCloudInitMeta", adjustCloudInitMetaModel);
|
||||||
var fmTemplate = fmConfig.getTemplate("runnerConfig.ftl.yaml");
|
var fmTemplate = fmConfig.getTemplate("runnerConfig.ftl.yaml");
|
||||||
|
|
@ -107,19 +118,6 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||||
.get().addProperty("logging.properties", props);
|
.get().addProperty("logging.properties", props);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Look for changes
|
|
||||||
var oldCm = channel
|
|
||||||
.associated(getClass(), DynamicKubernetesObject.class).orElse(null);
|
|
||||||
channel.setAssociated(getClass(), newCm);
|
|
||||||
if (oldCm != null && Objects.equals(oldCm.getRaw().get("data"),
|
|
||||||
newCm.getRaw().get("data"))) {
|
|
||||||
logger.finer(() -> "No changes in config map for "
|
|
||||||
+ DataPath.<String> get(model, "cr", "name").get());
|
|
||||||
model.put("configMapResourceVersion",
|
|
||||||
oldCm.getMetadata().getResourceVersion());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get API and update
|
// Get API and update
|
||||||
DynamicKubernetesApi cmApi = new DynamicKubernetesApi("", "v1",
|
DynamicKubernetesApi cmApi = new DynamicKubernetesApi("", "v1",
|
||||||
"configmaps", channel.client());
|
"configmaps", channel.client());
|
||||||
|
|
@ -131,6 +129,12 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||||
updatedCm.getMetadata().getResourceVersion());
|
updatedCm.getMetadata().getResourceVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key for association.
|
||||||
|
*/
|
||||||
|
private final class PrevData {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggers update of config map mounted in pod
|
* Triggers update of config map mounted in pod
|
||||||
* See https://ahmet.im/blog/kubernetes-secret-volumes-delay/
|
* See https://ahmet.im/blog/kubernetes-secret-volumes-delay/
|
||||||
|
|
|
||||||
|
|
@ -214,9 +214,8 @@ public class Reconciler extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create model for processing templates
|
// Create model for processing templates
|
||||||
Map<String, Object> model
|
Map<String, Object> model = prepareModel(event.vmDefinition());
|
||||||
= prepareModel(event.vmDefinition());
|
cmReconciler.reconcile(model, channel, event.specChanged());
|
||||||
cmReconciler.reconcile(model, channel);
|
|
||||||
|
|
||||||
// The remaining reconcilers depend only on changes of the spec part.
|
// The remaining reconcilers depend only on changes of the spec part.
|
||||||
if (!event.specChanged()) {
|
if (!event.specChanged()) {
|
||||||
|
|
@ -247,7 +246,7 @@ public class Reconciler extends Component {
|
||||||
vmDef.extra().ifPresent(e -> e.resetCount(e.resetCount() + 1));
|
vmDef.extra().ifPresent(e -> e.resetCount(e.resetCount() + 1));
|
||||||
Map<String, Object> model
|
Map<String, Object> model
|
||||||
= prepareModel(channel.vmDefinition());
|
= prepareModel(channel.vmDefinition());
|
||||||
cmReconciler.reconcile(model, channel);
|
cmReconciler.reconcile(model, channel, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> prepareModel(VmDefinition vmDef)
|
private Map<String, Object> prepareModel(VmDefinition vmDef)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue