Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AWS X-Ray Support #805

Merged
merged 13 commits into from May 30, 2019
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

/* 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 @@ -961,6 +962,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 @@ -342,6 +342,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
2 changes: 2 additions & 0 deletions pkg/ctl/cmdutils/nodegroup_flags.go
Expand Up @@ -57,11 +57,13 @@ 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")
fs.BoolVar(ng.IAM.WithAddonPolicies.AppMesh, "appmesh-access", false, "enable full access to AppMesh")
fs.BoolVar(ng.IAM.WithAddonPolicies.ALBIngress, "alb-ingress-access", false, "enable full access for alb-ingress-controller")
fs.BoolVar(ng.IAM.WithAddonPolicies.XRay, "xray-access", false, "enable full access to AWS X-Ray")
}

// AddNodeGroupFilterFlags add common `--include` and `--exclude` flags for filtering nodegroups
Expand Down