Skip to content

Commit e08ef60

Browse files
committed
Adding a propsal for changing the KRO instance and resource labels
1 parent bb56ff2 commit e08ef60

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

docs/design/proposals/labels.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Proposal: Standardize KRO Labels
2+
3+
## Problem statement
4+
5+
The current labels in KRO are used to track ownership and metadata of resources managed by the orchestrator. While these labels provide essential information, they lack a clear and standardized way to represent the relationships between different KRO components, such as ResourceGraphDefinitions (RGDs), instances, and the resources they generate. This ambiguity can make it difficult to query for related objects and understand the provenance of resources within a cluster.
6+
7+
Specifically, we need a clearer way to identify:
8+
1. Which RGD is responsible for reconciling a given instance.
9+
2. Which RGD a created resource originates from.
10+
3. Which instance a created resource belongs to.
11+
12+
This proposal aims to introduce new, more descriptive labels to clarify these relationships, aligning with Kubernetes best practices for resource management and observability.
13+
14+
## Proposal
15+
16+
We propose introducing a set of standardized labels to better represent the relationships between RGDs, instances, and the resources they manage. This will improve the ability to discover, manage, and debug resources created and managed by KRO.
17+
18+
#### Overview
19+
20+
The proposal is to add the following labels:
21+
- A label on an instance to indicate which RGD is reconciling it.
22+
- A label on resources created by an instance reconciliation to indicate which RGD they come from.
23+
- Labels on resources created by an instance reconciliation to indicate which instance created them.
24+
25+
This aligns with the common Kubernetes practice of using labels for discovery and organization of related resources, as seen in tools like Helm and Kustomize.
26+
27+
#### Design details
28+
29+
We will introduce the following new labels, which will be defined in `@pkg/metadata/labels.go`:
30+
31+
1. **Label for an instance being reconciled:**
32+
- **Proposed Label:** `kro.run/reconciled-by`
33+
- **Value:** The name of the ResourceGraphDefinition (e.g., `my-rgd-name`).
34+
- **Purpose:** To indicate that an instance is being actively reconciled against a specific RGD. This label will be applied to the instance itself.
35+
- **Alternative Names:** `kro.run/reconciling-rgd`, `kro.run/template`.
36+
37+
2. **Label for resources created during instance reconciliation:**
38+
- **Proposed Label:** `kro.run/created-by`
39+
- **Value:** The name of the ResourceGraphDefinition (e.g., `my-rgd-name`).
40+
- **Purpose:** To identify which RGD was used as a template to create a resource during the reconciliation of an instance. This label will be applied to all resources created by the instance controller.
41+
- **Alternative Names:** `kro.run/managed-by-rgd`, `kro.run/owner-rgd`, `kro.run/template-rgd`. The `managed-by` label is a common pattern in the Kubernetes ecosystem.
42+
43+
3. **Labels for resources to link back to the instance:**
44+
- **Proposed Labels:**
45+
- `kro.run/managed-by-instance-group`: The API group of the instance (e.g., `mygroup.example.com`).
46+
- `kro.run/managed-by-instance-kind`: The kind of the instance (e.g., `MyKind`).
47+
- `kro.run/managed-by-instance-namespace`: The namespace of the instance (e.g., `default`).
48+
- `kro.run/managed-by-instance-name`: The name of the instance (e.g., `my-instance`).
49+
- The `managed-by` label is a common pattern in the Kubernetes ecosystem.
50+
- **Purpose:** To provide a direct and queryable link from a created resource back to the instance that caused its creation. This set of labels uniquely identifies the instance.
51+
- **Alternative Name prefix:** `kro.run/owner-`, `kro.run/created-by-`, etc.
52+
53+
## Other solutions considered
54+
55+
We could continue using the existing labels, but their purpose is not as explicit for relationship tracking, which can lead to confusion for users and client tools. We could also use annotations, but labels are better suited for this purpose as they are queryable via the Kubernetes API, which is a key requirement for observability and tooling.
56+
57+
## Scoping
58+
59+
#### What is in scope for this proposal?
60+
61+
- Defining and adding the new labels to the KRO API.
62+
- Updating the instance controller to apply these labels to instances and created resources during reconciliation.
63+
- Updating the official KRO documentation to reflect the new labels and their usage.
64+
65+
#### What is not in scope?
66+
67+
- Removing or deprecating the existing labels. This could be considered in a future proposal to maintain backward compatibility.
68+
- Changing how KRO uses annotations.
69+
70+
## Testing strategy
71+
72+
#### Requirements
73+
74+
- A running Kubernetes cluster to deploy KRO and test the label application.
75+
76+
#### Test plan
77+
78+
- **Unit tests:** Add unit tests for any new labeler functions in `pkg/metadata/labels.go` to ensure they construct the correct labels.
79+
- **Integration tests:**
80+
- Create an RGD and an instance of that RGD.
81+
- Verify that the instance object has the `kro.run/reconciled-by` label pointing to the RGD.
82+
- Verify that all resources created by the instance reconciliation have the `kro.run/created-by` label, and the `kro.run/instance-group`, `kro.run/instance-kind`, `kro.run/instance-namespace`, and `kro.run/instance-name` labels with the correct values.
83+
- Update an instance to be reconciled by a different RGD and verify that the `kro.run/reconciled-by` label is updated accordingly.

0 commit comments

Comments
 (0)