Skip to content

Commit

Permalink
feat: added namespace override for caas resources (#10)
Browse files Browse the repository at this point in the history
* feat: added namespace override for caas resources

* chore: bumped release
  • Loading branch information
puffitos authored Jul 13, 2023
1 parent e672e76 commit a088c91
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 157 deletions.
10 changes: 5 additions & 5 deletions Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ annotations:
# catalog.cattle.io/certified: rancher
name: caas-project-monitoring
description: A Helm chart for Rancher Project Monitoring V3
version: 1.0.15
version: 1.0.16
appVersion: "40.1.2"
icon: https://raw.githubusercontent.com/caas-team/caas-project-monitoring/main/logo.png
keywords:
- monitoring
- monitoring
dependencies:
- name: kube-prometheus-stack
version: "40.1.2"
repository: "https://prometheus-community.github.io/helm-charts"
- name: kube-prometheus-stack
version: "40.1.2"
repository: "https://prometheus-community.github.io/helm-charts"
sources:
- https://github.com/caas-team/caas-project-monitoring
- https://github.com/prometheus-community/helm-charts
Expand Down
15 changes: 1 addition & 14 deletions app-readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,14 @@ spec:
</details>
* Additional permissions for Project-Owner, assigned from administrator within RoleTemplate:
* The CaaS Project Owner must be assigned to the user installing the app. It provides the additional permissions for the project monitoring stack:
<details>
<summary>code snippet</summary>
### rancher
```yaml
apiVersion: management.cattle.io/v3
builtin: false
context: project
displayName: CaaS-Project-Monitoring-Admin
external: false
hidden: false
kind: RoleTemplate
metadata:
annotations:
cleanup.cattle.io/rtUpgradeCluster: 'true'
name: caas-project-monitoring-admin
roleTemplateNames:
- project-owner
rules:
- apiGroups:
- monitoring.coreos.com
Expand Down
Binary file modified charts/kube-prometheus-stack-40.1.2.tgz
Binary file not shown.
10 changes: 5 additions & 5 deletions questions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ categories:
- monitoring
questions:
- variable: caas.projectNamespaces
description: List of additional namespaces to monitor (whitespace separated, without installation namespace!!!)
description: List of additional namespaces to monitor (whitespace separated, without installation namespace!). No need to define, if your namespaces are in the same project as the installation namespace.
group: CaaS
label: Caas projectNamespaces
required: true
Expand All @@ -15,25 +15,25 @@ questions:
# label: ProjectId
# group: "CaaS"
- variable: kube-prometheus-stack.alertmanager.alertmanagerSpec.alertmanagerConfigNamespaceSelector.matchLabels."field.cattle.io/projectId"
description: projectId for alertmanagerConfigNamespaceSelector label
description: Required. Project ID for alertmanagerConfigNamespaceSelector label. Set to your project's ID.
required: true
type: string
label: ProjectId
group: CaaS
- variable: kube-prometheus-stack.prometheus.prometheusSpec.ruleNamespaceSelector.matchLabels."field.cattle.io/projectId"
description: projectId for ruleNamespaceSelector label
description: Required. Project ID for ruleNamespaceSelector label. Set to your project's ID.
required: true
type: string
label: ProjectId
group: CaaS
- variable: kube-prometheus-stack.prometheus.prometheusSpec.podMonitorNamespaceSelector.matchLabels."field.cattle.io/projectId"
description: projectId for podMonitorNamespaceSelector label
description: Required. Project ID for podMonitorNamespaceSelector label. Set to your project's ID.
required: true
type: string
label: ProjectId
group: CaaS
- variable: kube-prometheus-stack.prometheus.prometheusSpec.serviceMonitorNamespaceSelector.matchLabels."field.cattle.io/projectId"
description: projectId for serviceMonitorNamespaceSelector label
description: Required. Project ID for serviceMonitorNamespaceSelector label. Set to your project's ID.
required: true
type: string
label: ProjectId
Expand Down
21 changes: 17 additions & 4 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@
Expand the name of the chart.
*/}}
{{- define "caas-project-monitoring.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- default .Chart.Name .Values.caas.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Allow the release namespace to be overridden for multi-namespace deployments in combined charts
*/}}
{{- define "caas-project-monitoring.namespace" -}}
{{- if .Values.caas.namespaceOverride -}}
{{- .Values.caas.namespaceOverride -}}
{{- else -}}
{{- .Release.Namespace -}}
{{- end -}}
{{- end -}}


{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "caas-project-monitoring.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- if .Values.caas.fullnameOverride }}
{{- .Values.caas.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- $name := default .Chart.Name .Values.caas.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
Expand Down Expand Up @@ -65,3 +77,4 @@ Create the name of the service account to use
{{- default "default" .Values.caas.rbac.serviceAccount.name }}
{{- end }}
{{- end }}

19 changes: 9 additions & 10 deletions templates/caas-project-monitoring-rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{{ if .Values.caas.rbac.enabled }}
{{ $fullname := include "caas-project-monitoring.fullname" . }}
{{ $serviceaccount :=include "caas-project-monitoring.serviceAccountName" . }}
{{ $releasenamespace := .Release.Namespace }}
{{ $monitornamespaces := .Release.Namespace }}
{{ $serviceaccount := include "caas-project-monitoring.serviceAccountName" . }}
{{ $monitornamespaces := include "caas-project-monitoring.namespace" . }}
{{ if .Values.caas.projectNamespaces }}
{{ $monitornamespaces = printf "%s %s" .Release.Namespace .Values.caas.projectNamespaces }}
{{ $monitornamespaces = printf "%s %s" $monitornamespaces .Values.caas.projectNamespaces }}
{{ end }}
---
apiVersion: v1
Expand All @@ -13,15 +12,15 @@ metadata:
labels:
{{- include "caas-project-monitoring.labels" . | nindent 4 }}
name: {{ include "caas-project-monitoring.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{- $ns1 := (splitList " " $monitornamespaces) }}
{{- range $s1 := $ns1 }}
namespace: {{ include "caas-project-monitoring.namespace" . }}
{{- $namespaces := (splitList " " $monitornamespaces) }}
{{- range $ns := $namespaces }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ $fullname }}
namespace: {{ $s1 }}
namespace: {{ $ns }}
rules:
- apiGroups:
- ""
Expand Down Expand Up @@ -69,14 +68,14 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ $fullname }}
namespace: {{ $s1 }}
namespace: {{ $ns }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ $fullname }}
subjects:
- kind: ServiceAccount
name: {{ $serviceaccount }}
namespace: {{ $releasenamespace }}
namespace: {{ $ns}}
{{ end }}
{{ end }}
1 change: 1 addition & 0 deletions templates/grafana-dashboards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: project-monitoring-rancher-default-dashboards
namespace: {{ include "caas-project-monitoring.namespace" . }}
labels:
grafana_dashboard: "1"
{{- include "caas-project-monitoring.labels" . | nindent 4 }}
Expand Down
3 changes: 2 additions & 1 deletion templates/grafana-nginx-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{{ if .Values.caas.grafana.configmaps }}
{{ $releasenamespace := .Release.Namespace }}
{{ $releasenamespace := include "caas-project-monitoring.namespace" . }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-proxy-config-project-monitoring-grafana
namespace: {{ include "caas-project-monitoring.namespace" . }}
labels:
{{- include "caas-project-monitoring.labels" . | nindent 4 }}
data:
Expand Down
Loading

0 comments on commit a088c91

Please sign in to comment.