Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
Get AMI data from helm value rather than from hardcoded string in the…
Browse files Browse the repository at this point in the history
… code.
  • Loading branch information
whites11 committed Sep 11, 2023
1 parent fca5be6 commit bc908a8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion helm/aws-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions service/controller/key/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions service/internal/images/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package images

import (
"context"
"os"
"strconv"
"testing"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bc908a8

Please sign in to comment.