Skip to content

Commit

Permalink
support loading starlib in starlark fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengqi Yu committed Sep 8, 2021
1 parent a608154 commit 5bf91e0
Show file tree
Hide file tree
Showing 21 changed files with 296 additions and 10 deletions.
13 changes: 13 additions & 0 deletions examples/starlark-load-library/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/app.yaml b/app.yaml
index b6ca925..d697d2f 100644
--- a/app.yaml
+++ b/app.yaml
@@ -5,7 +5,7 @@ metadata:
annotations:
last-applied: '{"spec":{"replicas":3}}'
spec:
- replicas: 1
+ replicas: 4
template:
spec:
containers:
2 changes: 2 additions & 0 deletions examples/starlark-load-library/.krmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.expected
results
8 changes: 8 additions & 0 deletions examples/starlark-load-library/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: example
pipeline:
mutators:
- image: gcr.io/kpt-fn/starlark:unstable
configPath: fn-config.yaml
62 changes: 62 additions & 0 deletions examples/starlark-load-library/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# starlark: Load Library

### Overview

In this example, we are going to demonstrate how to load a library in the
[`starlark`] function.

### Fetch the example package

Get the example package by running the following commands:

```shell
$ kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/starlark-load-library
```

We are going to use the following `Kptfile` and `fn-config.yaml` to configure
the function:

```yaml
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: example
pipeline:
mutators:
- image: gcr.io/kpt-fn/starlark:unstable
configPath: fn-config.yaml
```
```yaml
# fn-config.yaml
apiVersion: fn.kpt.dev/v1alpha1
kind: StarlarkRun
metadata:
name: set-namespace-to-prod
source: |
load('encoding/json.star', 'json')
def updateReplicas(resources):
for resource in resources:
if resource["kind"] == "Deployment":
obj = json.decode(resource["metadata"]["annotations"]["last-applied"])
resource["spec"]["replicas"] = obj["spec"]["replicas"]+1
updateReplicas(ctx.resource_list["items"])
```
We load the json library by `load('encoding/json.star', 'json')`. Then we invoke
the `json.decode` method to deserialize the content from an annotation.

### Function invocation

Invoke the function by running the following commands:

```shell
$ kpt fn render starlark-load-library
```

### Expected result

Check the `.spec.replicas` field should have been updated to 4.

[`starlark`]: https://catalog.kpt.dev/starlark/v0.1/
15 changes: 15 additions & 0 deletions examples/starlark-load-library/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
annotations:
last-applied: '{"spec":{"replicas":3}}'
spec:
replicas: 1
template:
spec:
containers:
- name: nginx
image: nginx:1.14.1
ports:
- containerPort: 80
13 changes: 13 additions & 0 deletions examples/starlark-load-library/fn-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: fn.kpt.dev/v1alpha1
kind: StarlarkRun
metadata:
name: set-namespace-to-prod
source: |
load('encoding/json.star', 'json')
def updateReplicas(resources):
for resource in resources:
if resource["kind"] == "Deployment":
obj = json.decode(resource["metadata"]["annotations"]["last-applied"])
resource["spec"]["replicas"] = obj["spec"]["replicas"]+1
updateReplicas(ctx.resource_list["items"])
51 changes: 51 additions & 0 deletions functions/go/starlark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,27 @@ Here's what you currently cannot do in the Starlark script:
kpt will attempt to retain comments by copying them from the function inputs
to the function outputs.

#### Libraries

We support the following [Starlib libraries]:

