cdk-eks-blueprints icon indicating copy to clipboard operation
cdk-eks-blueprints copied to clipboard

Existing Cluster Constructs

Open gbvanrenswoude opened this issue 3 years ago • 3 comments

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.

gbvanrenswoude avatar Apr 28 '22 13:04 gbvanrenswoude

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

shapirov103 avatar Apr 28 '22 14:04 shapirov103

@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);
        });

gbvanrenswoude avatar May 02 '22 12:05 gbvanrenswoude

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

shapirov103 avatar Jul 28 '22 04:07 shapirov103

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[bot] avatar Jul 22 '23 00:07 github-actions[bot]

Issue closed due to inactivity.

github-actions[bot] avatar Sep 20 '23 00:09 github-actions[bot]