From c23ffc15258b33a278cac2461b020f12d2cb81d7 Mon Sep 17 00:00:00 2001
From: Madeline Kusters <80541297+madeline-k@users.noreply.github.com>
Date: Fri, 21 Oct 2022 09:02:11 -0700
Subject: [PATCH] feat: include kubectl version explicitly in API (#43)
Based on feedback from @rix0rrr, explicitly including the version number in the class name.
This PR also bumps the major version to 2.0 so that it is clear to customers that this library is compatible with AWS CDK 2.0
---
.projen/tasks.json | 1 +
.projenrc.js | 1 +
API.md | 102 ++++++++++++++++++------------------
README.md | 8 +--
src/kubectl-layer.ts | 2 +-
test/kubectl-layer.integ.ts | 4 +-
test/kubectl-layer.test.ts | 4 +-
7 files changed, 62 insertions(+), 60 deletions(-)
diff --git a/.projen/tasks.json b/.projen/tasks.json
index cdf44d22..09d70c48 100644
--- a/.projen/tasks.json
+++ b/.projen/tasks.json
@@ -304,6 +304,7 @@
"description": "Prepare a release from \"kubectl-v24/main\" branch",
"env": {
"RELEASE": "true",
+ "MAJOR": "2",
"RELEASE_TAG_PREFIX": "kubectl-v24"
},
"steps": [
diff --git a/.projenrc.js b/.projenrc.js
index 9bccdc06..ed6b0be7 100644
--- a/.projenrc.js
+++ b/.projenrc.js
@@ -25,6 +25,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
run: 'sudo chown superchain /var/run/docker.sock',
},
],
+ majorVersion: 2,
npmAccess: NpmAccess.PUBLIC,
releaseTagPrefix: `kubectl-v${SPEC_VERSION}`,
releaseWorkflowName: releaseWorkflowName,
diff --git a/API.md b/API.md
index 367f21af..68b0ea33 100644
--- a/API.md
+++ b/API.md
@@ -2,32 +2,32 @@
## Constructs
-### KubectlLayer
+### KubectlV24Layer
A CDK Asset construct that contains `kubectl` and `helm`.
-#### Initializers
+#### Initializers
```typescript
-import { KubectlLayer } from '@aws-cdk/lambda-layer-kubectl-v24'
+import { KubectlV24Layer } from '@aws-cdk/lambda-layer-kubectl-v24'
-new KubectlLayer(scope: Construct, id: string)
+new KubectlV24Layer(scope: Construct, id: string)
```
| **Name** | **Type** | **Description** |
| --- | --- | --- |
-| scope
| constructs.Construct
| *No description.* |
-| id
| string
| *No description.* |
+| scope
| constructs.Construct
| *No description.* |
+| id
| string
| *No description.* |
---
-##### `scope`Required
+##### `scope`Required
- *Type:* constructs.Construct
---
-##### `id`Required
+##### `id`Required
- *Type:* string
@@ -37,13 +37,13 @@ new KubectlLayer(scope: Construct, id: string)
| **Name** | **Description** |
| --- | --- |
-| toString
| Returns a string representation of this construct. |
-| applyRemovalPolicy
| Apply the given removal policy to this resource. |
-| addPermission
| Add permission for this layer version to specific entities. |
+| toString
| Returns a string representation of this construct. |
+| applyRemovalPolicy
| Apply the given removal policy to this resource. |
+| addPermission
| Add permission for this layer version to specific entities. |
---
-##### `toString`
+##### `toString`
```typescript
public toString(): string
@@ -51,7 +51,7 @@ public toString(): string
Returns a string representation of this construct.
-##### `applyRemovalPolicy`
+##### `applyRemovalPolicy`
```typescript
public applyRemovalPolicy(policy: RemovalPolicy): void
@@ -67,13 +67,13 @@ to be replaced.
The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).
-###### `policy`Required
+###### `policy`Required
- *Type:* aws-cdk-lib.RemovalPolicy
---
-##### `addPermission`
+##### `addPermission`
```typescript
public addPermission(id: string, permission: LayerVersionPermission): void
@@ -88,13 +88,13 @@ Lambda function using the layer (for example, a CloudFormation changeset
execution role) also needs to have the ``lambda:GetLayerVersion``
permission on the layer version.
-###### `id`Required
+###### `id`Required
- *Type:* string
---
-###### `permission`Required
+###### `permission`Required
- *Type:* aws-cdk-lib.aws_lambda.LayerVersionPermission
@@ -104,24 +104,24 @@ permission on the layer version.
| **Name** | **Description** |
| --- | --- |
-| isConstruct
| Checks if `x` is a construct. |
-| isResource
| Check whether the given construct is a Resource. |
-| fromLayerVersionArn
| Imports a layer version by ARN. |
-| fromLayerVersionAttributes
| Imports a Layer that has been defined externally. |
+| isConstruct
| Checks if `x` is a construct. |
+| isResource
| Check whether the given construct is a Resource. |
+| fromLayerVersionArn
| Imports a layer version by ARN. |
+| fromLayerVersionAttributes
| Imports a Layer that has been defined externally. |
---
-##### ~~`isConstruct`~~
+##### ~~`isConstruct`~~
```typescript
-import { KubectlLayer } from '@aws-cdk/lambda-layer-kubectl-v24'
+import { KubectlV24Layer } from '@aws-cdk/lambda-layer-kubectl-v24'
-KubectlLayer.isConstruct(x: any)
+KubectlV24Layer.isConstruct(x: any)
```
Checks if `x` is a construct.
-###### `x`Required
+###### `x`Required
- *Type:* any
@@ -129,63 +129,63 @@ Any object.
---
-##### `isResource`
+##### `isResource`
```typescript
-import { KubectlLayer } from '@aws-cdk/lambda-layer-kubectl-v24'
+import { KubectlV24Layer } from '@aws-cdk/lambda-layer-kubectl-v24'
-KubectlLayer.isResource(construct: IConstruct)
+KubectlV24Layer.isResource(construct: IConstruct)
```
Check whether the given construct is a Resource.
-###### `construct`Required
+###### `construct`Required
- *Type:* constructs.IConstruct
---
-##### `fromLayerVersionArn`
+##### `fromLayerVersionArn`
```typescript
-import { KubectlLayer } from '@aws-cdk/lambda-layer-kubectl-v24'
+import { KubectlV24Layer } from '@aws-cdk/lambda-layer-kubectl-v24'
-KubectlLayer.fromLayerVersionArn(scope: Construct, id: string, layerVersionArn: string)
+KubectlV24Layer.fromLayerVersionArn(scope: Construct, id: string, layerVersionArn: string)
```
Imports a layer version by ARN.
Assumes it is compatible with all Lambda runtimes.
-###### `scope`Required
+###### `scope`Required
- *Type:* constructs.Construct
---
-###### `id`Required
+###### `id`Required
- *Type:* string
---
-###### `layerVersionArn`Required
+###### `layerVersionArn`Required
- *Type:* string
---
-##### `fromLayerVersionAttributes`
+##### `fromLayerVersionAttributes`
```typescript
-import { KubectlLayer } from '@aws-cdk/lambda-layer-kubectl-v24'
+import { KubectlV24Layer } from '@aws-cdk/lambda-layer-kubectl-v24'
-KubectlLayer.fromLayerVersionAttributes(scope: Construct, id: string, attrs: LayerVersionAttributes)
+KubectlV24Layer.fromLayerVersionAttributes(scope: Construct, id: string, attrs: LayerVersionAttributes)
```
Imports a Layer that has been defined externally.
-###### `scope`Required
+###### `scope`Required
- *Type:* constructs.Construct
@@ -193,7 +193,7 @@ the parent Construct that will use the imported layer.
---
-###### `id`Required
+###### `id`Required
- *Type:* string
@@ -201,7 +201,7 @@ the id of the imported layer in the construct tree.
---
-###### `attrs`Required
+###### `attrs`Required
- *Type:* aws-cdk-lib.aws_lambda.LayerVersionAttributes
@@ -213,15 +213,15 @@ the properties of the imported layer.
| **Name** | **Type** | **Description** |
| --- | --- | --- |
-| node
| constructs.Node
| The tree node. |
-| env
| aws-cdk-lib.ResourceEnvironment
| The environment this resource belongs to. |
-| stack
| aws-cdk-lib.Stack
| The stack in which this resource is defined. |
-| compatibleRuntimes
| aws-cdk-lib.aws_lambda.Runtime[]
| The runtimes compatible with this Layer. |
-| layerVersionArn
| string
| The ARN of the Lambda Layer version that this Layer defines. |
+| node
| constructs.Node
| The tree node. |
+| env
| aws-cdk-lib.ResourceEnvironment
| The environment this resource belongs to. |
+| stack
| aws-cdk-lib.Stack
| The stack in which this resource is defined. |
+| compatibleRuntimes
| aws-cdk-lib.aws_lambda.Runtime[]
| The runtimes compatible with this Layer. |
+| layerVersionArn
| string
| The ARN of the Lambda Layer version that this Layer defines. |
---
-##### `node`Required
+##### `node`Required
```typescript
public readonly node: Node;
@@ -233,7 +233,7 @@ The tree node.
---
-##### `env`Required
+##### `env`Required
```typescript
public readonly env: ResourceEnvironment;
@@ -252,7 +252,7 @@ that might be different than the stack they were imported into.
---
-##### `stack`Required
+##### `stack`Required
```typescript
public readonly stack: Stack;
@@ -264,7 +264,7 @@ The stack in which this resource is defined.
---
-##### `compatibleRuntimes`Optional
+##### `compatibleRuntimes`Optional
```typescript
public readonly compatibleRuntimes: Runtime[];
@@ -276,7 +276,7 @@ The runtimes compatible with this Layer.
---
-##### `layerVersionArn`Required
+##### `layerVersionArn`Required
```typescript
public readonly layerVersionArn: string;
diff --git a/README.md b/README.md
index c76adeb0..55f7f7f0 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
---
-![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)
+![cdk-constructs: Stable](https://img.shields.io/badge/cdk--constructs-stable-success.svg?style=for-the-badge)
---
@@ -11,7 +11,7 @@
-This module exports a single class called `KubectlLayer` which is a `lambda.LayerVersion` that
+This module exports a single class called `KubectlV24Layer` which is a `lambda.LayerVersion` that
bundles the [`kubectl`](https://kubernetes.io/docs/reference/kubectl/kubectl/) and the
[`helm`](https://helm.sh/) command line.
@@ -23,11 +23,11 @@ Usage:
```ts
// KubectlLayer bundles the 'kubectl' and 'helm' command lines
-import { KubectlLayer } from '@aws-cdk/lambda-layer-kubectl-v23';
+import { KubectlV24Layer } from '@aws-cdk/lambda-layer-kubectl-v23';
import * as lambda from 'aws-cdk-lib/aws-lambda';
declare const fn: lambda.Function;
-const kubectl = new KubectlLayer(this, 'KubectlLayer');
+const kubectl = new KubectlV24Layer(this, 'KubectlLayer');
fn.addLayers(kubectl);
```
diff --git a/src/kubectl-layer.ts b/src/kubectl-layer.ts
index b7e076fd..7c62c924 100644
--- a/src/kubectl-layer.ts
+++ b/src/kubectl-layer.ts
@@ -5,7 +5,7 @@ import { assetHash, ASSET_FILE } from './_asset';
/**
* A CDK Asset construct that contains `kubectl` and `helm`.
*/
-export class KubectlLayer extends lambda.LayerVersion {
+export class KubectlV24Layer extends lambda.LayerVersion {
constructor(scope: Construct, id: string) {
super(scope, id, {
code: lambda.Code.fromAsset(ASSET_FILE, {
diff --git a/test/kubectl-layer.integ.ts b/test/kubectl-layer.integ.ts
index af200772..4a3c3666 100644
--- a/test/kubectl-layer.integ.ts
+++ b/test/kubectl-layer.integ.ts
@@ -3,7 +3,7 @@ import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as cr from 'aws-cdk-lib/custom-resources';
-import { KubectlLayer } from '../lib';
+import { KubectlV24Layer } from '../lib';
/**
* Test verifies that kubectl and helm are invoked successfully inside Lambda runtime.
@@ -11,7 +11,7 @@ import { KubectlLayer } from '../lib';
const app = new cdk.App();
const stack = new cdk.Stack(app, 'lambda-layer-kubectl-integ-stack');
-const layer = new KubectlLayer(stack, 'KubectlLayer');
+const layer = new KubectlV24Layer(stack, 'KubectlLayer');
const runtimes = [
lambda.Runtime.PYTHON_3_7,
diff --git a/test/kubectl-layer.test.ts b/test/kubectl-layer.test.ts
index eba6d1e1..28228c56 100644
--- a/test/kubectl-layer.test.ts
+++ b/test/kubectl-layer.test.ts
@@ -1,13 +1,13 @@
import { Stack } from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';
-import { KubectlLayer } from '../lib';
+import { KubectlV24Layer } from '../lib';
test('synthesized to a layer version', () => {
// GIVEN
const stack = new Stack();
// WHEN
- new KubectlLayer(stack, 'MyLayer');
+ new KubectlV24Layer(stack, 'MyLayer');
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', {