Skip to content

Commit 58e2a38

Browse files
authored
improve: glue for glue operator handling (#91)
Signed-off-by: Attila Mészáros <[email protected]>
1 parent 11f41cd commit 58e2a38

13 files changed

+53
-37
lines changed

Diff for: src/main/java/io/csviri/operator/glue/reconciler/glue/GlueReconciler.java

+16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.csviri.operator.glue.dependent.GenericDependentResource;
1919
import io.csviri.operator.glue.dependent.GenericResourceDiscriminator;
2020
import io.csviri.operator.glue.reconciler.ValidationAndErrorHandler;
21+
import io.csviri.operator.glue.reconciler.operator.GlueOperatorReconciler;
2122
import io.csviri.operator.glue.templating.GenericTemplateHandler;
2223
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
2324
import io.fabric8.kubernetes.api.model.HasMetadata;
@@ -30,6 +31,7 @@
3031
import io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowBuilder;
3132

3233
import static io.csviri.operator.glue.Utils.getResourceForSSAFrom;
34+
import static io.csviri.operator.glue.reconciler.operator.GlueOperatorReconciler.FOR_GLUE_OPERATOR_LABEL_VALUE;
3335
import static io.csviri.operator.glue.reconciler.operator.GlueOperatorReconciler.PARENT_RELATED_RESOURCE_NAME;
3436

3537
@ControllerConfiguration(name = GlueReconciler.GLUE_RECONCILER_NAME)
@@ -222,6 +224,9 @@ private Condition toCondition(ConditionSpec condition) {
222224
}
223225

224226
private void addFinalizersToParentResource(Glue primary, Context<Glue> context) {
227+
if (!isGlueOfAGlueOperator(primary)) {
228+
return;
229+
}
225230
var parent = getParentRelatedResource(primary, context);
226231

227232
parent.ifPresent(p -> {
@@ -237,6 +242,9 @@ private void addFinalizersToParentResource(Glue primary, Context<Glue> context)
237242
}
238243

239244
private void removeFinalizerForParent(Glue primary, Context<Glue> context) {
245+
if (!isGlueOfAGlueOperator(primary)) {
246+
return;
247+
}
240248
var parent = getParentRelatedResource(primary, context);
241249
parent.ifPresentOrElse(p -> {
242250
log.debug("Removing finalizer from parent. Glue name: {} namespace: {}",
@@ -295,4 +303,12 @@ public ErrorStatusUpdateControl<Glue> updateErrorStatus(Glue resource, Context<G
295303
}
296304
return validationAndErrorHandler.updateStatusErrorMessage(e, resource);
297305
}
306+
307+
public static boolean isGlueOfAGlueOperator(Glue glue) {
308+
var labelValue =
309+
glue.getMetadata().getLabels().get(GlueOperatorReconciler.FOR_GLUE_OPERATOR_LABEL_KEY);
310+
return FOR_GLUE_OPERATOR_LABEL_VALUE.equals(labelValue);
311+
312+
}
313+
298314
}

Diff for: src/main/java/io/csviri/operator/glue/reconciler/operator/GlueOperatorReconciler.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public class GlueOperatorReconciler
3737

3838
private static final Logger log = LoggerFactory.getLogger(GlueOperatorReconciler.class);
3939

40-
public static final String GLUE_LABEL_KEY = "foroperator";
41-
public static final String GLUE_LABEL_VALUE = "true";
40+
public static final String FOR_GLUE_OPERATOR_LABEL_KEY = "for-glue-operator";
41+
public static final String FOR_GLUE_OPERATOR_LABEL_VALUE = "true";
4242
public static final String PARENT_RELATED_RESOURCE_NAME = "parent";
4343
public static final String GLUE_OPERATOR_RECONCILER_NAME = "glue-operator";
4444

@@ -98,7 +98,7 @@ private Glue createGlue(GenericKubernetesResource targetParentResource,
9898
.withName(
9999
glueName(targetParentResource.getMetadata().getName(), targetParentResource.getKind()))
100100
.withNamespace(targetParentResource.getMetadata().getNamespace())
101-
.withLabels(Map.of(GLUE_LABEL_KEY, GLUE_LABEL_VALUE))
101+
.withLabels(Map.of(FOR_GLUE_OPERATOR_LABEL_KEY, FOR_GLUE_OPERATOR_LABEL_VALUE))
102102
.build());
103103
glue.setSpec(toWorkflowSpec(glueOperator.getSpec()));
104104

@@ -160,7 +160,7 @@ public Map<String, EventSource> prepareEventSources(
160160
EventSourceContext<GlueOperator> eventSourceContext) {
161161
glueEventSource = new InformerEventSource<>(
162162
InformerConfiguration.from(Glue.class, eventSourceContext)
163-
.withLabelSelector(GLUE_LABEL_KEY + "=" + GLUE_LABEL_VALUE)
163+
.withLabelSelector(FOR_GLUE_OPERATOR_LABEL_KEY + "=" + FOR_GLUE_OPERATOR_LABEL_VALUE)
164164
.build(),
165165
eventSourceContext);
166166
return EventSourceInitializer.nameEventSources(glueEventSource);

Diff for: src/test/java/io/csviri/operator/glue/GlueLabelSelectorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class GlueLabelSelectorTest extends TestBase {
2727
@Test
2828
void testLabelSelectorHandling() {
2929
Glue glue =
30-
TestUtils.loadResoureFlow("/glue/SimpleGlue.yaml");
30+
TestUtils.loadGlue("/glue/SimpleGlue.yaml");
3131
glue = create(glue);
3232

3333
await().pollDelay(INITIAL_RECONCILE_WAIT_TIMEOUT).untilAsserted(() -> {

Diff for: src/test/java/io/csviri/operator/glue/GlueOperatorComplexLabelSelectorTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ void applyCRD() {
3333

3434
@Test
3535
void testGlueOperatorLabelSelector() {
36-
var go = create(TestUtils
37-
.loadResourceFlowOperator("/glueoperator/SimpleGlueOperator.yaml"));
36+
create(TestUtils
37+
.loadGlueOperator("/glueoperator/SimpleGlueOperator.yaml"));
3838

3939
var testCR = create(TestData.testCustomResource());
4040

@@ -49,7 +49,7 @@ void testGlueOperatorLabelSelector() {
4949
});
5050

5151
delete(testCR);
52-
await().untilAsserted(() -> {
52+
await().timeout(TestUtils.GC_WAIT_TIMEOUT).untilAsserted(() -> {
5353
var glue = get(Glue.class, GlueOperatorReconciler.glueName(testCR.getMetadata().getName(),
5454
testCR.getKind()));
5555
assertThat(glue).isNull();

Diff for: src/test/java/io/csviri/operator/glue/GlueOperatorLabelSelectorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void applyCRD() {
3636
@Test
3737
void testGlueOperatorLabelSelector() {
3838
var go = create(TestUtils
39-
.loadResourceFlowOperator("/glueoperator/SimpleGlueOperator.yaml"));
39+
.loadGlueOperator("/glueoperator/SimpleGlueOperator.yaml"));
4040

4141
var testCR = create(TestData.testCustomResource());
4242

Diff for: src/test/java/io/csviri/operator/glue/GlueOperatorTest.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import io.quarkus.test.junit.QuarkusTest;
2020

2121
import static io.csviri.operator.glue.TestData.*;
22-
import static io.csviri.operator.glue.TestUtils.GC_WAIT_TIMEOUT_SECOND;
22+
import static io.csviri.operator.glue.TestUtils.GC_WAIT_TIMEOUT;
2323
import static io.csviri.operator.glue.customresource.TestCustomResource.CR_GROUP;
2424
import static org.assertj.core.api.Assertions.assertThat;
2525
import static org.awaitility.Awaitility.await;
@@ -55,7 +55,7 @@ void smokeTest() {
5555
@Test
5656
void templating() {
5757
create(TestUtils
58-
.loadResourceFlowOperator("/glueoperator/SimpleGlueOperator.yaml"));
58+
.loadGlueOperator("/glueoperator/SimpleGlueOperator.yaml"));
5959

6060
var cr = create(testCustomResource());
6161
String initialValue = cr.getSpec().getValue();
@@ -78,7 +78,7 @@ void templating() {
7878

7979
delete(cr);
8080

81-
await().timeout(Duration.ofMinutes(5)).untilAsserted(() -> {
81+
await().timeout(GC_WAIT_TIMEOUT).untilAsserted(() -> {
8282
var cm1 = get(ConfigMap.class, name);
8383
var actualCR = get(TestCustomResource.class, name);
8484
assertThat(cm1).isNull();
@@ -91,7 +91,7 @@ void templating() {
9191
void simpleConcurrencyTest() {
9292
int num = 10;
9393
create(TestUtils
94-
.loadResourceFlowOperator("/glueoperator/Concurrency.yaml"));
94+
.loadGlueOperator("/glueoperator/Concurrency.yaml"));
9595

9696
var resources =
9797
IntStream.range(0, num).mapToObj(n -> create(testCustomResource(n))).toList();
@@ -115,9 +115,9 @@ void simpleConcurrencyTest() {
115115
void simpleConcurrencyForMultipleOperatorTest() {
116116
int num = 10;
117117
create(TestUtils
118-
.loadResourceFlowOperator("/glueoperator/Concurrency.yaml"));
118+
.loadGlueOperator("/glueoperator/Concurrency.yaml"));
119119
create(TestUtils
120-
.loadResourceFlowOperator("/glueoperator/Concurrency2.yaml"));
120+
.loadGlueOperator("/glueoperator/Concurrency2.yaml"));
121121

122122
var crs =
123123
IntStream.range(0, num).mapToObj(n -> create(testCustomResource(n))).toList();
@@ -137,7 +137,7 @@ void simpleConcurrencyForMultipleOperatorTest() {
137137
crs.forEach(this::delete);
138138
cr2s.forEach(this::delete);
139139

140-
await().timeout(GC_WAIT_TIMEOUT_SECOND)
140+
await().timeout(GC_WAIT_TIMEOUT)
141141
.untilAsserted(() -> IntStream.range(0, num).forEach(n -> {
142142
var cm = get(ConfigMap.class, TEST_RESOURCE_PREFIX + n);
143143
assertThat(cm).isNull();
@@ -149,7 +149,7 @@ void simpleConcurrencyForMultipleOperatorTest() {
149149
@Test
150150
void nonUniqueNameTest() {
151151
var go = create(TestUtils
152-
.loadResourceFlowOperator("/glueoperator/NonUniqueName.yaml"));
152+
.loadGlueOperator("/glueoperator/NonUniqueName.yaml"));
153153

154154
await().untilAsserted(() -> {
155155
var actual = get(GlueOperator.class, go.getMetadata().getName());
@@ -163,7 +163,7 @@ void nonUniqueNameTest() {
163163
@Test
164164
void parentWithLabelSelector() {
165165
create(TestUtils
166-
.loadResourceFlowOperator("/glueoperator/ParentLabelSelector.yaml"));
166+
.loadGlueOperator("/glueoperator/ParentLabelSelector.yaml"));
167167

168168
var cr = create(testCustomResource());
169169
String name = cr.getMetadata().getName();

Diff for: src/test/java/io/csviri/operator/glue/GlueRelatedResourcesTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void applyCRD() {
3434
void simpleRelatedResourceUsage() {
3535
create(secret());
3636
Glue glue =
37-
TestUtils.loadResoureFlow("/glue/RelatedResourceSimpleWithCondition.yaml");
37+
TestUtils.loadGlue("/glue/RelatedResourceSimpleWithCondition.yaml");
3838

3939
create(glue);
4040

@@ -64,7 +64,7 @@ void multipleResourceNamesInRelated() {
6464
create(secret("test-secret2", BASE64_VALUE_2));
6565

6666
Glue glue =
67-
create(TestUtils.loadResoureFlow("/glue/MultiNameRelatedResource.yaml"));
67+
create(TestUtils.loadGlue("/glue/MultiNameRelatedResource.yaml"));
6868

6969
await().untilAsserted(() -> {
7070
var cm1 = get(ConfigMap.class, "cm1");
@@ -85,7 +85,7 @@ void multipleResourceNamesInRelated() {
8585
void managedAndRelatedResourceOfSameTypeAndTriggering() {
8686
var relatedConfigMap = create(configMap());
8787
Glue glue =
88-
create(TestUtils.loadResoureFlow("/glue/RelatesResourceSameType.yaml"));
88+
create(TestUtils.loadGlue("/glue/RelatesResourceSameType.yaml"));
8989

9090
await().untilAsserted(() -> {
9191
var cm1 = get(ConfigMap.class, "cm1");

Diff for: src/test/java/io/csviri/operator/glue/GlueResourceLabelSelectorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class GlueResourceLabelSelectorTest extends TestBase {
1818

1919
@Test
2020
void showCreatingResourceWithLabelSelectorAndLabel() {
21-
var glue = create(TestUtils.loadResoureFlow("/glue/SimpleGlueWithLabeledResource.yaml"));
21+
var glue = create(TestUtils.loadGlue("/glue/SimpleGlueWithLabeledResource.yaml"));
2222

2323
// this serves more like a sample, hard to test here if the label selector is on informer
2424
await().untilAsserted(() -> {

Diff for: src/test/java/io/csviri/operator/glue/GlueTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class GlueTest extends TestBase {
2727
@Test
2828
void simpleTemplating() {
2929
Glue glue =
30-
TestUtils.loadResoureFlow("/glue/Templating.yaml");
30+
TestUtils.loadGlue("/glue/Templating.yaml");
3131
glue = create(glue);
3232

3333
await().untilAsserted(() -> {
@@ -64,7 +64,7 @@ void simpleTemplating() {
6464
@Test
6565
void crossReferenceResource() {
6666
Glue glue =
67-
TestUtils.loadResoureFlow("/glue/CrossReferenceResource.yaml");
67+
TestUtils.loadGlue("/glue/CrossReferenceResource.yaml");
6868
glue = create(glue);
6969

7070
await().untilAsserted(() -> {
@@ -103,7 +103,7 @@ void crossReferenceResource() {
103103
@Test
104104
void javaScriptCondition() {
105105
Glue glue =
106-
TestUtils.loadResoureFlow("/glue/TwoResourcesAndCondition.yaml");
106+
TestUtils.loadGlue("/glue/TwoResourcesAndCondition.yaml");
107107
create(glue);
108108

109109
await().pollDelay(Duration.ofMillis(150)).untilAsserted(() -> {
@@ -138,7 +138,7 @@ void javaScriptCondition() {
138138

139139
@Test
140140
void stringTemplate() {
141-
Glue glue = create(TestUtils.loadResoureFlow("/glue/ResourceTemplate.yaml"));
141+
Glue glue = create(TestUtils.loadGlue("/glue/ResourceTemplate.yaml"));
142142

143143
await().timeout(Duration.ofSeconds(120)).untilAsserted(() -> {
144144
var cm1 = get(ConfigMap.class, "templconfigmap1");
@@ -188,7 +188,7 @@ void simpleConcurrencyTest() {
188188

189189
@Test
190190
void changingWorkflow() {
191-
Glue glue = create(TestUtils.loadResoureFlow("/glue/ChanginResources.yaml"));
191+
Glue glue = create(TestUtils.loadGlue("/glue/ChanginResources.yaml"));
192192

193193
await().untilAsserted(() -> {
194194
var cm1 = get(ConfigMap.class, "configmap1");
@@ -226,7 +226,7 @@ void changingWorkflow() {
226226

227227
@Test
228228
void nonUniqueNameResultsInErrorMessageOnStatus() {
229-
Glue glue = create(TestUtils.loadResoureFlow("/glue/NonUniqueName.yaml"));
229+
Glue glue = create(TestUtils.loadGlue("/glue/NonUniqueName.yaml"));
230230

231231
await().untilAsserted(() -> {
232232
var actualGlue = get(Glue.class, glue.getMetadata().getName());
@@ -271,7 +271,7 @@ private List<Glue> testWorkflowList(int num) {
271271
List<Glue> res = new ArrayList<>();
272272
IntStream.range(0, num).forEach(index -> {
273273
Glue w =
274-
TestUtils.loadResoureFlow("/glue/TemplateForConcurrency.yaml");
274+
TestUtils.loadGlue("/glue/TemplateForConcurrency.yaml");
275275
w.getMetadata().setName(w.getMetadata().getName() + index);
276276
res.add(w);
277277
});

Diff for: src/test/java/io/csviri/operator/glue/TestUtils.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@
2424

2525
public class TestUtils {
2626

27-
public static final Duration GC_WAIT_TIMEOUT_SECOND = Duration.ofSeconds(45);
27+
public static final Duration GC_WAIT_TIMEOUT = Duration.ofSeconds(90);
2828
public static final Duration INITIAL_RECONCILE_WAIT_TIMEOUT = Duration.ofMillis(150);
2929

3030
public static final int CRD_READY_WAIT = 1000;
3131

3232

3333
private static final Logger log = LoggerFactory.getLogger(TestUtils.class);
3434

35-
public static Glue loadResoureFlow(String path) {
35+
public static Glue loadGlue(String path) {
3636
try (InputStream is = TestUtils.class.getResourceAsStream(path)) {
3737
return Serialization.unmarshal(is, Glue.class);
3838
} catch (IOException e) {
3939
throw new RuntimeException(e);
4040
}
4141
}
4242

43-
public static GlueOperator loadResourceFlowOperator(String path) {
43+
public static GlueOperator loadGlueOperator(String path) {
4444
try (InputStream is = TestUtils.class.getResourceAsStream(path)) {
4545
return Serialization.unmarshal(is, GlueOperator.class);
4646
} catch (IOException e) {

Diff for: src/test/java/io/csviri/operator/glue/sample/mutation/MutationWebhookDeploymentE2E.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
1717
import io.fabric8.kubernetes.client.dsl.NonDeletingOperation;
1818

19-
import static io.csviri.operator.glue.TestUtils.GC_WAIT_TIMEOUT_SECOND;
19+
import static io.csviri.operator.glue.TestUtils.GC_WAIT_TIMEOUT;
2020
import static org.assertj.core.api.Assertions.assertThat;
2121
import static org.awaitility.Awaitility.await;
2222

@@ -55,7 +55,7 @@ void testMutationHookDeployment() {
5555

5656
client.resource(glue).delete();
5757

58-
await().timeout(GC_WAIT_TIMEOUT_SECOND).untilAsserted(() -> {
58+
await().timeout(GC_WAIT_TIMEOUT).untilAsserted(() -> {
5959
var deployment = client.apps().deployments().withName("pod-mutating-hook").get();
6060
assertThat(deployment).isNull();
6161
});

Diff for: src/test/java/io/csviri/operator/glue/sample/webpage/WebPageE2E.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
1616
import io.fabric8.kubernetes.client.dsl.NonDeletingOperation;
1717

18-
import static io.csviri.operator.glue.TestUtils.GC_WAIT_TIMEOUT_SECOND;
18+
import static io.csviri.operator.glue.TestUtils.GC_WAIT_TIMEOUT;
1919
import static org.assertj.core.api.Assertions.assertThat;
2020
import static org.awaitility.Awaitility.await;
2121

@@ -62,7 +62,7 @@ void testWebPageCRUDOperations() {
6262

6363
client.resource(createdWebPage).delete();
6464

65-
await().timeout(GC_WAIT_TIMEOUT_SECOND).untilAsserted(() -> {
65+
await().timeout(GC_WAIT_TIMEOUT).untilAsserted(() -> {
6666
var deployment =
6767
client.resources(Deployment.class).withName(webPage.getMetadata().getName()).get();
6868
var configMap =

Diff for: src/test/java/io/csviri/operator/glue/sample/webpage/WebPageSampleTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void webPageCRUD() {
6060

6161
delete(webPage);
6262

63-
await().timeout(TestUtils.GC_WAIT_TIMEOUT_SECOND).untilAsserted(() -> {
63+
await().timeout(TestUtils.GC_WAIT_TIMEOUT).untilAsserted(() -> {
6464
var deployment = get(Deployment.class, webPage.getMetadata().getName());
6565
assertThat(deployment).isNull();
6666
});

0 commit comments

Comments
 (0)