Skip to content

Commit

Permalink
Merge pull request #805 from PaulMaddox/xray-access
Browse files Browse the repository at this point in the history
Added AWS X-Ray Support
  • Loading branch information
errordeveloper committed May 30, 2019
2 parents 3ffa0db + 7bf85c1 commit b12238d
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 6 deletions.
1 change: 1 addition & 0 deletions humans.txt
Expand Up @@ -39,6 +39,7 @@ Roli Schilter @rndstr
Mitchel Humpherys @mgalgs
Fred Cox @mcfedr
Adam Johnson @adamjohnson01
Paul Maddox @paulmaddox
Patrick Spek @tyil

/* Thanks */
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/eksctl.io/v1alpha5/defaults.go
Expand Up @@ -64,6 +64,9 @@ func SetNodeGroupDefaults(_ int, ng *NodeGroup) error {
if ng.IAM.WithAddonPolicies.ALBIngress == nil {
ng.IAM.WithAddonPolicies.ALBIngress = Disabled()
}
if ng.IAM.WithAddonPolicies.XRay == nil {
ng.IAM.WithAddonPolicies.XRay = Disabled()
}
if ng.IAM.WithAddonPolicies.EBS == nil {
ng.IAM.WithAddonPolicies.EBS = Disabled()
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/eksctl.io/v1alpha5/types.go
Expand Up @@ -355,6 +355,7 @@ func (c *ClusterConfig) NewNodeGroup() *NodeGroup {
FSX: Disabled(),
EFS: Disabled(),
ALBIngress: Disabled(),
XRay: Disabled(),
},
},
SSH: &NodeGroupSSH{
Expand Down Expand Up @@ -476,6 +477,8 @@ type (
EFS *bool `json:"efs"`
// +optional
ALBIngress *bool `json:"albIngress"`
// +optional
XRay *bool `json:"xRay"`
}

// NodeGroupSSH holds all the ssh access configuration to a NodeGroup
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/eksctl.io/v1alpha5/validation.go
Expand Up @@ -40,6 +40,9 @@ func validateNodeGroupIAM(i int, ng *NodeGroup, value, fieldName, path string) e
if IsEnabled(ng.IAM.WithAddonPolicies.ALBIngress) {
return fmt.Errorf("%s.albIngress cannot be set at the same time", p)
}
if IsEnabled(ng.IAM.WithAddonPolicies.XRay) {
return fmt.Errorf("%s.xRay cannot be set at the same time", p)
}
}
return nil
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/eksctl.io/v1alpha5/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions pkg/cfn/builder/api_test.go
Expand Up @@ -389,6 +389,7 @@ var _ = Describe("CloudFormation template builder API", func() {
FSX: api.Disabled(),
EFS: api.Disabled(),
ALBIngress: api.Disabled(),
XRay: api.Disabled(),
},
},
SSH: &api.NodeGroupSSH{
Expand Down Expand Up @@ -962,6 +963,39 @@ var _ = Describe("CloudFormation template builder API", func() {

})

Context("NodeGroupXRay", func() {
cfg, ng := newClusterConfigAndNodegroup(true)

ng.IAM.WithAddonPolicies.XRay = api.Enabled()

build(cfg, "eksctl-test-megaapps-cluster", ng)

roundtrip()

It("should have correct policies", func() {
Expect(ngTemplate.Resources).ToNot(BeEmpty())

Expect(ngTemplate.Resources).To(HaveKey("PolicyXRay"))

policy := ngTemplate.Resources["PolicyXRay"].Properties

Expect(policy.Roles).To(HaveLen(1))
isRefTo(policy.Roles[0], "NodeInstanceRole")

Expect(policy.PolicyDocument.Statement).To(HaveLen(1))
Expect(policy.PolicyDocument.Statement[0].Effect).To(Equal("Allow"))
Expect(policy.PolicyDocument.Statement[0].Resource).To(Equal("*"))
Expect(policy.PolicyDocument.Statement[0].Action).To(Equal([]string{
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
"xray:GetSamplingRules",
"xray:GetSamplingTargets",
"xray:GetSamplingStatisticSummaries",
}))
})

})

Context("NodeGroupEBS", func() {
cfg, ng := newClusterConfigAndNodegroup(true)

Expand Down
12 changes: 12 additions & 0 deletions pkg/cfn/builder/iam.go
Expand Up @@ -343,6 +343,18 @@ func (n *NodeGroupResourceSet) addResourcesForIAM() {
)
}

if api.IsEnabled(n.spec.IAM.WithAddonPolicies.XRay) {
n.rs.attachAllowPolicy("PolicyXRay", refIR, "*",
[]string{
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
"xray:GetSamplingRules",
"xray:GetSamplingTargets",
"xray:GetSamplingStatisticSummaries",
},
)
}

n.rs.defineOutputFromAtt(outputs.NodeGroupInstanceProfileARN, "NodeInstanceProfile.Arn", true, func(v string) error {
n.spec.IAM.InstanceProfileARN = v
return nil
Expand Down
18 changes: 12 additions & 6 deletions pkg/ctl/cmdutils/nodegroup_filter_test.go
Expand Up @@ -344,7 +344,8 @@ const expected = `
"ebs": false,
"fsx": false,
"efs": false,
"albIngress": false
"albIngress": false,
"xRay": false
}
}
},
Expand Down Expand Up @@ -379,7 +380,8 @@ const expected = `
"ebs": false,
"fsx": false,
"efs": false,
"albIngress": false
"albIngress": false,
"xRay": false
}
}
},
Expand Down Expand Up @@ -412,7 +414,8 @@ const expected = `
"ebs": false,
"fsx": false,
"efs": false,
"albIngress": false
"albIngress": false,
"xRay": false
}
},
"clusterDNS": "1.2.3.4"
Expand Down Expand Up @@ -446,7 +449,8 @@ const expected = `
"ebs": false,
"fsx": false,
"efs": false,
"albIngress": false
"albIngress": false,
"xRay": false
}
}
},
Expand Down Expand Up @@ -482,7 +486,8 @@ const expected = `
"ebs": false,
"fsx": false,
"efs": false,
"albIngress": false
"albIngress": false,
"xRay": false
}
},
"clusterDNS": "4.2.8.14"
Expand Down Expand Up @@ -519,7 +524,8 @@ const expected = `
"ebs": false,
"fsx": false,
"efs": false,
"albIngress": false
"albIngress": false,
"xRay": false
}
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/cmdutils/nodegroup_flags.go
Expand Up @@ -57,6 +57,7 @@ func AddCommonCreateNodeGroupIAMAddonsFlags(fs *pflag.FlagSet, ng *api.NodeGroup
ng.IAM.WithAddonPolicies.ImageBuilder = new(bool)
ng.IAM.WithAddonPolicies.AppMesh = new(bool)
ng.IAM.WithAddonPolicies.ALBIngress = new(bool)
ng.IAM.WithAddonPolicies.XRay = new(bool)
fs.BoolVar(ng.IAM.WithAddonPolicies.AutoScaler, "asg-access", false, "enable IAM policy for cluster-autoscaler")
fs.BoolVar(ng.IAM.WithAddonPolicies.ExternalDNS, "external-dns-access", false, "enable IAM policy for external-dns")
fs.BoolVar(ng.IAM.WithAddonPolicies.ImageBuilder, "full-ecr-access", false, "enable full access to ECR")
Expand Down

0 comments on commit b12238d

Please sign in to comment.