Skip to content

Commit a6fd772

Browse files
lilicjmrodri
authored andcommitted
doc/user/metrics/README.md: Add garbage collection (#1176)
Explain how to replace the default `deployments/finalizers` role in case user is using another way of creating the operator pod(s).
1 parent 4228df0 commit a6fd772

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

doc/user/metrics/README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Monitoring with Prometheus
22

3-
[Prometheus][prometheus] is an open-source systems monitoring and alerting toolkit. Below is the overview of the different helpers that exist in operator-sdk to help setup metrics in the generated operator.
3+
[Prometheus][prometheus] is an open-source systems monitoring and alerting toolkit. Below is the overview of the different helpers that exist in Operator SDK to help setup metrics in the generated operator.
44

5-
## Metrics in operator-sdk
5+
## Metrics in Operator SDK
66

77
The `func ExposeMetricsPort(ctx context.Context, port int32) (*v1.Service, error)` function exposes general metrics about the running program. These metrics are inherited from controller-runtime. This helper function creates a [Service][service] object with the metrics port exposed, which can then be accessed by Prometheus. The Service object is [garbage collected][gc] when the leader pod's root owner is deleted.
88

@@ -43,9 +43,28 @@ By default, the metrics are served on `0.0.0.0:8383/metrics`. To modify the port
4343
}
4444
```
4545

46-
*Note:* The above example is already present in `cmd/manager/main.go` in all the operators generated with operator-sdk.
46+
*Note:* The above example is already present in `cmd/manager/main.go` in all the operators generated with Operator SDK from v0.5.0 onwards.
47+
48+
### Garbage collection
49+
50+
The metrics Service is [garbage collected][gc] when the resource used to deploy the operator is deleted (e.g. `Deployment`). This resource is determined when the metrics Service is created, at that time the resource owner reference is added to the Service.
51+
52+
In Kubernetes clusters where [OwnerReferencesPermissionEnforcement][ownerref-permission] is enabled (on by default in all OpenShift clusters), the role requires a `<RESOURCE-KIND>/finalizers` rule to be added. By default when creating the operator with the Operator SDK, this is done automatically under the assumption that the `Deployment` object was used to create the operator pods. In case another method of deploying the operator is used, replace the `- deployments/finalizers` in the `deploy/role.yaml` file. Example rule from `deploy/role.yaml` file for deploying operator with a `StatefulSet`:
53+
54+
```yaml
55+
...
56+
- apiGroups:
57+
- apps
58+
resourceNames:
59+
- <STATEFULSET-NAME>
60+
resources:
61+
- statefulsets/finalizers
62+
verbs:
63+
- update
64+
...
65+
```
4766

4867
[prometheus]: https://prometheus.io/
4968
[service]: https://kubernetes.io/docs/concepts/services-networking/service/
5069
[gc]: https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/#owners-and-dependents
51-
70+
[ownerref-permission]: https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#ownerreferencespermissionenforcement

0 commit comments

Comments
 (0)