Skip to content

Commit

Permalink
feat(k8s): bring k8s (#298)
Browse files Browse the repository at this point in the history
Rename `cdk8s` to `k8s` to decouple it from CDK8s (at least semantically).
  • Loading branch information
eladb authored Jul 23, 2024
1 parent f8cea22 commit 16f291f
Show file tree
Hide file tree
Showing 23 changed files with 121 additions and 104 deletions.
66 changes: 33 additions & 33 deletions .github/workflows/canary.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/pull-request-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
revert
bedrock
budget
cdk8s
checks
cognito
containers
Expand All @@ -35,6 +34,7 @@ jobs:
fifoqueue
github
jwt
k8s
lock
messagefanout
ngrok
Expand Down
12 changes: 6 additions & 6 deletions .mergify.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ publishing them for you.
| --- | --- | --- |
| [bedrock](./bedrock) | [@winglibs/bedrock](https://www.npmjs.com/package/@winglibs/bedrock) | sim, tf-aws |
| [budget](./budget) | [@winglibs/budget](https://www.npmjs.com/package/@winglibs/budget) | sim, tf-aws |
| [cdk8s](./cdk8s) | [@winglibs/cdk8s](https://www.npmjs.com/package/@winglibs/cdk8s) | cdk8s |
| [checks](./checks) | [@winglibs/checks](https://www.npmjs.com/package/@winglibs/checks) | * |
| [cognito](./cognito) | [@winglibs/cognito](https://www.npmjs.com/package/@winglibs/cognito) | sim, tf-aws |
| [containers](./containers) | [@winglibs/containers](https://www.npmjs.com/package/@winglibs/containers) | sim, tf-aws |
Expand All @@ -23,6 +22,7 @@ publishing them for you.
| [fifoqueue](./fifoqueue) | [@winglibs/fifoqueue](https://www.npmjs.com/package/@winglibs/fifoqueue) | sim, tf-aws |
| [github](./github) | [@winglibs/github](https://www.npmjs.com/package/@winglibs/github) | * |
| [jwt](./jwt) | [@winglibs/jwt](https://www.npmjs.com/package/@winglibs/jwt) | * |
| [k8s](./k8s) | [@winglibs/k8s](https://www.npmjs.com/package/@winglibs/k8s) | k8s |
| [lock](./lock) | [@winglibs/lock](https://www.npmjs.com/package/@winglibs/lock) | * |
| [messagefanout](./messagefanout) | [@winglibs/messagefanout](https://www.npmjs.com/package/@winglibs/messagefanout) | sim, tf-aws |
| [ngrok](./ngrok) | [@winglibs/ngrok](https://www.npmjs.com/package/@winglibs/ngrok) | * |
Expand Down
File renamed without changes.
File renamed without changes.
82 changes: 49 additions & 33 deletions cdk8s/README.md → k8s/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# cdk8s support for Wing
# Wing for Kubernetes

This library is a custom Wing platform that can be used to synthesize Kubernetes YAML manifests
through [cdk8s](https://cdk8s.io) constructs.
A framework for synthesizing Kubernetes manifests using Winglang.

## Prerequisites

Expand All @@ -18,45 +17,71 @@ npm i -g winglang
Create a new project and install this library:

```sh
mkdir wing-loves-cdk8s
cd wing-loves-cdk8s
npm i @winglibs/cdk8s
```

If you wish to use [cdk8s-plus](https://cdk8s.io/docs/latest/plus/), you'll also
need to install it (choose the relevant K8S version):

```sh
npm i cdk8s-plus-27
mkdir wing-loves-k8s
cd wing-loves-k8s
npm i @winglibs/k8s
```

## Usage

Let's define a Deployment resource with 3 replicas of the `ubuntu` public Docker image:
Let's define an app with a simple Kubernetes object:

```js
// ubuntu.main.w
bring "cdk8s-plus-27" as k8s;

let deployment = new k8s.Deployment(replicas: 3);
deployment.addContainer(image: "ubuntu");
// main.w
bring k8s;

new k8s.ApiObject(
apiVersion: "v1",
kind: "ConfigMap",
spec: {
data: {
key: "value",
},
}
);
```

Now, compile it to YAML:

```sh
$ wing compile -t @winglibs/cdk8s ubuntu.main.w
target/ubuntu.main.cdk8s
$ wing compile -t @winglibs/k8s ubuntu.main.w
target/ubuntu.main.k8s
```

The output is a valid K8S YAML is in `target/ubuntu.main.cdk8s`:
You

The output is a valid K8S YAML is in `target/ubuntu.main.k8s`:

```sh
$ ls target/ubuntu.main.cdk8s
$ ls target/ubuntu.main.k8s
chart-c86185a7.k8s.yaml
```

Here's a more interesting example:
### Creating Helm charts

You can set `WING_K8S_OUTPUT` to `helm` in order to produce a helm chart instead of simple manifest.
This requires a `Chart.yaml` file next in the current directory.

### Applying labels to all resources

You can use the `WING_K8S_LABELS` environment variable to apply labels to all resources in an app.
The value is a JSON-encoded map.

```sh
export WING_K8S_LABELS='{ "my-label": "123", "your-label": "444" }'
wing compile -t @winglibs/k8s main.w
```

### CDK8s Support

This library supports [cdk8s](https://cdk8s.io) and
[cdk8s-plus](https://cdk8s.io/docs/latest/plus/), so you can do stuff like this:

```sh
npm i cdk8s-plus-27
```

And then:

```js
bring "cdk8s-plus-27" as k8s;
Expand Down Expand Up @@ -89,15 +114,6 @@ container.mount(appPath, appVolume);
deployment.exposeViaService(serviceType: k8s.ServiceType.LOAD_BALANCER);
```

### Applying labels to all resources

You can use the `WING_K8S_LABELS` environment variable to apply labels to all resources in an app.
The value is a JSON-encoded map.

```sh
export WING_K8S_LABELS='{ "my-label": "123", "your-label": "444" }'
wing compile -t @winglibs/cdk8s main.w
```

## Roadmap

Expand Down
2 changes: 1 addition & 1 deletion cdk8s/api-object.w → k8s/api-object.w
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
bring "cdk8s" as cdk8s;

pub struct ApiObjectProps extends cdk8s.ApiObjectProps{
pub struct ApiObjectProps extends cdk8s.ApiObjectProps {
spec: Json?;
}

Expand Down
1 change: 1 addition & 0 deletions k8s/bin/kwing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/sh
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cdk8s/lib/index.js → k8s/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const cdk8s = require('cdk8s');
const { core, std } = require('@winglang/sdk');;

exports.Platform = class {
target = "cdk8s";
target = "k8s";

newApp(props) {
const app = new cdk8s.App({ outdir: props.outdir });
Expand Down
Loading

0 comments on commit 16f291f

Please sign in to comment.