Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions manifests/0000_90_console-operator_01_prometheusrbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Role for accessing metrics exposed by the console-operator
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: prometheus-k8s
namespace: openshift-console-operator
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enable metrics to scrape in console-operator and console namespaces.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont actually have a /metrics endpoint exposed for console, yet.

rules:
- apiGroups:
- ""
resources:
- services
- endpoints
- pods
verbs:
- get
- list
- watch
---
# Grant cluster-monitoring access to console-operator metrics
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: prometheus-k8s
namespace: openshift-console-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: prometheus-k8s
subjects:
- kind: ServiceAccount
name: prometheus-k8s
namespace: openshift-monitoring
21 changes: 21 additions & 0 deletions manifests/0000_90_console-operator_02_servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Configure cluster-monitoring for console-operator
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: console-operator
namespace: openshift-console-operator
spec:
endpoints:
- bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
interval: 30s
path: /metrics
Comment thread
benjaminapetersen marked this conversation as resolved.
port: https
scheme: https
tlsConfig:
caFile: /etc/prometheus/configmaps/serving-certs-ca-bundle/service-ca.crt
serverName: metrics.openshift-console-operator.svc
jobLabel: component
selector:
matchLabels:
name: console-operator

2 changes: 2 additions & 0 deletions manifests/02-namespace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ metadata:
name: openshift-console-operator
annotations:
openshift.io/node-selector: ""
labels:
openshift.io/cluster-monitoring: "true"
29 changes: 29 additions & 0 deletions manifests/04-rbac-rolebinding-cluster.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
apiVersion: rbac.authorization.k8s.io/v1
Comment thread
benjaminapetersen marked this conversation as resolved.
kind: ClusterRoleBinding
metadata:
name: console-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: console-operator
subjects:
- kind: ServiceAccount
name: console-operator
namespace: openshift-console-operator
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
Expand All @@ -10,3 +23,19 @@ subjects:
- kind: Group
name: system:authenticated
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: console-operator-auth-delegator
roleRef:
# for protected endpoints like /metrics, the operator must perform
# authentication (tokenreview) & authorization (subjectaccessreview)
# which are granted by this ClusterRole
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: console-operator
namespace: openshift-console-operator
28 changes: 15 additions & 13 deletions manifests/04-rbac-rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@ subjects:
- kind: ServiceAccount
name: console-operator
---
apiVersion: rbac.authorization.k8s.io/v1
Comment thread
benjaminapetersen marked this conversation as resolved.
kind: ClusterRoleBinding
metadata:
name: console-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: console-operator
subjects:
- kind: ServiceAccount
name: console-operator
namespace: openshift-console-operator
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
Expand Down Expand Up @@ -79,3 +66,18 @@ subjects:
- kind: ServiceAccount
name: console-operator
namespace: openshift-console-operator
---
kind: RoleBinding
Comment thread
benjaminapetersen marked this conversation as resolved.
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: console-operator
namespace: kube-system
roleRef:
kind: Role
name: extension-apiserver-authentication-reader
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: console-operator
namespace: openshift-console-operator

4 changes: 0 additions & 4 deletions manifests/05-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ data:
kind: GenericOperatorConfig
leaderElection:
namespace: openshift-console-operator
authentication:
Comment thread
benjaminapetersen marked this conversation as resolved.
disabled: true
authorization:
disabled: true
20 changes: 20 additions & 0 deletions manifests/05-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Expose operator metrics
apiVersion: v1
kind: Service
metadata:
annotations:
service.alpha.openshift.io/serving-cert-secret-name: serving-cert
labels:
name: console-operator
name: metrics
Comment thread
benjaminapetersen marked this conversation as resolved.
namespace: openshift-console-operator
spec:
ports:
- name: https
port: 443
protocol: TCP
targetPort: 8443
selector:
name: console-operator
sessionAffinity: None
type: ClusterIP
6 changes: 6 additions & 0 deletions manifests/07-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ spec:
volumeMounts:
- mountPath: /var/run/configmaps/config
name: config
- mountPath: /var/run/secrets/serving-cert
Comment thread
benjaminapetersen marked this conversation as resolved.
name: serving-cert
env:
- name: IMAGE
value: registry.svc.ci.openshift.org/openshift:console
Expand All @@ -65,3 +67,7 @@ spec:
- name: config
configMap:
name: console-operator-config
- name: serving-cert
secret:
secretName: serving-cert
optional: true
27 changes: 27 additions & 0 deletions pkg/console/operator/sync_v400.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"os"

"github.com/prometheus/client_golang/prometheus"

// kube
oauthv1 "github.com/openshift/api/oauth/v1"
routev1 "github.com/openshift/api/route/v1"
Expand Down Expand Up @@ -35,6 +37,19 @@ import (
servicesub "github.com/openshift/console-operator/pkg/console/subresource/service"
)

var (
// metric: console_url{url="https://<url>"} 1
Comment thread
benjaminapetersen marked this conversation as resolved.
consoleURLMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Comment thread
benjaminapetersen marked this conversation as resolved.
Name: "console_url",
Help: "URL of the console exposed on the cluster",
// one label
}, []string{"url"})
)

func init() {
prometheus.MustRegister(consoleURLMetric)
}

// The sync loop starts from zero and works its way through the requirements for a running console.
// If at any point something is missing, it creates/updates that piece and immediately dies.
// The next loop will pick up where they previous left off and move the process forward one step.
Expand Down Expand Up @@ -151,6 +166,7 @@ func (co *consoleOperator) sync_v400(updatedOperatorConfig *operatorv1.Console,
// public hostname so that the world can know the console is ready to roll
klog.V(4).Infoln("sync_v400: updating console status")
consoleURL := getConsoleURL(rt)

if consoleURL == "" {
err := customerrors.NewSyncError("waiting on route host")
klog.Errorf("%q: %v", "route", err)
Expand Down Expand Up @@ -197,6 +213,17 @@ func (co *consoleOperator) sync_v400(updatedOperatorConfig *operatorv1.Console,

func (co *consoleOperator) SyncConsoleConfig(consoleConfig *configv1.Console, consoleURL string) (*configv1.Console, error) {
updated := consoleConfig.DeepCopy()

// track the URL state in prometheus before we update it
Comment thread
benjaminapetersen marked this conversation as resolved.
if consoleConfig.Status.ConsoleURL != consoleURL {
// not using this URL anymore
consoleURLMetric.WithLabelValues(consoleConfig.Status.ConsoleURL).Set(0)
}
if len(consoleURL) != 0 {
// only update to new if we have a url
consoleURLMetric.WithLabelValues(consoleURL).Set(1)
}

if updated.Status.ConsoleURL != consoleURL {
klog.V(4).Infof("updating console.config.openshift.io with url: %v", consoleURL)
updated.Status.ConsoleURL = consoleURL
Expand Down