-
Notifications
You must be signed in to change notification settings - Fork 983
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Security Group specification/override
- Loading branch information
Showing
12 changed files
with
358 additions
and
256 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ssm" | ||
"github.com/aws/aws-sdk-go/service/ssm/ssmiface" | ||
"github.com/patrickmn/go-cache" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
type AMIProvider struct { | ||
cache *cache.Cache | ||
ssm ssmiface.SSMAPI | ||
clientSet *kubernetes.Clientset | ||
} | ||
|
||
func NewAMIProvider(ssm ssmiface.SSMAPI, clientSet *kubernetes.Clientset) *AMIProvider { | ||
return &AMIProvider{ | ||
ssm: ssm, | ||
clientSet: clientSet, | ||
cache: cache.New(CacheTTL, CacheCleanupInterval), | ||
} | ||
} | ||
|
||
func (p *AMIProvider) Get(ctx context.Context, constraints *Constraints) (string, error) { | ||
version, err := p.kubeServerVersion() | ||
if err != nil { | ||
return "", fmt.Errorf("kube server version, %w", err) | ||
} | ||
name := fmt.Sprintf("/aws/service/bottlerocket/aws-k8s-%s/%s/latest/image_id", version, KubeToAWSArchitectures[*constraints.Architecture]) | ||
if id, ok := p.cache.Get(name); ok { | ||
return id.(string), nil | ||
} | ||
output, err := p.ssm.GetParameterWithContext(ctx, &ssm.GetParameterInput{Name: aws.String(name)}) | ||
if err != nil { | ||
return "", fmt.Errorf("getting ssm parameter, %w", err) | ||
} | ||
return aws.StringValue(output.Parameter.Value), nil | ||
} | ||
|
||
func (p *AMIProvider) kubeServerVersion() (string, error) { | ||
version, err := p.clientSet.Discovery().ServerVersion() | ||
if err != nil { | ||
return "", err | ||
} | ||
return fmt.Sprintf("%s.%s", version.Major, strings.TrimSuffix(version.Minor, "+")), 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
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 was deleted.
Oops, something went wrong.
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.