From bc908a8615da5ff8bed4c59a91b0de20e4a12f67 Mon Sep 17 00:00:00 2001 From: Christian Bianchi Date: Mon, 11 Sep 2023 09:44:49 +0200 Subject: [PATCH] Get AMI data from helm value rather than from hardcoded string in the code. --- helm/aws-operator/templates/deployment.yaml | 2 +- service/controller/key/common.go | 6 +-- service/internal/images/images_test.go | 50 +++++++++++++++++++++ 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/helm/aws-operator/templates/deployment.yaml b/helm/aws-operator/templates/deployment.yaml index 92ea03f708..b47a821886 100644 --- a/helm/aws-operator/templates/deployment.yaml +++ b/helm/aws-operator/templates/deployment.yaml @@ -58,7 +58,7 @@ spec: - name: {{ include "name" . }}-configmap mountPath: /var/run/{{ include "name" . }}/configmap/ - name: {{ include "name" . }}-ami - mountPath: /etc/ami.json + mountPath: /tmp/ami.json - name: {{ include "name" . }}-secret mountPath: /var/run/{{ include "name" . }}/secret/ readOnly: true diff --git a/service/controller/key/common.go b/service/controller/key/common.go index 9bd146ff97..679a8db5a3 100644 --- a/service/controller/key/common.go +++ b/service/controller/key/common.go @@ -39,7 +39,7 @@ const ( V19AlphaRelease = "19.0.0-alpha1" - amiFilePath = "/etc/ami.json" + amiFilePath = "/tmp/ami.json" ) var amiInfo = map[string]map[string]string{} @@ -81,12 +81,12 @@ func loadAMIs() error { amiJSON, err := os.ReadFile(amiFilePath) if err != nil { - panic(err) + return microerror.Mask(err) } err = json.Unmarshal(amiJSON, &amiInfo) if err != nil { - panic(err) + return microerror.Mask(err) } return nil diff --git a/service/internal/images/images_test.go b/service/internal/images/images_test.go index 94e2bec249..c68a6fd061 100644 --- a/service/internal/images/images_test.go +++ b/service/internal/images/images_test.go @@ -2,6 +2,7 @@ package images import ( "context" + "os" "strconv" "testing" @@ -30,6 +31,55 @@ func Test_Images_Cache(t *testing.T) { }, } + data := `{ + "2345.3.0": { + "ap-east-1": "ami-0a813620447e80b05", + "ap-northeast-1": "ami-02af6d096f0a2f96c", + "ap-northeast-2": "ami-0dd7a397031040ff1", + "ap-south-1": "ami-03205de7c095444bb", + "ap-southeast-1": "ami-0666b8c77a4148316", + "ap-southeast-2": "ami-0be9b0ada4e9f0c7a", + "ca-central-1": "ami-0b0044f3e521384ae", + "eu-central-1": "ami-0c9ac894c7ec2e6dd", + "eu-north-1": "ami-06420e2a1713889dd", + "eu-west-1": "ami-09f0cd6af1e455cd9", + "eu-west-2": "ami-0b1588137b7790e8c", + "eu-west-3": "ami-01a8e028daf4d66cf", + "me-south-1": "ami-0a6518241a90f491f", + "sa-east-1": "ami-037e10c3bd117fb3e", + "us-east-1": "ami-007776654941e2586", + "us-east-2": "ami-0b0a4944bd30c6b85", + "us-west-1": "ami-02fefca3d52d15b1d", + "us-west-2": "ami-0390d41fd4e4a3529" + }, + "2345.3.1": { + "ap-east-1": "ami-0e28e38ecce552688", + "ap-northeast-1": "ami-074891de68922e1f4", + "ap-northeast-2": "ami-0a1a6a05c79bcdfe4", + "ap-south-1": "ami-0765ae35424be8ad8", + "ap-southeast-1": "ami-0f20e37280d5c8c5c", + "ap-southeast-2": "ami-016e5e9a74cc6ef86", + "ca-central-1": "ami-09afcf2e90761d6e6", + "cn-north-1": "ami-019174dba14053d2a", + "cn-northwest-1": "ami-004e81bc53b1e6ffa", + "eu-central-1": "ami-0a9a5d2b65cce04eb", + "eu-north-1": "ami-0bbfc19aa4c355fe2", + "eu-west-1": "ami-002db020452770c0f", + "eu-west-2": "ami-024928e37dcc18a42", + "eu-west-3": "ami-083e4a190c9b050b1", + "me-south-1": "ami-078eb26f287443167", + "sa-east-1": "ami-01180d594d0315f65", + "us-east-1": "ami-011655f166912d5ba", + "us-east-2": "ami-0e30f3d8cbc900ff4", + "us-west-1": "ami-0360d32ce24f1f05f", + "us-west-2": "ami-0c1654a9988866a1f" + } +}` + err := os.WriteFile("/tmp/ami.json", []byte(data), os.ModePerm) + if err != nil { + panic(err) + } + for i, tc := range testCases { t.Run(strconv.Itoa(i), func(t *testing.T) { var err error