Skip to content

Commit

Permalink
Merge pull request #1315 from paulfantom/jsonnet-restructure
Browse files Browse the repository at this point in the history
Bug 1992567: jsonnet: cleanup jsonnet codebase and align with kube-prometheus
  • Loading branch information
openshift-ci[bot] committed Aug 11, 2021
2 parents 0b0bf96 + fcc1e97 commit e7e6b8c
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 134 deletions.
24 changes: 0 additions & 24 deletions jsonnet/add-workload-annotation.libsonnet

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local metrics = import 'github.com/openshift/telemeter/jsonnet/telemeter/metrics.jsonnet';

local cmoRules = import './rules.libsonnet';
local cmoRules = import './../rules.libsonnet';
local kubePrometheus = import 'github.com/prometheus-operator/kube-prometheus/jsonnet/kube-prometheus/components/mixin/custom.libsonnet';

local defaults = {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function(params) {
kind: 'PrometheusRule',
metadata: {
name: 'thanos-ruler',
namespace: 'openshift-user-workload-monitoring',
namespace: cfg.namespace,
},
spec: $.mixin.prometheusAlerts,
},
Expand Down Expand Up @@ -272,11 +272,11 @@ function(params) {
spec: {
ports: [{
name: 'web',
port: cfg.ports.web,
port: 9091,
targetPort: 'web',
}, {
name: 'grpc',
port: cfg.ports.grpc,
port: 10901,
targetPort: 'grpc',
}],
selector: cfg.selectorLabels,
Expand Down Expand Up @@ -332,7 +332,7 @@ function(params) {
runAsNonRoot: true,
runAsUser: 65534,
},
replicas: 2,
replicas: cfg.replicas,
resources: {
requests: {
memory: '21Mi',
Expand Down Expand Up @@ -382,20 +382,22 @@ function(params) {
{
name: 'secret-thanos-ruler-oauth-cookie',
secret: {
secretName: 'thanos-ruler-oauth-cookie',
secretName: $.oauthCookieSecret.metadata.name,
},
},
{
name: 'secret-thanos-ruler-oauth-htpasswd',
secret: {
secretName: 'thanos-ruler-oauth-htpasswd',
secretName: $.oauthHtpasswdSecret.metadata.name,
},
},
],
serviceAccountName: 'thanos-ruler',
priorityClassName: 'openshift-user-critical',
containers: [
{
// Note: this is performing strategic-merge-patch for thanos-ruler container.
// Remainder of the container configuration is managed by prometheus-operator based on $.thanosRuler.spec
name: 'thanos-ruler',
terminationMessagePolicy: 'FallbackToLogsOnError',
volumeMounts: [
Expand All @@ -417,7 +419,7 @@ function(params) {
name: 'thanos-ruler-proxy',
image: 'quay.io/openshift/oauth-proxy:latest', //FIXME(paulfantom)
ports: [{
containerPort: cfg.ports.web,
containerPort: $.service.spec.ports[0].port,
name: 'web',
}],
env: [
Expand Down Expand Up @@ -460,6 +462,8 @@ function(params) {
],
},
{
// Note: this is performing strategic-merge-patch for config-reloader container.
// Remainder of the container configuration is managed by prometheus-operator based on $.thanosRuler.spec
name: 'config-reloader',
resources: {
requests: {
Expand Down
90 changes: 38 additions & 52 deletions jsonnet/main.jsonnet
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
local removeLimits = (import 'remove-limits.libsonnet').removeLimits;
local addReleaseAnnotation = (import 'add-release-annotation.libsonnet').addReleaseAnnotation;
local addWorkloadAnnotation = (import 'add-workload-annotation.libsonnet').addWorkloadAnnotation;
local excludeRules = (import 'patch-rules.libsonnet').excludeRules;
local patchRules = (import 'patch-rules.libsonnet').patchRules;
local removeRunbookUrl = (import 'remove-runbook-urls.libsonnet').removeRunbookUrl;
local removeLimits = (import './utils/remove-limits.libsonnet').removeLimits;
local addAnnotations = (import './utils/add-annotations.libsonnet').addAnnotations;
local sanitizeAlertRules = (import './utils/sanitize-rules.libsonnet').sanitizeAlertRules;

local alertmanager = import './alertmanager.libsonnet';
local grafana = import './grafana.libsonnet';
local kubeStateMetrics = import './kube-state-metrics.libsonnet';
local controlPlane = import './control-plane.libsonnet';
local nodeExporter = import './node-exporter.libsonnet';
local prometheusAdapter = import './prometheus-adapter.libsonnet';
local prometheusOperator = import './prometheus-operator.libsonnet';
local prometheusOperatorUserWorkload = import './prometheus-operator-user-workload.libsonnet';
local prometheus = import './prometheus.libsonnet';
local prometheusUserWorkload = import './prometheus-user-workload.libsonnet';
local clusterMonitoringOperator = import './cluster-monitoring-operator.libsonnet';
local ibmCloudManagedProfile = import 'ibm-cloud-managed-profile.libsonnet';
local alertmanager = import './components/alertmanager.libsonnet';
local grafana = import './components/grafana.libsonnet';
local kubeStateMetrics = import './components/kube-state-metrics.libsonnet';
local controlPlane = import './components/control-plane.libsonnet';
local nodeExporter = import './components/node-exporter.libsonnet';
local prometheusAdapter = import './components/prometheus-adapter.libsonnet';
local prometheusOperator = import './components/prometheus-operator.libsonnet';
local prometheusOperatorUserWorkload = import './components/prometheus-operator-user-workload.libsonnet';
local prometheus = import './components/prometheus.libsonnet';
local prometheusUserWorkload = import './components/prometheus-user-workload.libsonnet';
local clusterMonitoringOperator = import './components/cluster-monitoring-operator.libsonnet';

local thanosRuler = import './thanos-ruler.libsonnet';
local thanosQuerier = import './thanos-querier.libsonnet';
local thanosRuler = import './components/thanos-ruler.libsonnet';
local thanosQuerier = import './components/thanos-querier.libsonnet';

local openshiftStateMetrics = import './openshift-state-metrics.libsonnet';
local telemeterClient = import './telemeter-client.libsonnet';

/*
TODO(paulfantom):
- thanos sidecar inclusion - needs https://github.com/prometheus-operator/kube-prometheus/pull/909
- grafana config - needs https://github.com/prometheus-operator/kube-prometheus/pull/907
*/
local openshiftStateMetrics = import './components/openshift-state-metrics.libsonnet';
local telemeterClient = import './components/telemeter-client.libsonnet';

// Common configuration
local commonConfig = {
Expand Down Expand Up @@ -72,7 +62,6 @@ local commonConfig = {
kubeRbacProxy: 'quay.io/brancz/kube-rbac-proxy:v' + $.versions.kubeRbacProxy,

openshiftOauthProxy: 'quay.io/openshift/oauth-proxy:latest',
//kubeRbacProxy: 'quay.io/brancz/kube-rbac-proxy:v0.8.0',
},
// Labels applied to every object
commonLabels: {
Expand Down Expand Up @@ -108,7 +97,9 @@ local inCluster =
image: $.values.common.images.alertmanager,
commonLabels+: $.values.common.commonLabels,
tlsCipherSuites: $.values.common.tlsCipherSuites,
mixin+: { ruleLabels: $.values.common.ruleLabels },
mixin+: {
ruleLabels: $.values.common.ruleLabels,
},
kubeRbacProxyImage: $.values.common.images.kubeRbacProxy,
promLabelProxyImage: $.values.common.images.promLabelProxy,
},
Expand Down Expand Up @@ -243,7 +234,14 @@ local inCluster =
thanosSelector: 'job=~"prometheus-(k8s|user-workload)-thanos-sidecar"',
},
},
thanos: $.values.thanosSidecar,
thanos: $.values.thanos {
resources: {
requests: {
cpu: '1m',
memory: '100Mi',
},
},
},
tlsCipherSuites: $.values.common.tlsCipherSuites,
kubeRbacProxyImage: $.values.common.images.kubeRbacProxy,
promLabelProxyImage: $.values.common.images.promLabelProxy,
Expand Down Expand Up @@ -275,28 +273,17 @@ local inCluster =
image: $.values.common.images.thanos,
version: $.values.common.versions.thanos,
},
thanosSidecar:: $.values.thanos {
resources: {
requests: {
cpu: '1m',
memory: '100Mi',
},
},
},
thanosRuler: $.values.thanos {
name: 'user-workload',
namespace: $.values.common.namespaceUserWorkload,
replicas: 2,
labels: {
'app.kubernetes.io/name': 'user-workload',
},
selectorLabels: {
app: 'thanos-ruler',
'thanos-ruler': 'user-workload',
},
ports: {
web: 9091,
grpc: 10901,
},
namespaceSelector: $.values.common.userWorkloadMonitoringNamespaceSelector,
},
thanosQuerier: $.values.thanos {
Expand Down Expand Up @@ -372,10 +359,10 @@ local inCluster =
telemeterClient: telemeterClient($.values.telemeterClient),
openshiftStateMetrics: openshiftStateMetrics($.values.openshiftStateMetrics),
} +
(import './anti-affinity.libsonnet') +
(import './utils/anti-affinity.libsonnet') +
(import 'github.com/prometheus-operator/kube-prometheus/jsonnet/kube-prometheus/addons/ksm-lite.libsonnet') +
ibmCloudManagedProfile +
{};
(import './utils/ibm-cloud-managed-profile.libsonnet') +
{}; // Including empty object to simplify adding and removing imports during development

// objects deployed in openshift-user-workload-monitoring namespace
local userWorkload =
Expand All @@ -402,7 +389,7 @@ local userWorkload =
prometheusSelector: 'job=~"prometheus-k8s|prometheus-user-workload"',
},
},
thanos: inCluster.values.thanosSidecar,
thanos: inCluster.values.prometheus.thanos,
tlsCipherSuites: $.values.common.tlsCipherSuites,
kubeRbacProxyImage: $.values.common.images.kubeRbacProxy,
},
Expand All @@ -426,12 +413,11 @@ local userWorkload =
prometheus: prometheusUserWorkload($.values.prometheus),
prometheusOperator: prometheusOperatorUserWorkload($.values.prometheusOperator),
} +
(import './anti-affinity.libsonnet') +
{};
(import './utils/anti-affinity.libsonnet') +
{}; // Including empty object to simplify adding and removing imports during development

// Manifestation
// TODO(paulfantom): removeRunbookUrl, excludeRules, and patchRules should be converted into sanitizeRules() function
removeRunbookUrl(patchRules(excludeRules(addWorkloadAnnotation(addReleaseAnnotation(removeLimits(
sanitizeAlertRules(addAnnotations(removeLimits(
{ ['alertmanager/' + name]: inCluster.alertmanager[name] for name in std.objectFields(inCluster.alertmanager) } +
{ ['cluster-monitoring-operator/' + name]: inCluster.clusterMonitoringOperator[name] for name in std.objectFields(inCluster.clusterMonitoringOperator) } +
{ ['grafana/' + name]: inCluster.grafana[name] for name in std.objectFields(inCluster.grafana) } +
Expand All @@ -450,4 +436,4 @@ removeRunbookUrl(patchRules(excludeRules(addWorkloadAnnotation(addReleaseAnnotat
{ ['control-plane/' + name]: inCluster.controlPlane[name] for name in std.objectFields(inCluster.controlPlane) } +
{ ['manifests/' + name]: inCluster.manifests[name] for name in std.objectFields(inCluster.manifests) } +
{}
))))))
)))
21 changes: 0 additions & 21 deletions jsonnet/remove-runbook-urls.libsonnet

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,30 @@
[k]: addAnnotation(o[k])
for k in std.objectFields(o)
},
addWorkloadAnnotation(o): {
local annotation = {
'target.workload.openshift.io/management': '{"effect": "PreferredDuringScheduling"}',
},
local addAnnotation(o) = o {
[if std.setMember(o.kind, ['DaemonSet', 'Deployment', 'ReplicaSet']) then 'spec']+: {
template+: {
metadata+: {
annotations+: annotation,
},
},
},
[if std.setMember(o.kind, ['Alertmanager', 'Prometheus', 'ThanosRuler']) then 'spec']+:
{
podMetadata+: {
annotations+: annotation,
},
},
},
[k]: addAnnotation(o[k])
for k in std.objectFields(o)
},

addAnnotations(o): $.addWorkloadAnnotation(
$.addReleaseAnnotation(o)
),
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e7e6b8c

Please sign in to comment.