-
Notifications
You must be signed in to change notification settings - Fork 9
Description
The crate operator does not find pods to restart as the app.kubernetes.io/managed-by label copied over from the cratedb resource is not overwritten.
We are using helm to deploy a cratedb definition to the cluster and as of Helm 3.2 (quite old) it adds automatically the app.kubernetes.io/managed-by label with the value Helm to it. This ends up in the StatefulSet which gets initially deployed. On an update of the cratedb version attribute the StatefulSet gets updated, but the operator cannot find the pods to restart as the value of the managed-by label is not set to crate-operator.
It looks like in the following snippet that label gets overwritten by the one from the cratedb resource.
crate-operator/crate/operator/handlers/handle_create_cratedb.py
Lines 61 to 68 in ae24778
| base_labels = { | |
| LABEL_MANAGED_BY: "crate-operator", | |
| LABEL_NAME: name, | |
| LABEL_PART_OF: "cratedb", | |
| } | |
| cratedb_labels = base_labels.copy() | |
| cratedb_labels[LABEL_COMPONENT] = "cratedb" | |
| cratedb_labels.update(meta.get("labels", {})) |
Also the lookup of the pods are defined in the following snippet validates my assumption
crate-operator/crate/operator/operations.py
Lines 139 to 157 in ae24778
| async def get_pods_in_cluster( | |
| core: CoreV1Api, namespace: str, name: str | |
| ) -> Tuple[Tuple[str], Tuple[str]]: | |
| """ | |
| Return a two-tuple with two tuples, the first containing all pod IDs, the | |
| second the corresponding pod names within the cluster. | |
| :param core: An instance of the Kubernetes Core V1 API. | |
| :param namespace: The Kubernetes namespace where to look up the CrateDB | |
| cluster. | |
| :param name: The CrateDB custom resource name defining the CrateDB cluster. | |
| """ | |
| labels = { | |
| LABEL_COMPONENT: "cratedb", | |
| LABEL_MANAGED_BY: "crate-operator", | |
| LABEL_NAME: name, | |
| LABEL_PART_OF: "cratedb", | |
| } | |
| label_selector = ",".join(f"{k}={v}" for k, v in labels.items()) |
I'm guessing the sequence should be turned around that the StatefulSet managed-by label should have the correct value of crate-operator.
Steps to reproduce
- Create a cratedb resource with the label
app.kubernetes.io/manged-by: foobar - a statefulset with that label will be created by by the operator
- update the version of the cratedb created in step1
- StatefulSet gets updated, but the pods were not restarted