Skip to content

Commit

Permalink
OperatorConfig CRD supports more of alertmanager_config (#47)
Browse files Browse the repository at this point in the history
* OperatorConfig CRD supports more of alertmanager_config
  • Loading branch information
pintohutch authored Oct 13, 2021
1 parent 4406fd4 commit 5c3d0cf
Show file tree
Hide file tree
Showing 7 changed files with 372 additions and 118 deletions.
5 changes: 5 additions & 0 deletions cmd/operator/deploy/operator/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ metadata:
rules:
- apiGroups: ["", "apps", "admissionregistration.k8s.io", "monitoring.googleapis.com", "certificates.k8s.io"]
resources:
# TODO(pintohutch): restrict access to non-CRD resources to select namespaces only.
# This can also be enforced via watch/list filters of controllers/managers.
# Ultimately we'll want that enforced here by the kube-apiserver and configured
# properly at the controller/manager level.
- deployments
- podmonitorings
- podmonitorings/status
Expand All @@ -48,6 +52,7 @@ rules:
- certificatesigningrequests
- rules
- operatorconfigs
- secrets
verbs: ["create", "update", "get", "list", "watch", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
47 changes: 2 additions & 45 deletions cmd/operator/deploy/operator/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -284,49 +284,6 @@ spec:
description: Alerting contains how the rule-evaluator configures alerting.
type: object
properties:
alertmanagerConfigs:
description: 'AlertmanagerConfigs contains a list of secret or configmap selectors that can be used to insert complete Alertmanager config specs. Each selector should return a payload that can be unmarshalled to a list of alertmanager_config: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#alertmanager_config.'
type: array
items:
description: 'NamespacedSecretOrConfigMap allows to specify data as a Secret or ConfigMap. Fields are mutually exclusive. Taking inspiration from prometheus-operator: https://github.com/prometheus-operator/prometheus-operator/blob/2c81b0cf6a5673e08057499a08ddce396b19dda4/Documentation/api.md#secretorconfigmap'
type: object
properties:
configMap:
description: ConfigMap containing data to use for the targets.
type: object
required:
- key
- namespace
properties:
key:
description: The key to select.
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
namespace:
type: string
optional:
description: Specify whether the ConfigMap or its key must be defined
type: boolean
secret:
description: Secret containing data to use for the targets.
type: object
required:
- key
- namespace
properties:
key:
description: The key of the secret to select from. Must be a valid secret key.
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
namespace:
type: string
optional:
description: Specify whether the Secret or its key must be defined
type: boolean
alertmanagers:
description: Alertmanagers contains endpoint configuration for designated Alertmanagers.
type: array
Expand Down Expand Up @@ -496,10 +453,10 @@ spec:
description: Used to verify the hostname for the targets.
type: string
labelLocation:
description: LabelLocation is the `location` label value on exported time series generated from recording rules. If left blank, the rule-evaluator will try and fetch the location from the GCE metadata server.
description: 'LabelLocation is the `location` label value on exported time series generated from recording rules. If left blank, the rule-evaluator will try and fetch the location from the GCE metadata server. TODO(pintohutch): promote LabelLocation to OperatorConfig to permit configuration of collectors as well.'
type: string
labelProjectID:
description: LabelProjectID is the `project_id` label value on exported time series generated from recording rules. If left blank, the rule-evaluator will try and fetch the project ID from the GCE metadata server.
description: 'LabelProjectID is the `project_id` label value on exported time series generated from recording rules. If left blank, the rule-evaluator will try and fetch the project ID from the GCE metadata server. TODO(pintohutch): promote LabelProjectID to OperatorConfig to permit configuration of collectors as well.'
type: string
projectID:
description: ProjectID is the GCP project ID to evaluate rules against. If left blank, the rule-evaluator will try and fetch the project ID from the GCE metadata server.
Expand Down
3 changes: 3 additions & 0 deletions cmd/rule-evaluator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/discovery"

// Import to enable 'kubernetes_sd_configs' to SD config register.
_ "github.com/prometheus/prometheus/discovery/kubernetes"
"github.com/prometheus/prometheus/notifier"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/promql"
Expand Down
5 changes: 0 additions & 5 deletions pkg/operator/apis/monitoring/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ type RuleEvaluatorSpec struct {
type AlertingSpec struct {
// Alertmanagers contains endpoint configuration for designated Alertmanagers.
Alertmanagers []AlertmanagerEndpoints `json:"alertmanagers,omitempty"`
// AlertmanagerConfigs contains a list of secret or configmap selectors
// that can be used to insert complete Alertmanager config specs.
// Each selector should return a payload that can be unmarshalled to
// a list of alertmanager_config: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#alertmanager_config.
AlertmanagerConfigs []NamespacedSecretOrConfigMap `json:"alertmanagerConfigs,omitempty"`
}

// AlertmanagerEndpoints defines a selection of a single Endpoints object
Expand Down
49 changes: 21 additions & 28 deletions pkg/operator/apis/monitoring/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func New(logger logr.Logger, clientConfig *rest.Config, registry prometheus.Regi
return nil, errors.Wrap(err, "build Kubernetes clientset")
}
// Create temporary directory to store webhook serving cert files.
certDir, err := ioutil.TempDir("", "prometheus-engine-operator-certs")
certDir, err := ioutil.TempDir("", "operator-cert")
if err != nil {
return nil, errors.Wrap(err, "create temporary certificate dir")
}
Expand Down
Loading

0 comments on commit 5c3d0cf

Please sign in to comment.