Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hi,

I'm using the latest version(5.2.2) of the operator framework and the sample "Dependent Resource Shared by Multiple Owners".

The share config-map will be maintained by the CRD's, but if you delete one of the owner crd-resource there are no events that signalling the reconcile and dependant resource that things need to be removed from the config-map.

@ This moment I added the Cleaner interface on the reconciler class and implemented the cleanup. The cleanup try's to find the config-map and clears all the data, removes the owner reference from the meta data and updates the config-map. This will trigger a new reconcile loop and the desired state is rebuild based on the owner references.

@Override
public DeleteControl cleanup(MultipleOwnerDependentCustomResource primary,
		Context<MultipleOwnerDependentCustomResource> context) throws Exception {
	
	logger.debug(String.format(">>> cleanup: %s", primary.getMetadata().getName()));

	if (primary != null) {

		Optional<ConfigMap> cm = getSecondaryResource(primary, context);

		cm.ifPresent(p -> {
			var data = cm.map(ConfigMap::getData).orElse(new HashMap<>());

			data.clear(); // will trigger the rebuild of the config-map with only the data that are part of the owner refs
			p.getMetadata().getOwnerReferences().remove(primary.getMetadata().getName());

			context.getClient().resource(p).update();
		});
	}

	return DeleteControl.defaultDelete();
}

public Optional<ConfigMap> getSecondaryResource(MultipleOwnerDependentCustomResource primary,
		Context<MultipleOwnerDependentCustomResource> context) {
	InformerEventSource<ConfigMap, MultipleOwnerDependentCustomResource> ies = (InformerEventSource<ConfigMap, MultipleOwnerDependentCustomResource>) context
			.eventSourceRetriever().getEventSourceFor(ConfigMap.class);
	return ies.get(
			new ResourceID(MultipleOwnerDependentConfigMap.RESOURCE_NAME, primary.getMetadata().getNamespace()));
}

Is this the proper way to handle this situation ?

Thnxs

You must be logged in to vote

Replies: 2 comments · 1 reply

Comment options

Hi @mancave ,

first, that could work, maybe here dont' clear the whole data just remove specific keys:

data.clear(); // will trigger the rebuild of the config-map with only the data that are part of the owner refs

also as mentioned here:
#3122

dependent resources are a bit limited in this regard, also it is relatively rare that multiple controllers manage the same resource (there are exceptions like Pods in Kubernetes).

So you might have easier time to implement your use case using the low level API.

I will create an issue to enhance the example, and will take a look soon at least to explore this problem better.

You must be logged in to vote
1 reply
@csviri
Comment options

#3124

Comment options

I need to look @ my use-case again thnxs

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.