mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 09:02:53 +00:00
Support publishing starlark functions from urls
This commit is contained in:
@@ -563,6 +563,90 @@ metadata:
|
||||
"deployment.yaml": `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
a-bool-value: true
|
||||
a-int-value: 2
|
||||
a-string-value: a
|
||||
`,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "starlark_function_url",
|
||||
args: func(d string) []string {
|
||||
return []string{
|
||||
"--enable-star", "--star-url", "https://storage.googleapis.com/kustomize-starlark-functions/annotate.star",
|
||||
"--star-name", "annotate",
|
||||
"--", "stringValue=a", "intValue=2", "boolValue=true",
|
||||
}
|
||||
},
|
||||
files: func(d string) map[string]string {
|
||||
return map[string]string{
|
||||
"deployment.yaml": `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: foo
|
||||
`,
|
||||
}
|
||||
},
|
||||
expectedFiles: func(d string) map[string]string {
|
||||
return map[string]string{
|
||||
"deployment.yaml": `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
a-bool-value: true
|
||||
a-int-value: 2
|
||||
a-string-value: a
|
||||
`,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "starlark_function_url_config",
|
||||
args: func(d string) []string {
|
||||
return []string{"--enable-star"}
|
||||
},
|
||||
files: func(d string) map[string]string {
|
||||
return map[string]string{
|
||||
"config.yaml": `
|
||||
apiVersion: example.com/v1alpha1
|
||||
kind: Input
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
a-bool-value: true
|
||||
a-int-value: 2
|
||||
a-string-value: a
|
||||
config.kubernetes.io/function: |
|
||||
starlark:
|
||||
url: https://storage.googleapis.com/kustomize-starlark-functions/annotate.star
|
||||
name: fn
|
||||
data:
|
||||
boolValue: true
|
||||
intValue: 2
|
||||
stringValue: a
|
||||
`,
|
||||
"deployment.yaml": `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: foo
|
||||
`,
|
||||
}
|
||||
},
|
||||
expectedFiles: func(d string) map[string]string {
|
||||
return map[string]string{
|
||||
"deployment.yaml": `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
@@ -607,7 +691,7 @@ metadata:
|
||||
|
||||
err = cmd.Run()
|
||||
if tt.expectedErr != "" {
|
||||
if !assert.Contains(t, stdErr.String(), tt.expectedErr) {
|
||||
if !assert.Contains(t, stdErr.String(), tt.expectedErr, stdErr.String()) {
|
||||
t.FailNow()
|
||||
}
|
||||
return
|
||||
@@ -618,10 +702,10 @@ metadata:
|
||||
|
||||
for path, data := range tt.expectedFiles(binDir) {
|
||||
b, err := ioutil.ReadFile(path)
|
||||
if !assert.NoError(t, err) {
|
||||
if !assert.NoError(t, err, stdErr.String()) {
|
||||
t.FailNow()
|
||||
}
|
||||
if !assert.Equal(t, strings.TrimSpace(data), strings.TrimSpace(string(b))) {
|
||||
if !assert.Equal(t, strings.TrimSpace(data), strings.TrimSpace(string(b)), stdErr.String()) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
7
cmd/config/internal/commands/e2e/starlark/annotate.star
Normal file
7
cmd/config/internal/commands/e2e/starlark/annotate.star
Normal file
@@ -0,0 +1,7 @@
|
||||
def run(r, fc):
|
||||
for resource in r:
|
||||
resource["metadata"]["annotations"]["a-string-value"] = fc["data"]["stringValue"]
|
||||
resource["metadata"]["annotations"]["a-int-value"] = fc["data"]["intValue"]
|
||||
resource["metadata"]["annotations"]["a-bool-value"] = fc["data"]["boolValue"]
|
||||
|
||||
run(ctx.resource_list["items"], ctx.resource_list["functionConfig"])
|
||||
Reference in New Issue
Block a user