github.com/tagesspiegel/helm-plugin-bootstrap@v0.2.3/internal/bootstrap/files.go (about)

     1  package bootstrap
     2  
     3  const (
     4  	// PodDisruptionBudgetFileName is the name of the file that will be created in the templates folder
     5  	PodDisruptionBudgetFileName = "pdb.yaml"
     6  	// NetworkPolicyFileName is the name of the file that will be created in the templates folder
     7  	NetworkPolicyFileName = "networkpolicy.yaml"
     8  	// ServiceMonitorFileName is the name of the file that will be created in the templates folder
     9  	ServiceMonitorFileName = "servicemonitor.yaml"
    10  )
    11  
    12  // manifest templates
    13  
    14  const pdbTemplate = `{{- if .Values.%[2]s.enabled }}
    15  apiVersion: policy/v1
    16  kind: PodDisruptionBudget
    17  metadata:
    18    name: {{ include "%[1]s.fullname" . }}
    19    labels:
    20      {{- include "%[1]s.labels" . | nindent 4 }}
    21    {{- with .Values.%[2]s.annotations }}
    22    annotations:
    23      {{- toYaml . | nindent 4 }}
    24    {{- end }}
    25  spec:
    26    {{- with .Values.%[2]s.maxUnavailable }}
    27    maxUnavailable: {{ . }}
    28    {{- end }}
    29    {{- with .Values.%[2]s.minAvailable }}
    30    minAvailable: {{ . }}
    31    {{- end }}
    32    selector:
    33      matchLabels:
    34        {{- include "%[1]s.selectorLabels" . | nindent 6 }}
    35  {{- end }}
    36  `
    37  const networkPolicyTemplate = `{{- if .Values.%[2]s.enabled }}
    38  apiVersion: networking.k8s.io/v1
    39  kind: NetworkPolicy
    40  metadata:
    41    name: {{ include "%[1]s.fullname" . }}
    42    labels:
    43      {{- include "%[1]s.labels" . | nindent 4 }}
    44  spec:
    45    podSelector:
    46      matchLabels:
    47        {{- include "%[1]s.selectorLabels" . | nindent 6 }}
    48    policyTypes:
    49    {{- if .Values.%[2]s.ingress }}
    50      - Ingress
    51    {{- end }}
    52    {{- if .Values.%[2]s.egress }}
    53      - Egress
    54    {{- end }}
    55    {{- with .Values.%[2]s.ingress }}
    56    ingress:
    57      {{- toYaml . | nindent 4 }}
    58    {{- end }}
    59    {{- with .Values.%[2]s.egress }}
    60    egress:
    61      {{- toYaml . | nindent 4 }}
    62    {{- end -}}
    63  {{- end }}
    64  `
    65  const serviceMonitorTemplate = `{{- if and .Values.%[2]s.enabled .Values.%[2]s.serviceMonitor.enabled }}
    66  apiVersion: monitoring.coreos.com/v1
    67  kind: ServiceMonitor
    68  metadata:
    69    name: {{ template "%[1]s.fullname" . }}
    70    {{- if .Values.%[2]s.serviceMonitor.namespace }}
    71    namespace: {{ .Values.%[2]s.serviceMonitor.namespace }}
    72    {{- end }}
    73    labels:
    74      {{- include "%[1]s.labels" . | nindent 4 }}
    75  spec:
    76    endpoints:
    77      - port: http
    78        path: {{ .Values.%[2]s.serviceMonitor.metricsPath }}
    79        {{- with .Values.%[2]s.serviceMonitor.interval }}
    80        interval: {{ . }}
    81        {{- end }}
    82        {{- with .Values.%[2]s.serviceMonitor.scrapeTimeout }}
    83        scrapeTimeout: {{ . }}
    84        {{- end }}
    85    selector:
    86      matchLabels:
    87        {{- include "%[1]s.selectorLabels" . | nindent 6 }}
    88  {{- end }}
    89  `
    90  
    91  // values.yaml configurations
    92  
    93  const pdbValuesYaml = `
    94  %[1]s:
    95    enabled: true
    96    annotations: {}
    97    minAvailable: 1
    98    maxUnavailable: 0
    99  `
   100  const networkPolicyValuesYaml = `
   101  %[1]s:
   102    enabled: false
   103    ingress: []
   104      # - from:
   105      #   - ipBlock:
   106      #       cidr: 10.0.0.0/24
   107      #       except:
   108      #         - 10.0.0.128/25
   109      #   - namespaceSelector:
   110      #       matchLabels:
   111      #         kubernetes.io/metadata.name: frontend
   112      #   - podSelector:
   113      #       matchLabels:
   114      #         app.kubernetes.io/name: frontend
   115      #   ports:
   116      #     - protocol: TCP
   117      #       port: 80
   118    egress: []
   119      # - to:
   120      #     - ipBlock:
   121      #         cidr: 10.0.0.0/24
   122      #   ports:
   123      #     - protocol: UDP
   124      #       port: 53
   125  `
   126  const serviceMonitorValuesYaml = `
   127  %[1]s:
   128    enabled: false
   129    serviceMonitor:
   130      enabled: false
   131      metricsPath: /metrics
   132      namespace: ""
   133      interval: ""
   134      scrapeTimeout: ""
   135  `