Skip to content

Commit e8ede1a

Browse files
committed
refactor
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent e9bcfbe commit e8ede1a

File tree

7 files changed

+36
-50
lines changed

7 files changed

+36
-50
lines changed

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public static <P extends HasMetadata> P editAndCacheStatusWith(
7272
*/
7373
public static <P extends HasMetadata> P patchAndCacheStatusWith(
7474
P primary, Context<P> context, BiFunction<P, KubernetesClient, P> patch) {
75-
checkResourceVersionPresent(primary);
7675
var updatedResource = patch.apply(primary, context.getClient());
7776
context
7877
.eventSourceRetriever()
@@ -93,7 +92,6 @@ public static <P extends HasMetadata> P patchAndCacheStatusWith(
9392
*/
9493
public static <P extends HasMetadata> P ssaPatchAndCacheStatusWith(
9594
P primary, P freshResourceWithStatus, Context<P> context) {
96-
checkResourceVersionPresent(freshResourceWithStatus);
9795
var res =
9896
context
9997
.getClient()
@@ -212,14 +210,6 @@ public static <P extends HasMetadata> P patchAndCacheStatus(
212210
return updatedResource;
213211
}
214212

215-
private static <P extends HasMetadata> void checkResourceVersionPresent(P primary) {
216-
if (primary.getMetadata().getResourceVersion() == null) {
217-
throw new IllegalStateException(
218-
"Primary resource version is null, it is expected to set resource version for updates for caching. Name: %s namespace: %s"
219-
.formatted(primary.getMetadata().getName(), primary.getMetadata().getNamespace()));
220-
}
221-
}
222-
223213
private static <P extends HasMetadata> void logWarnIfResourceVersionPresent(P primary) {
224214
if (primary.getMetadata().getResourceVersion() != null) {
225215
log.warn(

operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/withlock/StatusPatchCacheWithLockCustomResource.java renamed to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/internal/StatusPatchCacheCustomResource.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.javaoperatorsdk.operator.baseapi.statuscache.withlock;
1+
package io.javaoperatorsdk.operator.baseapi.statuscache.internal;
22

33
import io.fabric8.kubernetes.api.model.Namespaced;
44
import io.fabric8.kubernetes.client.CustomResource;
@@ -9,6 +9,5 @@
99
@Group("sample.javaoperatorsdk")
1010
@Version("v1")
1111
@ShortNames("spcl")
12-
public class StatusPatchCacheWithLockCustomResource
13-
extends CustomResource<StatusPatchCacheWithLockSpec, StatusPatchCacheWithLockStatus>
14-
implements Namespaced {}
12+
public class StatusPatchCacheCustomResource
13+
extends CustomResource<StatusPatchCacheSpec, StatusPatchCacheStatus> implements Namespaced {}

operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/withlock/StatusPatchCacheWithLockIT.java renamed to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/internal/StatusPatchCacheIT.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.javaoperatorsdk.operator.baseapi.statuscache.withlock;
1+
package io.javaoperatorsdk.operator.baseapi.statuscache.internal;
22

33
import java.time.Duration;
44

@@ -11,19 +11,19 @@
1111
import static org.assertj.core.api.Assertions.assertThat;
1212
import static org.awaitility.Awaitility.await;
1313

14-
public class StatusPatchCacheWithLockIT {
14+
public class StatusPatchCacheIT {
1515

1616
public static final String TEST_1 = "test1";
1717

1818
@RegisterExtension
1919
LocallyRunOperatorExtension extension =
2020
LocallyRunOperatorExtension.builder()
21-
.withReconciler(StatusPatchCacheWithLockReconciler.class)
21+
.withReconciler(StatusPatchCacheReconciler.class)
2222
.build();
2323

2424
@Test
2525
void testStatusAlwaysUpToDate() {
26-
var reconciler = extension.getReconcilerOfType(StatusPatchCacheWithLockReconciler.class);
26+
var reconciler = extension.getReconcilerOfType(StatusPatchCacheReconciler.class);
2727

2828
extension.create(testResource());
2929

@@ -39,10 +39,10 @@ void testStatusAlwaysUpToDate() {
3939
});
4040
}
4141

42-
StatusPatchCacheWithLockCustomResource testResource() {
43-
var res = new StatusPatchCacheWithLockCustomResource();
42+
StatusPatchCacheCustomResource testResource() {
43+
var res = new StatusPatchCacheCustomResource();
4444
res.setMetadata(new ObjectMetaBuilder().withName(TEST_1).build());
45-
res.setSpec(new StatusPatchCacheWithLockSpec());
45+
res.setSpec(new StatusPatchCacheSpec());
4646
return res;
4747
}
4848
}

operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/withlock/StatusPatchCacheWithLockReconciler.java renamed to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/internal/StatusPatchCacheReconciler.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.javaoperatorsdk.operator.baseapi.statuscache.withlock;
1+
package io.javaoperatorsdk.operator.baseapi.statuscache.internal;
22

33
import java.util.List;
44

@@ -13,16 +13,14 @@
1313
import io.javaoperatorsdk.operator.processing.event.source.EventSource;
1414

1515
@ControllerConfiguration
16-
public class StatusPatchCacheWithLockReconciler
17-
implements Reconciler<StatusPatchCacheWithLockCustomResource> {
16+
public class StatusPatchCacheReconciler implements Reconciler<StatusPatchCacheCustomResource> {
1817

1918
public volatile int latestValue = 0;
2019
public volatile boolean errorPresent = false;
2120

2221
@Override
23-
public UpdateControl<StatusPatchCacheWithLockCustomResource> reconcile(
24-
StatusPatchCacheWithLockCustomResource resource,
25-
Context<StatusPatchCacheWithLockCustomResource> context)
22+
public UpdateControl<StatusPatchCacheCustomResource> reconcile(
23+
StatusPatchCacheCustomResource resource, Context<StatusPatchCacheCustomResource> context)
2624
throws InterruptedException {
2725

2826
if (resource.getStatus() != null && resource.getStatus().getValue() != latestValue) {
@@ -50,21 +48,20 @@ public UpdateControl<StatusPatchCacheWithLockCustomResource> reconcile(
5048
}
5149

5250
@Override
53-
public List<EventSource<?, StatusPatchCacheWithLockCustomResource>> prepareEventSources(
54-
EventSourceContext<StatusPatchCacheWithLockCustomResource> context) {
51+
public List<EventSource<?, StatusPatchCacheCustomResource>> prepareEventSources(
52+
EventSourceContext<StatusPatchCacheCustomResource> context) {
5553
// periodic event triggering for testing purposes
5654
return List.of(new PeriodicTriggerEventSource<>(context.getPrimaryCache()));
5755
}
5856

59-
private StatusPatchCacheWithLockCustomResource createFreshCopy(
60-
StatusPatchCacheWithLockCustomResource resource) {
61-
var res = new StatusPatchCacheWithLockCustomResource();
57+
private StatusPatchCacheCustomResource createFreshCopy(StatusPatchCacheCustomResource resource) {
58+
var res = new StatusPatchCacheCustomResource();
6259
res.setMetadata(
6360
new ObjectMetaBuilder()
6461
.withName(resource.getMetadata().getName())
6562
.withNamespace(resource.getMetadata().getNamespace())
6663
.build());
67-
res.setStatus(new StatusPatchCacheWithLockStatus());
64+
res.setStatus(new StatusPatchCacheStatus());
6865

6966
return res;
7067
}

operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/withlock/StatusPatchCacheWithLockSpec.java renamed to operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/internal/StatusPatchCacheSpec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package io.javaoperatorsdk.operator.baseapi.statuscache.withlock;
1+
package io.javaoperatorsdk.operator.baseapi.statuscache.internal;
22

3-
public class StatusPatchCacheWithLockSpec {
3+
public class StatusPatchCacheSpec {
44

55
private int counter = 0;
66

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.javaoperatorsdk.operator.baseapi.statuscache.internal;
2+
3+
public class StatusPatchCacheStatus {
4+
5+
private Integer value = 0;
6+
7+
public Integer getValue() {
8+
return value;
9+
}
10+
11+
public StatusPatchCacheStatus setValue(Integer value) {
12+
this.value = value;
13+
return this;
14+
}
15+
}

operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/withlock/StatusPatchCacheWithLockStatus.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)