Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reference Files with Starlark Function? #4182

Closed
kferrone opened this issue Sep 14, 2021 · 3 comments
Closed

How to reference Files with Starlark Function? #4182

kferrone opened this issue Sep 14, 2021 · 3 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. triage/unresolved Indicates an issue that can not or will not be resolved.

Comments

@kferrone
Copy link

How do I reference a functionFiles from within a Starlark function?

Here is the yaml for my function:
embed.yaml

apiVersion: someteam
kind: Embed
metadata:
  name: test-embed
  annotations:
    config.kubernetes.io/function: |
      starlark:
        path: kustomize/functions/embed/embed.star
spec:
  target:
    kind: Function
    fieldPath: spec.source
    fileRef: cool.py
functionFiles:
- cool.py

Is it even possible for Starlark to reference files from the host? I have a feeling kustomize would have to read files and pass in the content as variables.

Within the code I can only get the name of the files in an array like so:

files = ctx.resource_list["functionConfig"]["functionFiles"]

Now how to actually read the file contents?

@k8s-ci-robot k8s-ci-robot added the needs-kind Indicates a PR lacks a `kind/foo` label and requires one. label Sep 14, 2021
@k8s-ci-robot
Copy link
Contributor

@kferrone: This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Sep 14, 2021
@KnVerey KnVerey self-assigned this Sep 29, 2021
@KnVerey
Copy link
Contributor

KnVerey commented Sep 30, 2021

To the best of my knowledge, Starlark intentionally cannot do filesystem IO as a feature of the language (not specific to Kustomize). If you're unable to encode the input data into the function config itself, then I suggest you switch to a container function (which supports specified mounts) or an exec function (which has filesystem access inherently).

Please note that we have an open KEP with a proposal for moving plugins in general forward from alpha, and it includes deprecating dedicated starlark support: kubernetes/enhancements#2954. Although Starlark has its advantages, it is a problem for us to maintain and notably causes a permanent inconsistency with kubectl kustomize due to the dependencies it requires. If you feel strongly about it, please comment on the KEP. Assuming the deprecation plan moves forward, we will not be adding features to Kustomize's Starlark function support.

/unassign
/kind feature
/triage unresolved

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. triage/unresolved Indicates an issue that can not or will not be resolved. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Sep 30, 2021
@KnVerey KnVerey removed the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Sep 30, 2021
@kferrone
Copy link
Author

kferrone commented Oct 4, 2021

I figured it didn't. I wrote normal plugin with python instead. Starlark was an interesting idea, not worried about it at all.

@kferrone kferrone closed this as completed Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. triage/unresolved Indicates an issue that can not or will not be resolved.
Projects
None yet
Development

No branches or pull requests

3 participants