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

[aws-eks]: Allow creating masters role in stacks other than the cluster stack #13529

Closed
fspaniol opened this issue Mar 10, 2021 · 6 comments
Closed
Labels
@aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. feature-request A feature should be added or improved. p2

Comments

@fspaniol
Copy link

I'm trying to create a role in a different stack and add it to the cluster using awsAuth methods. However, I get an error message stating the following:

Error: RoleStack/Role should be defined in the scope of the EKSCluster stack to prevent circular dependencies

I tried to work around it by using eks.Cluster.fromClusterAttributes but it returns an iCluster instead of a Cluster which does not contain awsAuth.

Reproduction Steps

import * as eks from "@aws-cdk/aws-eks";
import * as iam from "@aws-cdk/aws-iam";
import * as cdk from "@aws-cdk/core";

export class EKSCluster extends cdk.Stack {
  public eksCluster: eks.Cluster;

  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
    this.eksCluster = new eks.Cluster(this, "EKSCluster", {
      version: eks.KubernetesVersion.V1_18,
    });
  }
}

export class RoleStack extends cdk.Stack {
  constructor(
    scope: cdk.Construct,
    id: string,
    props: cdk.StackProps & { cluster: eks.Cluster }
  ) {
    super(scope, id, props);

    const user = new iam.User(this, "User");
    const role = new iam.Role(this, "Role", {
      assumedBy: user,
    });

    const cluster = eks.Cluster.fromClusterAttributes

    props.cluster.awsAuth.addMastersRole(role);
  }
}

const app = new cdk.App();
const eksCluster = new EKSCluster(app, "EKSCluster");
new RoleStack(app, "RoleStack", { cluster: eksCluster.eksCluster });

What did you expect to happen?

I expected to be able to configure the awsAuth in a different stack than the one where the cluster was created

What actually happened?

I got a circular dependency error

Environment

  • CDK CLI Version : 1.91.0
  • Framework Version: 1.91.0
  • Node.js Version: 12.20.1
  • OS : Mac
  • Language (Version): TypeScript

Other

This related to #8884


This is 🐛 Bug Report

@fspaniol fspaniol added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 10, 2021
@github-actions github-actions bot added the @aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service label Mar 10, 2021
@iliapolo
Copy link
Contributor

@fspaniol Thanks for reporting this.

Actually what you're seeing is not a circular dependency problem, but rather a validation (limitation) we put in place to prevent possible circular dependencies.

The main issue is that once the RoleStack uses some runtime property from the cluster, an actual circular dependency will be created that is hard to untangle and debug.

Having said that, we acknowledge that this might be too restrictive, and in your use-case, it actually prevents a would be successful deployment. (More details here)

I'll mark this as a feature request to be more targeted with this limitation.

@iliapolo iliapolo added feature-request A feature should be added or improved. p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. bug This issue is a bug. labels Mar 11, 2021
@iliapolo iliapolo changed the title [aws-eks]: Creating a Role to be used as master in a different stack than the EKS Cluster causes a circular dependency. [aws-eks]: Allow creating masters role in stacks other that the cluster stack Mar 11, 2021
@iliapolo iliapolo removed their assignment Mar 11, 2021
@fspaniol
Copy link
Author

Hi, thanks a lot for the explanation @iliapolo, so, currently the only solution would be to have both the Role and the Cluster be defined in the same stack?

@iliapolo
Copy link
Contributor

Thats right.

@fspaniol fspaniol changed the title [aws-eks]: Allow creating masters role in stacks other that the cluster stack [aws-eks]: Allow creating masters role in stacks other than the cluster stack Mar 30, 2021
@ericzbeard ericzbeard added the feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. label Apr 1, 2021
@iliapolo iliapolo removed their assignment Jun 27, 2021
@github-actions
Copy link

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jun 28, 2022
@github-actions github-actions bot closed this as completed Jul 3, 2022
@a-patel
Copy link

a-patel commented Aug 25, 2023

I am also facing a similar error when I have EksCluster created in a separate stack and make Nodegroup in a different stack for that cluster.

a-patel added a commit to a-patel/aws-cdk-typescript-aws-eks-workshop that referenced this issue Aug 30, 2023
@iantcrg
Copy link

iantcrg commented May 7, 2024

I am facing this issue, having one stack that creates the cluster, and another, dependent stack, create the node groups. Is there any traction here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

5 participants