Skip to content

Commit

Permalink
Change arguments of NodeGroup & NodeGroupV2 to accept inputs (#1415)
Browse files Browse the repository at this point in the history
Historically the following `NodeGroup` & `NodeGroupV2` input properties
have been plain:
- `kubeletExtraArgs`
- `bootstrapExtraArgs`
- `labels`
- `taints`
- `nodeAssociatePublicIpAddress`

Those should instead be inputs so users can pass outputs into them.

fixes #1274
  • Loading branch information
flostadler authored Oct 2, 2024
1 parent dfd76f2 commit ea15764
Show file tree
Hide file tree
Showing 22 changed files with 464 additions and 340 deletions.
12 changes: 12 additions & 0 deletions docs/eks-v3-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,15 @@ The Nodejs SDK is updated to use state of the art Pulumi tooling, improving stab
- `clusterOidcProvider` is an output now. `getKubeConfig` returns an output now
- The deprecated input property `deployDashboard` of the `Cluster` component has been removed from the Nodejs SDK. This has already been removed from the other SDKs in the past. If you’d like to continue using it, you can adopt the existing code into your own program from [here](https://github.com/pulumi/pulumi-eks/blob/bcc170e72b802a78e7f0a99bc92316a5f8a62b0e/nodejs/eks/dashboard.ts).
- The `createManagedNodeGroup` function will now create an Pulumi EKS `ManagedNodeGroup` instead of creating the underlying `aws.eks.NodeGroup` resource directly. During the upgrade to Pulumi EKS v3 you'll see the additional wrapper component being created.

## Miscellaneous changes

### NodeGroup & NodeGroupV2 accept inputs for its properties
The `NodeGroup` and `NodeGroupV2` components now accept inputs for the following input properties:
- `kubeletExtraArgs`
- `bootstrapExtraArgs`
- `labels`
- `taints`
- `nodeAssociatePublicIpAddress`

If you're using Go you'll need to adjust your program to handle those types being inputs.
132 changes: 50 additions & 82 deletions nodejs/eks/nodegroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export interface Taint {
/**
* The value of the taint.
*/
value: string;
value: pulumi.Input<string>;
/**
* The effect of the taint.
*/
effect: "NoSchedule" | "NoExecute" | "PreferNoSchedule";
effect: pulumi.Input<"NoSchedule" | "NoExecute" | "PreferNoSchedule">;
}

/**
Expand Down Expand Up @@ -231,37 +231,37 @@ export interface NodeGroupBaseOptions {
* Custom k8s node labels to be attached to each worker node. Adds the given key/value pairs to the `--node-labels`
* kubelet argument.
*/
labels?: { [key: string]: string };
labels?: pulumi.Input<{ [key: string]: pulumi.Input<string> }>;

/**
* Custom k8s node taints to be attached to each worker node. Adds the given taints to the `--register-with-taints`
* kubelet argument.
*/
taints?: { [key: string]: Taint };
taints?: pulumi.Input<{ [key: string]: pulumi.Input<Taint> }>;

/**
* Extra args to pass to the Kubelet. Corresponds to the options passed in the `--kubeletExtraArgs` flag to
* `/etc/eks/bootstrap.sh`. For example, '--port=10251 --address=0.0.0.0'. Note that the `labels` and `taints`
* properties will be applied to this list (using `--node-labels` and `--register-with-taints` respectively) after
* to the expicit `kubeletExtraArgs`.
*/
kubeletExtraArgs?: string;
kubeletExtraArgs?: pulumi.Input<string>;

/**
* Additional args to pass directly to `/etc/eks/bootstrap.sh`. For details on available options, see:
* https://github.com/awslabs/amazon-eks-ami/blob/master/files/bootstrap.sh. Note that the `--apiserver-endpoint`,
* `--b64-cluster-ca` and `--kubelet-extra-args` flags are included automatically based on other configuration
* parameters.
*/
bootstrapExtraArgs?: string;
bootstrapExtraArgs?: pulumi.Input<string>;

/**
* Whether or not to auto-assign public IP addresses on the EKS worker nodes.
* If this toggle is set to true, the EKS workers will be
* auto-assigned public IPs. If false, they will not be auto-assigned
* public IPs.
*/
nodeAssociatePublicIpAddress?: boolean;
nodeAssociatePublicIpAddress?: pulumi.Input<boolean>;

/**
* Desired Kubernetes master / control plane version. If you do not specify a value, the latest available version is used.
Expand Down Expand Up @@ -783,45 +783,31 @@ function createNodeGroupInternal(
return nodeadmExtraOptions ? pulumi.all(nodeadmExtraOptions) : undefined;
});

const nodegroupInputs = {
nodeUserData: args.nodeUserData,
nodeUserDataOverride: args.nodeUserDataOverride,
bottlerocketSettings: args.bottlerocketSettings,
kubeletExtraArgs: args.kubeletExtraArgs,
bootstrapExtraArgs: args.bootstrapExtraArgs,
labels: args.labels,
taints: args.taints,
};

const userdata = pulumi
.all([
awsRegion,
clusterMetadata,
cfnStackName,
args.nodeUserData,
args.nodeUserDataOverride,
os,
args.bottlerocketSettings,
nodeadmExtraOptions,
])
.apply(
([
region,
clusterMetadata,
.all([awsRegion, clusterMetadata, cfnStackName, os, nodeadmExtraOptions, nodegroupInputs])
.apply(([region, clusterMetadata, stackName, os, nodeadmExtraOptions, nodegroupInputs]) => {
const userDataArgs: SelfManagedV1NodeUserDataArgs = {
...nodegroupInputs,
nodeGroupType: "self-managed-v1",
awsRegion: region.name,
stackName,
extraUserData,
userDataOverride,
os,
bottlerocketSettings,
nodeadmExtraOptions,
]) => {
const userDataArgs: SelfManagedV1NodeUserDataArgs = {
nodeGroupType: "self-managed-v1",
awsRegion: region.name,
kubeletExtraArgs: args.kubeletExtraArgs,
bootstrapExtraArgs: args.bootstrapExtraArgs,
labels: args.labels,
taints: args.taints,
userDataOverride,
extraUserData,
stackName,
bottlerocketSettings,
nodeadmExtraOptions,
};
extraUserData: nodegroupInputs.nodeUserData,
userDataOverride: nodegroupInputs.nodeUserDataOverride,
};

return createUserData(os, clusterMetadata, userDataArgs, parent);
},
);
return createUserData(os, clusterMetadata, userDataArgs, parent);
});

const version = pulumi.output(args.version || core.cluster.version);

Expand All @@ -830,10 +816,7 @@ function createNodeGroupInternal(
// Enable auto-assignment of public IP addresses on worker nodes for
// backwards compatibility on existing EKS clusters launched with it
// enabled. Defaults to `true`.
let nodeAssociatePublicIpAddress: boolean = true;
if (args.nodeAssociatePublicIpAddress !== undefined) {
nodeAssociatePublicIpAddress = args.nodeAssociatePublicIpAddress;
}
const nodeAssociatePublicIpAddress = args.nodeAssociatePublicIpAddress ?? true;

const numeric = new RegExp("^\\d+$");

Expand Down Expand Up @@ -1241,42 +1224,30 @@ function createNodeGroupV2Internal(
return nodeadmExtraOptions ? pulumi.all(nodeadmExtraOptions) : undefined;
});

const nodegroupInputs = {
nodeUserData: args.nodeUserData,
nodeUserDataOverride: args.nodeUserDataOverride,
bottlerocketSettings: args.bottlerocketSettings,
kubeletExtraArgs: args.kubeletExtraArgs,
bootstrapExtraArgs: args.bootstrapExtraArgs,
labels: args.labels,
taints: args.taints,
};

const userdata = pulumi
.all([
clusterMetadata,
name,
args.nodeUserData,
args.nodeUserDataOverride,
os,
args.bottlerocketSettings,
nodeadmExtraOptions,
])
.apply(
([
clusterMetadata,
.all([clusterMetadata, name, os, nodeadmExtraOptions, nodegroupInputs])
.apply(([clusterMetadata, stackName, os, nodeadmExtraOptions, nodegroupInputs]) => {
const userDataArgs: SelfManagedV2NodeUserDataArgs = {
...nodegroupInputs,
nodeGroupType: "self-managed-v2",
stackName,
extraUserData,
userDataOverride,
os,
bottlerocketSettings,
nodeadmExtraOptions,
]) => {
const userDataArgs: SelfManagedV2NodeUserDataArgs = {
nodeGroupType: "self-managed-v2",
kubeletExtraArgs: args.kubeletExtraArgs,
bootstrapExtraArgs: args.bootstrapExtraArgs,
labels: args.labels,
taints: args.taints,
userDataOverride,
extraUserData,
stackName,
bottlerocketSettings,
nodeadmExtraOptions,
};
extraUserData: nodegroupInputs.nodeUserData,
userDataOverride: nodegroupInputs.nodeUserDataOverride,
};

return createUserData(os, clusterMetadata, userDataArgs, parent);
},
)
return createUserData(os, clusterMetadata, userDataArgs, parent);
})
.apply((x) => Buffer.from(x, "utf-8").toString("base64")); // Launch Templates require user data to be passed as base64.

const version = pulumi.output(args.version || core.cluster.version);
Expand All @@ -1286,10 +1257,7 @@ function createNodeGroupV2Internal(
// Enable auto-assignment of public IP addresses on worker nodes for
// backwards compatibility on existing EKS clusters launched with it
// enabled. Defaults to `true`.
let nodeAssociatePublicIpAddress: boolean = true;
if (args.nodeAssociatePublicIpAddress !== undefined) {
nodeAssociatePublicIpAddress = args.nodeAssociatePublicIpAddress;
}
const nodeAssociatePublicIpAddress = args.nodeAssociatePublicIpAddress ?? true;

const numeric = new RegExp("^\\d+$");

Expand Down
7 changes: 6 additions & 1 deletion nodejs/eks/userdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import * as pulumi from "@pulumi/pulumi";

import { OperatingSystem } from "./ami";
import { NodeadmOptions, Taint } from "./nodegroup";
import { NodeadmOptions } from "./nodegroup";
import * as jsyaml from "js-yaml";
import * as toml from "@iarna/toml";
import * as ipaddr from "ipaddr.js";
Expand Down Expand Up @@ -44,6 +44,11 @@ export interface ClusterMetadata {
serviceCidr: string;
}

interface Taint {
value: string;
effect: "NoSchedule" | "NoExecute" | "PreferNoSchedule";
}

// base arguments for all types of node groups
interface BaseUserDataArgs {
nodeGroupType: NodeGroupType;
Expand Down
23 changes: 7 additions & 16 deletions provider/cmd/pulumi-gen-eks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1522,15 +1522,13 @@ func generateSchema(version semver.Version) schema.PackageSpec {
Properties: map[string]schema.PropertySpec{
"value": {
TypeSpec: schema.TypeSpec{
Type: "string",
Plain: true,
Type: "string",
},
Description: "The value of the taint.",
},
"effect": {
TypeSpec: schema.TypeSpec{
Type: "string", // TODO strict string enum: "NoSchedule" | "NoExecute" | "PreferNoSchedule".
Plain: true,
Type: "string", // TODO strict string enum: "NoSchedule" | "NoExecute" | "PreferNoSchedule".
},
Description: "The effect of the taint.",
},
Expand Down Expand Up @@ -2162,10 +2160,8 @@ func nodeGroupProperties(cluster, v2 bool) map[string]schema.PropertySpec {
TypeSpec: schema.TypeSpec{
Type: "object",
AdditionalProperties: &schema.TypeSpec{
Type: "string",
Plain: true,
Type: "string",
},
Plain: true,
},
Description: "Custom k8s node labels to be attached to each worker node. Adds the given " +
"key/value pairs to the `--node-labels` kubelet argument.",
Expand All @@ -2174,18 +2170,15 @@ func nodeGroupProperties(cluster, v2 bool) map[string]schema.PropertySpec {
TypeSpec: schema.TypeSpec{
Type: "object",
AdditionalProperties: &schema.TypeSpec{
Ref: "#/types/eks:index:Taint",
Plain: true,
Ref: "#/types/eks:index:Taint",
},
Plain: true,
},
Description: "Custom k8s node taints to be attached to each worker node. Adds the given " +
"taints to the `--register-with-taints` kubelet argument",
},
"kubeletExtraArgs": {
TypeSpec: schema.TypeSpec{
Type: "string",
Plain: true,
Type: "string",
},
Description: "Extra args to pass to the Kubelet. Corresponds to the options passed in the " +
"`--kubeletExtraArgs` flag to `/etc/eks/bootstrap.sh`. For example, " +
Expand All @@ -2195,8 +2188,7 @@ func nodeGroupProperties(cluster, v2 bool) map[string]schema.PropertySpec {
},
"bootstrapExtraArgs": {
TypeSpec: schema.TypeSpec{
Type: "string",
Plain: true,
Type: "string",
},
Description: "Additional args to pass directly to `/etc/eks/bootstrap.sh`. For details on " +
"available options, see: " +
Expand All @@ -2206,8 +2198,7 @@ func nodeGroupProperties(cluster, v2 bool) map[string]schema.PropertySpec {
},
"nodeAssociatePublicIpAddress": {
TypeSpec: schema.TypeSpec{
Type: "boolean",
Plain: true,
Type: "boolean",
},
Description: "Whether or not to auto-assign public IP addresses on the EKS worker nodes. If " +
"this toggle is set to true, the EKS workers will be auto-assigned public IPs. If false, " +
Expand Down
Loading

0 comments on commit ea15764

Please sign in to comment.