_images.tpl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. {{/*
  2. Copyright VMware, Inc.
  3. SPDX-License-Identifier: APACHE-2.0
  4. */}}
  5. {{/* vim: set filetype=mustache: */}}
  6. {{/*
  7. Return the proper image name
  8. {{ include "common.images.image" ( dict "imageRoot" .Values.path.to.the.image "global" .Values.global ) }}
  9. */}}
  10. {{- define "common.images.image" -}}
  11. {{- $registryName := .imageRoot.registry -}}
  12. {{- $repositoryName := .imageRoot.repository -}}
  13. {{- $separator := ":" -}}
  14. {{- $termination := .imageRoot.tag | toString -}}
  15. {{- if .global }}
  16. {{- if .global.imageRegistry }}
  17. {{- $registryName = .global.imageRegistry -}}
  18. {{- end -}}
  19. {{- end -}}
  20. {{- if .imageRoot.digest }}
  21. {{- $separator = "@" -}}
  22. {{- $termination = .imageRoot.digest | toString -}}
  23. {{- end -}}
  24. {{- if $registryName }}
  25. {{- printf "%s/%s%s%s" $registryName $repositoryName $separator $termination -}}
  26. {{- else -}}
  27. {{- printf "%s%s%s" $repositoryName $separator $termination -}}
  28. {{- end -}}
  29. {{- end -}}
  30. {{/*
  31. Return the proper Docker Image Registry Secret Names (deprecated: use common.images.renderPullSecrets instead)
  32. {{ include "common.images.pullSecrets" ( dict "images" (list .Values.path.to.the.image1, .Values.path.to.the.image2) "global" .Values.global) }}
  33. */}}
  34. {{- define "common.images.pullSecrets" -}}
  35. {{- $pullSecrets := list }}
  36. {{- if .global }}
  37. {{- range .global.imagePullSecrets -}}
  38. {{- if kindIs "map" . -}}
  39. {{- $pullSecrets = append $pullSecrets .name -}}
  40. {{- else -}}
  41. {{- $pullSecrets = append $pullSecrets . -}}
  42. {{- end }}
  43. {{- end -}}
  44. {{- end -}}
  45. {{- range .images -}}
  46. {{- range .pullSecrets -}}
  47. {{- if kindIs "map" . -}}
  48. {{- $pullSecrets = append $pullSecrets .name -}}
  49. {{- else -}}
  50. {{- $pullSecrets = append $pullSecrets . -}}
  51. {{- end -}}
  52. {{- end -}}
  53. {{- end -}}
  54. {{- if (not (empty $pullSecrets)) }}
  55. imagePullSecrets:
  56. {{- range $pullSecrets | uniq }}
  57. - name: {{ . }}
  58. {{- end }}
  59. {{- end }}
  60. {{- end -}}
  61. {{/*
  62. Return the proper Docker Image Registry Secret Names evaluating values as templates
  63. {{ include "common.images.renderPullSecrets" ( dict "images" (list .Values.path.to.the.image1, .Values.path.to.the.image2) "context" $) }}
  64. */}}
  65. {{- define "common.images.renderPullSecrets" -}}
  66. {{- $pullSecrets := list }}
  67. {{- $context := .context }}
  68. {{- if $context.Values.global }}
  69. {{- range $context.Values.global.imagePullSecrets -}}
  70. {{- if kindIs "map" . -}}
  71. {{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" .name "context" $context)) -}}
  72. {{- else -}}
  73. {{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" . "context" $context)) -}}
  74. {{- end -}}
  75. {{- end -}}
  76. {{- end -}}
  77. {{- range .images -}}
  78. {{- range .pullSecrets -}}
  79. {{- if kindIs "map" . -}}
  80. {{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" .name "context" $context)) -}}
  81. {{- else -}}
  82. {{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" . "context" $context)) -}}
  83. {{- end -}}
  84. {{- end -}}
  85. {{- end -}}
  86. {{- if (not (empty $pullSecrets)) }}
  87. imagePullSecrets:
  88. {{- range $pullSecrets | uniq }}
  89. - name: {{ . }}
  90. {{- end }}
  91. {{- end }}
  92. {{- end -}}
  93. {{/*
  94. Return the proper image version (ingores image revision/prerelease info & fallbacks to chart appVersion)
  95. {{ include "common.images.version" ( dict "imageRoot" .Values.path.to.the.image "chart" .Chart ) }}
  96. */}}
  97. {{- define "common.images.version" -}}
  98. {{- $imageTag := .imageRoot.tag | toString -}}
  99. {{/* regexp from https://github.com/Masterminds/semver/blob/23f51de38a0866c5ef0bfc42b3f735c73107b700/version.go#L41-L44 */}}
  100. {{- if regexMatch `^([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?$` $imageTag -}}
  101. {{- $version := semver $imageTag -}}
  102. {{- printf "%d.%d.%d" $version.Major $version.Minor $version.Patch -}}
  103. {{- else -}}
  104. {{- print .chart.AppVersion -}}
  105. {{- end -}}
  106. {{- end -}}