Skip to content

Commit 28d389c

Browse files
committed
feat: label selectors for parent resource for GlueOperator
Signed-off-by: Attila Mészáros <[email protected]>
1 parent 6c3e636 commit 28d389c

File tree

6 files changed

+63
-9
lines changed

6 files changed

+63
-9
lines changed

src/main/java/io/csviri/operator/glue/customresource/operator/Parent.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ public class Parent {
44

55
private String apiVersion;
66
private String kind;
7+
private String labelSelector;
78

89
public Parent(String apiVersion, String kind) {
910
this.apiVersion = apiVersion;
1011
this.kind = kind;
1112
}
1213

13-
public Parent() {}
14-
1514
public String getApiVersion() {
1615
return apiVersion;
1716
}
@@ -29,4 +28,12 @@ public Parent setKind(String kind) {
2928
this.kind = kind;
3029
return this;
3130
}
31+
32+
public String getLabelSelector() {
33+
return labelSelector;
34+
}
35+
36+
public void setLabelSelector(String labelSelector) {
37+
this.labelSelector = labelSelector;
38+
}
3239
}

src/main/java/io/csviri/operator/glue/reconciler/operator/GlueOperatorReconciler.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,17 @@ private InformerEventSource<GenericKubernetesResource, GlueOperator> getOrRegist
139139
.getResourceEventSourceFor(GenericKubernetesResource.class, gvk.toString());
140140
es.start();
141141
} catch (IllegalArgumentException e) {
142-
es = new InformerEventSource<>(InformerConfiguration.from(gvk,
142+
var configBuilder = InformerConfiguration.from(gvk,
143143
context.eventSourceRetriever().eventSourceContextForDynamicRegistration())
144144
.withSecondaryToPrimaryMapper(
145-
resource -> Set.of(ResourceID.fromResource(glueOperator)))
146-
.build(), context.eventSourceRetriever().eventSourceContextForDynamicRegistration());
145+
resource -> Set.of(ResourceID.fromResource(glueOperator)));
146+
147+
if (spec.getParent().getLabelSelector() != null) {
148+
configBuilder.withLabelSelector(spec.getParent().getLabelSelector());
149+
}
150+
151+
es = new InformerEventSource<>(configBuilder.build(),
152+
context.eventSourceRetriever().eventSourceContextForDynamicRegistration());
147153
context.eventSourceRetriever().dynamicallyRegisterEventSource(gvk.toString(), es);
148154
}
149155
return es;

src/test/java/io/csviri/operator/glue/GlueOperatorComplexLabelSelectorTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ void testGlueOperatorLabelSelector() {
5454
testCR.getKind()));
5555
assertThat(glue).isNull();
5656
});
57-
delete(go);
5857
}
5958

6059
public static class GlueOperatorComplexLabelSelectorTestProfile implements QuarkusTestProfile {

src/test/java/io/csviri/operator/glue/GlueOperatorLabelSelectorTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ void testGlueOperatorLabelSelector() {
6363
testCR.getKind()));
6464
assertThat(glue).isNull();
6565
});
66-
delete(go);
6766
}
6867

6968
public static class GlueOperatorLabelSelectorTestProfile implements QuarkusTestProfile {

src/test/java/io/csviri/operator/glue/GlueOperatorTest.java

+27-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
@QuarkusTest
2828
class GlueOperatorTest extends TestBase {
2929

30-
31-
3230
@BeforeEach
3331
void applyCRD() {
3432
TestUtils.applyTestCrd(client, TestCustomResource.class, TestCustomResource2.class);
@@ -162,6 +160,33 @@ void nonUniqueNameTest() {
162160
});
163161
}
164162

163+
@Test
164+
void parentWithLabelSelector() {
165+
create(TestUtils
166+
.loadResourceFlowOperator("/glueoperator/ParentLabelSelector.yaml"));
167+
168+
var cr = create(testCustomResource());
169+
String name = cr.getMetadata().getName();
170+
171+
await().pollDelay(TestUtils.INITIAL_RECONCILE_WAIT_TIMEOUT).untilAsserted(() -> {
172+
var cm1 = get(ConfigMap.class, name);
173+
assertThat(cm1).isNull();
174+
});
175+
176+
cr.getMetadata().getLabels().put("mylabel", "value");
177+
update(cr);
178+
179+
await().untilAsserted(() -> {
180+
var cm1 = get(ConfigMap.class, name);
181+
assertThat(cm1).isNotNull();
182+
});
183+
184+
delete(cr);
185+
await().untilAsserted(() -> {
186+
var cm1 = get(ConfigMap.class, name);
187+
assertThat(cm1).isNull();
188+
});
189+
}
165190

166191

167192
GlueOperator testWorkflowOperator() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: io.csviri.operator.glue/v1beta1
2+
kind: GlueOperator
3+
metadata:
4+
name: templating-sample
5+
spec:
6+
parent:
7+
apiVersion: io.csviri.operator.glue/v1
8+
kind: TestCustomResource
9+
labelSelector: "mylabel=value"
10+
childResources:
11+
- name: configMap1
12+
resource:
13+
apiVersion: v1
14+
kind: ConfigMap
15+
metadata:
16+
name: "{parent.metadata.name}"
17+
data:
18+
key: "{parent.spec.value}"

0 commit comments

Comments
 (0)