Skip to content

Commit 3328fbe

Browse files
authored
Clean up provider internals (#1591)
This change cleans up the provider internals in preparation for more involved features like adding EFA support (#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.
1 parent adddef5 commit 3328fbe

30 files changed

+115
-456
lines changed
File renamed without changes.

nodejs/eks/addon.ts renamed to nodejs/eks/addons/addon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import * as pulumi from "@pulumi/pulumi";
1616
import * as aws from "@pulumi/aws";
17-
import { Cluster } from "./cluster";
17+
import { Cluster } from "../cluster";
1818

1919
/**
2020
* AddonOptions describes the configuration options available for the Amazon VPC CNI plugin for Kubernetes. This is obtained from
File renamed without changes.

nodejs/eks/cni-addon.ts renamed to nodejs/eks/addons/cni-addon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import * as pulumi from "@pulumi/pulumi";
1616
import * as aws from "@pulumi/aws";
1717
import * as k8s from "@pulumi/kubernetes";
1818
import { stringifyAddonConfiguration } from "./addon";
19-
import { isObject } from "./utilities";
19+
import { isObject } from "../utilities";
2020

2121
export interface VpcCniAddonOptions extends CniEnvVariables {
2222
clusterName: pulumi.Input<string>;

nodejs/eks/addons/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016-2024, Pulumi Corporation.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
export { Addon } from "./addon";
16+
export { VpcCniAddon, VpcCniAddonOptions } from "./cni-addon";
17+
export { stringifyAddonConfiguration } from "./addon";

nodejs/eks/authenticationMode.test.ts renamed to nodejs/eks/cluster/authenticationMode.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
validateAuthenticationMode,
1919
} from "./authenticationMode";
2020

21-
import { ClusterOptions, AuthenticationMode } from "./cluster";
21+
import { ClusterOptions } from "./cluster";
2222

2323
import * as aws from "@pulumi/aws";
2424

File renamed without changes.
File renamed without changes.

nodejs/eks/cluster.ts renamed to nodejs/eks/cluster/cluster.ts

Lines changed: 11 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,19 @@ import {
3030
validateAuthenticationMode,
3131
} from "./authenticationMode";
3232
import { getIssuerCAThumbprint } from "./cert-thumprint";
33-
import { assertCompatibleAWSCLIExists } from "./dependencies";
33+
import { assertCompatibleAWSCLIExists } from "../dependencies";
3434
import {
3535
computeWorkerSubnets,
3636
createNodeGroupV2,
3737
NodeGroupBaseOptions,
3838
NodeGroupV2Data,
39-
} from "./nodegroup";
40-
import { createNodeGroupSecurityGroup } from "./securitygroup";
41-
import { ServiceRole } from "./servicerole";
39+
} from "../nodes";
40+
import { createNodeGroupSecurityGroup } from "../nodes";
41+
import { ServiceRole } from "../servicerole";
4242
import { createStorageClass, EBSVolumeType, StorageClass } from "./storageclass";
43-
import { InputTags, UserStorageClasses } from "./utils";
44-
import { VpcCniAddon, VpcCniAddonOptions } from "./cni-addon";
45-
import { stringifyAddonConfiguration } from "./addon";
46-
import { getRegionFromArn } from "./utilities";
43+
import { InputTags, UserStorageClasses } from "../utils";
44+
import { stringifyAddonConfiguration, VpcCniAddon, VpcCniAddonOptions } from "../addons";
45+
import { getRegionFromArn } from "../utilities";
4746

4847
/**
4948
* RoleMapping describes a mapping from an AWS IAM role to a Kubernetes user and groups.
@@ -2015,137 +2014,6 @@ export const AccessEntryType = {
20152014
*/
20162015
export type AccessEntryType = (typeof AccessEntryType)[keyof typeof AccessEntryType];
20172016

2018-
/**
2019-
* Cluster is a component that wraps the AWS and Kubernetes resources necessary to run an EKS cluster, its worker
2020-
* nodes, its optional StorageClasses, and an optional deployment of the Kubernetes Dashboard.
2021-
*/
2022-
export class Cluster extends pulumi.ComponentResource {
2023-
/**
2024-
* A kubeconfig that can be used to connect to the EKS cluster.
2025-
*/
2026-
public readonly kubeconfig: pulumi.Output<any>;
2027-
2028-
/**
2029-
* A kubeconfig that can be used to connect to the EKS cluster as a JSON string.
2030-
*/
2031-
public readonly kubeconfigJson: pulumi.Output<string>;
2032-
2033-
/**
2034-
* The AWS resource provider.
2035-
*/
2036-
public readonly awsProvider: pulumi.ProviderResource;
2037-
2038-
/**
2039-
* A Kubernetes resource provider that can be used to deploy into this cluster. For example, the code below will
2040-
* create a new Pod in the EKS cluster.
2041-
*
2042-
* let eks = new Cluster("eks");
2043-
* let pod = new kubernetes.core.v1.Pod("pod", { ... }, { provider: eks.provider });
2044-
*
2045-
*/
2046-
public readonly provider: k8s.Provider;
2047-
2048-
/**
2049-
* The security group for the EKS cluster.
2050-
*/
2051-
public readonly clusterSecurityGroup: aws.ec2.SecurityGroup | undefined;
2052-
2053-
/**
2054-
* The service roles used by the EKS cluster.
2055-
*/
2056-
public readonly instanceRoles: pulumi.Output<aws.iam.Role[]>;
2057-
2058-
/**
2059-
* The security group for the cluster's nodes.
2060-
*/
2061-
public readonly nodeSecurityGroup: aws.ec2.SecurityGroup | undefined;
2062-
2063-
/**
2064-
* The ingress rule that gives node group access to cluster API server
2065-
*/
2066-
public readonly eksClusterIngressRule: aws.ec2.SecurityGroupRule | undefined;
2067-
2068-
/**
2069-
* The default Node Group configuration, or undefined if `skipDefaultNodeGroup` was specified.
2070-
*/
2071-
public readonly defaultNodeGroup: NodeGroupV2Data | undefined;
2072-
2073-
/**
2074-
* The EKS cluster.
2075-
*/
2076-
public readonly eksCluster: aws.eks.Cluster;
2077-
2078-
/**
2079-
* The EKS cluster and its dependencies.
2080-
*/
2081-
public readonly core: CoreData;
2082-
2083-
/**
2084-
* Create a new EKS cluster with worker nodes, optional storage classes, and deploy the Kubernetes Dashboard if
2085-
* requested.
2086-
*
2087-
* @param name The _unique_ name of this component.
2088-
* @param args The arguments for this cluster.
2089-
* @param opts A bag of options that control this component's behavior.
2090-
*/
2091-
constructor(name: string, args?: ClusterOptions, opts?: pulumi.ComponentResourceOptions) {
2092-
const type = "eks:index:Cluster";
2093-
2094-
if (opts?.urn) {
2095-
const props = {
2096-
kubeconfig: undefined,
2097-
eksCluster: undefined,
2098-
};
2099-
super(type, name, props, opts);
2100-
return;
2101-
}
2102-
2103-
super(type, name, args, opts);
2104-
2105-
const cluster = createCluster(name, this, args, opts);
2106-
this.kubeconfig = cluster.kubeconfig;
2107-
this.kubeconfigJson = cluster.kubeconfigJson;
2108-
this.clusterSecurityGroup = cluster.clusterSecurityGroup;
2109-
this.instanceRoles = cluster.instanceRoles;
2110-
this.nodeSecurityGroup = cluster.nodeSecurityGroup;
2111-
this.eksClusterIngressRule = cluster.eksClusterIngressRule;
2112-
this.defaultNodeGroup = cluster.defaultNodeGroup;
2113-
this.eksCluster = cluster.eksCluster;
2114-
this.core = cluster.core;
2115-
2116-
this.registerOutputs({
2117-
kubeconfig: this.kubeconfig,
2118-
eksCluster: this.eksCluster,
2119-
});
2120-
}
2121-
2122-
/**
2123-
* Generate a kubeconfig for cluster authentication that does not use the
2124-
* default AWS credential provider chain, and instead is scoped to
2125-
* the supported options in `KubeconfigOptions`.
2126-
*
2127-
* The kubeconfig generated is automatically stringified for ease of use
2128-
* with the pulumi/kubernetes provider.
2129-
*
2130-
* See for more details:
2131-
* - https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html
2132-
* - https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.html
2133-
* - https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html
2134-
*/
2135-
getKubeconfig(args: KubeconfigOptions): pulumi.Output<string> {
2136-
const region = this.eksCluster.arn.apply(getRegionFromArn);
2137-
const kc = generateKubeconfig(
2138-
this.eksCluster.name,
2139-
this.eksCluster.endpoint,
2140-
region,
2141-
true,
2142-
this.eksCluster.certificateAuthority?.data,
2143-
args,
2144-
);
2145-
return pulumi.output(kc).apply(JSON.stringify);
2146-
}
2147-
}
2148-
21492017
/** @internal */
21502018
export interface ClusterResult {
21512019
kubeconfig: pulumi.Output<any>;
@@ -2243,9 +2111,9 @@ export function createCluster(
22432111
defaultNodeGroup = createNodeGroupV2(
22442112
name,
22452113
{
2246-
cluster: core,
22472114
...core.nodeGroupOptions,
22482115
},
2116+
pulumi.output(core),
22492117
self,
22502118
);
22512119
}
@@ -2301,17 +2169,10 @@ export function createCluster(
23012169
}
23022170

23032171
/**
2304-
* This is a variant of `Cluster` that is used for the MLC `Cluster`. We don't just use `Cluster`,
2305-
* because not all of its output properties are typed as `Output<T>`, which prevents it from being
2306-
* able to be correctly "rehydrated" from a resource reference. So we use this copy instead rather
2307-
* than modifying the public surface area of the existing `Cluster` class, which is still being
2308-
* used directly by users using the Node.js SDK. Once we move Node.js over to the generated MLC SDK,
2309-
* we can clean all this up. Internally, this leverages the same `createCluster` helper method that
2310-
* `Cluster` uses.
2311-
*
2312-
* @internal
2172+
* Cluster is a component that wraps the AWS and Kubernetes resources necessary to run an EKS cluster, its worker
2173+
* nodes, its optional StorageClasses, and an optional deployment of the Kubernetes Dashboard.
23132174
*/
2314-
export class ClusterInternal extends pulumi.ComponentResource {
2175+
export class Cluster extends pulumi.ComponentResource {
23152176
public readonly clusterSecurityGroup!: pulumi.Output<aws.ec2.SecurityGroup | undefined>;
23162177
public readonly core!: pulumi.Output<pulumi.Unwrap<CoreData>>;
23172178
public readonly defaultNodeGroup!: pulumi.Output<pulumi.Unwrap<NodeGroupV2Data> | undefined>;

nodejs/eks/cluster/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016-2024, Pulumi Corporation.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
export { Cluster, ClusterCreationRoleProvider, CoreData } from "./cluster";
16+
export { supportsAccessEntries } from "./authenticationMode";

nodejs/eks/storageclass.ts renamed to nodejs/eks/cluster/storageclass.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import * as aws from "@pulumi/aws";
1615
import * as k8s from "@pulumi/kubernetes";
1716
import * as k8sInputs from "@pulumi/kubernetes/types/input";
1817
import * as pulumi from "@pulumi/pulumi";

nodejs/eks/cmd/provider/addon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import * as pulumi from "@pulumi/pulumi";
16-
import { Addon } from "../../addon";
16+
import { Addon } from "../../addons";
1717

1818
const managedAddonProvider: pulumi.provider.Provider = {
1919
construct: (

nodejs/eks/cmd/provider/cluster.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import * as pulumi from "@pulumi/pulumi";
16-
import { ClusterCreationRoleProvider, ClusterInternal } from "../../cluster";
16+
import { ClusterCreationRoleProvider, Cluster } from "../../cluster";
1717

1818
const clusterProvider: pulumi.provider.Provider = {
1919
construct: (
@@ -23,7 +23,7 @@ const clusterProvider: pulumi.provider.Provider = {
2323
options: pulumi.ComponentResourceOptions,
2424
) => {
2525
try {
26-
const cluster = new ClusterInternal(name, inputs, options);
26+
const cluster = new Cluster(name, inputs, options);
2727
return Promise.resolve({
2828
urn: cluster.urn,
2929
state: {

nodejs/eks/cmd/provider/cni-addon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import * as pulumi from "@pulumi/pulumi";
16-
import { VpcCniAddon } from "../../cni-addon";
16+
import { VpcCniAddon } from "../../addons";
1717

1818
const cniAddonProvider: pulumi.provider.Provider = {
1919
construct: (

nodejs/eks/cmd/provider/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import * as pulumi from "@pulumi/pulumi";
1616
import { readFileSync } from "fs";
17-
import { ClusterInternal } from "../../cluster";
18-
import { VpcCniAddon } from "../../cni-addon";
17+
import { Cluster } from "../../cluster";
18+
import { VpcCniAddon } from "../../addons/cni-addon";
1919
import { clusterCreationRoleProviderProviderFactory, clusterProviderFactory } from "./cluster";
2020
import { cniAddonProviderFactory } from "./cni-addon";
2121
import {
@@ -50,7 +50,7 @@ class Provider implements pulumi.provider.Provider {
5050
construct: (name, type, urn) => {
5151
switch (type) {
5252
case "eks:index:Cluster":
53-
return new ClusterInternal(name, undefined, { urn });
53+
return new Cluster(name, undefined, { urn });
5454
case "eks:index:VpcCniAddon":
5555
return new VpcCniAddon(name, undefined, { urn });
5656
default:
@@ -63,7 +63,7 @@ class Provider implements pulumi.provider.Provider {
6363
async call(token: string, inputs: pulumi.Inputs): Promise<pulumi.provider.InvokeResult> {
6464
switch (token) {
6565
case "eks:index:Cluster/getKubeconfig":
66-
const self: ClusterInternal = inputs.__self__;
66+
const self: Cluster = inputs.__self__;
6767
const result = self.getKubeconfig({
6868
profileName: inputs.profileName,
6969
roleArn: inputs.roleArn,

nodejs/eks/cmd/provider/nodegroup.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import * as pulumi from "@pulumi/pulumi";
16-
import { ManagedNodeGroupInternal, NodeGroupInternal, NodeGroupV2Internal } from "../../nodegroup";
16+
import { ManagedNodeGroup, NodeGroup, NodeGroupV2 } from "../../nodes";
1717

1818
const nodeGroupProvider: pulumi.provider.Provider = {
1919
construct: (
@@ -23,7 +23,7 @@ const nodeGroupProvider: pulumi.provider.Provider = {
2323
options: pulumi.ComponentResourceOptions,
2424
) => {
2525
try {
26-
const nodegroup = new NodeGroupInternal(name, <any>inputs, options);
26+
const nodegroup = new NodeGroup(name, <any>inputs, options);
2727
return Promise.resolve({
2828
urn: nodegroup.urn,
2929
state: {
@@ -54,7 +54,7 @@ const managedNodeGroupProvider: pulumi.provider.Provider = {
5454
options: pulumi.ComponentResourceOptions,
5555
) => {
5656
try {
57-
const nodegroup = new ManagedNodeGroupInternal(name, <any>inputs, options);
57+
const nodegroup = new ManagedNodeGroup(name, <any>inputs, options);
5858
return Promise.resolve({
5959
urn: nodegroup.urn,
6060
state: {
@@ -81,7 +81,7 @@ const nodeGroupV2Provider: pulumi.provider.Provider = {
8181
options: pulumi.ComponentResourceOptions,
8282
) => {
8383
try {
84-
const nodegroup = new NodeGroupV2Internal(name, <any>inputs, options);
84+
const nodegroup = new NodeGroupV2(name, <any>inputs, options);
8585
return Promise.resolve({
8686
urn: nodegroup.urn,
8787
state: {

nodejs/eks/cmd/provider/securitygroup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import * as pulumi from "@pulumi/pulumi";
16-
import { NodeGroupSecurityGroup } from "../../securitygroup";
16+
import { NodeGroupSecurityGroup } from "../../nodes";
1717

1818
const nodeGroupSecurityGroupProvider: pulumi.provider.Provider = {
1919
construct: (

0 commit comments

Comments
 (0)