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

Existing Cluster Constructs #370

Closed
gbvanrenswoude opened this issue Apr 28, 2022 · 5 comments
Closed

Existing Cluster Constructs #370

gbvanrenswoude opened this issue Apr 28, 2022 · 5 comments
Labels

Comments

@gbvanrenswoude
Copy link

Is the blueprints.ClusterAddOn usable on existing cdk eks.Cluster Constructs / ICluster interfaces? It would be awesome to be able to ship ClusterAddOns to existing clusters deployed using aws-cdk. I'm not sure if that is the point of the blueprints, but it would extend very nicely on top of people who code their own Clusters or have them already running.

@shapirov103
Copy link
Collaborator

I will add an example of importing an existing cluster and applying add-ons to them.

@gbvanrenswoude
Copy link
Author

gbvanrenswoude commented May 2, 2022

@shapirov103 Is it also possible to provide an example in the documentation on how to use blueprints in combination with existing eks.Cluster constructs?

e.g.

import { Cluster } from 'aws-cdk-lib/aws-eks';
<...>

export class InfrastructureStack extends Stack {
    private cluster: Cluster;

    constructor(scope: Construct, id: string, uniqueName: string, owner: nnOwner, featureBranchToggle: boolean, props?: StackProps) {
        super(scope, id, props);

        this.cluster = new eks.Cluster(this, 'eks', {...});
        <...use blueprint 'Construct' ClusterAddOn to build on top...>
<....>
        const clusterInfo = new blueprints.ClusterInfo(this.cluster, kubernetesVersion);

        const postDeploymentSteps = Array<blueprints.ClusterPostDeploy>();

        for (const addOn of stackPropsPassedIn.addOns ?? []) {
            // eslint-disable-next-line no-console
            console.log(`Adding AddOn: ${blueprints.utils.getAddOnNameOrId(addOn)}`);
            const result = addOn.deploy(clusterInfo);
            if (result) {
                const addOnKey = blueprints.utils.getAddOnNameOrId(addOn);
                clusterInfo.addScheduledAddOn(addOnKey, result);
            }
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
            const postDeploy: any = addOn;
            if ((postDeploy as blueprints.ClusterPostDeploy).postDeploy !== undefined) {
                postDeploymentSteps.push(<blueprints.ClusterPostDeploy>postDeploy);
            }
        }
        const scheduledAddOns = clusterInfo.getAllScheduledAddons();
        const addOnKeys = [...scheduledAddOns.keys()];
        const promises = scheduledAddOns.values();

        this.asyncTasks = Promise.all(promises).then((constructs) => {
            constructs.forEach((construct, index) => {
                clusterInfo.addProvisionedAddOn(addOnKeys[index], construct);
            });

            for (const step of postDeploymentSteps) {
                step.postDeploy(clusterInfo, []);
            }
        });

        this.asyncTasks.catch((err) => {
            // eslint-disable-next-line no-console
            console.error(err);
            throw new Error(err);
        });

@shapirov103
Copy link
Collaborator

Will add an item to show leveraging existing cluster and add add-ons / teams.

@github-actions
Copy link

This issue has been automatically marked as stale because it has been open 60 days
with no activity. Remove stale label or comment or this issue will be closed in 10 days

@github-actions github-actions bot added the stale label Jul 22, 2023
@github-actions
Copy link

Issue closed due to inactivity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants