Skip to content

Commit

Permalink
Merge pull request observatorium#26 from morvencao/br_support_configu…
Browse files Browse the repository at this point in the history
…re_alertmanager

support configure alertmanager in thanos ruler.
  • Loading branch information
openshift-merge-robot authored May 10, 2021
2 parents 666a3a8 + ed28ce3 commit c47b4b9
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 40 deletions.
31 changes: 31 additions & 0 deletions api/v1alpha1/observatorium_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,31 @@ type RuleConfig struct {
Key string `json:"key"`
}

type VolumeMountType string

var (
VolumeMountTypeConfigMap VolumeMountType = "configMap"
VolumeMountTypeSecret VolumeMountType = "secret"
)

type VolumeMount struct {
// Voume mount type, configMap or secret
Type VolumeMountType `json:"type"`
// Volume mount path in the pod
MountPath string `json:"mountPath"`
// Resource name for the volume mount source
Name string `json:"name"`
// File name for the mount
Key string `json:"key"`
}

type AlertmanagerConfigFile struct {
// Alertmanager ConfigMap Name
Name string `json:"name"`
// Alertmanager ConfigMap key
Key string `json:"key"`
}

type RuleSpec struct {
// Number of Rule replicas.
Replicas *int32 `json:"replicas,omitempty"`
Expand All @@ -331,6 +356,12 @@ type RuleSpec struct {
// AlertmanagerURLs
// +optional
AlertmanagerURLs []string `json:"alertmanagerURLs,omitempty"`
// ExtraVolumeMounts
// +optional
ExtraVolumeMounts []VolumeMount `json:"extraVolumeMounts,omitempty"`
// AlertmanagerConfigFile
// +optional
AlertmanagerConfigFile AlertmanagerConfigFile `json:"alertmanagerConfigFile,omitempty"`
// ReloaderImage is an image of configmap reloader
// +optional
ReloaderImage string `json:"reloaderImage,omitempty"`
Expand Down
36 changes: 36 additions & 0 deletions api/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 example/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,6 @@ local dex = (import 'github.com/observatorium/deployments/components/dex.libsonn
volumeClaimTemplate: obs.loki.config.volumeClaimTemplate,
},
securityContext: {
}
},
},
}
13 changes: 6 additions & 7 deletions jsonnet/jsonnetfile.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@
{
"source": {
"git": {
"remote": "https://github.com/thanos-io/kube-thanos.git",
"remote": "https://github.com/open-cluster-management/kube-thanos.git",
"subdir": "jsonnet/kube-thanos"
}
},
"version": "main",
"name": "upstream-kube-thanos"
},
"version": "release-2.3"
},
{
"source": {
"git": {
"remote": "https://github.com/open-cluster-management/kube-thanos.git",
"remote": "https://github.com/thanos-io/kube-thanos.git",
"subdir": "jsonnet/kube-thanos"
}
},
"version": "release-2.3",
"name": "kube-thanos"
"version": "main",
"name": "upstream-kube-thanos"
}
],
"legacyImports": true
Expand Down
8 changes: 4 additions & 4 deletions jsonnet/jsonnetfile.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"subdir": "jsonnet/kube-thanos"
}
},
"version": "e9fb845c5229f7972e70da1be2ae240467c91523",
"sum": "SnDBgbjieU2jfiA9C+KuLgAg5gC/rbvC5xrMMpoh83o="
"version": "ae9971c285449364854d0ad4aab8b8258e4b7638",
"sum": "Ih4YDcFrAuARANPUzFBtxpTZb8on1dOeE9SseXWaLLU="
},
{
"source": {
Expand All @@ -61,8 +61,8 @@
"subdir": "jsonnet/kube-thanos"
}
},
"version": "c288ec08feb24be5da0174f39b96d7c224857926",
"sum": "CItqZ740EF1q6L2YU+66pmx8nKX4mxzXWlYMXSvLoFg=",
"version": "f53ad9856c6f765989ea76ba8eff8dd1e77186b7",
"sum": "1wMHM/+NvluUAxS5cBW2c6APEKQNQYLYnv1ZCE1R3/A=",
"name": "upstream-kube-thanos"
}
],
Expand Down
42 changes: 21 additions & 21 deletions jsonnet/obs-operator.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ local operatorObs = obs {
stores+:: {
local deleteDelay = if std.objectHas(cr.spec.thanos, 'compact') && std.objectHas(cr.spec.thanos.compact, 'deleteDelay') then cr.spec.thanos.compact.deleteDelay else obs.thanos.compact.config.deleteDelay,
securityContext: if std.objectHas(cr.spec, 'securityContext') then cr.spec.securityContext else obs.thanos.stores.config.securityContext,
ignoreDeletionMarksDelay: std.parseInt(std.substr(deleteDelay, 0, std.length(deleteDelay)-1))/2 + std.substr(deleteDelay, std.length(deleteDelay)-1, std.length(deleteDelay)),
ignoreDeletionMarksDelay: std.parseInt(std.substr(deleteDelay, 0, std.length(deleteDelay) - 1)) / 2 + std.substr(deleteDelay, std.length(deleteDelay) - 1, std.length(deleteDelay)),
} + if std.objectHas(cr.spec.thanos, 'store') then cr.spec.thanos.store else {},

storeCache+:: (if std.objectHas(cr.spec.thanos, 'store') && std.objectHas(cr.spec.thanos.store, 'cache') then cr.spec.thanos.store.cache else {}) + {
memoryLimitMb: if std.objectHas(cr.spec.thanos.store, 'cache') && std.objectHas(cr.spec.thanos.store.cache, 'memoryLimitMb') then cr.spec.thanos.store.cache.memoryLimitMb else obs.thanos.storeCache.config.memoryLimitMb,
resources+: (
if std.objectHas(cr.spec.thanos.store.cache, 'resources') then {
memcached: cr.spec.thanos.store.cache.resources
memcached: cr.spec.thanos.store.cache.resources,
} else {}
) + (
if std.objectHas(cr.spec.thanos.store.cache, 'exporterResources') then {
exporter: cr.spec.thanos.store.cache.exporterResources
exporter: cr.spec.thanos.store.cache.exporterResources,
} else {}
),
securityContext: if std.objectHas(cr.spec, 'securityContext') then cr.spec.securityContext else obs.thanos.storeCache.config.securityContext,
Expand All @@ -65,26 +65,26 @@ local operatorObs = obs {
memoryLimitMb: if std.objectHas(cr.spec.thanos.queryFrontend, 'cache') && std.objectHas(cr.spec.thanos.queryFrontend.cache, 'memoryLimitMb') then cr.spec.thanos.queryFrontend.cache.memoryLimitMb else obs.thanos.queryFrontendCache.config.memoryLimitMb,
resources+: (
if std.objectHas(cr.spec.thanos.queryFrontend.cache, 'resources') then {
memcached: cr.spec.thanos.queryFrontend.cache.resources
memcached: cr.spec.thanos.queryFrontend.cache.resources,
} else {}
) + (
if std.objectHas(cr.spec.thanos.queryFrontend.cache, 'exporterResources') then {
exporter: cr.spec.thanos.queryFrontend.cache.exporterResources
exporter: cr.spec.thanos.queryFrontend.cache.exporterResources,
} else {}
),
securityContext: if std.objectHas(cr.spec, 'securityContext') then cr.spec.securityContext else obs.thanos.queryFrontendCache.config.securityContext,
}
},
}),

