-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Automated AMI management and Upgrade locking (#327)
Automated AMI management InstanceGroups can now set the image configuration to "latest". This will result the ami value being retrieved from a ssm parameter (https://docs.aws.amazon.com/eks/latest/userguide/retrieve-ami-id.html). This will ensure that nodes within an InstanceGroup are kept up-to-date and is especially useful in development clusters. Automated AMI management supports retrieving amazon amis for amazon linux 2, bottlerocket and windows nodes. This can be configured using the annotation `instancemgr.keikoproj.io/os-family`. Upgrade locking InstanceGroups can now set an annotation`instancemgr.keikoproj.io/lock-upgrades="true"` which will prevent the InstanceGroup from entering the InitUpgrade state. This is useful for controlling when the nodes of an InstanceGroup can be upgraded, pairing well with the automated AMI management feature. Signed-off-by: Sebastian Cole <[email protected]>
- Loading branch information
1 parent
19de2db
commit 165095e
Showing
34 changed files
with
789 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/request" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/ssm" | ||
"github.com/aws/aws-sdk-go/service/ssm/ssmiface" | ||
"github.com/keikoproj/aws-sdk-go-cache/cache" | ||
"github.com/keikoproj/instance-manager/controllers/common" | ||
) | ||
|
||
type architectureMap map[string]string | ||
|
||
const ( | ||
EksOptimisedAmiPath = "/aws/service/eks/optimized-ami/%s/amazon-linux-2/recommended/image_id" | ||
EksOptimisedAmazonLinux2Arm64 = "/aws/service/eks/optimized-ami/%s/amazon-linux-2-arm64/recommended/image_id" | ||
EksOptimisedBottlerocket = "/aws/service/bottlerocket/aws-k8s-%s/x86_64/latest/image_id" | ||
EksOptimisedBottlerocketArm64 = "/aws/service/bottlerocket/aws-k8s-%s/arm64/latest/image_id" | ||
EksOptimisedWindowsCore = "/aws/service/ami-windows-latest/Windows_Server-2019-English-Core-EKS_Optimized-%s/image_id" | ||
EksOptimisedWindowsFull = "/aws/service/ami-windows-latest/Windows_Server-2019-English-Full-EKS_Optimized-%s/image_id" | ||
) | ||
|
||
var ( | ||
EksAmis = map[string]architectureMap{ | ||
"amazonlinux2": architectureMap{ | ||
"x86_64": EksOptimisedAmiPath, | ||
"arm64": EksOptimisedAmazonLinux2Arm64, | ||
}, | ||
"bottlerocket": architectureMap{ | ||
"x86_64": EksOptimisedBottlerocket, | ||
"arm64": EksOptimisedBottlerocketArm64, | ||
}, | ||
"windows": architectureMap{ | ||
"x86_64": EksOptimisedWindowsCore, | ||
}, | ||
} | ||
) | ||
|
||
func GetAwsSsmClient(region string, cacheCfg *cache.Config, maxRetries int, collector *common.MetricsCollector) ssmiface.SSMAPI { | ||
config := aws.NewConfig().WithRegion(region).WithCredentialsChainVerboseErrors(true) | ||
config = request.WithRetryer(config, NewRetryLogger(maxRetries, collector)) | ||
sess, err := session.NewSession(config) | ||
if err != nil { | ||
panic(err) | ||
} | ||
cache.AddCaching(sess, cacheCfg) | ||
cacheCfg.SetCacheTTL("ssm", "GetParameter", GetParameterTTL) | ||
sess.Handlers.Complete.PushFront(func(r *request.Request) { | ||
ctx := r.HTTPRequest.Context() | ||
log.V(1).Info("AWS API call", | ||
"cacheHit", cache.IsCacheHit(ctx), | ||
"service", r.ClientInfo.ServiceName, | ||
"operation", r.Operation.Name, | ||
) | ||
}) | ||
return ssm.New(sess) | ||
} | ||
|
||
func (w *AwsWorker) GetEksLatestAmi(OSFamily string, arch string, kubernetesVersion string) (string, error) { | ||
input := &ssm.GetParameterInput{ | ||
Name: aws.String(fmt.Sprintf(EksAmis[OSFamily][arch], kubernetesVersion)), | ||
} | ||
|
||
output, err := w.SsmClient.GetParameter(input) | ||
if err != nil { | ||
return "", err | ||
} | ||
return aws.StringValue(output.Parameter.Value), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.