Skip to content

Commit

Permalink
*: remove CFN dependency from MNG
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <[email protected]>
  • Loading branch information
gyuho committed Jul 17, 2021
1 parent 89ab568 commit 50e5c1b
Show file tree
Hide file tree
Showing 30 changed files with 1,938 additions and 1,625 deletions.
1 change: 1 addition & 0 deletions CHANGELOG/CHANGELOG-1.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ See [code changes](https://github.com/aws/aws-k8s-tester/compare/v1.6.0...v1.6.1
- after, `AWS_K8S_TESTER_EKS_ADD_ON_NODE_GROUPS_ASGS='{"GetRef.Name-ng-for-cni":{"name":"GetRef.Name-ng-for-cni","remote-access-user-name":"ec2-user","ami-type":"AL2_x86_64","asg-min-size":30,"asg-max-size":35,"asg-desired-capacity":34, "instance-type":"type-2", "image-id":"my-ami", "ssm":{"document-create":true, "document-name":"GetRef.Name-document"}, "kubelet-extra-args":"aaa aa", "cluster-autoscaler": {"enable" : true}, "volume-size":500}}'`
- Rename [`AddOnNodeGroups.ASG.InstanceTypes` to `InstanceType`](https://github.com/aws/aws-k8s-tester/commit/a4a3e3635466731519a38f411a1035318fecec59).
- Rename `"instance-types"` to `"instance-type"`.
- [Remove CloudFormation dependency from `AddOnManagedNodeGroups`](https://github.com/aws/aws-k8s-tester/commit/).

### `k8s-tester`

Expand Down
4 changes: 2 additions & 2 deletions eks/app-mesh/app-mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ func (ts *tester) createPolicy() error {
if ts.cfg.EKSConfig.AddOnNodeGroups != nil && ts.cfg.EKSConfig.Role.Name != "" {
roleNames = append(roleNames, ts.cfg.EKSConfig.Role.Name)
}
if ts.cfg.EKSConfig.AddOnManagedNodeGroups != nil && ts.cfg.EKSConfig.AddOnManagedNodeGroups.RoleName != "" {
roleNames = append(roleNames, ts.cfg.EKSConfig.AddOnManagedNodeGroups.RoleName)
if ts.cfg.EKSConfig.AddOnManagedNodeGroups != nil && ts.cfg.EKSConfig.AddOnManagedNodeGroups.Role.Name != "" {
roleNames = append(roleNames, ts.cfg.EKSConfig.AddOnManagedNodeGroups.Role.Name)
}
if len(roleNames) == 0 {
return errors.New("roles not found from node group or managed node group")
Expand Down
26 changes: 22 additions & 4 deletions eks/cluster/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func (ts *tester) createRole() error {
}

ts.cfg.Logger.Info("created a new role and attached policy",
zap.String("cluster-role-arn", ts.cfg.EKSConfig.Role.ARN),
zap.String("cluster-role-name", ts.cfg.EKSConfig.Role.Name),
zap.String("role-arn", ts.cfg.EKSConfig.Role.ARN),
zap.String("role-name", ts.cfg.EKSConfig.Role.Name),
)
return nil
}
Expand Down Expand Up @@ -85,8 +85,8 @@ func (ts *tester) deleteRole() error {

if len(errs) == 0 {
ts.cfg.Logger.Info("successfully deleted role",
zap.String("cluster-role-arn", ts.cfg.EKSConfig.Role.ARN),
zap.String("cluster-role-name", ts.cfg.EKSConfig.Role.Name),
zap.String("role-arn", ts.cfg.EKSConfig.Role.ARN),
zap.String("role-name", ts.cfg.EKSConfig.Role.Name),
)
return nil
}
Expand Down Expand Up @@ -517,5 +517,23 @@ func createStatementEntriesForRolePolicyDocument(partition string, bucketName st
"s3:*",
},
},
{ // arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
Effect: "Allow",
Resource: "*",
Action: []string{
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:BatchGetImage",
"ecr:GetLifecyclePolicy",
"ecr:GetLifecyclePolicyPreview",
"ecr:ListTagsForResource",
"ecr:DescribeImageScanFindings",
},
},
}
}
19 changes: 15 additions & 4 deletions eks/cluster/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@ func (ts *tester) deletePublicNATGateways() (err error) {
if _, ok := ts.cfg.EKSConfig.Status.DeletedResources[id]; ok {
continue
}

_, err := ts.cfg.EC2APIV2.DeleteNatGateway(
context.Background(),
&aws_ec2_v2.DeleteNatGatewayInput{
Expand All @@ -1084,19 +1085,29 @@ func (ts *tester) deletePublicNATGateways() (err error) {
}
continue
}
for i := 0; i < 6; i++ {
for i := 0; i < 10; i++ {
time.Sleep(10 * time.Second)
_, err = ts.cfg.EC2APIV2.DeleteNatGateway(
_, err1 := ts.cfg.EC2APIV2.DeleteNatGateway(
context.Background(),
&aws_ec2_v2.DeleteNatGatewayInput{
NatGatewayId: aws_v2.String(id),
},
)
if err == nil {
_, err2 := ts.cfg.EC2APIV2.DescribeNatGateways(
context.Background(),
&aws_ec2_v2.DescribeNatGatewaysInput{
NatGatewayIds: []string{id},
},
)
if err2 == nil {
continue
}
ts.cfg.Logger.Warn("failed to describe NAT gateway during deletion",
zap.String("delete-error", fmt.Sprintf("%v", err1)),
zap.Error(err2),
)
var apiErr smithy.APIError
if errors.As(err, &apiErr) {
if errors.As(err2, &apiErr) {
if strings.Contains(apiErr.ErrorCode(), "NotFound") {
ts.cfg.EKSConfig.Status.DeletedResources[id] = "VPC.NATGatewayID"
ts.cfg.EKSConfig.Sync()
Expand Down
64 changes: 46 additions & 18 deletions eks/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ type Tester struct {
ecrAPIV2 *aws_ecr_v2.Client

// used for EKS + EKS MNG API calls
eksSession *session.Session
eksAPI eksiface.EKSAPI
eksAPIV2 *aws_eks_v2.Client
eksAPIForCluster eksiface.EKSAPI
eksAPIForClusterV2 *aws_eks_v2.Client
eksAPIForMNG eksiface.EKSAPI
eksAPIForMNGV2 *aws_eks_v2.Client

s3Uploaded bool

Expand Down Expand Up @@ -496,7 +497,8 @@ func New(cfg *eksconfig.Config) (ts *Tester, err error) {
}

// create a separate session for EKS (for resolver endpoint)
ts.eksSession, _, ts.cfg.Status.AWSCredentialPath, err = pkg_aws.New(&pkg_aws.Config{
var eksSessionForCluster *session.Session
eksSessionForCluster, _, ts.cfg.Status.AWSCredentialPath, err = pkg_aws.New(&pkg_aws.Config{
Logger: ts.lg,
DebugAPICalls: ts.cfg.LogLevel == "debug",
Partition: ts.cfg.Partition,
Expand All @@ -507,9 +509,8 @@ func New(cfg *eksconfig.Config) (ts *Tester, err error) {
if err != nil {
return nil, err
}
ts.eksAPI = aws_eks.New(ts.eksSession)
ts.eksAPIForCluster = aws_eks.New(eksSessionForCluster)

ts.lg.Info("checking AWS SDK Go v2 for EKS")
awsCfgV2EKS, err := pkg_aws.NewV2(&pkg_aws.Config{
Logger: ts.lg,
DebugAPICalls: ts.cfg.LogLevel == "debug",
Expand All @@ -521,11 +522,40 @@ func New(cfg *eksconfig.Config) (ts *Tester, err error) {
if err != nil {
return nil, err
}
ts.eksAPIV2 = aws_eks_v2.NewFromConfig(awsCfgV2EKS)
ts.eksAPIForClusterV2 = aws_eks_v2.NewFromConfig(awsCfgV2EKS)

if ts.cfg.IsEnabledAddOnManagedNodeGroups() {
var eksSessionForMNG *session.Session
eksSessionForMNG, _, ts.cfg.Status.AWSCredentialPath, err = pkg_aws.New(&pkg_aws.Config{
Logger: ts.lg,
DebugAPICalls: ts.cfg.LogLevel == "debug",
Partition: ts.cfg.Partition,
Region: ts.cfg.Region,
ResolverURL: ts.cfg.AddOnManagedNodeGroups.ResolverURL,
SigningName: ts.cfg.AddOnManagedNodeGroups.SigningName,
})
if err != nil {
return nil, err
}
ts.eksAPIForMNG = aws_eks.New(eksSessionForMNG)

awsCfgV2EKS, err := pkg_aws.NewV2(&pkg_aws.Config{
Logger: ts.lg,
DebugAPICalls: ts.cfg.LogLevel == "debug",
Partition: ts.cfg.Partition,
Region: ts.cfg.Region,
ResolverURL: ts.cfg.AddOnManagedNodeGroups.ResolverURL,
SigningName: ts.cfg.AddOnManagedNodeGroups.SigningName,
})
if err != nil {
return nil, err
}
ts.eksAPIForMNGV2 = aws_eks_v2.NewFromConfig(awsCfgV2EKS)
}

ts.lg.Info("checking EKS API v1 availability; listing clusters")
var eksListResp *aws_eks.ListClustersOutput
eksListResp, err = ts.eksAPI.ListClusters(&aws_eks.ListClustersInput{
eksListResp, err = ts.eksAPIForCluster.ListClusters(&aws_eks.ListClustersInput{
MaxResults: aws.Int64(20),
})
if err != nil {
Expand All @@ -539,7 +569,7 @@ func New(cfg *eksconfig.Config) (ts *Tester, err error) {
ts.lg.Info("checking EKS API v2 availability; listing clusters")
var eksListRespV2 *aws_eks_v2.ListClustersOutput
cctx, ccancel := context.WithTimeout(context.Background(), 10*time.Second)
eksListRespV2, err = ts.eksAPIV2.ListClusters(
eksListRespV2, err = ts.eksAPIForClusterV2.ListClusters(
cctx,
&aws_eks_v2.ListClustersInput{
MaxResults: aws.Int32(20),
Expand Down Expand Up @@ -618,8 +648,8 @@ func (ts *Tester) createTesters() (err error) {
KMSAPIV2: ts.kmsAPIV2,
CFNAPI: ts.cfnAPI,
EC2APIV2: ts.ec2APIV2,
EKSAPI: ts.eksAPI,
EKSAPIV2: ts.eksAPIV2,
EKSAPI: ts.eksAPIForCluster,
EKSAPIV2: ts.eksAPIForClusterV2,
ELBV2APIV2: ts.elbv2APIV2,
})

Expand Down Expand Up @@ -654,12 +684,10 @@ func (ts *Tester) createTesters() (err error) {
IAMAPIV2: ts.iamAPIV2,
EC2APIV2: ts.ec2APIV2,
ASGAPIV2: ts.asgAPIV2,
EKSAPI: ts.eksAPI,
EKSAPI: ts.eksAPIForMNG,
EKSAPIV2: ts.eksAPIForMNGV2,

IAMAPI: ts.iamAPI,
CFNAPI: ts.cfnAPI,
EC2API: ts.ec2API,
ASGAPI: ts.asgAPI,
})
ts.gpuTester = gpu.New(gpu.Config{
Logger: ts.lg,
Expand Down Expand Up @@ -873,7 +901,7 @@ func (ts *Tester) createTesters() (err error) {
S3API: ts.s3API,
IAMAPI: ts.iamAPI,
CFNAPI: ts.cfnAPI,
EKSAPI: ts.eksAPI,
EKSAPI: ts.eksAPIForCluster,
ECRAPI: ecr.New(ts.awsSession, aws.NewConfig().WithRegion(ts.cfg.GetAddOnFargateRepositoryRegion())),
}),
irsa.New(irsa.Config{
Expand All @@ -896,7 +924,7 @@ func (ts *Tester) createTesters() (err error) {
S3API: ts.s3API,
IAMAPI: ts.iamAPI,
CFNAPI: ts.cfnAPI,
EKSAPI: ts.eksAPI,
EKSAPI: ts.eksAPIForCluster,
ECRAPI: ecr.New(ts.awsSession, aws.NewConfig().WithRegion(ts.cfg.GetAddOnIRSAFargateRepositoryRegion())),
}),
wordpress.New(wordpress.Config{
Expand Down Expand Up @@ -995,7 +1023,7 @@ func (ts *Tester) createTesters() (err error) {
Stopc: ts.stopCreationCh,
EKSConfig: ts.cfg,
K8SClient: ts.k8sClient,
EKSAPI: ts.eksAPI,
EKSAPI: ts.eksAPIForCluster,
}),
ami_soft_lockup_issue_454.New(ami_soft_lockup_issue_454.Config{
Logger: ts.lg,
Expand Down
2 changes: 1 addition & 1 deletion eks/kubeflow/kubeflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (ts *tester) writeKfctlConfig() error {
nodeInstanceRoleName = ts.cfg.EKSConfig.Role.Name
}
if ts.cfg.EKSConfig.IsEnabledAddOnManagedNodeGroups() {
nodeInstanceRoleName = ts.cfg.EKSConfig.AddOnManagedNodeGroups.RoleName
nodeInstanceRoleName = ts.cfg.EKSConfig.AddOnManagedNodeGroups.Role.Name
}

tpl := template.Must(template.New("kfctlConfigTmpl").Parse(kfctlConfigTmpl))
Expand Down
Loading

0 comments on commit 50e5c1b

Please sign in to comment.