Skip to content

feat: label selectors for parent resource for GlueOperator #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ The `DependentResource` implementation of JOSDK makes all kinds of optimizations
## [GlueOperator resource](https://github.com/csviri/kubernetes-glue-operator/releases/latest/download/glueoperators.glue-v1.yml)

The specs of `GlueOperator` are almost identical to `Glue`, it just adds one additional attribute **`parent`**,
which has two sub-attributes: **`apiVersion`** and **`kind`**. This structure specifies the resource
types - usually but not necessarily custom resources - watched.
which has the following sub-attributes:
- **`apiVersion`** and **`kind`** - specifies the resources to reconciler according to the spec.
Targets are usually custom resources but not necessarily, it also works with built-in Kubernetes
resources.
- **`labelSelector`** - an optional label selector for the target resources

See minimal `GlueOperator` [here](https://github.com/csviri/kubernetes-glue-operator/blob/main/src/test/resources/glueoperator/Templating.yaml).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ public class Parent {

private String apiVersion;
private String kind;
private String labelSelector;

public Parent() {}

public Parent(String apiVersion, String kind) {
this.apiVersion = apiVersion;
this.kind = kind;
}

public Parent() {}

public String getApiVersion() {
return apiVersion;
}
Expand All @@ -29,4 +30,12 @@ public Parent setKind(String kind) {
this.kind = kind;
return this;
}

public String getLabelSelector() {
return labelSelector;
}

public void setLabelSelector(String labelSelector) {
this.labelSelector = labelSelector;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,17 @@ private InformerEventSource<GenericKubernetesResource, GlueOperator> getOrRegist
.getResourceEventSourceFor(GenericKubernetesResource.class, gvk.toString());
es.start();
} catch (IllegalArgumentException e) {
es = new InformerEventSource<>(InformerConfiguration.from(gvk,
var configBuilder = InformerConfiguration.from(gvk,
context.eventSourceRetriever().eventSourceContextForDynamicRegistration())
.withSecondaryToPrimaryMapper(
resource -> Set.of(ResourceID.fromResource(glueOperator)))
.build(), context.eventSourceRetriever().eventSourceContextForDynamicRegistration());
resource -> Set.of(ResourceID.fromResource(glueOperator)));

if (spec.getParent().getLabelSelector() != null) {
configBuilder.withLabelSelector(spec.getParent().getLabelSelector());
}

es = new InformerEventSource<>(configBuilder.build(),
context.eventSourceRetriever().eventSourceContextForDynamicRegistration());
context.eventSourceRetriever().dynamicallyRegisterEventSource(gvk.toString(), es);
}
return es;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ void testGlueOperatorLabelSelector() {
testCR.getKind()));
assertThat(glue).isNull();
});
delete(go);
}

public static class GlueOperatorComplexLabelSelectorTestProfile implements QuarkusTestProfile {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ void testGlueOperatorLabelSelector() {
testCR.getKind()));
assertThat(glue).isNull();
});
delete(go);
}

public static class GlueOperatorLabelSelectorTestProfile implements QuarkusTestProfile {
Expand Down
29 changes: 27 additions & 2 deletions src/test/java/io/csviri/operator/glue/GlueOperatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
@QuarkusTest
class GlueOperatorTest extends TestBase {



@BeforeEach
void applyCRD() {
TestUtils.applyTestCrd(client, TestCustomResource.class, TestCustomResource2.class);
Expand Down Expand Up @@ -162,6 +160,33 @@ void nonUniqueNameTest() {
});
}

@Test
void parentWithLabelSelector() {
create(TestUtils
.loadResourceFlowOperator("/glueoperator/ParentLabelSelector.yaml"));

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

await().pollDelay(TestUtils.INITIAL_RECONCILE_WAIT_TIMEOUT).untilAsserted(() -> {
var cm1 = get(ConfigMap.class, name);
assertThat(cm1).isNull();
});

cr.getMetadata().getLabels().put("mylabel", "value");
update(cr);

await().untilAsserted(() -> {
var cm1 = get(ConfigMap.class, name);
assertThat(cm1).isNotNull();
});

delete(cr);
await().untilAsserted(() -> {
var cm1 = get(ConfigMap.class, name);
assertThat(cm1).isNull();
});
}


GlueOperator testWorkflowOperator() {
Expand Down
18 changes: 18 additions & 0 deletions src/test/resources/glueoperator/ParentLabelSelector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: io.csviri.operator.glue/v1beta1
kind: GlueOperator
metadata:
name: templating-sample
spec:
parent:
apiVersion: io.csviri.operator.glue/v1
kind: TestCustomResource
labelSelector: "mylabel=value"
childResources:
- name: configMap1
resource:
apiVersion: v1
kind: ConfigMap
metadata:
name: "{parent.metadata.name}"
data:
key: "{parent.spec.value}"
Loading