Skip to content

Commit 71a294a

Browse files
committed
MGMT-21395: Add cluster monitoring label to operators's namespace with monitoring enabled by default
To provide a consistent, out-of-the-box monitoring experience, the Assisted Installer automatically enables cluster monitoring for all operators that support this feature (i.e., those with the "Enable Operator-recommended cluster monitoring..." option in OperatorHub). This choice is enabled by default and cannot be changed by the user during the assisted installation process. To enforce this, the Assisted Installer's code must perform two key actions for each monitoring-aware operator: 1. apply the openshift.io/cluster-monitoring=true label to the operator's pre-created namespace 2. if an operator does not provide its own RBAC, the installer code is responsible for creating the standard Prometheus Role and RoleBinding in the operator's namespace. Note: When a developer adds a new operator to Assisted, they are responsible for the following: 1. Check the operator's CSV for the openshift.io/cluster-monitoring=true annotation. If the annotation is present, add the openshift.io/cluster-monitoring=true namespace label. 2. Check if the operator already includes its own Prometheus Role and RoleBinding. If not, add the logic to the installer to create them.
1 parent 97571e5 commit 71a294a

File tree

11 files changed

+116
-5
lines changed

11 files changed

+116
-5
lines changed

docs/dev/olm-operator-plugins.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,11 @@ The first return value could be used to specify a set of manifests that will be
148148
manifest for creating a new namespace, a new subscription and a new operator group CR for the involved operator.
149149

150150
The second return value it's a manifest used to configure the freshly installed operator, and it will be applied by the ```assisted-installer-controller``` job, only after the cluster have been successfully created and the OLM operators are all ready (currently the ```assisted-installer-controller``` retrieves the whole list of configurations by downloading the ```custom_manifests.json``` file fetched from the Assisted Service).
151+
152+
## General Notes
153+
154+
### Cluster Monitoring
155+
156+
When adding a new operator:
157+
1. Check the operator's CSV for the ```openshift.io/cluster-monitoring=true``` annotation. If the annotation is present, add the ```openshift.io/cluster-monitoring=true``` namespace label.
158+
2. Check if the operator already includes its own Prometheus Role and RoleBinding. If not, add the logic to the installer to create them.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apiVersion: v1
22
kind: Namespace
33
metadata:
4-
name: {{ .Operator.Namespace }}
4+
name: {{ .Operator.Namespace }}
5+
labels:
6+
openshift.io/cluster-monitoring: "true"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
3+
metadata:
4+
name: {{ .Operator.Namespace }}-prometheus-k8s
5+
namespace: {{ .Operator.Namespace }}
6+
rules:
7+
- apiGroups:
8+
- ""
9+
resources:
10+
- services
11+
- endpoints
12+
- pods
13+
verbs:
14+
- get
15+
- list
16+
- watch
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: RoleBinding
3+
metadata:
4+
name: {{ .Operator.Namespace }}-prometheus-k8s
5+
namespace: {{ .Operator.Namespace }}
6+
roleRef:
7+
apiGroup: rbac.authorization.k8s.io
8+
kind: Role
9+
name: {{ .Operator.Namespace }}-prometheus-k8s
10+
subjects:
11+
- kind: ServiceAccount
12+
name: prometheus-k8s
13+
namespace: openshift-monitoring

internal/operators/clusterobservability/templates/openshift/50_cluster_observability_namespace.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ apiVersion: v1
22
kind: Namespace
33
metadata:
44
name: {{ .Operator.Namespace }}
5+
labels:
6+
openshift.io/cluster-monitoring: "true"
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apiVersion: v1
22
kind: Namespace
33
metadata:
4-
name: {{ .Operator.Namespace }}
4+
name: {{ .Operator.Namespace }}
5+
labels:
6+
openshift.io/cluster-monitoring: "true"

internal/operators/lso/manifest.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func Manifests() (map[string][]byte, []byte, error) {
4343
openshiftManifests["50_openshift-lso_ns.yaml"] = []byte(localStorageNamespace)
4444
openshiftManifests["50_openshift-lso_operator_group.yaml"] = []byte(lsoOperatorGroup)
4545
openshiftManifests["50_openshift-lso_subscription.yaml"] = lsoSubs
46+
openshiftManifests["50_openshift-lso_prometheus-role.yaml"] = []byte(localStoragePrometheusRole)
47+
openshiftManifests["50_openshift-lso_prometheus-rolebinding.yaml"] = []byte(localStoragePrometheusRoleBinding)
4648
return openshiftManifests, []byte(localVolumeSet), nil
4749
}
4850

@@ -60,7 +62,9 @@ spec:
6062
const localStorageNamespace = `apiVersion: v1
6163
kind: Namespace
6264
metadata:
63-
name: openshift-local-storage`
65+
name: openshift-local-storage
66+
labels:
67+
openshift.io/cluster-monitoring: "true"`
6468

6569
const localVolumeSet = `apiVersion: "local.storage.openshift.io/v1alpha1"
6670
kind: "LocalVolumeSet"
@@ -73,3 +77,34 @@ spec:
7377
deviceInclusionSpec:
7478
deviceTypes:
7579
- "disk"`
80+
81+
const localStoragePrometheusRole = `apiVersion: "rbac.authorization.k8s.io/v1"
82+
kind: "Role"
83+
metadata:
84+
name: "openshift-local-storage-prometheus-k8s"
85+
namespace: "openshift-local-storage"
86+
rules:
87+
- apiGroups:
88+
- ""
89+
resources:
90+
- "services"
91+
- "endpoints"
92+
- "pods"
93+
verbs:
94+
- "get"
95+
- "list"
96+
- "watch"`
97+
98+
const localStoragePrometheusRoleBinding = `apiVersion: "rbac.authorization.k8s.io/v1"
99+
kind: "RoleBinding"
100+
metadata:
101+
name: "openshift-local-storage-prometheus-k8s"
102+
namespace: "openshift-local-storage"
103+
roleRef:
104+
apiGroup: "rbac.authorization.k8s.io"
105+
kind: "Role"
106+
name: "openshift-local-storage-prometheus-k8s"
107+
subjects:
108+
- kind: "ServiceAccount"
109+
name: "prometheus-k8s"
110+
namespace: "openshift-monitoring"`
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apiVersion: v1
22
kind: Namespace
33
metadata:
4-
name: {{ .Operator.Namespace }}
4+
name: {{ .Operator.Namespace }}
5+
labels:
6+
openshift.io/cluster-monitoring: "true"
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apiVersion: v1
22
kind: Namespace
33
metadata:
4-
name: {{ .Operator.Namespace }}
4+
name: {{ .Operator.Namespace }}
5+
labels:
6+
openshift.io/cluster-monitoring: "true"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
3+
metadata:
4+
name: {{ .Operator.Namespace }}-prometheus-k8s
5+
namespace: {{ .Operator.Namespace }}
6+
rules:
7+
- apiGroups:
8+
- ""
9+
resources:
10+
- services
11+
- endpoints
12+
- pods
13+
verbs:
14+
- get
15+
- list
16+
- watch

0 commit comments

Comments
 (0)