From 9b26d18cb025011d9918799d29d0d1d303b94a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 31 Jan 2024 16:46:13 +0100 Subject: [PATCH] improve: resource creation api in JUnit extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../event/source/cache/BoundedCacheTestBase.java | 2 +- .../operator/junit/AbstractOperatorExtension.java | 15 +++++++++++++++ .../operator/ChangeNamespaceIT.java | 2 +- .../operator/CleanupConflictIT.java | 2 +- .../operator/ClusterScopedResourceIT.java | 2 +- ...ateUpdateInformerEventSourceEventFilterIT.java | 2 +- .../DependentAnnotationSecondaryMapperIT.java | 2 +- .../DependentCustomMappingAnnotationIT.java | 2 +- .../operator/DependentDifferentNamespaceIT.java | 2 +- .../operator/DependentFilterIT.java | 2 +- .../operator/DependentOperationEventFilterIT.java | 2 +- .../operator/DependentSSAMatchingIT.java | 2 +- .../DynamicGenericEventSourceRegistrationIT.java | 2 +- .../operator/ExternalStateBulkIT.java | 6 +++--- .../javaoperatorsdk/operator/ExternalStateIT.java | 2 +- .../operator/ExternalStateTestBase.java | 2 +- .../io/javaoperatorsdk/operator/FilterIT.java | 4 ++-- .../GenericKubernetesDependentTestBase.java | 2 +- .../javaoperatorsdk/operator/GracefulStopIT.java | 2 +- .../operator/IndexDiscriminatorIT.java | 2 +- .../operator/InformerEventSourceIT.java | 2 +- .../KubernetesDependentGarbageCollectionIT.java | 2 +- .../ManagedDependentDeleteConditionIT.java | 4 ++-- .../operator/MultiOwnerDependentTriggeringIT.java | 4 ++-- .../MultipleDependentSameTypeMultiInformerIT.java | 2 +- .../MultipleManagedDependentSameTypeIT.java | 2 +- ...ultipleManagedExternalDependentSameTypeIT.java | 2 +- .../operator/MultipleSecondaryEventSourceIT.java | 2 +- .../operator/PreviousAnnotationDisabledIT.java | 2 +- .../operator/PrimaryToSecondaryDependentIT.java | 2 +- .../io/javaoperatorsdk/operator/RateLimitIT.java | 2 +- .../operator/ServiceStrictMatcherIT.java | 2 +- .../operator/SpecialResourcesDependentIT.java | 2 +- .../operator/StandaloneDependentResourceIT.java | 2 +- .../operator/StatefulSetDesiredSanitizerIT.java | 2 +- .../operator/StatusPatchNotLockingIT.java | 4 ++-- .../operator/StatusUpdateLockingIT.java | 2 +- .../operator/UnmodifiableDependentPartIT.java | 2 +- .../operator/WorkflowAllFeatureIT.java | 4 ++-- .../operator/WorkflowMultipleActivationIT.java | 6 +++--- .../bulkdependent/BulkDependentTestBase.java | 8 ++++---- .../sample/WebPageOperatorAbstractTest.java | 2 +- 42 files changed, 68 insertions(+), 53 deletions(-) diff --git a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/BoundedCacheTestBase.java b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/BoundedCacheTestBase.java index 21adf81cc0..88fa597449 100644 --- a/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/BoundedCacheTestBase.java +++ b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/BoundedCacheTestBase.java @@ -63,7 +63,7 @@ private void updateTestResources() { IntStream.range(0, NUMBER_OF_RESOURCE_TO_TEST).forEach(i -> { var cm = extension().get(ConfigMap.class, RESOURCE_NAME_PREFIX + i); cm.getData().put(DATA_KEY, UPDATED_PREFIX + i); - extension().replace(cm); + extension().createOrUpdate(cm); }); } diff --git a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/AbstractOperatorExtension.java b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/AbstractOperatorExtension.java index 1ce14b73ed..db958194a1 100644 --- a/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/AbstractOperatorExtension.java +++ b/operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/AbstractOperatorExtension.java @@ -20,6 +20,7 @@ import io.fabric8.kubernetes.api.model.*; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; +import io.fabric8.kubernetes.client.dsl.NonDeletingOperation; import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.utils.Utils; @@ -107,6 +108,16 @@ public T get(Class type, String name) { return kubernetesClient.resources(type).inNamespace(namespace).withName(name).get(); } + public T createOr(T resource, + Function, T> conflictAction) { + return kubernetesClient.resource(resource).inNamespace(namespace).createOr(conflictAction); + } + + public T createOrUpdate(T resource) { + return kubernetesClient.resource(resource).inNamespace(namespace) + .createOr(NonDeletingOperation::update); + } + public T create(T resource) { return kubernetesClient.resource(resource).inNamespace(namespace).create(); } @@ -116,6 +127,10 @@ public T create(Class type, T resource) { return create(resource); } + /** + * Use createOrUpdate instead. + */ + @Deprecated(forRemoval = true) public T replace(T resource) { return kubernetesClient.resource(resource).inNamespace(namespace).replace(); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ChangeNamespaceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ChangeNamespaceIT.java index e669f6d06c..ff310f061a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ChangeNamespaceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ChangeNamespaceIT.java @@ -71,7 +71,7 @@ void addNewAndRemoveOldNamespaceTest() { ConfigMap firstMap = operator.get(ConfigMap.class, TEST_RESOURCE_NAME_1); firstMap.setData(Map.of("data", "newdata")); - operator.replace(firstMap); + operator.createOrUpdate(firstMap); assertReconciled(reconciler, defaultNamespaceResource); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CleanupConflictIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/CleanupConflictIT.java index e1c571c4a5..fc5bec3133 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CleanupConflictIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/CleanupConflictIT.java @@ -39,7 +39,7 @@ void cleanupRemovesFinalizerWithoutConflict() throws InterruptedException { testResource = operator.get(CleanupConflictCustomResource.class, TEST_RESOURCE_NAME); testResource.getMetadata().getFinalizers().remove(ADDITIONAL_FINALIZER); testResource.getMetadata().setResourceVersion(null); - operator.replace(testResource); + operator.createOrUpdate(testResource); await().pollDelay(Duration.ofMillis(WAIT_TIME * 2)).untilAsserted( () -> assertThat(operator.getReconcilerOfType(CleanupConflictReconciler.class) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ClusterScopedResourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ClusterScopedResourceIT.java index b1a3797bea..70bcb59b59 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ClusterScopedResourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ClusterScopedResourceIT.java @@ -40,7 +40,7 @@ void crudOperationOnClusterScopedCustomResource() { }); resource.getSpec().setData(UPDATED_DATA); - operator.replace(resource); + operator.createOrUpdate(resource); await().untilAsserted(() -> { var cm = operator.get(ConfigMap.class, TEST_NAME); assertThat(cm).isNotNull(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CreateUpdateInformerEventSourceEventFilterIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/CreateUpdateInformerEventSourceEventFilterIT.java index 8a68c9a2b3..69a9be536a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/CreateUpdateInformerEventSourceEventFilterIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/CreateUpdateInformerEventSourceEventFilterIT.java @@ -37,7 +37,7 @@ void updateEventNotReceivedAfterCreateOrUpdate() { operator.get(CreateUpdateEventFilterTestCustomResource.class, resource.getMetadata().getName()); actualCreatedResource.getSpec().setValue("2"); - operator.replace(actualCreatedResource); + operator.createOrUpdate(actualCreatedResource); assertData(operator, actualCreatedResource, 2, 2); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentAnnotationSecondaryMapperIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentAnnotationSecondaryMapperIT.java index b5b01e1530..a86e1f867d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentAnnotationSecondaryMapperIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentAnnotationSecondaryMapperIT.java @@ -46,7 +46,7 @@ void mapsSecondaryByAnnotation() { assertThat(configMap.getMetadata().getOwnerReferences()).isEmpty(); configMap.getData().put("additional_data", "data"); - operator.replace(configMap); + operator.createOrUpdate(configMap); await().pollDelay(Duration.ofMillis(150)) .untilAsserted(() -> assertThat(reconciler.getNumberOfExecutions()).isEqualTo(2)); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentCustomMappingAnnotationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentCustomMappingAnnotationIT.java index 8a7d168b26..754d2a1de1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentCustomMappingAnnotationIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentCustomMappingAnnotationIT.java @@ -35,7 +35,7 @@ void testCustomMappingAnnotationForDependent() { assertConfigMapData(INITIAL_VALUE); cr.getSpec().setValue(CHANGED_VALUE); - cr = extension.replace(cr); + cr = extension.createOrUpdate(cr); assertConfigMapData(CHANGED_VALUE); extension.delete(cr); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentDifferentNamespaceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentDifferentNamespaceIT.java index 452de53930..dc2e76149c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentDifferentNamespaceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentDifferentNamespaceIT.java @@ -38,7 +38,7 @@ void managesCRUDOperationsForDependentInDifferentNamespace() { }); resource.getSpec().setValue(CHANGED_VALUE); - resource = extension.replace(resource); + resource = extension.createOrUpdate(resource); await().untilAsserted(() -> { var cm = getDependentConfigMap(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentFilterIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentFilterIT.java index 19d6678a59..f1ecbc6ea5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentFilterIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentFilterIT.java @@ -39,7 +39,7 @@ void filtersUpdateOnConfigMap() { var configMap = operator.get(ConfigMap.class, RESOURCE_NAME); configMap.setData(Map.of(CM_VALUE_KEY, CONFIG_MAP_FILTER_VALUE)); - operator.replace(configMap); + operator.createOrUpdate(configMap); await().pollDelay(Duration.ofMillis(150)).untilAsserted(() -> { assertThat(operator.getReconcilerOfType(DependentFilterTestReconciler.class) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentOperationEventFilterIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentOperationEventFilterIT.java index eb354bf96d..0c50d2d2f6 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentOperationEventFilterIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentOperationEventFilterIT.java @@ -43,7 +43,7 @@ void reconcileNotTriggeredWithDependentResourceCreateOrUpdate() { .containsEntry(ConfigMapDependentResource.KEY, SPEC_VAL_1); resource.getSpec().setValue(SPEC_VAL_2); - operator.replace(resource); + operator.createOrUpdate(resource); await().pollDelay(Duration.ofSeconds(1)).atMost(Duration.ofSeconds(3)) .until( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentSSAMatchingIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentSSAMatchingIT.java index 0249b44927..ed9fe96e5a 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentSSAMatchingIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/DependentSSAMatchingIT.java @@ -74,7 +74,7 @@ void testMatchingAndUpdate() { }); resource.getSpec().setValue(CHANGED_VALUE); - extension.replace(resource); + extension.createOrUpdate(resource); await().untilAsserted(() -> { var cm = extension.get(ConfigMap.class, TEST_RESOURCE_NAME); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DynamicGenericEventSourceRegistrationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/DynamicGenericEventSourceRegistrationIT.java index 308630a365..e5f8293f76 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/DynamicGenericEventSourceRegistrationIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/DynamicGenericEventSourceRegistrationIT.java @@ -43,7 +43,7 @@ void registersEventSourcesDynamically() { var cm = extension.get(ConfigMap.class, TEST_RESOURCE_NAME); cm.getData().put("key2", "val2"); - extension.replace(cm); // triggers the reconciliation + extension.createOrUpdate(cm); // triggers the reconciliation await().untilAsserted(() -> { assertThat(reconciler.getNumberOfExecutions() - executions).isEqualTo(2); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateBulkIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateBulkIT.java index 7452958b8c..5682471101 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateBulkIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateBulkIT.java @@ -39,15 +39,15 @@ void reconcilesResourceWithPersistentState() throws InterruptedException { assertResources(resource, INITIAL_TEST_DATA, INITIAL_BULK_SIZE); resource.getSpec().setData(UPDATED_DATA); - resource = operator.replace(resource); + resource = operator.createOrUpdate(resource); assertResources(resource, UPDATED_DATA, INITIAL_BULK_SIZE); resource.getSpec().setNumber(INCREASED_BULK_SIZE); - resource = operator.replace(resource); + resource = operator.createOrUpdate(resource); assertResources(resource, UPDATED_DATA, INCREASED_BULK_SIZE); resource.getSpec().setNumber(DECREASED_BULK_SIZE); - resource = operator.replace(resource); + resource = operator.createOrUpdate(resource); assertResources(resource, UPDATED_DATA, DECREASED_BULK_SIZE); operator.delete(resource); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateIT.java index 3da607e324..c874b90111 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateIT.java @@ -35,7 +35,7 @@ public void reconcilesResourceWithPersistentState() { assertResourcesCreated(resource, INITIAL_TEST_DATA); resource.getSpec().setData(UPDATED_DATA); - operator.replace(resource); + operator.createOrUpdate(resource); assertResourcesCreated(resource, UPDATED_DATA); operator.delete(resource); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateTestBase.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateTestBase.java index 43982a6109..ceb2d499b1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateTestBase.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateTestBase.java @@ -28,7 +28,7 @@ public void reconcilesResourceWithPersistentState() { assertResourcesCreated(resource, INITIAL_TEST_DATA); resource.getSpec().setData(UPDATED_DATA); - extension().replace(resource); + extension().createOrUpdate(resource); assertResourcesCreated(resource, UPDATED_DATA); extension().delete(resource); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/FilterIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/FilterIT.java index 28ce794de9..17f46ee3c3 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/FilterIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/FilterIT.java @@ -34,7 +34,7 @@ void filtersControllerResourceUpdate() { .getNumberOfExecutions()).isEqualTo(2)); res.getSpec().setValue(FilterTestReconciler.CUSTOM_RESOURCE_FILTER_VALUE); - operator.replace(res); + operator.createOrUpdate(res); // not more reconciliation with the filtered value await().pollDelay(Duration.ofMillis(POLL_DELAY)) @@ -51,7 +51,7 @@ void filtersSecondaryResourceUpdate() { .getNumberOfExecutions()).isEqualTo(2)); res.getSpec().setValue(CONFIG_MAP_FILTER_VALUE); - operator.replace(res); + operator.createOrUpdate(res); // the CM event filtered out await().pollDelay(Duration.ofMillis(POLL_DELAY)) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesDependentTestBase.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesDependentTestBase.java index fea23b7796..c70c74e41d 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesDependentTestBase.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/GenericKubernetesDependentTestBase.java @@ -30,7 +30,7 @@ void testReconciliation() { }); resource.getSpec().setValue(CHANGED_DATA); - resource = extension().replace(resource); + resource = extension().createOrUpdate(resource); await().untilAsserted(() -> { var cm = extension().get(ConfigMap.class, TEST_RESOURCE_NAME); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GracefulStopIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/GracefulStopIT.java index 715921ecbb..833786dc55 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/GracefulStopIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/GracefulStopIT.java @@ -48,7 +48,7 @@ private void testGracefulStop(String resourceName, int stopTimeout, int expected }); testRes.getSpec().setValue(2); - operator.replace(testRes); + operator.createOrUpdate(testRes); await().pollDelay(Duration.ofMillis(50)).untilAsserted( () -> assertThat(operator.getReconcilerOfType(GracefulStopTestReconciler.class) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/IndexDiscriminatorIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/IndexDiscriminatorIT.java index fe5b63de8a..838843a147 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/IndexDiscriminatorIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/IndexDiscriminatorIT.java @@ -39,7 +39,7 @@ void resourcesFoundAndReconciled() { }); res.getSpec().setValue(CHANGED_SPEC_VALUE); - res = operator.replace(res); + res = operator.createOrUpdate(res); await().untilAsserted(() -> { assertThat(reconciler.getNumberOfExecutions()).isEqualTo(2); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerEventSourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerEventSourceIT.java index 45983145da..91da1eb8ad 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerEventSourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerEventSourceIT.java @@ -40,7 +40,7 @@ void testUsingInformerToWatchChangesOfConfigMap() { waitForCRStatusValue(INITIAL_STATUS_MESSAGE); configMap.getData().put(TARGET_CONFIG_MAP_KEY, UPDATE_STATUS_MESSAGE); - operator.replace(configMap); + operator.createOrUpdate(configMap); waitForCRStatusValue(UPDATE_STATUS_MESSAGE); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/KubernetesDependentGarbageCollectionIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/KubernetesDependentGarbageCollectionIT.java index c32f328d76..f79e9062f5 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/KubernetesDependentGarbageCollectionIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/KubernetesDependentGarbageCollectionIT.java @@ -62,7 +62,7 @@ void deletesSecondaryResource() { }); createdResources.getSpec().setCreateConfigMap(false); - operator.replace(createdResources); + operator.createOrUpdate(createdResources); await().untilAsserted(() -> { ConfigMap cm = operator.get(ConfigMap.class, TEST_RESOURCE_NAME); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ManagedDependentDeleteConditionIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ManagedDependentDeleteConditionIT.java index b2ef89f0f9..6f3ba35b62 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ManagedDependentDeleteConditionIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ManagedDependentDeleteConditionIT.java @@ -45,7 +45,7 @@ void resourceNotDeletedUntilDependentDeleted() { var secret = extension.get(Secret.class, RESOURCE_NAME); secret.getMetadata().getFinalizers().add(CUSTOM_FINALIZER); - secret = extension.replace(secret); + secret = extension.createOrUpdate(secret); extension.delete(resource); @@ -58,7 +58,7 @@ void resourceNotDeletedUntilDependentDeleted() { }); secret.getMetadata().getFinalizers().clear(); - extension.replace(secret); + extension.createOrUpdate(secret); await().untilAsserted(() -> { var cm = extension.get(ConfigMap.class, RESOURCE_NAME); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultiOwnerDependentTriggeringIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultiOwnerDependentTriggeringIT.java index 7f6f917c55..4d33f1f6b2 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultiOwnerDependentTriggeringIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultiOwnerDependentTriggeringIT.java @@ -47,7 +47,7 @@ void multiOwnerTriggeringAndManagement() { }); res1.getSpec().setValue(NEW_VALUE_1); - extension.replace(res1); + extension.createOrUpdate(res1); await().untilAsserted(() -> { var cm = extension.get(ConfigMap.class, MultipleOwnerDependentConfigMap.RESOURCE_NAME); @@ -59,7 +59,7 @@ void multiOwnerTriggeringAndManagement() { }); res2.getSpec().setValue(NEW_VALUE_2); - extension.replace(res2); + extension.createOrUpdate(res2); await().untilAsserted(() -> { var cm = extension.get(ConfigMap.class, MultipleOwnerDependentConfigMap.RESOURCE_NAME); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentSameTypeMultiInformerIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentSameTypeMultiInformerIT.java index 53d29f4552..6139402c3c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentSameTypeMultiInformerIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentSameTypeMultiInformerIT.java @@ -37,7 +37,7 @@ void handlesCrudOperations() { var updatedResource = testResource(); updatedResource.getSpec().setValue(UPDATED_SPEC_VALUE); - operator.replace(updatedResource); + operator.createOrUpdate(updatedResource); assertConfigMapsPresent(UPDATED_SPEC_VALUE); operator.delete(testResource()); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentSameTypeIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentSameTypeIT.java index 32fe0eaec4..701e59e585 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentSameTypeIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentSameTypeIT.java @@ -38,7 +38,7 @@ void handlesCrudOperations() { var updatedResource = testResource(); updatedResource.getSpec().setValue(UPDATED_SPEC_VALUE); - operator.replace(updatedResource); + operator.createOrUpdate(updatedResource); assertConfigMapsPresent(UPDATED_SPEC_VALUE); operator.delete(testResource()); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedExternalDependentSameTypeIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedExternalDependentSameTypeIT.java index e62835c063..966ef1f7be 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedExternalDependentSameTypeIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedExternalDependentSameTypeIT.java @@ -34,7 +34,7 @@ void handlesExternalCrudOperations() { var updatedResource = testResource(); updatedResource.getSpec().setValue(UPDATED_SPEC_VALUE); - operator.replace(updatedResource); + operator.createOrUpdate(updatedResource); assertResourceCreatedWithData(UPDATED_SPEC_VALUE); operator.delete(testResource()); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleSecondaryEventSourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleSecondaryEventSourceIT.java index 85be323379..168eaaaf8f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleSecondaryEventSourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleSecondaryEventSourceIT.java @@ -51,7 +51,7 @@ private void updateConfigMap(MultipleSecondaryEventSourceCustomResource resource number == 1 ? MultipleSecondaryEventSourceReconciler.getName1(resource) : MultipleSecondaryEventSourceReconciler.getName2(resource)); map1.getData().put("value2", "value2"); - operator.replace(map1); + operator.createOrUpdate(map1); } public MultipleSecondaryEventSourceCustomResource createTestCustomResource() { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PreviousAnnotationDisabledIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PreviousAnnotationDisabledIT.java index c636737d0a..87a85476ba 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PreviousAnnotationDisabledIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PreviousAnnotationDisabledIT.java @@ -30,7 +30,7 @@ void updateEventReceivedAfterCreateOrUpdate() { operator.get(CreateUpdateEventFilterTestCustomResource.class, resource.getMetadata().getName()); actualCreatedResource.getSpec().setValue("2"); - operator.replace(actualCreatedResource); + operator.createOrUpdate(actualCreatedResource); CreateUpdateInformerEventSourceEventFilterIT.assertData(operator, actualCreatedResource, 2, 4); } diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryDependentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryDependentIT.java index eaa7e4410f..234f58e094 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryDependentIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryDependentIT.java @@ -44,7 +44,7 @@ void testPrimaryToSecondaryInDependentResources() { cm.setData(Map.of(DATA_KEY, TEST_DATA)); var executions = reconciler.getNumberOfExecutions(); - operator.replace(cm); + operator.createOrUpdate(cm); await().pollDelay(Duration.ofMillis(250)).untilAsserted(() -> { assertThat(reconciler.getNumberOfExecutions()).isGreaterThan(executions); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/RateLimitIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/RateLimitIT.java index f1d5bed6f1..bbe9092150 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/RateLimitIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/RateLimitIT.java @@ -35,7 +35,7 @@ void rateLimitsExecution() { log.debug("replacing resource version: {}", i); var resource = createResource(); resource.getSpec().setNumber(i); - operator.replace(resource); + operator.createOrUpdate(resource); }); await().pollInterval(Duration.ofMillis(100)) .pollDelay(Duration.ofMillis(REFRESH_PERIOD / 2)) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ServiceStrictMatcherIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ServiceStrictMatcherIT.java index 97caab21ee..49ecfe98b9 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/ServiceStrictMatcherIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/ServiceStrictMatcherIT.java @@ -34,7 +34,7 @@ void testTheMatchingDoesNoTTriggersFurtherUpdates() { // make an update to spec to reconcile again resource.getSpec().setValue(2); - operator.replace(resource); + operator.createOrUpdate(resource); await().pollDelay(Duration.ofMillis(300)).untilAsserted(() -> { assertThat(operator.getReconcilerOfType(ServiceStrictMatcherTestReconciler.class) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/SpecialResourcesDependentIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/SpecialResourcesDependentIT.java index a050417254..af1a03e93e 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/SpecialResourcesDependentIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/SpecialResourcesDependentIT.java @@ -39,7 +39,7 @@ void specialCRUDReconciler() { }); resource.getSpec().setValue(CHANGED_VALUE); - extension.replace(resource); + extension.createOrUpdate(resource); await().untilAsserted(() -> { var sa = extension.get(ServiceAccount.class, RESOURCE_NAME); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StandaloneDependentResourceIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StandaloneDependentResourceIT.java index 5d1c570410..53554d446c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StandaloneDependentResourceIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StandaloneDependentResourceIT.java @@ -57,7 +57,7 @@ void executeUpdateForTestingCacheUpdateForGetResource() { var clonedCr = cloner().clone(createdCR); clonedCr.getSpec().setReplicaCount(2); - operator.replace(clonedCr); + operator.createOrUpdate(clonedCr); awaitForDeploymentReadyReplicas(2); assertThat( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatefulSetDesiredSanitizerIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatefulSetDesiredSanitizerIT.java index 5313fb7dfb..05d3faba34 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatefulSetDesiredSanitizerIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatefulSetDesiredSanitizerIT.java @@ -36,7 +36,7 @@ void testSSAMatcher() { }); // make sure reconciliation happens at least once more resource.getSpec().setValue("changed value"); - extension.replace(resource); + extension.createOrUpdate(resource); await().untilAsserted( () -> assertThat(StatefulSetDesiredSanitizerDependentResource.nonMatchedAtLeastOnce) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchNotLockingIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchNotLockingIT.java index 1746e5737d..b64b7feff1 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchNotLockingIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusPatchNotLockingIT.java @@ -31,7 +31,7 @@ void noOptimisticLockingDoneOnStatusUpdate() throws InterruptedException { var resource = operator.create(createResource()); Thread.sleep(WAIT_TIME / 2); resource.getMetadata().setAnnotations(Map.of("key", "value")); - operator.replace(resource); + operator.createOrUpdate(resource); await().pollDelay(Duration.ofMillis(WAIT_TIME)).untilAsserted(() -> { assertThat( @@ -59,7 +59,7 @@ void valuesAreDeletedIfSetToNull() { }); resource.getSpec().setMessageInStatus(false); - operator.replace(resource); + operator.createOrUpdate(resource); await().untilAsserted(() -> { var actual = operator.get(StatusPatchLockingCustomResource.class, diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusUpdateLockingIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusUpdateLockingIT.java index 147c0403c3..618bdb20f4 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusUpdateLockingIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/StatusUpdateLockingIT.java @@ -29,7 +29,7 @@ void optimisticLockingDoneOnStatusUpdate() throws InterruptedException { var resource = operator.create(createResource()); Thread.sleep(WAIT_TIME / 2); resource.getMetadata().setAnnotations(Map.of("key", "value")); - operator.replace(resource); + operator.createOrUpdate(resource); await().pollDelay(Duration.ofMillis(WAIT_TIME)).untilAsserted(() -> { assertThat( diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/UnmodifiableDependentPartIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/UnmodifiableDependentPartIT.java index bc0e951d8a..5a3fb96b4c 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/UnmodifiableDependentPartIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/UnmodifiableDependentPartIT.java @@ -39,7 +39,7 @@ void partConfigMapDataUnmodifiable() { }); resource.getSpec().setData(UPDATED_DATA); - operator.replace(resource); + operator.createOrUpdate(resource); await().untilAsserted(() -> { var cm = operator.get(ConfigMap.class, TEST_RESOURCE_NAME); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowAllFeatureIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowAllFeatureIT.java index f60f2b6fde..dc1ae1dc40 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowAllFeatureIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowAllFeatureIT.java @@ -66,7 +66,7 @@ void configMapNotReconciledIfReconcileConditionNotMet() { }); resource.getSpec().setCreateConfigMap(true); - operator.replace(resource); + operator.createOrUpdate(resource); await().untilAsserted(() -> { assertThat(operator.get(ConfigMap.class, RESOURCE_NAME)).isNotNull(); @@ -109,7 +109,7 @@ private void markConfigMapForDelete() { cm.getMetadata().setAnnotations(new HashMap<>()); } cm.getMetadata().getAnnotations().put(READY_TO_DELETE_ANNOTATION, "true"); - operator.replace(cm); + operator.createOrUpdate(cm); } private WorkflowAllFeatureCustomResource customResource(boolean createConfigMap) { diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowMultipleActivationIT.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowMultipleActivationIT.java index a7f93935ee..14e40e57cd 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowMultipleActivationIT.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/WorkflowMultipleActivationIT.java @@ -61,7 +61,7 @@ void deactivatingAndReactivatingDependent() { ActivationCondition.MET = true; cr1.getSpec().setValue(CHANGED_VALUE); - extension.replace(cr1); + extension.createOrUpdate(cr1); await().untilAsserted(() -> { var cm = extension.get(ConfigMap.class, TEST_RESOURCE1); @@ -71,7 +71,7 @@ void deactivatingAndReactivatingDependent() { ActivationCondition.MET = false; cr1.getSpec().setValue(INITIAL_DATA); - extension.replace(cr1); + extension.createOrUpdate(cr1); await().pollDelay(Duration.ofMillis(POLL_DELAY)).untilAsserted(() -> { var cm = extension.get(ConfigMap.class, TEST_RESOURCE1); @@ -85,7 +85,7 @@ void deactivatingAndReactivatingDependent() { .getNumberOfReconciliationExecution(); var actualCM = extension.get(ConfigMap.class, TEST_RESOURCE1); actualCM.getData().put("data2", "additionaldata"); - extension.replace(actualCM); + extension.createOrUpdate(actualCM); await().pollDelay(Duration.ofMillis(POLL_DELAY)).untilAsserted(() -> { // change in config map does not induce reconciliation if inactive (thus informer is not // present) diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentTestBase.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentTestBase.java index 605731623c..c1e29a09ed 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentTestBase.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentTestBase.java @@ -88,26 +88,26 @@ public static BulkDependentTestCustomResource testResource() { private void updateSpecWithNewAdditionalData(String data) { var resource = testResource(); resource.getSpec().setAdditionalData(data); - extension().replace(resource); + extension().createOrUpdate(resource); } public static void updateSpecWithNewAdditionalData(LocallyRunOperatorExtension extension, String data) { var resource = testResource(); resource.getSpec().setAdditionalData(data); - extension.replace(resource); + extension.createOrUpdate(resource); } private void updateSpecWithNumber(int n) { var resource = testResource(); resource.getSpec().setNumberOfResources(n); - extension().replace(resource); + extension().createOrUpdate(resource); } public static void updateSpecWithNumber(LocallyRunOperatorExtension extension, int n) { var resource = testResource(); resource.getSpec().setNumberOfResources(n); - extension.replace(resource); + extension.createOrUpdate(resource); } abstract LocallyRunOperatorExtension extension(); diff --git a/sample-operators/webpage/src/test/java/io/javaoperatorsdk/operator/sample/WebPageOperatorAbstractTest.java b/sample-operators/webpage/src/test/java/io/javaoperatorsdk/operator/sample/WebPageOperatorAbstractTest.java index 040b3b2f8f..b0a15e66df 100644 --- a/sample-operators/webpage/src/test/java/io/javaoperatorsdk/operator/sample/WebPageOperatorAbstractTest.java +++ b/sample-operators/webpage/src/test/java/io/javaoperatorsdk/operator/sample/WebPageOperatorAbstractTest.java @@ -69,7 +69,7 @@ void testAddingWebPage() { assertThat(httpGetForWebPage(webPage)).contains(TITLE1); // update part: changing title - operator().replace(createWebPage(TITLE2)); + operator().createOrUpdate(createWebPage(TITLE2)); await().atMost(Duration.ofSeconds(LONG_WAIT_SECONDS)) .pollInterval(POLL_INTERVAL)