_warnings.tpl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. {{/*
  2. Copyright Broadcom, Inc. All Rights Reserved.
  3. SPDX-License-Identifier: APACHE-2.0
  4. */}}
  5. {{/* vim: set filetype=mustache: */}}
  6. {{/*
  7. Warning about using rolling tag.
  8. Usage:
  9. {{ include "common.warnings.rollingTag" .Values.path.to.the.imageRoot }}
  10. */}}
  11. {{- define "common.warnings.rollingTag" -}}
  12. {{- if and (contains "bitnami/" .repository) (not (.tag | toString | regexFind "-r\\d+$|sha256:")) }}
  13. WARNING: Rolling tag detected ({{ .repository }}:{{ .tag }}), please note that it is strongly recommended to avoid using rolling tags in a production environment.
  14. +info https://docs.vmware.com/en/VMware-Tanzu-Application-Catalog/services/tutorials/GUID-understand-rolling-tags-containers-index.html
  15. {{- end }}
  16. {{- end -}}
  17. {{/*
  18. Warning about replaced images from the original.
  19. Usage:
  20. {{ include "common.warnings.modifiedImages" (dict "images" (list .Values.path.to.the.imageRoot) "context" $) }}
  21. */}}
  22. {{- define "common.warnings.modifiedImages" -}}
  23. {{- $affectedImages := list -}}
  24. {{- $printMessage := false -}}
  25. {{- $originalImages := .context.Chart.Annotations.images -}}
  26. {{- range .images -}}
  27. {{- $fullImageName := printf (printf "%s/%s:%s" .registry .repository .tag) -}}
  28. {{- if not (contains $fullImageName $originalImages) }}
  29. {{- $affectedImages = append $affectedImages (printf "%s/%s:%s" .registry .repository .tag) -}}
  30. {{- $printMessage = true -}}
  31. {{- end -}}
  32. {{- end -}}
  33. {{- if $printMessage }}
  34. ⚠ SECURITY WARNING: Original containers have been substituted. This Helm chart was designed, tested, and validated on multiple platforms using a specific set of Bitnami and Tanzu Application Catalog containers. Substituting other containers is likely to cause degraded security and performance, broken chart features, and missing environment variables.
  35. Substituted images detected:
  36. {{- range $affectedImages }}
  37. - {{ . }}
  38. {{- end }}
  39. {{- end -}}
  40. {{- end -}}
  41. {{/*
  42. Warning about not setting the resource object in all deployments.
  43. Usage:
  44. {{ include "common.warnings.resources" (dict "sections" (list "path1" "path2") context $) }}
  45. Example:
  46. {{- include "common.warnings.resources" (dict "sections" (list "csiProvider.provider" "server" "volumePermissions" "") "context" $) }}
  47. The list in the example assumes that the following values exist:
  48. - csiProvider.provider.resources
  49. - server.resources
  50. - volumePermissions.resources
  51. - resources
  52. */}}
  53. {{- define "common.warnings.resources" -}}
  54. {{- $values := .context.Values -}}
  55. {{- $printMessage := false -}}
  56. {{ $affectedSections := list -}}
  57. {{- range .sections -}}
  58. {{- if eq . "" -}}
  59. {{/* Case where the resources section is at the root (one main deployment in the chart) */}}
  60. {{- if not (index $values "resources") -}}
  61. {{- $affectedSections = append $affectedSections "resources" -}}
  62. {{- $printMessage = true -}}
  63. {{- end -}}
  64. {{- else -}}
  65. {{/* Case where the are multiple resources sections (more than one main deployment in the chart) */}}
  66. {{- $keys := split "." . -}}
  67. {{/* We iterate through the different levels until arriving to the resource section. Example: a.b.c.resources */}}
  68. {{- $section := $values -}}
  69. {{- range $keys -}}
  70. {{- $section = index $section . -}}
  71. {{- end -}}
  72. {{- if not (index $section "resources") -}}
  73. {{/* If the section has enabled=false or replicaCount=0, do not include it */}}
  74. {{- if and (hasKey $section "enabled") -}}
  75. {{- if index $section "enabled" -}}
  76. {{/* enabled=true */}}
  77. {{- $affectedSections = append $affectedSections (printf "%s.resources" .) -}}
  78. {{- $printMessage = true -}}
  79. {{- end -}}
  80. {{- else if and (hasKey $section "replicaCount") -}}
  81. {{/* We need a casting to int because number 0 is not treated as an int by default */}}
  82. {{- if (gt (index $section "replicaCount" | int) 0) -}}
  83. {{/* replicaCount > 0 */}}
  84. {{- $affectedSections = append $affectedSections (printf "%s.resources" .) -}}
  85. {{- $printMessage = true -}}
  86. {{- end -}}
  87. {{- else -}}
  88. {{/* Default case, add it to the affected sections */}}
  89. {{- $affectedSections = append $affectedSections (printf "%s.resources" .) -}}
  90. {{- $printMessage = true -}}
  91. {{- end -}}
  92. {{- end -}}
  93. {{- end -}}
  94. {{- end -}}
  95. {{- if $printMessage }}
  96. WARNING: There are "resources" sections in the chart not set. Using "resourcesPreset" is not recommended for production. For production installations, please set the following values according to your workload needs:
  97. {{- range $affectedSections }}
  98. - {{ . }}
  99. {{- end }}
  100. +info https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
  101. {{- end -}}
  102. {{- end -}}