Skip to content

Commit 42bfa47

Browse files
committed
refactor: change default implementations of build and update
1 parent eafd8d8 commit 42bfa47

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DependentResource.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
public interface DependentResource<R extends HasMetadata> {
99
default R build() {
10-
throw new UnsupportedOperationException(
11-
"Should be implemented only if DependentResource is configured as creatable");
10+
if (getConfiguration().creatable()) {
11+
throw new IllegalStateException(
12+
"Should be implemented if DependentResource is configured as creatable");
13+
}
14+
throw new IllegalStateException("Should not be called if DependentResource is not creatable");
1215
}
1316

1417
ResourceCache<R> getCache();
@@ -20,7 +23,11 @@ default R fetchFor(HasMetadata owner) {
2023
DependentResourceConfiguration<R> getConfiguration();
2124

2225
default R update(R fetched) {
23-
return fetched;
26+
if (getConfiguration().updatable()) {
27+
throw new IllegalStateException(
28+
"Should be implemented if DependentResource is configured as updatable");
29+
}
30+
throw new IllegalStateException("Should not be called if DependentResource is not updatable");
2431
}
2532

2633
}

0 commit comments

Comments
 (0)