loki:: if std.objectHas(cr.spec, 'loki') then loki(obs.loki.config {
local cfg = self,
name: cr.metadata.name + '-' + cfg.commonLabels['app.kubernetes.io/name'],
namespace: cr.metadata.namespace,
image: if std.objectHas(cr.spec.loki, 'image') then cr.spec.loki.image else obs.loki.config.image,
replicas: if std.objectHas(cr.spec.loki, 'replicas') then cr.spec.loki.replicas else obs.loki.config.replicas,
version: if std.objectHas(cr.spec.loki, 'version') then cr.spec.loki.version else obs.loki.config.version,
objectStorageConfig: if cr.spec.objectStorageConfig.loki != null then cr.spec.objectStorageConfig.loki else obs.loki.config.objectStorageConfig,
}) else {},
local cfg = self,
name: cr.metadata.name + '-' + cfg.commonLabels['app.kubernetes.io/name'],
namespace: cr.metadata.namespace,
image: if std.objectHas(cr.spec.loki, 'image') then cr.spec.loki.image else obs.loki.config.image,
replicas: if std.objectHas(cr.spec.loki, 'replicas') then cr.spec.loki.replicas else obs.loki.config.replicas,
version: if std.objectHas(cr.spec.loki, 'version') then cr.spec.loki.version else obs.loki.config.version,
objectStorageConfig: if cr.spec.objectStorageConfig.loki != null then cr.spec.objectStorageConfig.loki else obs.loki.config.objectStorageConfig,
}) else {},

gubernator:: {},

Expand Down Expand Up @@ -151,14 +151,14 @@ local operatorObs = obs {
) + (
if (v.kind == 'StatefulSet' || v.kind == 'Deployment') then {
template+: {
spec+:{
spec+: {
affinity: {
podAntiAffinity: {
preferredDuringSchedulingIgnoredDuringExecution: [
{
podAffinityTerm: {
labelSelector: {
matchExpressions:[
matchExpressions: [
{
key: 'app.kubernetes.io/name',
operator: 'In',
Expand All @@ -175,14 +175,14 @@ local operatorObs = obs {
},
],
},
topologyKey: "kubernetes.io/hostname",
topologyKey: 'kubernetes.io/hostname',
},
weight: 30,
},
{
podAffinityTerm: {
labelSelector: {
matchExpressions:[
matchExpressions: [
{
key: 'app.kubernetes.io/name',
operator: 'In',
Expand All @@ -199,7 +199,7 @@ local operatorObs = obs {
},
],
},
topologyKey: "topology.kubernetes.io/zone",
topologyKey: 'topology.kubernetes.io/zone',
},
weight: 70,
},
Expand All @@ -220,15 +220,15 @@ local operatorObs = obs {
) + (
if (std.objectHas(cr.spec, 'tolerations') && (v.kind == 'StatefulSet' || v.kind == 'Deployment')) then {
template+: {
spec+:{
spec+: {
tolerations: cr.spec.tolerations,
},
},
} else {}
) + (
if (std.objectHas(cr.spec.thanos.rule, 'reloaderResources') && (v.kind == 'StatefulSet') && v.metadata.name == obs.config.name + '-thanos-rule') then {
template+: {
spec+:{
spec+: {
containers: [
if c.name == 'configmap-reloader' then c {
resources: cr.spec.thanos.rule.reloaderResources,
Expand Down
Loading

0 comments on commit c47b4b9

Please sign in to comment.