Skip to content

Commit 20134c9

Browse files
committed
correct ITs
Signed-off-by: Lukas Kral <lukywill16@gmail.com>
1 parent c9f798d commit 20134c9

5 files changed

Lines changed: 42 additions & 18 deletions

File tree

cluster-operator/src/test/java/io/strimzi/operator/cluster/operator/resource/kubernetes/AbstractNamespacedResourceOperatorServerSideApplyIT.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.HashMap;
2525
import java.util.Map;
2626

27+
import static java.util.Collections.singletonMap;
2728
import static org.hamcrest.MatcherAssert.assertThat;
2829
import static org.hamcrest.Matchers.is;
2930
import static org.hamcrest.Matchers.notNullValue;
@@ -42,6 +43,8 @@ public abstract class AbstractNamespacedResourceOperatorServerSideApplyIT<C exte
4243
R extends Resource<T>> extends AbstractNamespacedResourceOperatorIT<C, T, L, R> {
4344
protected static final Logger LOGGER = LogManager.getLogger(AbstractNamespacedResourceOperatorServerSideApplyIT.class);
4445

46+
abstract T getModifiedAnno();
47+
4548
@Test
4649
public void testCreateModifyDelete(VertxTestContext context) {
4750
Checkpoint async = context.checkpoint();
@@ -51,7 +54,7 @@ public void testCreateModifyDelete(VertxTestContext context) {
5154
T modResource = getModified();
5255

5356
Map<String, String> annotations = new HashMap<>();
54-
annotations.put("my-annotation", "my-value");
57+
annotations.put("my-annotation2", "my-value2");
5558

5659
op.reconcile(Reconciliation.DUMMY_RECONCILIATION, namespace, resourceName, newResource)
5760
.onComplete(context.succeeding(rrCreated -> {
@@ -72,6 +75,7 @@ public void testCreateModifyDelete(VertxTestContext context) {
7275
})
7376
.compose(rr -> op.reconcile(Reconciliation.DUMMY_RECONCILIATION, namespace, resourceName, modResource))
7477
.onComplete(context.succeeding(rrModified -> {
78+
annotations.put("my-annotation", "my-value2");
7579
T modified = op.get(namespace, resourceName);
7680

7781
assertThat(rrModified.getType(), is(ReconcileResult.Type.PATCHED_WITH_SERVER_SIDE_APPLY));
@@ -104,7 +108,7 @@ void testCreateModifyWithConflictAndDelete(VertxTestContext context) {
104108
T modResource = getModified();
105109

106110
Map<String, String> annotations = new HashMap<>();
107-
annotations.put("my-annotation", "my-value");
111+
annotations.put("my-annotation", "my-value2");
108112

109113
op.reconcile(Reconciliation.DUMMY_RECONCILIATION, namespace, resourceName, newResource)
110114
.onComplete(context.succeeding(rrCreated -> {
@@ -114,25 +118,17 @@ void testCreateModifyWithConflictAndDelete(VertxTestContext context) {
114118
assertResources(context, newResource, created);
115119
}))
116120
.andThen(rr -> {
117-
Map<String, String> anotherOperatorAnnos = new HashMap<>();
118-
anotherOperatorAnnos.put("my-annotation", "my-value2");
119-
120-
newResource.getMetadata().setAnnotations(anotherOperatorAnnos);
121-
// we need to set this to null otherwise SSA will keep the older label as it is and it will not be actually deleted
122-
// the next check using assertResources would then fail
123-
newResource.getMetadata().setLabels(null);
124-
125121
PatchContext patchContext = new PatchContext.Builder()
126122
.withFieldManager("another-operator")
127123
.withForce(false)
128124
.withPatchType(PatchType.SERVER_SIDE_APPLY)
129125
.build();
130126

131-
op.operation().inNamespace(namespace).withName(resourceName).patch(patchContext, newResource);
127+
op.operation().inNamespace(namespace).withName(resourceName).patch(patchContext, getModifiedAnno());
132128

133129
T currentResource = op.get(namespace, resourceName);
134130

135-
assertThat(currentResource.getMetadata().getAnnotations(), is(anotherOperatorAnnos));
131+
assertThat(currentResource.getMetadata().getAnnotations(), is(singletonMap("my-annotation", "my-value")));
136132
})
137133
.compose(rr -> op.reconcile(Reconciliation.DUMMY_RECONCILIATION, namespace, resourceName, modResource))
138134
.onComplete(context.succeeding(rrModified -> {

cluster-operator/src/test/java/io/strimzi/operator/cluster/operator/resource/kubernetes/AbstractNamespacedResourceOperatorTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import static org.mockito.Mockito.verify;
4848
import static org.mockito.Mockito.when;
4949

50-
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
5150
@ExtendWith(VertxExtension.class)
5251
public abstract class AbstractNamespacedResourceOperatorTest<C extends KubernetesClient, T extends HasMetadata,
5352
L extends KubernetesResourceList<T>, R extends Resource<T>> {
@@ -157,6 +156,10 @@ public void testCreateWhenExistsWithChangeIsAPatch(VertxTestContext context, boo
157156
}
158157

159158
@Test
159+
public void testCreateWhenExistsWithoutChangeIsNotAPatch(VertxTestContext context) {
160+
testCreateWhenExistsWithoutChangeIsNotAPatch(context, true);
161+
}
162+
160163
public void testCreateWhenExistsWithoutChangeIsNotAPatch(VertxTestContext context, boolean cascade) {
161164
T resource = resource();
162165
Resource mockResource = mock(resourceType());
@@ -252,7 +255,6 @@ public void testCreateOrUpdateThrowsWhenCreateThrows(VertxTestContext context) {
252255

253256
MixedOperation mockCms = mock(MixedOperation.class);
254257
when(mockCms.inNamespace(matches(resource.getMetadata().getNamespace()))).thenReturn(mockNameable);
255-
256258
when(mockResource.create()).thenThrow(ex);
257259

258260
C mockClient = mock(clientType());
@@ -591,9 +593,12 @@ public void testBatchReconciliation(VertxTestContext context) {
591593
verify(mockResource1, never()).patch(any(), any());
592594
verify(mockResource1, never()).create();
593595
verify(mockDeletable1, times(1)).delete();
596+
594597
verify(mockResource2, times(1)).get();
598+
verify(mockResource2, times(1)).patch(any(), eq(resource2Mod));
595599
verify(mockResource2, never()).create();
596600
verify(mockResource2, never()).delete();
601+
597602
verify(mockResource3, times(1)).get();
598603
verify(mockResource3, never()).patch(any(), any());
599604
verify(mockResource3, times(1)).create();

cluster-operator/src/test/java/io/strimzi/operator/cluster/operator/resource/kubernetes/ServiceAccountOperatorServerSideApplyIT.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ protected ServiceAccount getModified() {
4242
.withName(resourceName)
4343
.withNamespace(namespace)
4444
.withLabels(singletonMap("foo2", "bar2"))
45+
.withAnnotations(singletonMap("my-annotation", "my-value2"))
46+
.endMetadata()
47+
.build();
48+
}
49+
50+
@Override
51+
protected ServiceAccount getModifiedAnno() {
52+
return new ServiceAccountBuilder()
53+
.withNewMetadata()
54+
.withName(resourceName)
55+
.withNamespace(namespace)
4556
.withAnnotations(singletonMap("my-annotation", "my-value"))
4657
.endMetadata()
4758
.build();

cluster-operator/src/test/java/io/strimzi/operator/cluster/operator/resource/kubernetes/ServiceOperatorServerSideApplyIT.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ protected Service getModified() {
6565
.withName(resourceName)
6666
.withNamespace(namespace)
6767
.withLabels(singletonMap("state", "modified"))
68+
.withAnnotations(singletonMap("my-annotation", "my-value2"))
6869
.endMetadata()
6970
.withNewSpec()
7071
.withType("ClusterIP")
@@ -74,6 +75,17 @@ protected Service getModified() {
7475
.build();
7576
}
7677

78+
@Override
79+
protected Service getModifiedAnno() {
80+
return new ServiceBuilder()
81+
.withNewMetadata()
82+
.withName(resourceName)
83+
.withNamespace(namespace)
84+
.withAnnotations(singletonMap("my-annotation", "my-value"))
85+
.endMetadata()
86+
.build();
87+
}
88+
7789
@Override
7890
protected void assertResources(VertxTestContext context, Service expected, Service actual) {
7991
context.verify(() -> assertThat(actual.getMetadata().getName(), is(expected.getMetadata().getName())));

packaging/install/cluster-operator/060-Deployment-strimzi-cluster-operator.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ spec:
2727
name: strimzi-cluster-operator
2828
containers:
2929
- name: strimzi-cluster-operator
30-
image: quay.io/lkral/operator:server-side-apply-arm64
30+
image: quay.io/strimzi/operator:latest
3131
ports:
3232
- containerPort: 8080
3333
name: http
@@ -67,11 +67,11 @@ spec:
6767
3.9.1=quay.io/strimzi/kafka:latest-kafka-3.9.1
6868
4.0.0=quay.io/strimzi/kafka:latest-kafka-4.0.0
6969
- name: STRIMZI_DEFAULT_TOPIC_OPERATOR_IMAGE
70-
value: quay.io/lkral/operator:server-side-apply-arm64
70+
value: quay.io/strimzi/operator:latest
7171
- name: STRIMZI_DEFAULT_USER_OPERATOR_IMAGE
72-
value: quay.io/lkral/operator:server-side-apply-arm64
72+
value: quay.io/strimzi/operator:latest
7373
- name: STRIMZI_DEFAULT_KAFKA_INIT_IMAGE
74-
value: quay.io/lkral/operator:server-side-apply-arm64
74+
value: quay.io/strimzi/operator:latest
7575
- name: STRIMZI_DEFAULT_KAFKA_BRIDGE_IMAGE
7676
value: quay.io/strimzi/kafka-bridge:0.32.0
7777
- name: STRIMZI_DEFAULT_KANIKO_EXECUTOR_IMAGE

0 commit comments

Comments
 (0)