-
Notifications
You must be signed in to change notification settings - Fork 236
feat: ResourceIDMapper for external event sources, external dependents and bulk dependents #3020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from 13 commits
9b331da
cb532df
d0867e4
f615a86
a620cbe
c295061
4d274b4
c31eab1
9c7b6ad
b39cafe
e511b1a
bae1e76
5020e76
5332039
f8ccb78
3b25831
1bb99cd
35be84a
be27232
bdf08c4
261e741
108cb82
70038a6
e5d0380
1bf7b17
adeabcc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --- | ||
| title: Migrating from v5.1 to v5.2 | ||
| description: Migrating from v5.1 to v5.2 | ||
| --- | ||
|
|
||
| Version 5.2 brings some breaking changes on some components, for those we provide | ||
| a migration guide. For all the new features see release notes. | ||
|
|
||
| ## Custom ID types and ResourceIDProvider across multiple components | ||
|
|
||
| TODO | ||
|
|
||
| See also: | ||
| - related issue: [link](https://github.com/operator-framework/java-operator-sdk/issues/2972) | ||
| - related pull requests: | ||
| - [2970](https://github.com/operator-framework/java-operator-sdk/pull/2970) | ||
| - [3020](https://github.com/operator-framework/java-operator-sdk/pull/3020) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * Copyright Java Operator SDK Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.javaoperatorsdk.operator.processing; | ||
|
|
||
| import io.fabric8.kubernetes.api.model.HasMetadata; | ||
| import io.javaoperatorsdk.operator.processing.event.ResourceID; | ||
| import io.javaoperatorsdk.operator.processing.event.source.ExternalResourceCachingEventSource; | ||
|
|
||
| /** | ||
| * Provides id for the target resource. This mapper is used across multiple component of the | ||
csviri marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * framework, like the {@link | ||
| * io.javaoperatorsdk.operator.processing.dependent.AbstractExternalDependentResource}, in {@link | ||
csviri marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * ExternalResourceCachingEventSource}, and {@link | ||
| * io.javaoperatorsdk.operator.processing.dependent.KubernetesBulkDependentResource}. | ||
| */ | ||
| public interface ResourceIDMapper<R, ID> { | ||
|
|
||
| ID idFor(R resource); | ||
csviri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Can be used if a polling event source handles only single secondary resource and the id is | ||
| * String. See also docs for: {@link ExternalResourceCachingEventSource} | ||
| * | ||
| * @return static id mapper, all resources are mapped for same id. | ||
| * @param <R> secondary resource type | ||
| */ | ||
| static <R> ResourceIDMapper<R, String> singleResourceResourceIDMapper() { | ||
| return r -> "id"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The value should be irrelevant and we should rather use a value that has not risk of conflicting with an identifier a user would create.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will have to upgrade upgrade the javadocs, there is no situation where there can be a collision. Assuming that this is by definition not usable for BulkDependentResources - will add javadoc. If you see some situation where it actually can lead to a collision pls describe it. |
||
| } | ||
|
|
||
| static <R, ID> ResourceIDMapper<R, ID> resourceIdProviderMapper() { | ||
| return r -> { | ||
| if (r instanceof ResourceIDProvider resourceIDProvider) { | ||
| return (ID) resourceIDProvider.resourceId(); | ||
| } else { | ||
| throw new IllegalStateException( | ||
| "Resource does not implement ExternalDependentIDProvider: " + r.getClass()); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| static <R extends HasMetadata> ResourceIDMapper<R, ResourceID> kubernetesResourceIdMapper() { | ||
| return ResourceID::fromResource; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Copyright Java Operator SDK Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.javaoperatorsdk.operator.processing; | ||
|
|
||
| /** | ||
| * Provides the identifier for an object that represents resource. This ID is used to select target | ||
csviri marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * external resource for a dependent resource from the resources returned by `{@link | ||
| * io.javaoperatorsdk.operator.api.reconciler.Context#getSecondaryResources(Class)}`. But also for | ||
csviri marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * {@link ResourceIDMapper} for event sources in external resources. But also for bulk dependent | ||
| * resource see {@link | ||
| * io.javaoperatorsdk.operator.processing.dependent.ExternalBulkDependentResource} and external | ||
| * event sources, see {@link | ||
| * io.javaoperatorsdk.operator.processing.event.source.ExternalResourceCachingEventSource} | ||
csviri marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @param <ID> | ||
| */ | ||
| public interface ResourceIDProvider<ID> { | ||
|
|
||
| ID resourceId(); | ||
csviri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Copyright Java Operator SDK Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.javaoperatorsdk.operator.processing.dependent; | ||
|
|
||
| import io.fabric8.kubernetes.api.model.HasMetadata; | ||
| import io.javaoperatorsdk.operator.processing.ResourceIDMapper; | ||
| import io.javaoperatorsdk.operator.processing.ResourceIDProvider; | ||
|
|
||
| /** | ||
| * Specialized interface for bulk dependent resources where resource implement {@link | ||
| * ResourceIDProvider}. | ||
| */ | ||
| public interface ExternalBulkDependentResource< | ||
| R extends ResourceIDProvider<ID>, P extends HasMetadata, ID> | ||
| extends ResourceIDMapperBulkDependentResource<R, P, ID> { | ||
|
|
||
| default ResourceIDMapper<R, ID> resourceIDMapper() { | ||
| return ResourceIDMapper.resourceIdProviderMapper(); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.