Skip to content

Commit 25e29ba

Browse files
authored
Add release job for demo functions (#85)
* Add release job for demo functions * Remove globall install from docs * format
1 parent bb9429e commit 25e29ba

File tree

10 files changed

+198
-12
lines changed

10 files changed

+198
-12
lines changed

.github/workflows/release-create-kpt-functions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- release-create-kpt-functions-*
77

88
jobs:
9-
node-ci:
9+
release:
1010
runs-on: ubuntu-latest
1111
env:
1212
GOPATH: /home/runner/work/kpt-functions-sdk/go
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: release-create-kpt-functions
2+
3+
on:
4+
push:
5+
tags:
6+
- release-demo-functions-*
7+
8+
jobs:
9+
e2e-ci:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
node-version: [12.x]
14+
steps:
15+
- uses: actions/checkout@v1
16+
- name: Set up gcloud
17+
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
18+
with:
19+
version: '275.0.0'
20+
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
21+
service_account_key: ${{ secrets.GCP_SA_KEY }}
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v1
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
registry-url: 'https://npm.pkg.github.com'
27+
- name: Install NPM packages
28+
run: |
29+
cd ts/demo-functions
30+
npm ci
31+
envsubst < $NPM_CONFIG_USERCONFIG > .npmrc
32+
env:
33+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
- name: Build docker images
35+
run: |
36+
cd ts/demo-functions
37+
npm run kpt:docker-build -- --tag=latest
38+
- name: Run e2e tests
39+
run: |
40+
npm install -g bats
41+
TAG=latest bats tests/e2e.bats
42+
- name: Push docker images
43+
run: |
44+
cd ts/demo-functions
45+
npm run kpt:docker-push -- --tag=latest

.github/workflows/release-kpt-functions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- release-kpt-functions-*
77

88
jobs:
9-
node-ci:
9+
release:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v1

docs/develop.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ Run the interactive initializer:
128128
npm init @googlecontainertools/kpt-functions
129129
```
130130
131-
Or, alternatively install the package globally and then run it:
132-
133-
```sh
134-
npm install -g @googlecontainertools/create-kpt-functions
135-
create-kpt-functions
136-
```
137-
138131
Follow the instructions and respond to all prompts.
139132
140133
This process will create the following:

tests/e2e.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bats
22

3+
export TAG=${TAG:-dev}
34
export EXAMPLE_CONFIGS=${BATS_TEST_DIRNAME}/../example-configs
4-
export TAG=dev
55
export EMPTY_OUTPUT=$(cat <<-EOF
66
apiVersion: v1
77
kind: List
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { addLabel, Configs } from '@googlecontainertools/kpt-functions';
18+
import { isNamespace } from './gen/io.k8s.api.core.v1';
19+
20+
export const LABEL_NAME = 'label_name';
21+
export const LABEL_VALUE = 'label_value';
22+
23+
export async function labelNamespace(configs: Configs) {
24+
const labelName = configs.getFunctionConfigValueOrThrow(LABEL_NAME);
25+
const labelValue = configs.getFunctionConfigValueOrThrow(LABEL_VALUE);
26+
configs.get(isNamespace).forEach((n) => addLabel(n, labelName, labelValue));
27+
}
28+
29+
labelNamespace.usage = `
30+
Adds a label to all Namespaces.
31+
32+
Configured using a ConfigMap with the following keys:
33+
34+
${LABEL_NAME}: Label name to add to Namespaces.
35+
${LABEL_VALUE}: Label value to add to Namespaces.
36+
37+
Example:
38+
39+
To add a label 'color: orange' to Namespaces:
40+
41+
apiVersion: v1
42+
kind: ConfigMap
43+
data:
44+
${LABEL_NAME}: color
45+
${LABEL_VALUE}: orange
46+
metadata:
47+
name: my-config
48+
`;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { labelNamespace } from './label_namespace';
18+
import { run } from '@googlecontainertools/kpt-functions';
19+
20+
run(labelNamespace);
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { Configs, TestRunner } from '@googlecontainertools/kpt-functions';
18+
import { labelNamespace, LABEL_NAME, LABEL_VALUE } from './label_namespace';
19+
import { Namespace, ConfigMap } from './gen/io.k8s.api.core.v1';
20+
21+
const TEST_NAMESPACE = 'testNamespace';
22+
const TEST_LABEL_NAME = 'costCenter';
23+
const TEST_LABEL_VALUE = 'xyz';
24+
25+
describe('labelNamespace', () => {
26+
let functionConfig = ConfigMap.named('foo');
27+
functionConfig.data = {};
28+
functionConfig.data[LABEL_NAME] = TEST_LABEL_NAME;
29+
functionConfig.data[LABEL_VALUE] = TEST_LABEL_VALUE;
30+
31+
const RUNNER = new TestRunner(labelNamespace);
32+
33+
it('empty input ok', RUNNER.assertCallback(new Configs(undefined, functionConfig)));
34+
35+
it('requires functionConfig', RUNNER.assertCallback(undefined, undefined, TypeError));
36+
37+
it('adds label namespace when metadata.labels is undefined', async () => {
38+
const actual = new Configs(undefined, functionConfig);
39+
actual.insert(Namespace.named(TEST_NAMESPACE));
40+
41+
const expected = new Configs();
42+
expected.insert(
43+
new Namespace({
44+
metadata: {
45+
name: TEST_NAMESPACE,
46+
labels: { [TEST_LABEL_NAME]: TEST_LABEL_VALUE },
47+
},
48+
}),
49+
);
50+
51+
await RUNNER.assert(actual, expected);
52+
});
53+
54+
it('adds label to namespace when metadata.labels is defined', async () => {
55+
const actual = new Configs(undefined, functionConfig);
56+
actual.insert(
57+
new Namespace({
58+
metadata: {
59+
name: TEST_NAMESPACE,
60+
labels: { a: 'b' },
61+
},
62+
}),
63+
);
64+
65+
const expected = new Configs();
66+
expected.insert(
67+
new Namespace({
68+
metadata: {
69+
name: TEST_NAMESPACE,
70+
labels: {
71+
a: 'b',
72+
[TEST_LABEL_NAME]: TEST_LABEL_VALUE,
73+
},
74+
},
75+
}),
76+
);
77+
78+
await RUNNER.assert(actual, expected);
79+
});
80+
});

ts/hello-world/src/label_namespace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const LABEL_VALUE = 'label_value';
2323
export async function labelNamespace(configs: Configs) {
2424
const labelName = configs.getFunctionConfigValueOrThrow(LABEL_NAME);
2525
const labelValue = configs.getFunctionConfigValueOrThrow(LABEL_VALUE);
26-
configs.get(isNamespace).forEach(n => addLabel(n, labelName, labelValue));
26+
configs.get(isNamespace).forEach((n) => addLabel(n, labelName, labelValue));
2727
}
2828

2929
labelNamespace.usage = `

ts/hello-world/src/label_namespace_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('labelNamespace', () => {
5151
await RUNNER.assert(actual, expected);
5252
});
5353

54-
it('adds label to namespace when metadata.labels is defined', async () => {
54+
it('adds label to namespace when metadata.labels is defined', async () => {
5555
const actual = new Configs(undefined, functionConfig);
5656
actual.insert(
5757
new Namespace({

0 commit comments

Comments
 (0)