diff --git a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/ConfigMapReconciler.java b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/ConfigMapReconciler.java index e136a31..f133542 100644 --- a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/ConfigMapReconciler.java +++ b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/ConfigMapReconciler.java @@ -76,13 +76,24 @@ import org.yaml.snakeyaml.constructor.SafeConstructor; * * @param model the model * @param channel the channel + * @param modelChanged the model has changed * @throws IOException Signals that an I/O exception has occurred. * @throws TemplateException the template exception - * @throws ApiException the api exception + * @throws ApiException the API exception */ @SuppressWarnings("PMD.AvoidDuplicateLiterals") - public void reconcile(Map model, VmChannel channel) + public void reconcile(Map model, VmChannel channel, + boolean modelChanged) 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 model.put("adjustCloudInitMeta", adjustCloudInitMetaModel); var fmTemplate = fmConfig.getTemplate("runnerConfig.ftl.yaml"); @@ -107,19 +118,6 @@ import org.yaml.snakeyaml.constructor.SafeConstructor; .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. get(model, "cr", "name").get()); - model.put("configMapResourceVersion", - oldCm.getMetadata().getResourceVersion()); - return; - } - // Get API and update DynamicKubernetesApi cmApi = new DynamicKubernetesApi("", "v1", "configmaps", channel.client()); @@ -131,6 +129,12 @@ import org.yaml.snakeyaml.constructor.SafeConstructor; updatedCm.getMetadata().getResourceVersion()); } + /** + * Key for association. + */ + private final class PrevData { + } + /** * Triggers update of config map mounted in pod * See https://ahmet.im/blog/kubernetes-secret-volumes-delay/ 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 fddd5c8..70f684a 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 @@ -214,9 +214,8 @@ public class Reconciler extends Component { } // Create model for processing templates - Map model - = prepareModel(event.vmDefinition()); - cmReconciler.reconcile(model, channel); + Map model = prepareModel(event.vmDefinition()); + cmReconciler.reconcile(model, channel, event.specChanged()); // The remaining reconcilers depend only on changes of the spec part. if (!event.specChanged()) { @@ -247,7 +246,7 @@ public class Reconciler extends Component { vmDef.extra().ifPresent(e -> e.resetCount(e.resetCount() + 1)); Map model = prepareModel(channel.vmDefinition()); - cmReconciler.reconcile(model, channel); + cmReconciler.reconcile(model, channel, true); } private Map prepareModel(VmDefinition vmDef)