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
#3599)

* Get AMI data from helm value rather than from hardcoded string in the code.

* Get AMI data from helm value rather than from hardcoded string in the code.

* Get AMI data from helm value rather than from hardcoded string in the code.

* Get AMI data from helm value rather than from hardcoded string in the code.

* Get AMI data from helm value rather than from hardcoded string in the code.

* Get AMI data from helm value rather than from hardcoded string in the code.

* Get AMI data from helm value rather than from hardcoded string in the code.

* Get AMI data from helm value rather than from hardcoded string in the code.
  • Loading branch information
whites11 authored Sep 11, 2023
1 parent 80497dd commit 5950466
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 1,203 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Get AMI data from helm value rather than from hardcoded string in the code.

## [14.21.0] - 2023-09-01

## [14.20.0] - 2023-08-29
Expand Down
2 changes: 2 additions & 0 deletions helm/aws-operator/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,5 @@ data:
{{- end }}
kubernetes:
incluster: true
ami.json: |
{{- .Values.aws.amiJSON |nindent 4 }}
9 changes: 9 additions & 0 deletions helm/aws-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ spec:
items:
- key: config.yaml
path: config.yaml
- name: {{ include "name" . }}-ami
configMap:
name: {{ include "resource.default.name" . }}
items:
- key: ami.json
path: ami.json
- name: {{ include "name" . }}-secret
secret:
secretName: {{ include "resource.default.name" . }}
Expand All @@ -51,6 +57,9 @@ spec:
volumeMounts:
- name: {{ include "name" . }}-configmap
mountPath: /var/run/{{ include "name" . }}/configmap/
- name: {{ include "name" . }}-ami
mountPath: /tmp/ami.json
subPath: ami.json
- name: {{ include "name" . }}-secret
mountPath: /var/run/{{ include "name" . }}/secret/
readOnly: true
Expand Down
2 changes: 1 addition & 1 deletion helm/aws-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ aws:
enabled: false
vault:
address: "http://localhost:8200"

amiJSON: "{}"
tenant:
cni:
mask: 16
Expand Down
30 changes: 30 additions & 0 deletions service/controller/key/common.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package key

import (
"encoding/json"
"fmt"
"os"
"strings"
"time"
"unicode"
Expand Down Expand Up @@ -36,8 +38,12 @@ const (
ServiceAccountV2Priv = "key"

V19AlphaRelease = "19.0.0-alpha1"

amiFilePath = "/tmp/ami.json"
)

var amiInfo = map[string]map[string]string{}

const (
// TerminateUnhealthyNodeResyncPeriod defines resync period for the terminateunhealthynode controller
TerminateUnhealthyNodeResyncPeriod = time.Minute * 3
Expand Down Expand Up @@ -67,6 +73,25 @@ const sslOnlyBucketPolicyTemplate = `{
]
}`

func loadAMIs() error {
// Data already there, avoid reloading from file.
if len(amiInfo) > 0 {
return nil
}

amiJSON, err := os.ReadFile(amiFilePath)
if err != nil {
return microerror.Mask(err)
}

err = json.Unmarshal(amiJSON, &amiInfo)
if err != nil {
return microerror.Mask(err)
}

return nil
}

// AMI returns the EC2 AMI for the configured region and given version.
func AMI(region string, release releasev1alpha1.Release, flatcarReleaseVersion string) (string, error) {

Expand All @@ -82,6 +107,11 @@ func AMI(region string, release releasev1alpha1.Release, flatcarReleaseVersion s
osVersion = flatcarReleaseVersion
}

err = loadAMIs()
if err != nil {
return "", microerror.Mask(err)
}

regionAMIs, ok := amiInfo[osVersion]
if !ok {
return "", microerror.Maskf(notFoundError, "no image id for version '%s'", osVersion)
Expand Down
Loading

0 comments on commit 5950466

Please sign in to comment.