| Name | How to load | Example |
|--------------------|----------------------------------------|---------|
| [bsoup] | load('bsoup.star', 'bsoup') | [example](https://github.com/qri-io/starlib/blob/master/bsoup/testdata/test.star) |
| [encoding/base64] | load('encoding/base64.star', 'base64') | [example](https://github.com/qri-io/starlib/blob/master/encoding/base64/testdata/test.star) |
| [encoding/csv] | load('encoding/csv.star', 'csv') | [example](https://github.com/qri-io/starlib/blob/master/encoding/csv/testdata/test.star) |
| [encoding/json] | load('encoding/json.star', 'json') | [example](https://github.com/google/starlark-go/blob/master/starlark/testdata/json.star) |
| [encoding/yaml] | load('encoding/yaml.star', 'yaml') | [example](https://github.com/qri-io/starlib/blob/master/encoding/yaml/testdata/test.star) |
| [geo] | load('geo.star', 'geo') | [example](https://github.com/qri-io/starlib/blob/master/geo/testdata/test.star) |
| [hash] | load('hash.star', 'hash') | [example](https://github.com/qri-io/starlib/blob/master/hash/testdata/test.star) |
| [html] | load('html.star', 'html') | [example](https://github.com/qri-io/starlib/blob/master/html/testdata/test.star) |
| [http] | load('http.star', 'http') | [example](https://github.com/qri-io/starlib/blob/master/http/testdata/test.star) |
| [math] | load('math.star', 'math') | [example](https://github.com/google/starlark-go/blob/master/starlark/testdata/math.star) |
| [re] | load('re.star', 're') | [example](https://github.com/qri-io/starlib/blob/master/re/testdata/test.star) |
| [time] | load('time.star', 'time') | [example](https://github.com/google/starlark-go/blob/master/starlark/testdata/time.star) |
| [xlsx] | load('xlsx.star', 'xlsx') | [example](https://github.com/qri-io/starlib/blob/master/xlsx/testdata/test.star) |
| [zipfile] | load('zipfile.star', 'ZipFile') | [example](https://github.com/qri-io/starlib/blob/master/zipfile/testdata/test.star) |

### Debugging

It is possible to debug the `starlark` functions using [`print`][print].
Expand Down Expand Up @@ -190,3 +211,33 @@ You will find your debugging output in `functionResultList items.stderr`.
[fail]: https://docs.bazel.build/versions/master/skylark/lib/globals.html#fail

[print]: https://docs.bazel.build/versions/master/skylark/lib/globals.html#print

[Starlib libraries]: https://github.com/qri-io/starlib#packages

[bsoup]: https://github.com/qri-io/starlib/tree/v0.5.0/bsoup

[encoding/base64]: https://github.com/qri-io/starlib/tree/v0.5.0/encoding/base64

[encoding/csv]: https://github.com/qri-io/starlib/tree/v0.5.0/encoding/csv

[encoding/json]: https://pkg.go.dev/go.starlark.net/lib/json

[encoding/yaml]: https://github.com/qri-io/starlib/tree/v0.5.0/encoding/yaml

[geo]: https://github.com/qri-io/starlib/tree/v0.5.0/geo

[hash]: https://github.com/qri-io/starlib/tree/v0.5.0/hash

[html]: https://github.com/qri-io/starlib/tree/v0.5.0/html

[http]: https://github.com/qri-io/starlib/tree/v0.5.0/http

[math]: https://pkg.go.dev/go.starlark.net/lib/math

[re]: https://github.com/qri-io/starlib/tree/v0.5.0/re

[time]: https://pkg.go.dev/go.starlark.net/lib/time

[xlsx]: https://github.com/qri-io/starlib/tree/v0.5.0/xlsx

[zipfile]: https://github.com/qri-io/starlib/tree/v0.5.0/zipfile
21 changes: 21 additions & 0 deletions functions/go/starlark/generated/docs.go

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

6 changes: 2 additions & 4 deletions functions/go/starlark/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ go 1.16

require (
github.com/qri-io/starlib v0.5.0
go.starlark.net v0.0.0-20210406145628-7a1108eaa012
go.starlark.net v0.0.0-20210901212718-87f333178d59
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/api v0.21.0
k8s.io/apimachinery v0.21.0
// We use a unreleased version to pickup https://github.com/kubernetes-sigs/kustomize/pull/4023.
// We should switch to a released version when the next kyaml is out.
sigs.k8s.io/kustomize/kyaml v0.11.1-0.20210630191550-02d14d724aa6
sigs.k8s.io/kustomize/kyaml v0.11.1
sigs.k8s.io/yaml v1.2.0
)
15 changes: 10 additions & 5 deletions functions/go/starlark/go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/360EntSecGroup-Skylar/excelize v1.4.1 h1:l55mJb6rkkaUzOpSsgEeKYtS6/0gHwBYyfo5Jcjv/Ks=
github.com/360EntSecGroup-Skylar/excelize v1.4.1/go.mod h1:vnax29X2usfl7HHkBrX5EvSCJcmH3dT9luvxzu8iGAE=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/PuerkitoBio/goquery v1.5.1 h1:PSPBGne8NIUWw+/7vFBV+kG2J/5MOjbzc7154OaKCSE=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5zzsLTo=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
Expand All @@ -34,6 +37,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dustmop/soup v1.1.2-0.20190516214245-38228baa104e h1:44fmjqDtdCiUNlSjJVp+w1AOs6na3Y6Ai0aIeseFjkI=
github.com/dustmop/soup v1.1.2-0.20190516214245-38228baa104e/go.mod h1:CgNC6SGbT+Xb8wGGvzilttZL1mc5sQ/5KkcxsZttMIk=
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
Expand Down Expand Up @@ -141,6 +145,7 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
Expand All @@ -155,6 +160,7 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/paulmach/orb v0.1.5 h1:GUcATabvxciqEzGd+c01/9ek3B6pUp9OdcIHFSDDSSg=
github.com/paulmach/orb v0.1.5/go.mod h1:pPwxxs3zoAyosNSbNKn1jiXV2+oovRDObDKfTvRegDI=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -215,8 +221,9 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5/go.mod h1:nmDLcffg48OtT/PSW0Hg7FvpRQsQh5OSqIylirxKC7o=
go.starlark.net v0.0.0-20210406145628-7a1108eaa012 h1:4RGobP/iq7S22H0Bb92OEt+M8/cfBQnW+T+a2MC0sQo=
go.starlark.net v0.0.0-20210406145628-7a1108eaa012/go.mod h1:t3mmBBPzAVvK0L0n1drDmrQsJ8FoIx4INCqVMTr/Zo0=
go.starlark.net v0.0.0-20210901212718-87f333178d59 h1:F8ArBy9n1l7HE1JjzOIYqweEqoUlywy5+L3bR0tIa9g=
go.starlark.net v0.0.0-20210901212718-87f333178d59/go.mod h1:t3mmBBPzAVvK0L0n1drDmrQsJ8FoIx4INCqVMTr/Zo0=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
Expand Down Expand Up @@ -347,10 +354,8 @@ k8s.io/klog/v2 v2.8.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec=
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7/go.mod h1:wXW5VT87nVfh/iLV8FpR2uDvrFyomxbtb1KivDbvPTE=
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e h1:KLHHjkdQFomZy8+06csTWZ0m1343QqxZhR2LJ1OxCYM=
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e/go.mod h1:vHXdDvt9+2spS2Rx9ql3I8tycm3H9FDfdUoIuKCefvw=
sigs.k8s.io/kustomize/kyaml v0.10.21 h1:KdoEgz3HzmcaLUTFqs6aaqFpsaA9MVRIwOZbi8vMaD0=
sigs.k8s.io/kustomize/kyaml v0.10.21/go.mod h1:TYWhGwW9vjoRh3rWqBwB/ZOXyEGRVWe7Ggc3+KZIO+c=
sigs.k8s.io/kustomize/kyaml v0.11.1-0.20210630191550-02d14d724aa6 h1:uc5vfXuZPwjYPtIJ9G7Q9Tt2Fqdq61g23n8nomjwSj8=
sigs.k8s.io/kustomize/kyaml v0.11.1-0.20210630191550-02d14d724aa6/go.mod h1:GNMwjim4Ypgp/MueD3zXHLRJEjz7RvtPae0AwlvEMFM=
sigs.k8s.io/kustomize/kyaml v0.11.1 h1:MWihd9syKG7VQnAzr/OpKb94FvH+cw96nEV1u3it7pI=
sigs.k8s.io/kustomize/kyaml v0.11.1/go.mod h1:FTJxEZ86ScK184NpGSAQcfEqee0nul8oLCK30D47m4E=
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
sigs.k8s.io/structured-merge-diff/v4 v4.1.0 h1:C4r9BgJ98vrKnnVCjwCSXcWjWe0NKcUQkmzDXZXGwH8=
sigs.k8s.io/structured-merge-diff/v4 v4.1.0/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
Expand Down
1 change: 1 addition & 0 deletions functions/go/starlark/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ examplePackageURLs:
- https://github.com/GoogleContainerTools/kpt-functions-catalog/tree/master/examples/starlark-poddisruptionbudget
- https://github.com/GoogleContainerTools/kpt-functions-catalog/tree/master/examples/starlark-validation
- https://github.com/GoogleContainerTools/kpt-functions-catalog/tree/master/examples/starlark-configmap-as-functionconfig
- https://github.com/GoogleContainerTools/kpt-functions-catalog/tree/master/examples/starlark-load-library
emails:
- kpt-team@google.com
license: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package starlark

import (
"github.com/qri-io/starlib/bsoup"
"github.com/qri-io/starlib/encoding/base64"
"github.com/qri-io/starlib/encoding/csv"
"github.com/qri-io/starlib/encoding/json"
"github.com/qri-io/starlib/encoding/yaml"
"github.com/qri-io/starlib/geo"
"github.com/qri-io/starlib/hash"
"github.com/qri-io/starlib/html"
"github.com/qri-io/starlib/http"
"github.com/qri-io/starlib/math"
"github.com/qri-io/starlib/re"
"github.com/qri-io/starlib/time"
"github.com/qri-io/starlib/xlsx"
"github.com/qri-io/starlib/zipfile"
"go.starlark.net/starlark"
)

// load loads starlark libraries from https://github.com/qri-io/starlib#packages.
func load(_ *starlark.Thread, module string) (starlark.StringDict, error) {
switch module {
case bsoup.ModuleName:
return bsoup.LoadModule()
case base64.ModuleName:
return base64.LoadModule()
case csv.ModuleName:
return csv.LoadModule()
case json.ModuleName:
return starlark.StringDict{"json": json.Module}, nil
case yaml.ModuleName:
return yaml.LoadModule()
case geo.ModuleName:
return geo.LoadModule()
case hash.ModuleName:
return hash.LoadModule()
case html.ModuleName:
return html.LoadModule()
case http.ModuleName:
return http.LoadModule()
case math.ModuleName:
return starlark.StringDict{"math": math.Module}, nil
case re.ModuleName:
return re.LoadModule()
case time.ModuleName:
return starlark.StringDict{"time": time.Module}, nil
case xlsx.ModuleName:
return xlsx.LoadModule()
case zipfile.ModuleName:
return zipfile.LoadModule()
}
return nil, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (sf *Filter) Run(reader io.Reader, writer io.Writer) error {
// runStarlark runs the starlark script
func runStarlark(name, starlarkProgram string, resourceList starlark.Value) error {
// run the starlark as program as transformation function
thread := &starlark.Thread{Name: name}
thread := &starlark.Thread{Name: name, Load: load}

ctx := &Context{resourceList: resourceList}
pd, err := ctx.predeclared()
Expand Down
1 change: 1 addition & 0 deletions functions/go/starlark/~/.docker/.buildNodeID
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7fb55e20cd4f03912c7a77682ecaea1bd46a03a43b542908b917d21e3fe90c50
5 changes: 5 additions & 0 deletions functions/go/starlark/~/.docker/.token_seed
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"registry-1.docker.io": {
"Seed": "tORtWHykzW3E1tslm0aGVw=="
}
}
Empty file.
1 change: 1 addition & 0 deletions tests/starlark/load-library/.expected/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exitCode: 0
2 changes: 2 additions & 0 deletions tests/starlark/load-library/.krmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.expected
results
8 changes: 8 additions & 0 deletions tests/starlark/load-library/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: example
pipeline:
mutators:
- image: gcr.io/kpt-fn/starlark:unstable
configPath: fn-config.yaml
6 changes: 6 additions & 0 deletions tests/starlark/load-library/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: apps/v1
kind: ConfigMap
metadata:
name: my-nginx
data:
foo: bar
Loading

0 comments on commit 5bf91e0

Please sign in to comment.