From 3328fbefede61dcb28e35b07f0ef23e8593c9724 Mon Sep 17 00:00:00 2001 From: Florian Stadler Date: Fri, 24 Jan 2025 14:54:40 +0100 Subject: [PATCH] Clean up provider internals (#1591) This change cleans up the provider internals in preparation for more involved features like adding EFA support (https://github.com/pulumi/pulumi-eks/issues/1564). This was necessary because there was still a substantial amount of legacy cruft in the provider that wasn't even exposed to users (seem to be leftovers from moving the nodejs implementation onto MLCs). Additionally it slightly reorganizes the internal module structure in order to have a more manageable code structure (compared to the current flat structure and HUGE files). This change should be fully transparent to users. --- .../__snapshots__/cni-addon.test.ts.snap | 0 nodejs/eks/{ => addons}/addon.test.ts | 0 nodejs/eks/{ => addons}/addon.ts | 2 +- nodejs/eks/{ => addons}/cni-addon.test.ts | 0 nodejs/eks/{ => addons}/cni-addon.ts | 2 +- nodejs/eks/addons/index.ts | 17 ++ .../{ => cluster}/authenticationMode.test.ts | 2 +- .../eks/{ => cluster}/authenticationMode.ts | 0 nodejs/eks/{ => cluster}/cert-thumprint.ts | 0 nodejs/eks/{ => cluster}/cluster.test.ts | 0 nodejs/eks/{ => cluster}/cluster.ts | 161 +------------ nodejs/eks/cluster/index.ts | 16 ++ nodejs/eks/{ => cluster}/storageclass.ts | 1 - nodejs/eks/cmd/provider/addon.ts | 2 +- nodejs/eks/cmd/provider/cluster.ts | 4 +- nodejs/eks/cmd/provider/cni-addon.ts | 2 +- nodejs/eks/cmd/provider/index.ts | 8 +- nodejs/eks/cmd/provider/nodegroup.ts | 8 +- nodejs/eks/cmd/provider/securitygroup.ts | 2 +- nodejs/eks/index.ts | 31 --- .../__snapshots__/userdata.test.ts.snap | 0 nodejs/eks/{ => nodes}/ami.test.ts | 0 nodejs/eks/{ => nodes}/ami.ts | 0 nodejs/eks/nodes/index.ts | 24 ++ nodejs/eks/{ => nodes}/nodegroup.test.ts | 8 +- nodejs/eks/{ => nodes}/nodegroup.ts | 219 ++---------------- nodejs/eks/{ => nodes}/securitygroup.ts | 2 +- nodejs/eks/{ => nodes}/userdata.test.ts | 0 nodejs/eks/{ => nodes}/userdata.ts | 2 +- nodejs/eks/transform.ts | 58 ----- 30 files changed, 115 insertions(+), 456 deletions(-) rename nodejs/eks/{ => addons}/__snapshots__/cni-addon.test.ts.snap (100%) rename nodejs/eks/{ => addons}/addon.test.ts (100%) rename nodejs/eks/{ => addons}/addon.ts (98%) rename nodejs/eks/{ => addons}/cni-addon.test.ts (100%) rename nodejs/eks/{ => addons}/cni-addon.ts (99%) create mode 100644 nodejs/eks/addons/index.ts rename nodejs/eks/{ => cluster}/authenticationMode.test.ts (99%) rename nodejs/eks/{ => cluster}/authenticationMode.ts (100%) rename nodejs/eks/{ => cluster}/cert-thumprint.ts (100%) rename nodejs/eks/{ => cluster}/cluster.test.ts (100%) rename nodejs/eks/{ => cluster}/cluster.ts (94%) create mode 100644 nodejs/eks/cluster/index.ts rename nodejs/eks/{ => cluster}/storageclass.ts (99%) rename nodejs/eks/{ => nodes}/__snapshots__/userdata.test.ts.snap (100%) rename nodejs/eks/{ => nodes}/ami.test.ts (100%) rename nodejs/eks/{ => nodes}/ami.ts (100%) create mode 100644 nodejs/eks/nodes/index.ts rename nodejs/eks/{ => nodes}/nodegroup.test.ts (98%) rename nodejs/eks/{ => nodes}/nodegroup.ts (91%) rename nodejs/eks/{ => nodes}/securitygroup.ts (99%) rename nodejs/eks/{ => nodes}/userdata.test.ts (100%) rename nodejs/eks/{ => nodes}/userdata.ts (99%) delete mode 100644 nodejs/eks/transform.ts diff --git a/nodejs/eks/__snapshots__/cni-addon.test.ts.snap b/nodejs/eks/addons/__snapshots__/cni-addon.test.ts.snap similarity index 100% rename from nodejs/eks/__snapshots__/cni-addon.test.ts.snap rename to nodejs/eks/addons/__snapshots__/cni-addon.test.ts.snap diff --git a/nodejs/eks/addon.test.ts b/nodejs/eks/addons/addon.test.ts similarity index 100% rename from nodejs/eks/addon.test.ts rename to nodejs/eks/addons/addon.test.ts diff --git a/nodejs/eks/addon.ts b/nodejs/eks/addons/addon.ts similarity index 98% rename from nodejs/eks/addon.ts rename to nodejs/eks/addons/addon.ts index 1c8c029fa..fdae9aeb9 100644 --- a/nodejs/eks/addon.ts +++ b/nodejs/eks/addons/addon.ts @@ -14,7 +14,7 @@ import * as pulumi from "@pulumi/pulumi"; import * as aws from "@pulumi/aws"; -import { Cluster } from "./cluster"; +import { Cluster } from "../cluster"; /** * AddonOptions describes the configuration options available for the Amazon VPC CNI plugin for Kubernetes. This is obtained from diff --git a/nodejs/eks/cni-addon.test.ts b/nodejs/eks/addons/cni-addon.test.ts similarity index 100% rename from nodejs/eks/cni-addon.test.ts rename to nodejs/eks/addons/cni-addon.test.ts diff --git a/nodejs/eks/cni-addon.ts b/nodejs/eks/addons/cni-addon.ts similarity index 99% rename from nodejs/eks/cni-addon.ts rename to nodejs/eks/addons/cni-addon.ts index aa1fc8c41..af98d0099 100644 --- a/nodejs/eks/cni-addon.ts +++ b/nodejs/eks/addons/cni-addon.ts @@ -16,7 +16,7 @@ import * as pulumi from "@pulumi/pulumi"; import * as aws from "@pulumi/aws"; import * as k8s from "@pulumi/kubernetes"; import { stringifyAddonConfiguration } from "./addon"; -import { isObject } from "./utilities"; +import { isObject } from "../utilities"; export interface VpcCniAddonOptions extends CniEnvVariables { clusterName: pulumi.Input; diff --git a/nodejs/eks/addons/index.ts b/nodejs/eks/addons/index.ts new file mode 100644 index 000000000..c8458b3cf --- /dev/null +++ b/nodejs/eks/addons/index.ts @@ -0,0 +1,17 @@ +// Copyright 2016-2024, Pulumi Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export { Addon } from "./addon"; +export { VpcCniAddon, VpcCniAddonOptions } from "./cni-addon"; +export { stringifyAddonConfiguration } from "./addon"; diff --git a/nodejs/eks/authenticationMode.test.ts b/nodejs/eks/cluster/authenticationMode.test.ts similarity index 99% rename from nodejs/eks/authenticationMode.test.ts rename to nodejs/eks/cluster/authenticationMode.test.ts index 824abac05..fe0ba8c03 100644 --- a/nodejs/eks/authenticationMode.test.ts +++ b/nodejs/eks/cluster/authenticationMode.test.ts @@ -18,7 +18,7 @@ import { validateAuthenticationMode, } from "./authenticationMode"; -import { ClusterOptions, AuthenticationMode } from "./cluster"; +import { ClusterOptions } from "./cluster"; import * as aws from "@pulumi/aws"; diff --git a/nodejs/eks/authenticationMode.ts b/nodejs/eks/cluster/authenticationMode.ts similarity index 100% rename from nodejs/eks/authenticationMode.ts rename to nodejs/eks/cluster/authenticationMode.ts diff --git a/nodejs/eks/cert-thumprint.ts b/nodejs/eks/cluster/cert-thumprint.ts similarity index 100% rename from nodejs/eks/cert-thumprint.ts rename to nodejs/eks/cluster/cert-thumprint.ts diff --git a/nodejs/eks/cluster.test.ts b/nodejs/eks/cluster/cluster.test.ts similarity index 100% rename from nodejs/eks/cluster.test.ts rename to nodejs/eks/cluster/cluster.test.ts diff --git a/nodejs/eks/cluster.ts b/nodejs/eks/cluster/cluster.ts similarity index 94% rename from nodejs/eks/cluster.ts rename to nodejs/eks/cluster/cluster.ts index 728bd4edd..5c2721793 100644 --- a/nodejs/eks/cluster.ts +++ b/nodejs/eks/cluster/cluster.ts @@ -30,20 +30,19 @@ import { validateAuthenticationMode, } from "./authenticationMode"; import { getIssuerCAThumbprint } from "./cert-thumprint"; -import { assertCompatibleAWSCLIExists } from "./dependencies"; +import { assertCompatibleAWSCLIExists } from "../dependencies"; import { computeWorkerSubnets, createNodeGroupV2, NodeGroupBaseOptions, NodeGroupV2Data, -} from "./nodegroup"; -import { createNodeGroupSecurityGroup } from "./securitygroup"; -import { ServiceRole } from "./servicerole"; +} from "../nodes"; +import { createNodeGroupSecurityGroup } from "../nodes"; +import { ServiceRole } from "../servicerole"; import { createStorageClass, EBSVolumeType, StorageClass } from "./storageclass"; -import { InputTags, UserStorageClasses } from "./utils"; -import { VpcCniAddon, VpcCniAddonOptions } from "./cni-addon"; -import { stringifyAddonConfiguration } from "./addon"; -import { getRegionFromArn } from "./utilities"; +import { InputTags, UserStorageClasses } from "../utils"; +import { stringifyAddonConfiguration, VpcCniAddon, VpcCniAddonOptions } from "../addons"; +import { getRegionFromArn } from "../utilities"; /** * RoleMapping describes a mapping from an AWS IAM role to a Kubernetes user and groups. @@ -2015,137 +2014,6 @@ export const AccessEntryType = { */ export type AccessEntryType = (typeof AccessEntryType)[keyof typeof AccessEntryType]; -/** - * Cluster is a component that wraps the AWS and Kubernetes resources necessary to run an EKS cluster, its worker - * nodes, its optional StorageClasses, and an optional deployment of the Kubernetes Dashboard. - */ -export class Cluster extends pulumi.ComponentResource { - /** - * A kubeconfig that can be used to connect to the EKS cluster. - */ - public readonly kubeconfig: pulumi.Output; - - /** - * A kubeconfig that can be used to connect to the EKS cluster as a JSON string. - */ - public readonly kubeconfigJson: pulumi.Output; - - /** - * The AWS resource provider. - */ - public readonly awsProvider: pulumi.ProviderResource; - - /** - * A Kubernetes resource provider that can be used to deploy into this cluster. For example, the code below will - * create a new Pod in the EKS cluster. - * - * let eks = new Cluster("eks"); - * let pod = new kubernetes.core.v1.Pod("pod", { ... }, { provider: eks.provider }); - * - */ - public readonly provider: k8s.Provider; - - /** - * The security group for the EKS cluster. - */ - public readonly clusterSecurityGroup: aws.ec2.SecurityGroup | undefined; - - /** - * The service roles used by the EKS cluster. - */ - public readonly instanceRoles: pulumi.Output; - - /** - * The security group for the cluster's nodes. - */ - public readonly nodeSecurityGroup: aws.ec2.SecurityGroup | undefined; - - /** - * The ingress rule that gives node group access to cluster API server - */ - public readonly eksClusterIngressRule: aws.ec2.SecurityGroupRule | undefined; - - /** - * The default Node Group configuration, or undefined if `skipDefaultNodeGroup` was specified. - */ - public readonly defaultNodeGroup: NodeGroupV2Data | undefined; - - /** - * The EKS cluster. - */ - public readonly eksCluster: aws.eks.Cluster; - - /** - * The EKS cluster and its dependencies. - */ - public readonly core: CoreData; - - /** - * Create a new EKS cluster with worker nodes, optional storage classes, and deploy the Kubernetes Dashboard if - * requested. - * - * @param name The _unique_ name of this component. - * @param args The arguments for this cluster. - * @param opts A bag of options that control this component's behavior. - */ - constructor(name: string, args?: ClusterOptions, opts?: pulumi.ComponentResourceOptions) { - const type = "eks:index:Cluster"; - - if (opts?.urn) { - const props = { - kubeconfig: undefined, - eksCluster: undefined, - }; - super(type, name, props, opts); - return; - } - - super(type, name, args, opts); - - const cluster = createCluster(name, this, args, opts); - this.kubeconfig = cluster.kubeconfig; - this.kubeconfigJson = cluster.kubeconfigJson; - this.clusterSecurityGroup = cluster.clusterSecurityGroup; - this.instanceRoles = cluster.instanceRoles; - this.nodeSecurityGroup = cluster.nodeSecurityGroup; - this.eksClusterIngressRule = cluster.eksClusterIngressRule; - this.defaultNodeGroup = cluster.defaultNodeGroup; - this.eksCluster = cluster.eksCluster; - this.core = cluster.core; - - this.registerOutputs({ - kubeconfig: this.kubeconfig, - eksCluster: this.eksCluster, - }); - } - - /** - * Generate a kubeconfig for cluster authentication that does not use the - * default AWS credential provider chain, and instead is scoped to - * the supported options in `KubeconfigOptions`. - * - * The kubeconfig generated is automatically stringified for ease of use - * with the pulumi/kubernetes provider. - * - * See for more details: - * - https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html - * - https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.html - * - https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html - */ - getKubeconfig(args: KubeconfigOptions): pulumi.Output { - const region = this.eksCluster.arn.apply(getRegionFromArn); - const kc = generateKubeconfig( - this.eksCluster.name, - this.eksCluster.endpoint, - region, - true, - this.eksCluster.certificateAuthority?.data, - args, - ); - return pulumi.output(kc).apply(JSON.stringify); - } -} - /** @internal */ export interface ClusterResult { kubeconfig: pulumi.Output; @@ -2243,9 +2111,9 @@ export function createCluster( defaultNodeGroup = createNodeGroupV2( name, { - cluster: core, ...core.nodeGroupOptions, }, + pulumi.output(core), self, ); } @@ -2301,17 +2169,10 @@ export function createCluster( } /** - * This is a variant of `Cluster` that is used for the MLC `Cluster`. We don't just use `Cluster`, - * because not all of its output properties are typed as `Output`, which prevents it from being - * able to be correctly "rehydrated" from a resource reference. So we use this copy instead rather - * than modifying the public surface area of the existing `Cluster` class, which is still being - * used directly by users using the Node.js SDK. Once we move Node.js over to the generated MLC SDK, - * we can clean all this up. Internally, this leverages the same `createCluster` helper method that - * `Cluster` uses. - * - * @internal + * Cluster is a component that wraps the AWS and Kubernetes resources necessary to run an EKS cluster, its worker + * nodes, its optional StorageClasses, and an optional deployment of the Kubernetes Dashboard. */ -export class ClusterInternal extends pulumi.ComponentResource { +export class Cluster extends pulumi.ComponentResource { public readonly clusterSecurityGroup!: pulumi.Output; public readonly core!: pulumi.Output>; public readonly defaultNodeGroup!: pulumi.Output | undefined>; diff --git a/nodejs/eks/cluster/index.ts b/nodejs/eks/cluster/index.ts new file mode 100644 index 000000000..9cda82fed --- /dev/null +++ b/nodejs/eks/cluster/index.ts @@ -0,0 +1,16 @@ +// Copyright 2016-2024, Pulumi Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export { Cluster, ClusterCreationRoleProvider, CoreData } from "./cluster"; +export { supportsAccessEntries } from "./authenticationMode"; diff --git a/nodejs/eks/storageclass.ts b/nodejs/eks/cluster/storageclass.ts similarity index 99% rename from nodejs/eks/storageclass.ts rename to nodejs/eks/cluster/storageclass.ts index 8ed212af0..036c83d83 100644 --- a/nodejs/eks/storageclass.ts +++ b/nodejs/eks/cluster/storageclass.ts @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -import * as aws from "@pulumi/aws"; import * as k8s from "@pulumi/kubernetes"; import * as k8sInputs from "@pulumi/kubernetes/types/input"; import * as pulumi from "@pulumi/pulumi"; diff --git a/nodejs/eks/cmd/provider/addon.ts b/nodejs/eks/cmd/provider/addon.ts index 5cb9491d4..277c08f03 100644 --- a/nodejs/eks/cmd/provider/addon.ts +++ b/nodejs/eks/cmd/provider/addon.ts @@ -13,7 +13,7 @@ // limitations under the License. import * as pulumi from "@pulumi/pulumi"; -import { Addon } from "../../addon"; +import { Addon } from "../../addons"; const managedAddonProvider: pulumi.provider.Provider = { construct: ( diff --git a/nodejs/eks/cmd/provider/cluster.ts b/nodejs/eks/cmd/provider/cluster.ts index 8247730db..9ea839f52 100644 --- a/nodejs/eks/cmd/provider/cluster.ts +++ b/nodejs/eks/cmd/provider/cluster.ts @@ -13,7 +13,7 @@ // limitations under the License. import * as pulumi from "@pulumi/pulumi"; -import { ClusterCreationRoleProvider, ClusterInternal } from "../../cluster"; +import { ClusterCreationRoleProvider, Cluster } from "../../cluster"; const clusterProvider: pulumi.provider.Provider = { construct: ( @@ -23,7 +23,7 @@ const clusterProvider: pulumi.provider.Provider = { options: pulumi.ComponentResourceOptions, ) => { try { - const cluster = new ClusterInternal(name, inputs, options); + const cluster = new Cluster(name, inputs, options); return Promise.resolve({ urn: cluster.urn, state: { diff --git a/nodejs/eks/cmd/provider/cni-addon.ts b/nodejs/eks/cmd/provider/cni-addon.ts index 767c85b5f..03fa75364 100644 --- a/nodejs/eks/cmd/provider/cni-addon.ts +++ b/nodejs/eks/cmd/provider/cni-addon.ts @@ -13,7 +13,7 @@ // limitations under the License. import * as pulumi from "@pulumi/pulumi"; -import { VpcCniAddon } from "../../cni-addon"; +import { VpcCniAddon } from "../../addons"; const cniAddonProvider: pulumi.provider.Provider = { construct: ( diff --git a/nodejs/eks/cmd/provider/index.ts b/nodejs/eks/cmd/provider/index.ts index 157ebfca9..e8661d1ff 100644 --- a/nodejs/eks/cmd/provider/index.ts +++ b/nodejs/eks/cmd/provider/index.ts @@ -14,8 +14,8 @@ import * as pulumi from "@pulumi/pulumi"; import { readFileSync } from "fs"; -import { ClusterInternal } from "../../cluster"; -import { VpcCniAddon } from "../../cni-addon"; +import { Cluster } from "../../cluster"; +import { VpcCniAddon } from "../../addons/cni-addon"; import { clusterCreationRoleProviderProviderFactory, clusterProviderFactory } from "./cluster"; import { cniAddonProviderFactory } from "./cni-addon"; import { @@ -50,7 +50,7 @@ class Provider implements pulumi.provider.Provider { construct: (name, type, urn) => { switch (type) { case "eks:index:Cluster": - return new ClusterInternal(name, undefined, { urn }); + return new Cluster(name, undefined, { urn }); case "eks:index:VpcCniAddon": return new VpcCniAddon(name, undefined, { urn }); default: @@ -63,7 +63,7 @@ class Provider implements pulumi.provider.Provider { async call(token: string, inputs: pulumi.Inputs): Promise { switch (token) { case "eks:index:Cluster/getKubeconfig": - const self: ClusterInternal = inputs.__self__; + const self: Cluster = inputs.__self__; const result = self.getKubeconfig({ profileName: inputs.profileName, roleArn: inputs.roleArn, diff --git a/nodejs/eks/cmd/provider/nodegroup.ts b/nodejs/eks/cmd/provider/nodegroup.ts index fa5808107..841e77cdd 100644 --- a/nodejs/eks/cmd/provider/nodegroup.ts +++ b/nodejs/eks/cmd/provider/nodegroup.ts @@ -13,7 +13,7 @@ // limitations under the License. import * as pulumi from "@pulumi/pulumi"; -import { ManagedNodeGroupInternal, NodeGroupInternal, NodeGroupV2Internal } from "../../nodegroup"; +import { ManagedNodeGroup, NodeGroup, NodeGroupV2 } from "../../nodes"; const nodeGroupProvider: pulumi.provider.Provider = { construct: ( @@ -23,7 +23,7 @@ const nodeGroupProvider: pulumi.provider.Provider = { options: pulumi.ComponentResourceOptions, ) => { try { - const nodegroup = new NodeGroupInternal(name, inputs, options); + const nodegroup = new NodeGroup(name, inputs, options); return Promise.resolve({ urn: nodegroup.urn, state: { @@ -54,7 +54,7 @@ const managedNodeGroupProvider: pulumi.provider.Provider = { options: pulumi.ComponentResourceOptions, ) => { try { - const nodegroup = new ManagedNodeGroupInternal(name, inputs, options); + const nodegroup = new ManagedNodeGroup(name, inputs, options); return Promise.resolve({ urn: nodegroup.urn, state: { @@ -81,7 +81,7 @@ const nodeGroupV2Provider: pulumi.provider.Provider = { options: pulumi.ComponentResourceOptions, ) => { try { - const nodegroup = new NodeGroupV2Internal(name, inputs, options); + const nodegroup = new NodeGroupV2(name, inputs, options); return Promise.resolve({ urn: nodegroup.urn, state: { diff --git a/nodejs/eks/cmd/provider/securitygroup.ts b/nodejs/eks/cmd/provider/securitygroup.ts index a7196a618..83d25e83b 100644 --- a/nodejs/eks/cmd/provider/securitygroup.ts +++ b/nodejs/eks/cmd/provider/securitygroup.ts @@ -13,7 +13,7 @@ // limitations under the License. import * as pulumi from "@pulumi/pulumi"; -import { NodeGroupSecurityGroup } from "../../securitygroup"; +import { NodeGroupSecurityGroup } from "../../nodes"; const nodeGroupSecurityGroupProvider: pulumi.provider.Provider = { construct: ( diff --git a/nodejs/eks/index.ts b/nodejs/eks/index.ts index 45fa1a98b..d1077c88b 100644 --- a/nodejs/eks/index.ts +++ b/nodejs/eks/index.ts @@ -11,34 +11,3 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - -export { - AccessEntry, - AccessEntryType, - AccessPolicyAssociation, - AuthenticationMode, - Cluster, - ClusterOptions, - ClusterNodeGroupOptions, - CoreData, - RoleMapping, - UserMapping, - CreationRoleProvider, - ClusterCreationRoleProvider, - ClusterCreationRoleProviderOptions, - KubeconfigOptions, -} from "./cluster"; -export { - ManagedNodeGroup, - ManagedNodeGroupOptions, - NodeGroup, - NodeGroupV2, - NodeGroupOptions, - NodeGroupData, -} from "./nodegroup"; -export { VpcCniAddon, VpcCniAddonOptions } from "./cni-addon"; -export { NodeGroupSecurityGroup } from "./securitygroup"; -export { StorageClass, EBSVolumeType } from "./storageclass"; -export { InputTags, UserStorageClasses } from "./utils"; -export { Addon, AddonOptions } from "./addon"; -export { AmiType, OperatingSystem } from "./ami"; diff --git a/nodejs/eks/__snapshots__/userdata.test.ts.snap b/nodejs/eks/nodes/__snapshots__/userdata.test.ts.snap similarity index 100% rename from nodejs/eks/__snapshots__/userdata.test.ts.snap rename to nodejs/eks/nodes/__snapshots__/userdata.test.ts.snap diff --git a/nodejs/eks/ami.test.ts b/nodejs/eks/nodes/ami.test.ts similarity index 100% rename from nodejs/eks/ami.test.ts rename to nodejs/eks/nodes/ami.test.ts diff --git a/nodejs/eks/ami.ts b/nodejs/eks/nodes/ami.ts similarity index 100% rename from nodejs/eks/ami.ts rename to nodejs/eks/nodes/ami.ts diff --git a/nodejs/eks/nodes/index.ts b/nodejs/eks/nodes/index.ts new file mode 100644 index 000000000..89560e963 --- /dev/null +++ b/nodejs/eks/nodes/index.ts @@ -0,0 +1,24 @@ +// Copyright 2016-2024, Pulumi Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export { + computeWorkerSubnets, + createNodeGroupV2, + NodeGroupBaseOptions, + NodeGroupV2Data, + NodeGroup, + ManagedNodeGroup, + NodeGroupV2, +} from "./nodegroup"; +export { NodeGroupSecurityGroup, createNodeGroupSecurityGroup } from "./securitygroup"; diff --git a/nodejs/eks/nodegroup.test.ts b/nodejs/eks/nodes/nodegroup.test.ts similarity index 98% rename from nodejs/eks/nodegroup.test.ts rename to nodejs/eks/nodes/nodegroup.test.ts index b64e040aa..2ad7f731d 100644 --- a/nodejs/eks/nodegroup.test.ts +++ b/nodejs/eks/nodes/nodegroup.test.ts @@ -17,7 +17,7 @@ import * as aws from "@pulumi/aws"; import { isGravitonInstance, resolveInstanceProfileName } from "./nodegroup"; import { getArchitecture } from "./nodegroup"; -import { Cluster as ClusterComponent, CoreData } from "./cluster"; +import { CoreData } from "../cluster"; const gravitonInstances = [ "c6g.12xlarge", @@ -375,7 +375,7 @@ describe("createManagedNodeGroup", function () { }); test("should default to the cluster version if no version is provided", async () => { - const mng = ng.createManagedNodeGroupInternal( + const mng = ng.createManagedNodeGroup( "test", { nodeRoleArn: pulumi.output("nodeRoleArn"), @@ -397,7 +397,7 @@ describe("createManagedNodeGroup", function () { }); test("should use user defined version if provided", async () => { - const mng = ng.createManagedNodeGroupInternal( + const mng = ng.createManagedNodeGroup( "test", { nodeRoleArn: pulumi.output("nodeRoleArn"), @@ -420,7 +420,7 @@ describe("createManagedNodeGroup", function () { }); test("should not default the version if a custom launch template is configured", async () => { - const mng = ng.createManagedNodeGroupInternal( + const mng = ng.createManagedNodeGroup( "test", { nodeRoleArn: pulumi.output("nodeRoleArn"), diff --git a/nodejs/eks/nodegroup.ts b/nodejs/eks/nodes/nodegroup.ts similarity index 91% rename from nodejs/eks/nodegroup.ts rename to nodejs/eks/nodes/nodegroup.ts index 35fc7e025..4d1c840a3 100644 --- a/nodejs/eks/nodegroup.ts +++ b/nodejs/eks/nodes/nodegroup.ts @@ -26,11 +26,9 @@ import { OperatingSystem, toAmiType, } from "./ami"; -import { supportsAccessEntries } from "./authenticationMode"; -import { Cluster, ClusterInternal, CoreData } from "./cluster"; -import randomSuffix from "./randomSuffix"; +import { Cluster, CoreData, supportsAccessEntries } from "../cluster"; import { createNodeGroupSecurityGroup } from "./securitygroup"; -import { InputTags } from "./utils"; +import { InputTags } from "../utils"; import { createUserData, customUserDataArgs, @@ -39,7 +37,7 @@ import { SelfManagedV1NodeUserDataArgs, SelfManagedV2NodeUserDataArgs, } from "./userdata"; -import { InstanceProfile } from "@pulumi/aws/iam"; +import randomSuffix from "../randomSuffix"; export type TaintEffect = "NoSchedule" | "NoExecute" | "PreferNoSchedule"; @@ -446,62 +444,14 @@ export interface NodeGroupV2Data { /** * NodeGroup is a component that wraps the AWS EC2 instances that provide compute capacity for an EKS cluster. */ -export class NodeGroup extends pulumi.ComponentResource implements NodeGroupData { - /** - * The security group for the node group to communicate with the cluster. - */ - public readonly nodeSecurityGroup: aws.ec2.SecurityGroup | undefined; - public readonly nodeSecurityGroupId: pulumi.Output; - /** - * The additional security groups for the node group that captures user-specific rules. - */ - public readonly extraNodeSecurityGroups: aws.ec2.SecurityGroup[]; - - /** - * The CloudFormation Stack which defines the Node AutoScalingGroup. - */ - cfnStack: aws.cloudformation.Stack; - - /** - * The AutoScalingGroup name for the Node group. - */ - autoScalingGroupName: pulumi.Output; - - /** - * Create a new EKS cluster with worker nodes, optional storage classes, and deploy the Kubernetes Dashboard if - * requested. - * - * @param name The _unique_ name of this component. - * @param args The arguments for this cluster. - * @param opts A bag of options that control this component's behavior. - */ - constructor(name: string, args: NodeGroupOptions, opts?: pulumi.ComponentResourceOptions) { - super("eks:index:NodeGroup", name, args, opts); - - const group = createNodeGroup(name, args, this, opts?.provider); - this.nodeSecurityGroup = group.nodeSecurityGroup; - this.nodeSecurityGroupId = group.nodeSecurityGroupId; - this.cfnStack = group.cfnStack; - this.autoScalingGroupName = group.autoScalingGroupName; - this.registerOutputs(undefined); - } -} - -/** - * This is a variant of `NodeGroup` that is used for the MLC `NodeGroup`. We don't just use `NodeGroup`, - * because we need to accept `ClusterInternal` as the `cluster` arg, so we can correctly pull out `cluster.core` - * for use in creating the `NodeGroup`. - * - * @internal - */ -export class NodeGroupInternal extends pulumi.ComponentResource { +export class NodeGroup extends pulumi.ComponentResource { public readonly autoScalingGroupName!: pulumi.Output; public readonly cfnStack!: pulumi.Output; public readonly extraNodeSecurityGroups!: pulumi.Output; public readonly nodeSecurityGroup!: pulumi.Output; public readonly nodeSecurityGroupId!: pulumi.Output; - constructor(name: string, args: NodeGroupInternalArgs, opts?: pulumi.ComponentResourceOptions) { + constructor(name: string, args: NodeGroupArgs, opts?: pulumi.ComponentResourceOptions) { const type = "eks:index:NodeGroup"; if (opts?.urn) { @@ -520,11 +470,11 @@ export class NodeGroupInternal extends pulumi.ComponentResource { const core = pulumi .output(args.cluster) - .apply((c) => (c instanceof ClusterInternal ? c.core : c)) as pulumi.Output< + .apply((c) => (c instanceof Cluster ? c.core : c)) as pulumi.Output< pulumi.Unwrap >; - const group = createNodeGroupInternal(name, args, core, this, opts?.provider); + const group = createNodeGroup(name, args, core, this, opts?.provider); this.autoScalingGroupName = group.autoScalingGroupName; this.cfnStack = pulumi.output(group.cfnStack); this.extraNodeSecurityGroups = pulumi.output(group.extraNodeSecurityGroups ?? []); @@ -541,63 +491,22 @@ export class NodeGroupInternal extends pulumi.ComponentResource { } /** @internal */ -export type NodeGroupInternalArgs = Omit & { - cluster: pulumi.Input>; +export type NodeGroupArgs = Omit & { + cluster: pulumi.Input>; }; -export class NodeGroupV2 extends pulumi.ComponentResource implements NodeGroupV2Data { - /** - * The security group for the node group to communicate with the cluster. - */ - public readonly nodeSecurityGroup: aws.ec2.SecurityGroup | undefined; - public readonly nodeSecurityGroupId: pulumi.Output; - /** - * The additional security groups for the node group that captures user-specific rules. - */ - public readonly extraNodeSecurityGroups: aws.ec2.SecurityGroup[]; - - /** - * The AutoScalingGroup name for the Node group. - */ - autoScalingGroup: aws.autoscaling.Group; - - /** - * Create a new EKS cluster with worker nodes, optional storage classes, and deploy the Kubernetes Dashboard if - * requested. - * - * @param name The _unique_ name of this component. - * @param args The arguments for this cluster. - * @param opts A bag of options that control this component's behavior. - */ - constructor(name: string, args: NodeGroupV2Options, opts?: pulumi.ComponentResourceOptions) { - super("eks:index:NodeGroupV2", name, args, opts); - - const group = createNodeGroupV2(name, args, this, opts?.provider); - this.nodeSecurityGroup = group.nodeSecurityGroup; - this.nodeSecurityGroupId = group.nodeSecurityGroupId; - this.autoScalingGroup = group.autoScalingGroup; - this.registerOutputs(undefined); - } -} - /** - * This is a variant of `NodeGroupV2` that is used for the MLC `NodeGroupV2`. We don't just use `NodeGroupV2`, - * because we need to accept `ClusterInternal` as the `cluster` arg, so we can correctly pull out `cluster.core` - * for use in creating the `NodeGroupV2`. - * - * @internal + * NodeGroupV2 is a component that wraps the AWS EC2 instances that provide compute capacity for an EKS cluster. + * In contrast to NodeGroup, it uses Launch Templates and AutoScaling Groups to manage the EC2 instances instead + * of shelling out to CloudFormation and using the deprecated Launch Configuration resources. */ -export class NodeGroupV2Internal extends pulumi.ComponentResource { +export class NodeGroupV2 extends pulumi.ComponentResource { public readonly autoScalingGroup!: pulumi.Output; public readonly extraNodeSecurityGroups!: pulumi.Output; public readonly nodeSecurityGroup!: pulumi.Output; public readonly nodeSecurityGroupId!: pulumi.Output; - constructor( - name: string, - args: NodeGroupV2InternalArgs, - opts?: pulumi.ComponentResourceOptions, - ) { + constructor(name: string, args: NodeGroupV2Args, opts?: pulumi.ComponentResourceOptions) { const type = "eks:index:NodeGroupV2"; if (opts?.urn) { @@ -615,11 +524,11 @@ export class NodeGroupV2Internal extends pulumi.ComponentResource { const core = pulumi .output(args.cluster) - .apply((c) => (c instanceof ClusterInternal ? c.core : c)) as pulumi.Output< + .apply((c) => (c instanceof Cluster ? c.core : c)) as pulumi.Output< pulumi.Unwrap >; - const group = createNodeGroupV2Internal(name, args, core, this, opts?.provider); + const group = createNodeGroupV2(name, args, core, this, opts?.provider); this.autoScalingGroup = pulumi.output(group.autoScalingGroup); this.extraNodeSecurityGroups = pulumi.output(group.extraNodeSecurityGroups ?? []); this.nodeSecurityGroup = pulumi.output(group.nodeSecurityGroup); @@ -634,26 +543,10 @@ export class NodeGroupV2Internal extends pulumi.ComponentResource { } /** @internal */ -export type NodeGroupV2InternalArgs = Omit & { - cluster: pulumi.Input>; +export type NodeGroupV2Args = Omit & { + cluster: pulumi.Input>; }; -/** - * Create a self-managed node group using CloudFormation and an ASG. - * - * See for more details: - * https://docs.aws.amazon.com/eks/latest/userguide/worker.html - */ -export function createNodeGroup( - name: string, - args: NodeGroupOptions, - parent: pulumi.ComponentResource, - provider?: pulumi.ProviderResource, -): NodeGroupData { - const core = args.cluster instanceof Cluster ? args.cluster.core : args.cluster; - return createNodeGroupInternal(name, args, pulumi.output(core), parent, provider); -} - export function resolveInstanceProfileName( name: string, args: Omit, @@ -686,7 +579,7 @@ export function resolveInstanceProfileName( } } -function createNodeGroupInternal( +function createNodeGroup( name: string, args: Omit, core: pulumi.Output>, @@ -1145,16 +1038,6 @@ function createNodeGroupInternal( * https://docs.aws.amazon.com/eks/latest/userguide/worker.html */ export function createNodeGroupV2( - name: string, - args: NodeGroupV2Options, - parent: pulumi.ComponentResource, - provider?: pulumi.ProviderResource, -): NodeGroupV2Data { - const core = args.cluster instanceof Cluster ? args.cluster.core : args.cluster; - return createNodeGroupV2Internal(name, args, pulumi.output(core), parent, provider); -} - -function createNodeGroupV2Internal( name: string, args: Omit, core: pulumi.Output>, @@ -1879,45 +1762,9 @@ export type ManagedNodeGroupOptions = Omit< * https://docs.aws.amazon.com/eks/latest/userguide/managed-node-groups.html */ export class ManagedNodeGroup extends pulumi.ComponentResource { - /** - * The AWS managed node group. - */ - public readonly nodeGroup: aws.eks.NodeGroup; - - /** - * Create a new AWS managed node group. - * - * @param name The _unique_ name of this component. - * @param args The arguments for this node group. - * @param opts A bag of options that control this component's behavior. - */ - constructor( - name: string, - args: ManagedNodeGroupOptions, - opts?: pulumi.ComponentResourceOptions, - ) { - super("eks:index:ManagedNodeGroup", name, args, opts); - - this.nodeGroup = createManagedNodeGroup(name, args, this, opts?.provider); - this.registerOutputs(undefined); - } -} - -/** - * This is a variant of `ManagedNodeGroup` that is used for the MLC `ManagedNodeGroup`. We don't just use - * `ManagedNodeGroup`, because we need to accept `ClusterInternal` as the `cluster` arg, so we can correctly - * pull out `cluster.core` for use in creating the `NodeGroupV2`. - * - * @internal - */ -export class ManagedNodeGroupInternal extends pulumi.ComponentResource { public readonly nodeGroup!: pulumi.Output; - constructor( - name: string, - args: ManagedNodeGroupInternalArgs, - opts?: pulumi.ComponentResourceOptions, - ) { + constructor(name: string, args: ManagedNodeGroupArgs, opts?: pulumi.ComponentResourceOptions) { const type = "eks:index:ManagedNodeGroup"; if (opts?.urn) { @@ -1932,11 +1779,11 @@ export class ManagedNodeGroupInternal extends pulumi.ComponentResource { const core = pulumi .output(args.cluster) - .apply((c) => (c instanceof ClusterInternal ? c.core : c)) as pulumi.Output< + .apply((c) => (c instanceof Cluster ? c.core : c)) as pulumi.Output< pulumi.Unwrap >; - const group = createManagedNodeGroupInternal(name, args, core, this, opts?.provider); + const group = createManagedNodeGroup(name, args, core, this, opts?.provider); this.nodeGroup = pulumi.output(group); this.registerOutputs({ nodeGroup: this.nodeGroup, @@ -1945,8 +1792,8 @@ export class ManagedNodeGroupInternal extends pulumi.ComponentResource { } /** @internal */ -export type ManagedNodeGroupInternalArgs = Omit & { - cluster: pulumi.Input>; +export type ManagedNodeGroupArgs = Omit & { + cluster: pulumi.Input>; }; /** @@ -1955,23 +1802,7 @@ export type ManagedNodeGroupInternalArgs = Omit, core: pulumi.Output>, diff --git a/nodejs/eks/securitygroup.ts b/nodejs/eks/nodes/securitygroup.ts similarity index 99% rename from nodejs/eks/securitygroup.ts rename to nodejs/eks/nodes/securitygroup.ts index 60a96f258..dbdc397e7 100644 --- a/nodejs/eks/securitygroup.ts +++ b/nodejs/eks/nodes/securitygroup.ts @@ -15,7 +15,7 @@ import * as aws from "@pulumi/aws"; import * as pulumi from "@pulumi/pulumi"; -import { InputTags } from "./utils"; +import { InputTags } from "../utils"; /** * NodeGroupSecurityGroupOptions describes the configuration options accepted diff --git a/nodejs/eks/userdata.test.ts b/nodejs/eks/nodes/userdata.test.ts similarity index 100% rename from nodejs/eks/userdata.test.ts rename to nodejs/eks/nodes/userdata.test.ts diff --git a/nodejs/eks/userdata.ts b/nodejs/eks/nodes/userdata.ts similarity index 99% rename from nodejs/eks/userdata.ts rename to nodejs/eks/nodes/userdata.ts index 0e833b47e..1c85b550e 100644 --- a/nodejs/eks/userdata.ts +++ b/nodejs/eks/nodes/userdata.ts @@ -19,7 +19,7 @@ import { NodeadmOptions } from "./nodegroup"; import * as jsyaml from "js-yaml"; import * as toml from "@iarna/toml"; import * as ipaddr from "ipaddr.js"; -import { isObject } from "./utilities"; +import { isObject } from "../utilities"; // linux is the default user data type for AMIs that use the eks bootstrap script. (e.g. AL2) // nodeadm is the user data type for AMIs that use nodeadm to bootstrap the node. (e.g. AL2023) diff --git a/nodejs/eks/transform.ts b/nodejs/eks/transform.ts deleted file mode 100644 index 76a93f706..000000000 --- a/nodejs/eks/transform.ts +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2016-2019, Pulumi Corporation. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import * as pulumi from "@pulumi/pulumi"; -import * as dynamic from "@pulumi/pulumi/dynamic"; - -/** - * Transform is a dynamic resource that evaluates a function when its inputs change and exports the result. - */ -class Transform extends dynamic.Resource { - public readonly output: pulumi.Output; - - constructor(name: string, input: T, func: (v: T) => U, opts?: pulumi.CustomResourceOptions) { - const provider = { - check: (olds: any, news: any) => Promise.resolve({ inputs: news, failedChecks: [] }), - diff: (id: pulumi.ID, olds: any, news: any) => Promise.resolve({}), - create: (inputs: any) => - Promise.resolve({ - id: name, - outs: { output: func(inputs.input as T) }, - }), - update: (id: pulumi.ID, olds: any, news: any) => - Promise.resolve({ - outs: { output: func(news.input as T) }, - }), - read: (id: pulumi.ID, state: any) => Promise.resolve({ id: id, props: state }), - delete: (id: pulumi.ID, props: any) => Promise.resolve(), - }; - - super(provider, name, { input: input, output: undefined }, opts); - } -} - -/** - * transform evaluates the given function on the given input iff the input's value has changed and returns the result - * as an output. - * - * @deprecated This is no longer used and will be removed in the future. - */ -export default function transform( - name: string, - input: T, - func: (v: T) => U, - opts?: pulumi.CustomResourceOptions, -): pulumi.Output { - return new Transform(name, input, func, opts).output; -}