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

Exec plugins with argsFromFile can look for the file in wrong locations #4115

Closed
Gikkman opened this issue Aug 11, 2021 · 6 comments
Closed
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. triage/under-consideration

Comments

@Gikkman
Copy link

Gikkman commented Aug 11, 2021

When writing a exec custom plugin, the argsFromFile seems to try to load the file relative to the root folder of the kustomize project, and not relative to the file describing the plugin. I recon this might be intentional, but since there is no documentation on argsFromFile, at least to me, this feels unintuitive.

You can find an example repo which exhibits the problem here

Files that can reproduce the issue

.
├── base/
│   ├── kustomization.yaml
│   ├── ingress.yaml
├── transformers/
│   ├── kustomization.yaml
│   ├── SedTransformer.yaml
│   └── sed-input.txt
└── plugins/teamname/v1/sedtransformer
    └── SedTransformer
-> base/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - ingress.yml

transformers:
  - ../transformers
-> base/ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
    - host: HELLO-SERVER-CLUSTER
      http:
        paths:
          - backend:
              serviceName: some-svc
              servicePort: 8081
-> transformers/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - SedTransformer.yaml
-> transformers/SedTransformer.yaml
apiVersion: teamname/v1
kind: SedTransformer
metadata:
  name: not-really-used
argsOneLiner: s/HELLO/WORLD/g
argsFromFile: sed-input.txt
-> transformers/sed-input.txt
s/SERVER/MyAwsomeServer/g
s/CLUSTER/SomeoneElsesCluster/g
-> plugins/teamname/v1/sedtransformer/SedTransformer
#!/bin/bash


# Skip the config file name argument.
shift

args=""
for arg in "$@"; do
  args="$args -e $arg"
done

cat - | eval sed $args

Expected output

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
  - host: WORLD-MyAwesomeServer-SomeoneElsesCluster
    http:
      paths:
      - backend:
          serviceName: some-svc
          servicePort: 8081

Actual output

$ kustomize build --enable-alpha-plugins kustomize/base
> Error: plugin myteam_v1_SedTransformer|~X|not-really-used fails configuration: evalsymlink failure on '/Users/gikkman/Development/kustomize-plugin/kustomize/base/sed-input.txt' : lstat /Users/gikkman/Development/kustomize-plugin/kustomize/base/sed-input.txt: no such file or directory

Kustomize version

{Version:kustomize/v4.2.0 GitCommit:d53a2ad45d04b0264bcee9e19879437d851cb778 BuildDate:2021-07-01T01:00:35+01:00 GoOs:darwin GoArch:amd64}

Platform

macOS

Additional notes
If you move the sed-input.txt to the base folder, the sed transformations are applied as expected.

@Gikkman Gikkman added the kind/bug Categorizes issue or PR as related to a bug. label Aug 11, 2021
@k8s-ci-robot
Copy link
Contributor

@Gikkman: 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 Aug 11, 2021
@natasha41575
Copy link
Contributor

Similar issue with exec functions: #4117

@galexeyev
Copy link

It's still reproducible on recently released 4.3.0 version. Fix from #4125 seems not to be working properly.

@KnVerey KnVerey self-assigned this Sep 29, 2021
@KnVerey
Copy link
Contributor

KnVerey commented Sep 30, 2021

#4125 only fixed the "function" version of exec plugins, whereas the examples on this issue are using the older env-lookup-based exec plugins. While we would accept a fix to the older exec plugins so that they also use the Kustomization's dir as their working dir, I would recommend switching to the newer "function" style, as the older style is proposed for deprecation as part of the plan to move plugins as a whole out of alpha: kubernetes/enhancements#2954.

E.g. it would look like this:

apiVersion: teamname/v1
kind: SedTransformer
metadata:
  name: not-really-used
  annotations:
      config.kubernetes.io/function: |-
        exec:
          path: ../plugins/teamname/v1/sedtransformer/SedTransformer # can be anywhere within the Kustomize root
          args:  s/HELLO/WORLD/g
argsFromFile: sed-input.txt

The function version of exec doesn't have argsFromFile support, so those can either be inlined in the functionConfig as well, or you can pass the filename for your executable to read. If that is problematic for your use case, I'd be interested to hear more details to inform our deprecation plan.

/triage under-consideration
/unassign

@KnVerey KnVerey removed the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Sep 30, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 29, 2021
@Gikkman
Copy link
Author

Gikkman commented Jan 3, 2022

I had completely forgotten about this issue until I got the stale reminder.

Our use case was creating a plugin that did some templating for us, to handle the auto-generated namespaces that we generate for testing. We had a list of what variables were pulled from the environment, using a file. But I think we can solve our case using what you described, by passing the path to the file to the plugin and let it read what it needs.

If you plan to deprecate argsFromFile, I think you can mark this as a known issue and close it with the reason that it'll be deprecated

@KnVerey KnVerey closed this as completed Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. triage/under-consideration
Projects
None yet
Development

No branches or pull requests

6 participants