mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Remove starlark support
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
@@ -25,7 +25,6 @@ require (
|
||||
github.com/sergi/go-diff v1.2.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/xlab/treeprint v1.2.0 // indirect
|
||||
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@@ -69,9 +66,6 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
|
||||
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
|
||||
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 h1:+FNtrFTmVw0YZGpBGX56XDee331t6JAXeK2bcyhLOOc=
|
||||
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5/go.mod h1:nmDLcffg48OtT/PSW0Hg7FvpRQsQh5OSqIylirxKC7o=
|
||||
golang.org/x/sys v0.0.0-20191002063906-3421d5a6bb1c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
|
||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
||||
@@ -493,204 +493,6 @@ metadata:
|
||||
a-string-value: 'a'
|
||||
a-int-value: '2'
|
||||
a-bool-value: 'true'
|
||||
`,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "starlark_function_config",
|
||||
args: func(d string) []string { return []string{"--enable-star"} },
|
||||
files: func(d string) map[string]string {
|
||||
return map[string]string{
|
||||
"script.star": `
|
||||
# set the foo annotation on each resource
|
||||
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"])
|
||||
`,
|
||||
"config.yaml": `
|
||||
apiVersion: example.com/v1alpha1
|
||||
kind: Input
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
config.kubernetes.io/function: |
|
||||
starlark:
|
||||
path: script.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{
|
||||
"config.yaml": `
|
||||
apiVersion: example.com/v1alpha1
|
||||
kind: Input
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
config.kubernetes.io/function: |
|
||||
starlark:
|
||||
path: script.star
|
||||
name: fn
|
||||
a-bool-value: true
|
||||
a-int-value: 2
|
||||
a-string-value: a
|
||||
data:
|
||||
boolValue: true
|
||||
intValue: 2
|
||||
stringValue: a
|
||||
`,
|
||||
"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_path",
|
||||
args: func(d string) []string {
|
||||
return []string{
|
||||
"--enable-star", "--star-path", "script.star",
|
||||
"--", "stringValue=a", "intValue=2", "boolValue=true",
|
||||
}
|
||||
},
|
||||
files: func(d string) map[string]string {
|
||||
return map[string]string{
|
||||
"script.star": `
|
||||
# set the foo annotation on each resource
|
||||
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"])
|
||||
`,
|
||||
"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",
|
||||
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:
|
||||
a-bool-value: true
|
||||
a-int-value: 2
|
||||
a-string-value: a
|
||||
`,
|
||||
}
|
||||
},
|
||||
|
||||
@@ -51,14 +51,6 @@ func GetRunFnRunner(name string) *RunFnRunner {
|
||||
"enable support for exec functions -- note: exec functions run arbitrary code -- do not use for untrusted configs!!! (Alpha)")
|
||||
r.Command.Flags().StringVar(
|
||||
&r.ExecPath, "exec-path", "", "run an executable as a function. (Alpha)")
|
||||
r.Command.Flags().BoolVar(
|
||||
&r.EnableStar, "enable-star", false, "enable support for starlark functions. (Alpha)")
|
||||
r.Command.Flags().StringVar(
|
||||
&r.StarPath, "star-path", "", "run a starlark script as a function. (Alpha)")
|
||||
r.Command.Flags().StringVar(
|
||||
&r.StarURL, "star-url", "", "run a starlark script as a function. (Alpha)")
|
||||
r.Command.Flags().StringVar(
|
||||
&r.StarName, "star-name", "", "name of starlark program. (Alpha)")
|
||||
|
||||
r.Command.Flags().StringVar(
|
||||
&r.ResultsDir, "results-dir", "", "write function results to this dir")
|
||||
@@ -91,7 +83,6 @@ type RunFnRunner struct {
|
||||
GlobalScope bool
|
||||
FnPaths []string
|
||||
Image string
|
||||
EnableStar bool
|
||||
StarPath string
|
||||
StarURL string
|
||||
StarName string
|
||||
@@ -128,8 +119,6 @@ func (r *RunFnRunner) getContainerFunctions(dataItems []string) (
|
||||
switch {
|
||||
case r.Image != "":
|
||||
fnAnnotation, err = fnAnnotationForImage(r.Image, r.Network)
|
||||
case r.EnableStar && (r.StarPath != "" || r.StarURL != ""):
|
||||
fnAnnotation, err = fnAnnotationForStar(r.StarPath, r.StarURL, r.StarName)
|
||||
case r.EnableExec && r.ExecPath != "":
|
||||
fnAnnotation, err = fnAnnotationForExec(r.ExecPath)
|
||||
}
|
||||
@@ -218,37 +207,6 @@ func fnAnnotationForExec(path string) (*yaml.RNode, error) {
|
||||
return fn, nil
|
||||
}
|
||||
|
||||
func fnAnnotationForStar(path string, url string, name string) (*yaml.RNode, error) {
|
||||
fn, err := yaml.Parse(`starlark: {}`)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
|
||||
if path != "" {
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("starlark"),
|
||||
yaml.SetField("path", yaml.NewScalarRNode(path)))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
}
|
||||
if url != "" {
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("starlark"),
|
||||
yaml.SetField("url", yaml.NewScalarRNode(url)))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
}
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("starlark"),
|
||||
yaml.SetField("name", yaml.NewScalarRNode(name)))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
return fn, nil
|
||||
}
|
||||
|
||||
func fnAnnotationForImage(image string, enableNetwork bool) (*yaml.RNode, error) {
|
||||
fn, err := yaml.Parse(`container: {}`)
|
||||
if err != nil {
|
||||
@@ -286,16 +244,11 @@ func toStorageMounts(mounts []string) []runtimeutil.StorageMount {
|
||||
}
|
||||
|
||||
func (r *RunFnRunner) preRunE(c *cobra.Command, args []string) error {
|
||||
if !r.EnableStar && (r.StarPath != "" || r.StarURL != "") {
|
||||
return errors.Errorf("must specify --enable-star with --star-path and --star-url")
|
||||
}
|
||||
|
||||
if !r.EnableExec && r.ExecPath != "" {
|
||||
return errors.Errorf("must specify --enable-exec with --exec-path")
|
||||
}
|
||||
|
||||
if c.ArgsLenAtDash() >= 0 && r.Image == "" &&
|
||||
!(r.EnableStar && (r.StarPath != "" || r.StarURL != "")) && !(r.EnableExec && r.ExecPath != "") {
|
||||
if c.ArgsLenAtDash() >= 0 && r.Image == "" && !(r.EnableExec && r.ExecPath != "") {
|
||||
return errors.Errorf("must specify --image")
|
||||
}
|
||||
|
||||
@@ -346,7 +299,6 @@ func (r *RunFnRunner) preRunE(c *cobra.Command, args []string) error {
|
||||
Input: input,
|
||||
Path: path,
|
||||
Network: r.Network,
|
||||
EnableStarlark: r.EnableStar,
|
||||
EnableExec: r.EnableExec,
|
||||
StorageMounts: storageMounts,
|
||||
ResultsDir: r.ResultsDir,
|
||||
|
||||
@@ -157,55 +157,6 @@ kind: Foo
|
||||
apiVersion: v1
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "star",
|
||||
args: []string{"run", "dir",
|
||||
"--enable-star",
|
||||
"--star-path", "a/b/c",
|
||||
"--star-name", "foo",
|
||||
"--", "Foo", "g=h"},
|
||||
path: "dir",
|
||||
expected: `
|
||||
metadata:
|
||||
name: function-input
|
||||
annotations:
|
||||
config.kubernetes.io/function: |
|
||||
starlark: {path: a/b/c, name: foo}
|
||||
data: {g: h}
|
||||
kind: Foo
|
||||
apiVersion: v1
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "star-not-enabled",
|
||||
args: []string{"run", "dir",
|
||||
"--star-path", "a/b/c",
|
||||
"--star-name", "foo",
|
||||
"--", "Foo", "g=h"},
|
||||
path: "dir",
|
||||
err: "must specify --enable-star with --star-path",
|
||||
},
|
||||
{
|
||||
name: "image-star-not-enabled",
|
||||
args: []string{"run", "dir",
|
||||
"--image", "some_image",
|
||||
"--star-path", "a/b/c",
|
||||
"--star-name", "foo",
|
||||
"--", "Foo", "g=h"},
|
||||
path: "dir",
|
||||
err: "must specify --enable-star with --star-path",
|
||||
},
|
||||
{
|
||||
name: "star-enabled",
|
||||
args: []string{"run", "dir", "--enable-star"},
|
||||
path: "dir",
|
||||
expectedStruct: &runfn.RunFns{
|
||||
Path: "dir",
|
||||
EnableStarlark: true,
|
||||
Env: []string{},
|
||||
WorkingDir: wd,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "function paths",
|
||||
args: []string{"run", "dir", "--fn-path", "path1", "--fn-path", "path2"},
|
||||
|
||||
Reference in New Issue
Block a user