github.com/microsoft/fabrikate@v1.0.0-alpha.1.0.20210115014322-dc09194d0885/testdata/local-charts/prometheus/templates/_helpers.tpl (about)

     1  {{/* vim: set filetype=mustache: */}}
     2  {{/*
     3  Expand the name of the chart.
     4  */}}
     5  {{- define "prometheus.name" -}}
     6  {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
     7  {{- end -}}
     8  
     9  {{/*
    10  Create chart name and version as used by the chart label.
    11  */}}
    12  {{- define "prometheus.chart" -}}
    13  {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
    14  {{- end -}}
    15  
    16  {{/*
    17  Create unified labels for prometheus components
    18  */}}
    19  {{- define "prometheus.common.matchLabels" -}}
    20  app: {{ template "prometheus.name" . }}
    21  release: {{ .Release.Name }}
    22  {{- end -}}
    23  
    24  {{- define "prometheus.common.metaLabels" -}}
    25  chart: {{ template "prometheus.chart" . }}
    26  heritage: {{ .Release.Service }}
    27  {{- end -}}
    28  
    29  {{- define "prometheus.alertmanager.labels" -}}
    30  {{ include "prometheus.alertmanager.matchLabels" . }}
    31  {{ include "prometheus.common.metaLabels" . }}
    32  {{- end -}}
    33  
    34  {{- define "prometheus.alertmanager.matchLabels" -}}
    35  component: {{ .Values.alertmanager.name | quote }}
    36  {{ include "prometheus.common.matchLabels" . }}
    37  {{- end -}}
    38  
    39  {{- define "prometheus.nodeExporter.labels" -}}
    40  {{ include "prometheus.nodeExporter.matchLabels" . }}
    41  {{ include "prometheus.common.metaLabels" . }}
    42  {{- end -}}
    43  
    44  {{- define "prometheus.nodeExporter.matchLabels" -}}
    45  component: {{ .Values.nodeExporter.name | quote }}
    46  {{ include "prometheus.common.matchLabels" . }}
    47  {{- end -}}
    48  
    49  {{- define "prometheus.pushgateway.labels" -}}
    50  {{ include "prometheus.pushgateway.matchLabels" . }}
    51  {{ include "prometheus.common.metaLabels" . }}
    52  {{- end -}}
    53  
    54  {{- define "prometheus.pushgateway.matchLabels" -}}
    55  component: {{ .Values.pushgateway.name | quote }}
    56  {{ include "prometheus.common.matchLabels" . }}
    57  {{- end -}}
    58  
    59  {{- define "prometheus.server.labels" -}}
    60  {{ include "prometheus.server.matchLabels" . }}
    61  {{ include "prometheus.common.metaLabels" . }}
    62  {{- end -}}
    63  
    64  {{- define "prometheus.server.matchLabels" -}}
    65  component: {{ .Values.server.name | quote }}
    66  {{ include "prometheus.common.matchLabels" . }}
    67  {{- end -}}
    68  
    69  {{/*
    70  Create a default fully qualified app name.
    71  We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
    72  */}}
    73  {{- define "prometheus.fullname" -}}
    74  {{- if .Values.fullnameOverride -}}
    75  {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
    76  {{- else -}}
    77  {{- $name := default .Chart.Name .Values.nameOverride -}}
    78  {{- if contains $name .Release.Name -}}
    79  {{- .Release.Name | trunc 63 | trimSuffix "-" -}}
    80  {{- else -}}
    81  {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
    82  {{- end -}}
    83  {{- end -}}
    84  {{- end -}}
    85  
    86  {{/*
    87  Create a fully qualified alertmanager name.
    88  We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
    89  */}}
    90  
    91  {{- define "prometheus.alertmanager.fullname" -}}
    92  {{- if .Values.alertmanager.fullnameOverride -}}
    93  {{- .Values.alertmanager.fullnameOverride | trunc 63 | trimSuffix "-" -}}
    94  {{- else -}}
    95  {{- $name := default .Chart.Name .Values.nameOverride -}}
    96  {{- if contains $name .Release.Name -}}
    97  {{- printf "%s-%s" .Release.Name .Values.alertmanager.name | trunc 63 | trimSuffix "-" -}}
    98  {{- else -}}
    99  {{- printf "%s-%s-%s" .Release.Name $name .Values.alertmanager.name | trunc 63 | trimSuffix "-" -}}
   100  {{- end -}}
   101  {{- end -}}
   102  {{- end -}}
   103  
   104  {{/*
   105  Create a fully qualified node-exporter name.
   106  We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
   107  */}}
   108  {{- define "prometheus.nodeExporter.fullname" -}}
   109  {{- if .Values.nodeExporter.fullnameOverride -}}
   110  {{- .Values.nodeExporter.fullnameOverride | trunc 63 | trimSuffix "-" -}}
   111  {{- else -}}
   112  {{- $name := default .Chart.Name .Values.nameOverride -}}
   113  {{- if contains $name .Release.Name -}}
   114  {{- printf "%s-%s" .Release.Name .Values.nodeExporter.name | trunc 63 | trimSuffix "-" -}}
   115  {{- else -}}
   116  {{- printf "%s-%s-%s" .Release.Name $name .Values.nodeExporter.name | trunc 63 | trimSuffix "-" -}}
   117  {{- end -}}
   118  {{- end -}}
   119  {{- end -}}
   120  
   121  {{/*
   122  Create a fully qualified Prometheus server name.
   123  We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
   124  */}}
   125  {{- define "prometheus.server.fullname" -}}
   126  {{- if .Values.server.fullnameOverride -}}
   127  {{- .Values.server.fullnameOverride | trunc 63 | trimSuffix "-" -}}
   128  {{- else -}}
   129  {{- $name := default .Chart.Name .Values.nameOverride -}}
   130  {{- if contains $name .Release.Name -}}
   131  {{- printf "%s-%s" .Release.Name .Values.server.name | trunc 63 | trimSuffix "-" -}}
   132  {{- else -}}
   133  {{- printf "%s-%s-%s" .Release.Name $name .Values.server.name | trunc 63 | trimSuffix "-" -}}
   134  {{- end -}}
   135  {{- end -}}
   136  {{- end -}}
   137  
   138  {{/*
   139  Create a fully qualified pushgateway name.
   140  We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
   141  */}}
   142  {{- define "prometheus.pushgateway.fullname" -}}
   143  {{- if .Values.pushgateway.fullnameOverride -}}
   144  {{- .Values.pushgateway.fullnameOverride | trunc 63 | trimSuffix "-" -}}
   145  {{- else -}}
   146  {{- $name := default .Chart.Name .Values.nameOverride -}}
   147  {{- if contains $name .Release.Name -}}
   148  {{- printf "%s-%s" .Release.Name .Values.pushgateway.name | trunc 63 | trimSuffix "-" -}}
   149  {{- else -}}
   150  {{- printf "%s-%s-%s" .Release.Name $name .Values.pushgateway.name | trunc 63 | trimSuffix "-" -}}
   151  {{- end -}}
   152  {{- end -}}
   153  {{- end -}}
   154  
   155  {{/*
   156  Return the appropriate apiVersion for deployment.
   157  */}}
   158  {{- define "prometheus.deployment.apiVersion" -}}
   159  {{- if semverCompare "<1.9-0" .Capabilities.KubeVersion.GitVersion -}}
   160  {{- print "extensions/v1beta1" -}}
   161  {{- else if semverCompare "^1.9-0" .Capabilities.KubeVersion.GitVersion -}}
   162  {{- print "apps/v1" -}}
   163  {{- end -}}
   164  {{- end -}}
   165  {{/*
   166  Return the appropriate apiVersion for daemonset.
   167  */}}
   168  {{- define "prometheus.daemonset.apiVersion" -}}
   169  {{- if semverCompare "<1.9-0" .Capabilities.KubeVersion.GitVersion -}}
   170  {{- print "extensions/v1beta1" -}}
   171  {{- else if semverCompare "^1.9-0" .Capabilities.KubeVersion.GitVersion -}}
   172  {{- print "apps/v1" -}}
   173  {{- end -}}
   174  {{- end -}}
   175  {{/*
   176  Return the appropriate apiVersion for networkpolicy.
   177  */}}
   178  {{- define "prometheus.networkPolicy.apiVersion" -}}
   179  {{- if semverCompare ">=1.4-0, <1.7-0" .Capabilities.KubeVersion.GitVersion -}}
   180  {{- print "extensions/v1beta1" -}}
   181  {{- else if semverCompare "^1.7-0" .Capabilities.KubeVersion.GitVersion -}}
   182  {{- print "networking.k8s.io/v1" -}}
   183  {{- end -}}
   184  {{- end -}}
   185  {{/*
   186  Return the appropriate apiVersion for podsecuritypolicy.
   187  */}}
   188  {{- define "prometheus.podSecurityPolicy.apiVersion" -}}
   189  {{- if semverCompare ">=1.3-0, <1.10-0" .Capabilities.KubeVersion.GitVersion -}}
   190  {{- print "extensions/v1beta1" -}}
   191  {{- else if semverCompare "^1.10-0" .Capabilities.KubeVersion.GitVersion -}}
   192  {{- print "policy/v1beta1" -}}
   193  {{- end -}}
   194  {{- end -}}
   195  {{/*
   196  Return the appropriate apiVersion for rbac.
   197  */}}
   198  {{- define "rbac.apiVersion" -}}
   199  {{- if .Capabilities.APIVersions.Has "rbac.authorization.k8s.io/v1" }}
   200  {{- print "rbac.authorization.k8s.io/v1" -}}
   201  {{- else -}}
   202  {{- print "rbac.authorization.k8s.io/v1beta1" -}}
   203  {{- end -}}
   204  {{- end -}}
   205  
   206  {{/*
   207  Create the name of the service account to use for the alertmanager component
   208  */}}
   209  {{- define "prometheus.serviceAccountName.alertmanager" -}}
   210  {{- if .Values.serviceAccounts.alertmanager.create -}}
   211      {{ default (include "prometheus.alertmanager.fullname" .) .Values.serviceAccounts.alertmanager.name }}
   212  {{- else -}}
   213      {{ default "default" .Values.serviceAccounts.alertmanager.name }}
   214  {{- end -}}
   215  {{- end -}}
   216  
   217  {{/*
   218  Create the name of the service account to use for the nodeExporter component
   219  */}}
   220  {{- define "prometheus.serviceAccountName.nodeExporter" -}}
   221  {{- if .Values.serviceAccounts.nodeExporter.create -}}
   222      {{ default (include "prometheus.nodeExporter.fullname" .) .Values.serviceAccounts.nodeExporter.name }}
   223  {{- else -}}
   224      {{ default "default" .Values.serviceAccounts.nodeExporter.name }}
   225  {{- end -}}
   226  {{- end -}}
   227  
   228  {{/*
   229  Create the name of the service account to use for the pushgateway component
   230  */}}
   231  {{- define "prometheus.serviceAccountName.pushgateway" -}}
   232  {{- if .Values.serviceAccounts.pushgateway.create -}}
   233      {{ default (include "prometheus.pushgateway.fullname" .) .Values.serviceAccounts.pushgateway.name }}
   234  {{- else -}}
   235      {{ default "default" .Values.serviceAccounts.pushgateway.name }}
   236  {{- end -}}
   237  {{- end -}}
   238  
   239  {{/*
   240  Create the name of the service account to use for the server component
   241  */}}
   242  {{- define "prometheus.serviceAccountName.server" -}}
   243  {{- if .Values.serviceAccounts.server.create -}}
   244      {{ default (include "prometheus.server.fullname" .) .Values.serviceAccounts.server.name }}
   245  {{- else -}}
   246      {{ default "default" .Values.serviceAccounts.server.name }}
   247  {{- end -}}
   248  {{- end -}}
   249  
   250  {{/*
   251  Define the prometheus.namespace template if set with forceNamespace or .Release.Namespace is set
   252  */}}
   253  {{- define "prometheus.namespace" -}}
   254  {{- if .Values.forceNamespace -}}
   255  {{ printf "namespace: %s" .Values.forceNamespace }}
   256  {{- else -}}
   257  {{ printf "namespace: %s" .Release.Namespace }}
   258  {{- end -}}
   259  {{- end -}}