Remove starlark support

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas
2024-09-23 16:52:05 -04:00
parent 88f19bffa9
commit d32eacf034
91 changed files with 285 additions and 2410 deletions

View File

@@ -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
`,
}
},

View File

@@ -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,

View File

@@ -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"},