Skip to content

Commit 5d2fd46

Browse files
authored
improve: rename resources to childResources in CRDs (#82)
Signed-off-by: Attila Mészáros <[email protected]>
1 parent 97bc450 commit 5d2fd46

29 files changed

+58
-57
lines changed

Diff for: README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ spec:
6161
parent:
6262
apiVersion: glueoperator.sample/v1 # watches all the custom resource of type WebPage
6363
kind: WebPage
64-
resources:
64+
childResources:
6565
- name: htmlconfigmap
6666
resource:
6767
apiVersion: v1
@@ -109,7 +109,7 @@ spec:
109109
```
110110

111111
There are multiple aspects to see here. The four related resources will be templated
112-
and applied to the cluster if such a resource is created. The reconciliation will be triggered if anything changes in the custom or managed resources.
112+
and applied to the cluster if such a resource is created. The reconciliation will be triggered if anything changes in the custom or child resources.
113113

114114
Note also the `condition` part for `Ingress` resource contains multiple types of conditions, `JSCondition` is
115115
used in this example, which allows writing conditions in Javascript. The `Ingress` will be created if the `.spec.exposed` property
@@ -137,7 +137,7 @@ kind: Glue
137137
metadata:
138138
name: mutation-webhook-deployment
139139
spec:
140-
resources:
140+
childResources:
141141
- name: service
142142
resource:
143143
apiVersion: v1

Diff for: docs/reference.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@ Although it is limited only to Kubernetes resources it makes it very easy to use
99
## [Glue resource](https://github.com/csviri/kubernetes-glue-operator/releases/latest/download/glues.glue-v1.yml)
1010

1111
`Glue` is the heart of the operator. Note that `GlueOperator` controller just creates a new `Glue` with a related resource,
12-
for each parent custom resource. `Glue` defines `resources` (sometimes referred to as managed resources) and `related resources`:
12+
for each parent custom resource. `Glue` defines `childResources` (sometimes referred to as managed resources) and `related resources`:
1313

14-
### Managed resources
14+
### Child Resources
1515

1616
#### Attributes
1717

18-
The `resources` section is a list of resources to be reconciled. It has several attributes:
18+
The `childResources` section is a list of resources to be reconciled (created, updated, deleted by controller).
19+
It has several attributes:
1920

2021
- **`name`** - is a mandatory unique (unique also regarding related resources) attribute.
2122
The resource is referenced by this name from other places, typically other resource templates and `JSCondition`.
2223
If it is used in a `JSCondition` the `name` must be a valid JavaScript variable name.
2324
- **`resource`** - is the desired state of the resource applied by default using Server Side Apply. The resource is templated using
2425
[qute templating engine](https://quarkus.io/guides/qute-reference), other resources can be referenced from the templates, see below.
25-
There is a restriction, that the managed resource is namespaced, and the namespace is always the same as the namespace of the `Glue`
26+
There is a restriction, that the child resource is namespaced, and the namespace is always the same as the namespace of the `Glue`
2627
(and/or parent for `GlueOperator`), so the `namespace` field in resource **metadata should not be specified**.
27-
- **`dependsOn`** - is a list of names of other managed resources (not related resources). The resource is not reconciled until all the resources
28+
- **`dependsOn`** - is a list of names of other child resources (not related resources). The resource is not reconciled until all the resources
2829
which it depends on are not reconciled and ready (if there is a `readyPostCondition` present).
2930
Note that during the cleanup phase (when a `Glue` is deleted) resources are cleaned up in reverse order.
3031
- **`condition`** - a condition to specify if the resource should be there or not, thus even if the condition is evaluated to be `true`
@@ -39,17 +40,17 @@ At the moment there are two types of built-in conditions provided:
3940

4041
- **`ReadyCondition`** - check if a resource is up and running. Use it only as a `readyPostCondition`. See sample usage [here](https://github.com/csviri/kubernetes-glue-operator/blob/main/src/test/resources/sample/mutation/mutation.glue.yaml#L24-L25).
4142
- **`JSCondition`** - a generic condition, that allows writing conditions in JavaScript. As input, all the resources are available which
42-
are either managed or related. The script should return a boolean value.
43+
are either child or related. The script should return a boolean value.
4344
See accessing the related resource in [WebPage sample](https://github.com/csviri/kubernetes-glue-operator/blob/main/src/test/resources/sample/webpage/webpage.operator.yaml#L62-L64),
4445
and cross-referencing resources [here](https://github.com/csviri/kubernetes-glue-operator/blob/main/src/test/resources/glue/TwoResourcesAndCondition.yaml#L23-L28).
4546

4647
### Related resources
4748

48-
Related resources are resources that are not managed (not created, updated, or deleted) during reconciliation, but serve as an input for it.
49+
Related resources are resources that are not reconciled (not created, updated, or deleted) during reconciliation, but serve as an input for it.
4950
See sample usage within `Glue` [here](https://github.com/csviri/kubernetes-glue-operator/blob/main/src/test/resources/glue/RelatedResourceSimpleWithCondition.yaml)
5051
The following attributes can be defined for a related resource:
5152

52-
- **`name`** - same as for managed resource, unique identifier, used to reference the resource.
53+
- **`name`** - same as for child resource, unique identifier, used to reference the resource.
5354
- **`apiVersion`** - Kubernetes resource API Version of the resource
5455
- **`kind`** - Kubernetes kind property of the resource
5556
- **`resourceNames`** - list of string of the resource names within the same namespace as `Glue`.
@@ -71,9 +72,9 @@ In addition to that in `GlueOperator` the **`parent`** attribute can be used to
7172

7273
### Reconciliation notes
7374

74-
The reconciliation is triggered either on a change of the `Glue` or any managed or related resources.
75+
The reconciliation is triggered either on a change of the `Glue` or any child or related resources.
7576

76-
On every reconciliation, each managed resource is reconciled, and if a resource is updated, it is added to a cache, so it is available for templating
77+
On every reconciliation, each child resource is reconciled, and if a resource is updated, it is added to a cache, so it is available for templating
7778
for a resource that depends on it.
7879

7980
The `DependentResource` implementation of JOSDK makes all kinds of optimizations on the reconciliation which are utilized (or will be also here).
@@ -98,7 +99,7 @@ While we will provide more options, users are encouraged to enhance/adjust this
9899

99100
Since the project is a meta-controller, it needs to have access rights to all the resources it manages.
100101
When creating specialized roles for a deployment, roles should contain the union of required access rights
101-
for all the managed resources, specifically: `["list", "watch", "create", "patch", "delete"]`
102+
for all the child resources, specifically: `["list", "watch", "create", "patch", "delete"]`
102103
and `["list", "watch"]` for related resources.
103104

104105
The project is mainly tested with cluster-scoped deployment, however, QOSDK namespace-scoped deployments are also supported.

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static Map<String, GenericKubernetesResource> getActualResourcesByNameInW
3030
var secondaryResources = context.getSecondaryResources(GenericKubernetesResource.class);
3131
Map<String, GenericKubernetesResource> res = new HashMap<>();
3232
secondaryResources.forEach(sr -> {
33-
var dependentSpec = glue.getSpec().getResources().stream()
33+
var dependentSpec = glue.getSpec().getChildResources().stream()
3434
.filter(r -> Utils.getApiVersion(r).equals(sr.getApiVersion())
3535
&& Utils.getKind(r).equals(sr.getKind())
3636
// comparing the name from annotation since the resource name might be templated in spec
@@ -139,8 +139,8 @@ public static String getKindFromTemplate(String resourceTemplate) {
139139

140140
public static Set<String> leafResourceNames(Glue glue) {
141141
Set<String> result = new HashSet<>();
142-
glue.getSpec().getResources().forEach(r -> result.add(r.getName()));
143-
glue.getSpec().getResources().forEach(r -> {
142+
glue.getSpec().getChildResources().forEach(r -> result.add(r.getName()));
143+
glue.getSpec().getChildResources().forEach(r -> {
144144
r.getDependsOn().forEach(result::remove);
145145
});
146146
return result;

Diff for: src/main/java/io/csviri/operator/glue/customresource/glue/GlueSpec.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66

77
public class GlueSpec {
88

9-
private List<DependentResourceSpec> resources = new ArrayList<>();
9+
private List<DependentResourceSpec> childResources = new ArrayList<>();
1010

1111
private List<RelatedResourceSpec> relatedResources = new ArrayList<>();
1212

13-
public List<DependentResourceSpec> getResources() {
14-
return resources;
13+
public List<DependentResourceSpec> getChildResources() {
14+
return childResources;
1515
}
1616

17-
public void setResources(List<DependentResourceSpec> resources) {
18-
this.resources = resources;
17+
public void setChildResources(List<DependentResourceSpec> childResources) {
18+
this.childResources = childResources;
1919
}
2020

2121
public List<RelatedResourceSpec> getRelatedResources() {
@@ -30,7 +30,7 @@ public GlueSpec setRelatedResources(List<RelatedResourceSpec> relatedResources)
3030
@Override
3131
public String toString() {
3232
return "GlueSpec{" +
33-
"resources=" + resources +
33+
"resources=" + childResources +
3434
'}';
3535
}
3636

@@ -41,11 +41,11 @@ public boolean equals(Object o) {
4141
if (o == null || getClass() != o.getClass())
4242
return false;
4343
GlueSpec that = (GlueSpec) o;
44-
return Objects.equals(resources, that.resources);
44+
return Objects.equals(childResources, that.childResources);
4545
}
4646

4747
@Override
4848
public int hashCode() {
49-
return Objects.hash(resources);
49+
return Objects.hash(childResources);
5050
}
5151
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void checkIfNamesAreUnique(GlueSpec glueSpec) {
5353
seen.add(n);
5454
}
5555
};
56-
glueSpec.getResources().stream().map(DependentResourceSpec::getName).forEach(deduplicate);
56+
glueSpec.getChildResources().stream().map(DependentResourceSpec::getName).forEach(deduplicate);
5757
glueSpec.getRelatedResources().stream().map(RelatedResourceSpec::getName).forEach(deduplicate);
5858

5959
if (!duplicates.isEmpty()) {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void cleanupRemovedResourcesFromWorkflow(Context<Glue> context,
126126
context.getSecondaryResources(GenericKubernetesResource.class).forEach(r -> {
127127
String dependentName = r.getMetadata().getAnnotations().get(DEPENDENT_NAME_ANNOTATION_KEY);
128128
// dependent name is null for related resources
129-
if (dependentName != null && primary.getSpec().getResources().stream()
129+
if (dependentName != null && primary.getSpec().getChildResources().stream()
130130
.filter(pr -> pr.getName().equals(dependentName)).findAny().isEmpty()) {
131131
try {
132132
log.debug("Deleting resource with name: {}", dependentName + "for resource flow: {} "
@@ -146,7 +146,7 @@ private io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow<Glue>
146146
Set<String> leafDependentNames = Utils.leafResourceNames(primary);
147147

148148
Map<String, GenericDependentResource> genericDependentResourceMap = new HashMap<>();
149-
primary.getSpec().getResources().forEach(spec -> createAndAddDependentToWorkflow(primary,
149+
primary.getSpec().getChildResources().forEach(spec -> createAndAddDependentToWorkflow(primary,
150150
context, spec, genericDependentResourceMap, builder,
151151
leafDependentNames.contains(spec.getName())));
152152

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public synchronized void deRegisterInformerOnResourceFlowChange(Context<Glue> co
3333
var registeredGVKSet =
3434
new HashSet<>(glueToInformerGVK.get(primary.getMetadata().getName()));
3535

36-
var currentGVKSet = primary.getSpec().getResources().stream()
36+
var currentGVKSet = primary.getSpec().getChildResources().stream()
3737
.map(Utils::getGVK)
3838
.collect(Collectors.toSet());
3939

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private Glue createResourceFlow(GenericKubernetesResource targetParentResource,
9999

100100
private GlueSpec toWorkflowSpec(GlueOperatorSpec spec) {
101101
var res = new GlueSpec();
102-
res.setResources(new ArrayList<>(spec.getResources()));
102+
res.setChildResources(new ArrayList<>(spec.getChildResources()));
103103
res.setRelatedResources(new ArrayList<>(spec.getRelatedResources()));
104104
return res;
105105
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ GlueOperator testWorkflowOperator() {
197197
wo.setSpec(spec);
198198
spec.setParent(new Parent(CR_GROUP + "/v1", TestCustomResource.class.getSimpleName()));
199199

200-
spec.setResources(new ArrayList<>());
200+
spec.setChildResources(new ArrayList<>());
201201
DependentResourceSpec drs = new DependentResourceSpec();
202-
spec.getResources().add(drs);
202+
spec.getChildResources().add(drs);
203203
drs.setResource(TestUtils.load("/ConfigMap.yaml"));
204204
drs.setName("configMap1");
205205
return wo;

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void simpleTemplating() {
3939
assertThat(cm2.getData().get("valueFromCM1")).isEqualTo("value1");
4040
});
4141

42-
((Map<String, String>) glue.getSpec().getResources().get(0).getResource()
42+
((Map<String, String>) glue.getSpec().getChildResources().get(0).getResource()
4343
.getAdditionalProperties().get("data"))
4444
.put("key", CHANGED_VALUE);
4545

@@ -77,7 +77,7 @@ void crossReferenceResource() {
7777
});
7878

7979
var resourceTemplate =
80-
glue.getSpec().getResources().stream().filter(r -> r.getName().equals("configMap1"))
80+
glue.getSpec().getChildResources().stream().filter(r -> r.getName().equals("configMap1"))
8181
.findAny().orElseThrow().getResource();
8282
// set new value
8383
((Map<String, String>) resourceTemplate.getAdditionalProperties().get("data")).put("key",
@@ -113,7 +113,7 @@ void javaScriptCondition() {
113113
assertThat(cm2).isNull();
114114
});
115115

116-
Map<String, String> map = (Map<String, String>) glue.getSpec().getResources()
116+
Map<String, String> map = (Map<String, String>) glue.getSpec().getChildResources()
117117
.get(0).getResource().getAdditionalProperties().get("data");
118118
map.put("createOther", "true");
119119

@@ -197,8 +197,8 @@ void changingWorkflow() {
197197
assertThat(cm2).isNotNull();
198198
});
199199

200-
glue.getSpec().getResources().remove(1);
201-
glue.getSpec().getResources().add(new DependentResourceSpec()
200+
glue.getSpec().getChildResources().remove(1);
201+
glue.getSpec().getChildResources().add(new DependentResourceSpec()
202202
.setName("secret")
203203
.setResource(TestUtils.load("/Secret.yaml")));
204204

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ void injectsSecondaryResourcesResource() {
7373

7474
Glue glue = new Glue();
7575
glue.setSpec(new GlueSpec());
76-
glue.getSpec().setResources(new ArrayList<>());
76+
glue.getSpec().setChildResources(new ArrayList<>());
7777
var drSpec = new DependentResourceSpec();
7878
drSpec.setName(DR_NAME);
7979
drSpec.setResource(configMap());
80-
glue.getSpec().getResources().add(drSpec);
80+
glue.getSpec().getChildResources().add(drSpec);
8181

8282
var condition = new JavaScripCondition("""
8383
secondary.data.key1 == "val1";

Diff for: src/test/resources/glue/ChanginResources.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Glue
33
metadata:
44
name: rf-to-change
55
spec:
6-
resources:
6+
childResources:
77
- name: configMap1
88
resource:
99
apiVersion: v1

Diff for: src/test/resources/glue/ClusterScopeResource.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Glue
33
metadata:
44
name: "glue1"
55
spec:
6-
resources:
6+
childResources:
77
- name: cluster-scoped-resource
88
resource:
99
apiVersion: io.csviri.operator.glue/v1

Diff for: src/test/resources/glue/CrossReferenceResource.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Glue
33
metadata:
44
name: "crossreference"
55
spec:
6-
resources:
6+
childResources:
77
- name: configMap1
88
resource:
99
apiVersion: v1

Diff for: src/test/resources/glue/MultiNameRelatedResource.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Glue
33
metadata:
44
name: related-resource-test1
55
spec:
6-
resources:
6+
childResources:
77
- name: configMap1
88
resource:
99
apiVersion: v1

Diff for: src/test/resources/glue/NonUniqueName.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ kind: Glue
44
metadata:
55
name: templating-sample
66
spec:
7-
resources:
7+
childResources:
88
- name: configMap1
99
resource:
1010
apiVersion: v1

Diff for: src/test/resources/glue/RelatedResourceSimpleWithCondition.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Glue
33
metadata:
44
name: related-resource-test1
55
spec:
6-
resources:
6+
childResources:
77
- name: configMap1
88
resource:
99
apiVersion: v1

Diff for: src/test/resources/glue/RelatesResourceSameType.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Glue
33
metadata:
44
name: related-resource-test1
55
spec:
6-
resources:
6+
childResources:
77
- name: configMap1
88
resource:
99
apiVersion: v1

Diff for: src/test/resources/glue/ResourceInDifferentNamespace.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Glue
33
metadata:
44
name: "testglue"
55
spec:
6-
resources:
6+
childResources:
77
- name: configMap1
88
resource:
99
apiVersion: v1

Diff for: src/test/resources/glue/ResourceTemplate.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Glue
33
metadata:
44
name: resource-templating-sample
55
spec:
6-
resources:
6+
childResources:
77
- name: configMap1
88
resourceTemplate: |
99
apiVersion: v1

Diff for: src/test/resources/glue/TemplateForConcurrency.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Glue
33
metadata:
44
name: "concurrencysample"
55
spec:
6-
resources:
6+
childResources:
77
- name: configMap1
88
resource:
99
apiVersion: v1

Diff for: src/test/resources/glue/Templating.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Glue
33
metadata:
44
name: templating-sample
55
spec:
6-
resources:
6+
childResources:
77
- name: configMap1
88
resource:
99
apiVersion: v1

Diff for: src/test/resources/glue/TwoResourcesAndCondition.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Glue
33
metadata:
44
name: two-resource-cross-condition
55
spec:
6-
resources:
6+
childResources:
77
- name: configMap1
88
resource:
99
apiVersion: v1

Diff for: src/test/resources/glueoperator/Concurrency.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ spec:
66
parent:
77
apiVersion: io.csviri.operator.glue/v1
88
kind: TestCustomResource
9-
resources:
9+
childResources:
1010
- name: configMap1
1111
resource:
1212
apiVersion: v1

Diff for: src/test/resources/glueoperator/Concurrency2.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ spec:
66
parent:
77
apiVersion: io.csviri.operator.glue/v1
88
kind: TestCustomResource2
9-
resources:
9+
childResources:
1010
- name: configMap1
1111
resource:
1212
apiVersion: v1

0 commit comments

Comments
 (0)