Replies: 3 comments
-
|
Hi @mancave Some questions first to see this clearly:
|
Beta Was this translation helpful? Give feedback.
-
|
Hi csvire,
|
Beta Was this translation helpful? Give feedback.
-
|
I think I still don't understand all the details, but will describe you how to implement the following situation: To manage config map content from a custom resource (CR); if the config map already present if there is no CR yet, after creating the CR the config map concent should be overriten, if the CR is deleted the config map should be still there (so we don't delete the ConfigMap): I think this is doable with base API but also with dependent resources + workflows. But I think this might be simpler to underdstand with base API, pseudo code: public class MyCustomResourceReconciler implements Reconciler<MyCustomResource> {
InformerEventSource<ConfigMap> configMapEventSource;
public void reconcie(MyCustomResource cr, Context context) {
// this assumes you have some naming convention for the config map name;
Optional<MyCustomResource> configMap = configMapEventSource.get(new ResourceID(cr.getMetadata().getName(),cr.getMetadata().getNamespace()))
// check if CM exists
if (configMap.isPresent()) {
// check the content of the config map, add missing annotations if needed, update the content with Kubernetes client (data from cr)
} else {
// create the config map with data from cr add annotations
}
// you can here add some info to status of the CR, for example the resource version of the config Map
return UpdateControl.noUpdate();
}
@Override
public List<EventSource<?, MyCustomResource>> prepareEventSources(EventSourceContext<MyCustomResource> context) {
configMapEventSource =
new InformerEventSource<>(
InformerEventSourceConfiguration.from(ConfigMap.class, MyCustomResource.class)
// this is important, the CR will triggered based on the annotation no owner references,
// so if you delete the CR the K8S GC won't delete the config map. See source code what annotations you need
// to add in reconiler.
.withSecondaryToPrimaryMapper(Mappers.fromDefaultAnnotations(MyCustomResource.class))
.build(),
context);
return List.of(configMapEventSource);
}
}In additional to that you can implement |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Team,
Here is my use-case:
I want that the configMap content can be changed by a CRD, but I'm running in some problems.
The configmap needs to be there before the application is deployed, so having a Reconciler with a dependant configmap will not work because the configmap will only be created when the Reconciler is triggers with a CRD.
The same thing is when the configmap is managend as a dependancy on the Reconciler when the last CRD is delete, the configmap will also be deleted result is that the file on the pod will reflect the n-1 state of the configmap.
It looks like we can't manage the content of the configmap with a Reconciler and managed configmap as a resource.
So we need a Reconciler that managed the config map on it's own and not as a dependancy. Also it needs some different bootstrap because the configmap needs already to be existing(with some "empty" configuration) before the application is deployed, otherwise the pod will not be started because of the missing dependancy. It will only start if the configmap is create with some CRD.
Also when the configmap is changed(external) the reconcil loop needs to be triggerd to get the configmap again in the correct state with the CRD's data.
Can you please help me out how I can achieve this with the java-operator-sdk framework ?
yours sincerely
Beta Was this translation helpful? Give feedback.
All reactions