|
| 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 := "1.0.674.0_1.0.199.0" -}} |
| 59 | + |
| 60 | +{{/* Try to get region from various sources in priority order */}} |
| 61 | +{{- if .Values.region -}} |
| 62 | + {{/* 1. Explicit region setting (highest priority) */}} |
| 63 | + {{- $region = .Values.region -}} |
| 64 | +{{- else if and .Values.global .Values.global.region -}} |
| 65 | + {{/* 2. Global region setting */}} |
| 66 | + {{- $region = .Values.global.region -}} |
| 67 | +{{- else -}} |
| 68 | + {{/* 3. Try to detect region from Kubernetes cluster context */}} |
| 69 | + {{- $detectedRegion := "" -}} |
| 70 | + |
| 71 | + {{/* Try to get region from cluster info */}} |
| 72 | + {{- $clusterInfo := lookup "v1" "ConfigMap" "kube-system" "cluster-info" -}} |
| 73 | + {{- if $clusterInfo -}} |
| 74 | + {{- $server := index $clusterInfo.data "kubeconfig" | fromYaml -}} |
| 75 | + {{- if $server -}} |
| 76 | + {{- range $server.clusters -}} |
| 77 | + {{- if .cluster.server -}} |
| 78 | + {{/* Extract region from EKS API server URL pattern: https://XXXXX.gr7.REGION.eks.amazonaws.com */}} |
| 79 | + {{- $serverUrl := .cluster.server -}} |
| 80 | + {{- if contains ".eks.amazonaws.com" $serverUrl -}} |
| 81 | + {{- $urlParts := split "." $serverUrl -}} |
| 82 | + {{- if gt (len $urlParts) 3 -}} |
| 83 | + {{- $detectedRegion = index $urlParts 2 -}} |
| 84 | + {{- end -}} |
| 85 | + {{- end -}} |
| 86 | + {{- end -}} |
| 87 | + {{- end -}} |
| 88 | + {{- end -}} |
| 89 | + {{- end -}} |
| 90 | + |
| 91 | + {{/* Try alternative method: look for AWS node info */}} |
| 92 | + {{- if not $detectedRegion -}} |
| 93 | + {{- $nodes := lookup "v1" "Node" "" "" -}} |
| 94 | + {{- if $nodes -}} |
| 95 | + {{- range $nodes.items -}} |
| 96 | + {{- if .metadata.labels -}} |
| 97 | + {{/* Check for topology.kubernetes.io/region label */}} |
| 98 | + {{- if index .metadata.labels "topology.kubernetes.io/region" -}} |
| 99 | + {{- $detectedRegion = index .metadata.labels "topology.kubernetes.io/region" -}} |
| 100 | + {{- break -}} |
| 101 | + {{- end -}} |
| 102 | + {{/* Check for failure-domain.beta.kubernetes.io/region label (legacy) */}} |
| 103 | + {{- if and (not $detectedRegion) (index .metadata.labels "failure-domain.beta.kubernetes.io/region") -}} |
| 104 | + {{- $detectedRegion = index .metadata.labels "failure-domain.beta.kubernetes.io/region" -}} |
| 105 | + {{- break -}} |
| 106 | + {{- end -}} |
| 107 | + {{- end -}} |
| 108 | + {{- end -}} |
| 109 | + {{- end -}} |
| 110 | + {{- end -}} |
| 111 | + |
| 112 | + {{/* Use detected region or fall back to default */}} |
| 113 | + {{- if $detectedRegion -}} |
| 114 | + {{- $region = $detectedRegion -}} |
| 115 | + {{- else -}} |
| 116 | + {{/* 4. Default fallback to us-west-2 */}} |
| 117 | + {{- $region = "us-west-2" -}} |
| 118 | + {{- end -}} |
| 119 | +{{- end -}} |
| 120 | + |
| 121 | +{{/* Region to ECR account ID mapping */}} |
| 122 | +{{- $regionAccountMap := dict |
| 123 | + "us-east-1" "767398015722" |
| 124 | + "us-west-2" "905418368575" |
| 125 | + "us-east-2" "851725546812" |
| 126 | + "us-west-1" "011528288828" |
| 127 | + "eu-central-1" "211125453373" |
| 128 | + "eu-north-1" "654654141839" |
| 129 | + "eu-west-1" "533267293120" |
| 130 | + "eu-west-2" "011528288831" |
| 131 | + "ap-northeast-1" "533267052152" |
| 132 | + "ap-south-1" "011528288864" |
| 133 | + "ap-southeast-1" "905418428165" |
| 134 | + "ap-southeast-2" "851725636348" |
| 135 | + "sa-east-1" "025066253954" |
| 136 | +-}} |
| 137 | + |
| 138 | +{{/* Get the account ID for the region, default to us-west-2 account if region not found */}} |
| 139 | +{{- $accountId := index $regionAccountMap $region | default "905418368575" -}} |
| 140 | + |
| 141 | +{{/* Allow override of the full image URI if specified */}} |
| 142 | +{{- if .Values.hmaimage -}} |
| 143 | + {{- .Values.hmaimage -}} |
| 144 | +{{- else -}} |
| 145 | + {{- printf "%s.dkr.ecr.%s.amazonaws.com/hyperpod-health-monitoring-agent:%s" $accountId $region $imageTag -}} |
| 146 | +{{- end -}} |
| 147 | +{{- end }} |
0 commit comments