Skip to content

Commit

Permalink
Changed 'assumeRole' to 'assumeRoleARN'
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesGAWS committed Aug 8, 2023
1 parent ae81508 commit b4df2c1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions charts/karpenter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ settings:
# -- AWS-specific configuration values
aws:
# -- Role to assume for calling AWS services.
assumeRole: ""
# -- Duration of assumed credentials in minutes. Default value is 15 minutes. Not used unless aws.assumeRole set.
assumeRoleARN: ""
# -- Duration of assumed credentials in minutes. Default value is 15 minutes. Not used unless aws.assumeRoleARN set.
assumeRoleDuration: ""
# -- Cluster name.
clusterName: ""
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type settingsKeyType struct{}
var ContextKey = settingsKeyType{}

var defaultSettings = &Settings{
AssumeRole: "",
AssumeRoleARN: "",
ClusterName: "",
ClusterEndpoint: "",
AssumeRoleDuration: time.Duration(15) * time.Minute,
Expand All @@ -51,7 +51,7 @@ var defaultSettings = &Settings{

// +k8s:deepcopy-gen=true
type Settings struct {
AssumeRole string
AssumeRoleARN string
ClusterName string `validate:"required"`
ClusterEndpoint string
AssumeRoleDuration time.Duration `validate:"min=15m"`
Expand All @@ -74,7 +74,7 @@ func (*Settings) Inject(ctx context.Context, cm *v1.ConfigMap) (context.Context,
s := defaultSettings.DeepCopy()

if err := configmap.Parse(cm.Data,
configmap.AsString("aws.assumeRole", &s.AssumeRole),
configmap.AsString("aws.assumeRoleARN", &s.AssumeRoleARN),
configmap.AsString("aws.clusterName", &s.ClusterName),
configmap.AsString("aws.clusterEndpoint", &s.ClusterEndpoint),
configmap.AsDuration("aws.assumeRoleDuration", &s.AssumeRoleDuration),
Expand Down
13 changes: 7 additions & 6 deletions pkg/apis/settings/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package settings_test
import (
"context"
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -45,8 +46,8 @@ var _ = Describe("Validation", func() {
ctx, err := (&settings.Settings{}).Inject(ctx, cm)
Expect(err).ToNot(HaveOccurred())
s := settings.FromContext(ctx)
Expect(s.AssumeRole).To(Equal(""))
Expect(s.AssumeRoleDuration).To(Equal(15))
Expect(s.AssumeRoleARN).To(Equal(""))
Expect(s.AssumeRoleDuration).To(Equal(time.Duration(15) * time.Minute))
Expect(s.DefaultInstanceProfile).To(Equal(""))
Expect(s.EnablePodENI).To(BeFalse())
Expect(s.EnableENILimitedPodDensity).To(BeTrue())
Expand All @@ -58,8 +59,8 @@ var _ = Describe("Validation", func() {
It("should succeed to set custom values", func() {
cm := &v1.ConfigMap{
Data: map[string]string{
"aws.assumeRole": "arn:aws:iam::111222333444:role/testrole",
"aws.assumeRoleDuration": "27",
"aws.assumeRoleARN": "arn:aws:iam::111222333444:role/testrole",
"aws.assumeRoleDuration": "27m",
"aws.clusterEndpoint": "https://00000000000000000000000.gr7.us-west-2.eks.amazonaws.com",
"aws.clusterName": "my-cluster",
"aws.defaultInstanceProfile": "karpenter",
Expand All @@ -74,8 +75,8 @@ var _ = Describe("Validation", func() {
ctx, err := (&settings.Settings{}).Inject(ctx, cm)
Expect(err).ToNot(HaveOccurred())
s := settings.FromContext(ctx)
Expect(s.AssumeRole).To(Equal("arn:aws:iam::111222333444:role/testrole"))
Expect(s.AssumeRoleDuration).To(Equal(27))
Expect(s.AssumeRoleARN).To(Equal("arn:aws:iam::111222333444:role/testrole"))
Expect(s.AssumeRoleDuration).To(Equal(time.Duration(27) * time.Minute))
Expect(s.DefaultInstanceProfile).To(Equal("karpenter"))
Expect(s.EnablePodENI).To(BeTrue())
Expect(s.EnableENILimitedPodDensity).To(BeFalse())
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func NewOperator(ctx context.Context, operator *operator.Operator) (context.Cont
STSRegionalEndpoint: endpoints.RegionalSTSEndpoint,
}

if assumeRole := settings.FromContext(ctx).AssumeRole; assumeRole != "" {
config.Credentials = stscreds.NewCredentials(session.Must(session.NewSession()), assumeRole,
if assumeRoleARN := settings.FromContext(ctx).AssumeRoleARN; assumeRoleARN != "" {
config.Credentials = stscreds.NewCredentials(session.Must(session.NewSession()), assumeRoleARN,
func(provider *stscreds.AssumeRoleProvider) { setDurationAndExpiry(provider, ctx) })
}

Expand Down
2 changes: 1 addition & 1 deletion website/content/en/preview/concepts/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ data:
# will be batched separately.
batchIdleDuration: 1s
# Role to assume for calling AWS services.
aws.assumerole: arn:aws:iam::111222333444:role/examplerole
aws.assumeRoleARN: arn:aws:iam::111222333444:role/examplerole
# Duration of assumed credentials in minutes. Default value is 15 minutes. Not used unless aws.assumeRole set.
aws.assumeRoleDuration: 15
# [REQUIRED] The kubernetes cluster name for resource discovery
Expand Down

0 comments on commit b4df2c1

Please sign in to comment.