Skip to content

Commit

Permalink
Merge pull request #5768 from dims/remove-starlark-support
Browse files Browse the repository at this point in the history
Remove starlark support
  • Loading branch information
k8s-ci-robot authored Sep 25, 2024
2 parents 88f19bf + d32eacf commit 2cd9a2e
Show file tree
Hide file tree
Showing 91 changed files with 285 additions and 2,410 deletions.
1 change: 0 additions & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ require (
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sergi/go-diff v1.2.0 // 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
Expand Down
6 changes: 0 additions & 6 deletions api/go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
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/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=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -67,11 +64,8 @@ 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=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
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=
Expand Down
1 change: 0 additions & 1 deletion api/internal/plugins/fnplugin/fnplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func NewFnPlugin(o *types.FnPluginLoadingOptions) *FnPlugin {
runFns: runfn.RunFns{
Functions: []*yaml.RNode{},
Network: o.Network,
EnableStarlark: o.EnableStar,
EnableExec: o.EnableExec,
StorageMounts: toStorageMounts(o.Mounts),
Env: o.Env,
Expand Down
1 change: 0 additions & 1 deletion api/types/pluginconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type PluginConfig struct {

func EnabledPluginConfig(b BuiltinPluginLoadingOptions) (pc *PluginConfig) {
pc = MakePluginConfig(PluginRestrictionsNone, b)
pc.FnpLoadingOptions.EnableStar = true
pc.HelmConfig.Enabled = true
// If this command is not on PATH, tests needing it should skip.
pc.HelmConfig.Command = "helmV3"
Expand Down
2 changes: 0 additions & 2 deletions api/types/pluginrestrictions.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ const (
type FnPluginLoadingOptions struct {
// Allow to run executables
EnableExec bool
// Allow to run starlark
EnableStar bool
// Allow container access to network
Network bool
NetworkName string
Expand Down
1 change: 0 additions & 1 deletion cmd/config/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions cmd/config/go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down Expand Up @@ -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=
Expand Down
198 changes: 0 additions & 198 deletions cmd/config/internal/commands/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
`,
}
},
Expand Down
50 changes: 1 addition & 49 deletions cmd/config/internal/commands/run-fns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -91,7 +83,6 @@ type RunFnRunner struct {
GlobalScope bool
FnPaths []string
Image string
EnableStar bool
StarPath string
StarURL string
StarName string
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 2cd9a2e

Please sign in to comment.