|
| 1 | +{{/* |
| 2 | +Expand the name of the chart. |
| 3 | +*/}} |
| 4 | +{{- define "health-monitoring-agent.name" -}} |
| 5 | +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} |
| 6 | +{{- end }} |
| 7 | + |
| 8 | +{{/* |
| 9 | +Create a default fully qualified app name. |
| 10 | +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). |
| 11 | +If release name contains chart name it will be used as a full name. |
| 12 | +*/}} |
| 13 | +{{- define "health-monitoring-agent.fullname" -}} |
| 14 | +{{- if .Values.fullnameOverride }} |
| 15 | +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} |
| 16 | +{{- else }} |
| 17 | +{{- $name := default .Chart.Name .Values.nameOverride }} |
| 18 | +{{- if contains $name .Release.Name }} |
| 19 | +{{- .Release.Name | trunc 63 | trimSuffix "-" }} |
| 20 | +{{- else }} |
| 21 | +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} |
| 22 | +{{- end }} |
| 23 | +{{- end }} |
| 24 | +{{- end }} |
| 25 | + |
| 26 | +{{/* |
| 27 | +Create chart name and version as used by the chart label. |
| 28 | +*/}} |
| 29 | +{{- define "health-monitoring-agent.chart" -}} |
| 30 | +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} |
| 31 | +{{- end }} |
| 32 | + |
| 33 | +{{/* |
| 34 | +Common labels |
| 35 | +*/}} |
| 36 | +{{- define "health-monitoring-agent.labels" -}} |
| 37 | +helm.sh/chart: {{ include "health-monitoring-agent.chart" . }} |
| 38 | +{{ include "health-monitoring-agent.selectorLabels" . }} |
| 39 | +{{- if .Chart.AppVersion }} |
| 40 | +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
| 41 | +{{- end }} |
| 42 | +app.kubernetes.io/managed-by: {{ .Release.Service }} |
| 43 | +{{- end }} |
| 44 | + |
| 45 | +{{/* |
| 46 | +Selector labels |
| 47 | +*/}} |
| 48 | +{{- define "health-monitoring-agent.selectorLabels" -}} |
| 49 | +app.kubernetes.io/name: {{ include "health-monitoring-agent.name" . }} |
| 50 | +app.kubernetes.io/instance: {{ .Release.Name }} |
| 51 | +{{- end }} |
| 52 | + |
| 53 | +{{/* |
| 54 | +Generate the health monitoring agent image URI based on AWS region |
| 55 | +*/}} |
| 56 | +{{- define "health-monitoring-agent.imageUri" -}} |
| 57 | +{{- $region := "" -}} |
| 58 | +{{- $imageTag := .Values.imageTag | default "1.0.674.0_1.0.199.0" -}} |
| 59 | + |
| 60 | +{{/* Debug: Show image tag selection if debug is enabled */}} |
| 61 | +{{- if .Values.debug -}} |
| 62 | + {{/* DEBUG: Image tag selection - Values.imageTag: {{ .Values.imageTag | default "not set" }}, Final imageTag: {{ $imageTag }} */}} |
| 63 | +{{- end -}} |
| 64 | + |
| 65 | +{{/* Try to get region from various sources in priority order */}} |
| 66 | +{{- if .Values.region -}} |
| 67 | + {{/* 1. Explicit region setting (highest priority) */}} |
| 68 | + {{- $region = .Values.region -}} |
| 69 | + {{- if .Values.debug -}} |
| 70 | + {{/* DEBUG: Using explicit region setting: {{ $region }} */}} |
| 71 | + {{- end -}} |
| 72 | +{{- else if and .Values.global .Values.global.region -}} |
| 73 | + {{/* 2. Global region setting */}} |
| 74 | + {{- $region = .Values.global.region -}} |
| 75 | + {{- if .Values.debug -}} |
| 76 | + {{/* DEBUG: Using global region setting: {{ $region }} */}} |
| 77 | + {{- end -}} |
| 78 | +{{- else -}} |
| 79 | + {{/* 3. Try to detect region from Kubernetes cluster context */}} |
| 80 | + {{- $detectedRegion := "" -}} |
| 81 | + {{- if .Values.debug -}} |
| 82 | + {{/* DEBUG: Attempting automatic region detection... */}} |
| 83 | + {{- end -}} |
| 84 | + |
| 85 | + {{/* Note: cluster-info ConfigMap doesn't exist in EKS clusters, so we skip this method */}} |
| 86 | + {{- if .Values.debug -}} |
| 87 | + {{/* DEBUG: Skipping cluster-info ConfigMap lookup (not available in EKS clusters) */}} |
| 88 | + {{- end -}} |
| 89 | + |
| 90 | + {{/* Try alternative method: look for AWS node info */}} |
| 91 | + {{- if not $detectedRegion -}} |
| 92 | + {{- if .Values.debug -}} |
| 93 | + {{/* DEBUG: Trying to detect region from node labels... */}} |
| 94 | + {{- end -}} |
| 95 | + {{- $nodes := lookup "v1" "Node" "" "" -}} |
| 96 | + {{- if $nodes -}} |
| 97 | + {{- if .Values.debug -}} |
| 98 | + {{/* DEBUG: Found {{ len $nodes.items }} nodes, checking labels... */}} |
| 99 | + {{- end -}} |
| 100 | + {{- range $nodes.items -}} |
| 101 | + {{- if .metadata.labels -}} |
| 102 | + {{/* Check for topology.kubernetes.io/region label */}} |
| 103 | + {{- if index .metadata.labels "topology.kubernetes.io/region" -}} |
| 104 | + {{- $detectedRegion = index .metadata.labels "topology.kubernetes.io/region" -}} |
| 105 | + {{- if $.Values.debug -}} |
| 106 | + {{/* DEBUG: Found region from topology.kubernetes.io/region label: {{ $detectedRegion }} */}} |
| 107 | + {{- end -}} |
| 108 | + {{- break -}} |
| 109 | + {{- end -}} |
| 110 | + {{/* Check for failure-domain.beta.kubernetes.io/region label (legacy) */}} |
| 111 | + {{- if and (not $detectedRegion) (index .metadata.labels "failure-domain.beta.kubernetes.io/region") -}} |
| 112 | + {{- $detectedRegion = index .metadata.labels "failure-domain.beta.kubernetes.io/region" -}} |
| 113 | + {{- if $.Values.debug -}} |
| 114 | + {{/* DEBUG: Found region from failure-domain.beta.kubernetes.io/region label: {{ $detectedRegion }} */}} |
| 115 | + {{- end -}} |
| 116 | + {{- break -}} |
| 117 | + {{- end -}} |
| 118 | + {{- end -}} |
| 119 | + {{- end -}} |
| 120 | + {{- else -}} |
| 121 | + {{- if .Values.debug -}} |
| 122 | + {{/* DEBUG: No nodes found for region detection */}} |
| 123 | + {{- end -}} |
| 124 | + {{- end -}} |
| 125 | + {{- end -}} |
| 126 | + |
| 127 | + {{/* Use detected region or fall back to default */}} |
| 128 | + {{- if $detectedRegion -}} |
| 129 | + {{- $region = $detectedRegion -}} |
| 130 | + {{- if .Values.debug -}} |
| 131 | + {{/* DEBUG: Using detected region: {{ $region }} */}} |
| 132 | + {{- end -}} |
| 133 | + {{- else -}} |
| 134 | + {{/* 4. Default fallback to us-east-1 */}} |
| 135 | + {{- $region = "us-east-1" -}} |
| 136 | + {{- if .Values.debug -}} |
| 137 | + {{/* DEBUG: No region detected, using default fallback: {{ $region }} */}} |
| 138 | + {{- end -}} |
| 139 | + {{- end -}} |
| 140 | +{{- end -}} |
| 141 | +
|
| 142 | +{{/* Region to ECR account ID mapping */}} |
| 143 | +{{- $regionAccountMap := dict |
| 144 | + "us-east-1" "767398015722" |
| 145 | + "us-west-2" "905418368575" |
| 146 | + "us-east-2" "851725546812" |
| 147 | + "us-west-1" "011528288828" |
| 148 | + "eu-central-1" "211125453373" |
| 149 | + "eu-north-1" "654654141839" |
| 150 | + "eu-west-1" "533267293120" |
| 151 | + "eu-west-2" "011528288831" |
| 152 | + "ap-northeast-1" "533267052152" |
| 153 | + "ap-south-1" "011528288864" |
| 154 | + "ap-southeast-1" "905418428165" |
| 155 | + "ap-southeast-2" "851725636348" |
| 156 | + "sa-east-1" "025066253954" |
| 157 | +-}} |
| 158 | +
|
| 159 | +{{/* Get the account ID for the region, default to us-west-2 account if region not found */}} |
| 160 | +{{- $accountId := index $regionAccountMap $region | default "767398015722" -}} |
| 161 | +
|
| 162 | +{{/* Debug: Show final region and account mapping */}} |
| 163 | +{{- if .Values.debug -}} |
| 164 | + {{/* DEBUG: Final region: {{ $region }}, Account ID: {{ $accountId }} */}} |
| 165 | +{{- end -}} |
| 166 | +
|
| 167 | +{{/* Allow override of the full image URI if specified */}} |
| 168 | +{{- if .Values.hmaimage -}} |
| 169 | + {{- if .Values.debug -}} |
| 170 | + {{/* DEBUG: Using override image URI: {{ .Values.hmaimage }} */}} |
| 171 | + {{- end -}} |
| 172 | + {{- .Values.hmaimage -}} |
| 173 | +{{- else -}} |
| 174 | + {{- $finalImageUri := printf "%s.dkr.ecr.%s.amazonaws.com/hyperpod-health-monitoring-agent:%s" $accountId $region $imageTag -}} |
| 175 | + {{- if .Values.debug -}} |
| 176 | + {{/* DEBUG: Generated image URI: {{ $finalImageUri }} */}} |
| 177 | + {{- end -}} |
| 178 | + {{- $finalImageUri -}} |
| 179 | +{{- end -}} |
| 180 | +{{- end }} |
0 commit comments