Skip to content

Commit e175b72

Browse files
author
Mengqi Yu
authored
Merge pull request #538 from mengqiy/starlark/v0.2
Merge master into starlark/v0.2
2 parents e7f69d5 + b92f040 commit e175b72

File tree

107 files changed

+7449
-64
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+7449
-64
lines changed

.github/hooks/pre-commit

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
echo "Updating docs..."
4+
make generate;
5+
diff=`git diff`
6+
7+
if [[ $diff != "" ]];
8+
then
9+
echo "Found unstaged changes [$diff]. Make sure to run `make generate` for updating the docs before you commit the changes."
10+
exit 1
11+
else
12+
exit 0
13+
fi

.github/workflows/check-doc-sync.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2021 Google LLC
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+
name: Check Documentation Synchronized
16+
on:
17+
pull_request:
18+
push:
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v2
24+
- run: |
25+
./.github/hooks/pre-commit

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,5 @@ node_modules
99
bin/
1010
__pycache__
1111

12-
functions/go/*/generated
13-
1412
# We use sed -i.bak when doing in-line replace, because it works better cross-platform
1513
*.bak

CODEOWNERS

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* @frankfarzan @mengqiy @droot
2-
*.md @droot @frankfarzan
1+
* @frankfarzan @mengqiy @droot @phanimarupaka

CONTRIBUTING.md

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ Contributions are required to follow these style guides:
6262
For each function, its files spread in the follow places:
6363

6464
- `functions/` directory: Each function must have its own directory in one
65-
of `functions/` sub-directory. In each function's directory, it must have
66-
the following:
65+
of `functions/` sub-directory. In each function's directory, it must have the
66+
following:
6767
- Source code (and unit tests).
6868
- A README.md file serving as the usage doc and will be shown in
6969
the [catalog website].
@@ -77,14 +77,74 @@ For each function, its files spread in the follow places:
7777
should follow the [template][example-template].
7878
- The `tests/` directory contains additional e2e tests.
7979

80-
### E2E Tests
80+
For golang-based functions, you need to generate some doc related variables from
81+
the `README.md` by running
82+
83+
```shell
84+
$ cd functions/go
85+
$ make generate
86+
```
87+
88+
### Tests
89+
90+
#### Unit Tests
91+
92+
To run all unit tests
93+
94+
```shell
95+
$ make unit-test
96+
```
97+
98+
#### E2E Tests
8199

82100
The e2e tests are the recommended way to test functions in the catalog. They are
83-
very easy to write and set up with our [e2e test harness].
101+
very easy to write and set up with our e2e test harness. You can find all the
102+
supported options and expected test directory
103+
structure [here][e2e test harness doc].
84104

85105
You can choose to put the e2e test in either the `examples/` directory or in the
86106
`tests/` directory depending on if it is worthwhile to be shown as an example.
87107

108+
To test a specific example or the e2e test, run
109+
110+
```shell
111+
$ cd tests/e2etest
112+
$ go test -v ./... -run TestE2E/../../examples/$EXAMPLE_NAME
113+
```
114+
115+
Most contributors don't need this, but if you happen to need to test all
116+
examples and e2e tests, run the following command
117+
118+
```shell
119+
$ make e2e-test
120+
```
121+
122+
#### Doc Verifier
123+
124+
We have a script to ensure the usage docs and the examples are consistent.
125+
Please ensure it's passing by running:
126+
127+
```shell
128+
$ ./scripts/verify-docs.py
129+
```
130+
131+
This script requires Python 3, `pyyaml` and `mdrip` which is a CLI tool.
132+
133+
To install `pyyaml`, run the following command:
134+
135+
```shell
136+
pip install pyyaml
137+
```
138+
139+
To install `mdrip`, run the following commands:
140+
141+
```shell
142+
$ go get github.com/russross/blackfriday/v2@v2.0.1
143+
$ go get github.com/monopole/mdrip@v1.0.2
144+
```
145+
146+
And you need to ensure `$GOPATH/bin` is in your `PATH`.
147+
88148
### Change Existing Functions
89149

90150
You must follow the layout convention when you make changes to existing
@@ -99,6 +159,11 @@ If you fix a bug, you must add (unit or e2e) tests to cover that.
99159

100160
You must follow the layout convention when you contribute new functions.
101161

162+
You need to add new function name to the respective language Makefiles.
163+
164+
- `functions/go/Makefile` for golang.
165+
- `functions/ts/Makefile` for typescript.
166+
102167
## Contact Us
103168

104169
Do you need a review or release of functions? We’d love to hear from you!
@@ -112,7 +177,7 @@ Do you need a review or release of functions? We’d love to hear from you!
112177

113178
[catalog website]: https://catalog.kpt.dev/
114179

115-
[e2e test harness]: https://pkg.go.dev/github.com/GoogleContainerTools/kpt@v1.0.0-beta.2/pkg/test/runner
180+
[e2e test harness doc]: https://github.com/GoogleContainerTools/kpt/blob/main/pkg/test/runner/README.md
116181

117182
[golang-template]: https://raw.githubusercontent.com/GoogleContainerTools/kpt-functions-catalog/master/functions/go/_template/README.md
118183

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
diff --git a/deployment_test-helloworld-chart.yaml b/deployment_test-helloworld-chart.yaml
2+
new file mode 100644
3+
index 0000000..8ba7f5c
4+
--- /dev/null
5+
+++ b/deployment_test-helloworld-chart.yaml
6+
@@ -0,0 +1,43 @@
7+
+# Source: helloworld-chart/templates/deployment.yaml
8+
+apiVersion: apps/v1
9+
+kind: Deployment
10+
+metadata:
11+
+ name: test-helloworld-chart
12+
+ labels:
13+
+ helm.sh/chart: helloworld-chart-0.1.0
14+
+ app.kubernetes.io/name: helloworld-chart
15+
+ app.kubernetes.io/instance: test
16+
+ app.kubernetes.io/version: "1.16.0"
17+
+ app.kubernetes.io/managed-by: Helm
18+
+spec:
19+
+ replicas: 5
20+
+ selector:
21+
+ matchLabels:
22+
+ app.kubernetes.io/name: helloworld-chart
23+
+ app.kubernetes.io/instance: test
24+
+ template:
25+
+ metadata:
26+
+ labels:
27+
+ app.kubernetes.io/name: helloworld-chart
28+
+ app.kubernetes.io/instance: test
29+
+ spec:
30+
+ serviceAccountName: test-helloworld-chart
31+
+ securityContext: {}
32+
+ containers:
33+
+ - name: helloworld-chart
34+
+ securityContext: {}
35+
+ image: "nginx:1.16.0"
36+
+ imagePullPolicy: Always
37+
+ ports:
38+
+ - name: http
39+
+ containerPort: 80
40+
+ protocol: TCP
41+
+ livenessProbe:
42+
+ httpGet:
43+
+ path: /
44+
+ port: http
45+
+ readinessProbe:
46+
+ httpGet:
47+
+ path: /
48+
+ port: http
49+
+ resources: {}
50+
diff --git a/pod_test-helloworld-chart-test-connection.yaml b/pod_test-helloworld-chart-test-connection.yaml
51+
new file mode 100644
52+
index 0000000..8793304
53+
--- /dev/null
54+
+++ b/pod_test-helloworld-chart-test-connection.yaml
55+
@@ -0,0 +1,20 @@
56+
+# Source: helloworld-chart/templates/tests/test-connection.yaml
57+
+apiVersion: v1
58+
+kind: Pod
59+
+metadata:
60+
+ name: "test-helloworld-chart-test-connection"
61+
+ labels:
62+
+ helm.sh/chart: helloworld-chart-0.1.0
63+
+ app.kubernetes.io/name: helloworld-chart
64+
+ app.kubernetes.io/instance: test
65+
+ app.kubernetes.io/version: "1.16.0"
66+
+ app.kubernetes.io/managed-by: Helm
67+
+ annotations:
68+
+ "helm.sh/hook": test-success
69+
+spec:
70+
+ containers:
71+
+ - name: wget
72+
+ image: busybox
73+
+ command: ['wget']
74+
+ args: ['test-helloworld-chart:80']
75+
+ restartPolicy: Never
76+
diff --git a/service_test-helloworld-chart.yaml b/service_test-helloworld-chart.yaml
77+
new file mode 100644
78+
index 0000000..7d734d3
79+
--- /dev/null
80+
+++ b/service_test-helloworld-chart.yaml
81+
@@ -0,0 +1,21 @@
82+
+# Source: helloworld-chart/templates/service.yaml
83+
+apiVersion: v1
84+
+kind: Service
85+
+metadata:
86+
+ name: test-helloworld-chart
87+
+ labels:
88+
+ helm.sh/chart: helloworld-chart-0.1.0
89+
+ app.kubernetes.io/name: helloworld-chart
90+
+ app.kubernetes.io/instance: test
91+
+ app.kubernetes.io/version: "1.16.0"
92+
+ app.kubernetes.io/managed-by: Helm
93+
+spec:
94+
+ type: ClusterIP
95+
+ ports:
96+
+ - port: 80
97+
+ targetPort: http
98+
+ protocol: TCP
99+
+ name: http
100+
+ selector:
101+
+ app.kubernetes.io/name: helloworld-chart
102+
+ app.kubernetes.io/instance: test
103+
diff --git a/serviceaccount_test-helloworld-chart.yaml b/serviceaccount_test-helloworld-chart.yaml
104+
new file mode 100644
105+
index 0000000..5800f2a
106+
--- /dev/null
107+
+++ b/serviceaccount_test-helloworld-chart.yaml
108+
@@ -0,0 +1,11 @@
109+
+# Source: helloworld-chart/templates/serviceaccount.yaml
110+
+apiVersion: v1
111+
+kind: ServiceAccount
112+
+metadata:
113+
+ name: test-helloworld-chart
114+
+ labels:
115+
+ helm.sh/chart: helloworld-chart-0.1.0
116+
+ app.kubernetes.io/name: helloworld-chart
117+
+ app.kubernetes.io/instance: test
118+
+ app.kubernetes.io/version: "1.16.0"
119+
+ app.kubernetes.io/managed-by: Helm
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
kpt fn eval --image-pull-policy ifNotPresent --image gcr.io/kpt-fn/inflate-helm-chart:unstable \
4+
--mount type=bind,src="$(pwd)",dst=/tmp/charts -- \
5+
name=helloworld-chart \
6+
releaseName=test \
7+
valuesFile=/tmp/charts/helloworld-values/values.yaml
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.expected
2+
helloworld-chart
3+
helloworld-values
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# inflate-helm-chart: Local Chart
2+
3+
### Overview
4+
5+
This example demonstrated how to imperatively invoke the `inflate-helm-chart`
6+
function to inflate a helm chart that lives in your local filesystem.
7+
8+
### Function invocation
9+
10+
Run the following command to fetch the example package:
11+
12+
```shell
13+
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/inflate-helm-chart-local
14+
```
15+
16+
```shell
17+
$ cd inflate-helm-chart-local
18+
```
19+
20+
Run the following commands to inflate the helm chart in your local
21+
filesystem.
22+
23+
```shell
24+
$ kpt fn eval --image gcr.io/kpt-fn/inflate-helm-chart:unstable \
25+
--mount type=bind,src=$(pwd),dst=/tmp/charts \
26+
-- name=helloworld-chart \
27+
releaseName=test
28+
```
29+
30+
You can optionally provide your own values files using `--valuesFile`.
31+
32+
```shell
33+
$ kpt fn eval --image gcr.io/kpt-fn/inflate-helm-chart:unstable \
34+
--mount type=bind,src=$(pwd),dst=/tmp/charts -- \
35+
name=helloworld-chart \
36+
releaseName=test \
37+
valuesFile=tmp/charts/helloworld-values/values.yaml
38+
```
39+
40+
### Expected result
41+
42+
You can run the following command to see the new files you have:
43+
44+
```shell
45+
$ kpt pkg tree
46+
├── [deployment_test-helloworld-chart.yaml] Deployment test-helloworld-chart
47+
├── [pod_test-helloworld-chart-test-connection.yaml] Pod test-helloworld-chart-test-connection
48+
├── [service_test-helloworld-chart.yaml] Service test-helloworld-chart
49+
└── [serviceaccount_test-helloworld-chart.yaml] ServiceAccount test-helloworld-chart
50+
```
51+
52+
You should be able to find `replicas: 5` in
53+
file `deployment_test-helloworld-chart.yaml`, which demonstrates that
54+
the correct values file provided by --valuesFile was used.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: v2
2+
name: helloworld-chart
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
version: 0.1.0
18+
19+
# This is the version number of the application being deployed. This version number should be
20+
# incremented each time you make changes to the application.
21+
appVersion: 1.16.0

0 commit comments

Comments
 (0)