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

incomprehensible error message #3812

Closed
symbiont-ji opened this issue Apr 15, 2021 · 17 comments · Fixed by #4497
Closed

incomprehensible error message #3812

symbiont-ji opened this issue Apr 15, 2021 · 17 comments · Fixed by #4497
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. triage/not-an-issue

Comments

@symbiont-ji
Copy link

In

"got file '%s', but '%s' must be a directory to be a root",
, what does "must be a directory to be a root" even mean? That's not English!

@symbiont-ji symbiont-ji added the kind/bug Categorizes issue or PR as related to a bug. label Apr 15, 2021
@Shell32-Natsu
Copy link
Contributor

This error message means the path must be a directory, so it can be used as a build root.

@symbiont-ji
Copy link
Author

symbiont-ji commented Apr 16, 2021 via email

@rdxmb
Copy link

rdxmb commented Jun 16, 2021

This is indeed very confusing. I have a syntax error in my services.yaml , e.g. the ports key is missing. As a result I get

$ kustomize build .
Error: accumulating resources: accumulation err='accumulating resources from 'resources/service.yaml': yaml: line 9: did not find expected key': got file 'service.yaml', but '/home/marc/projects/k8-orchestration/tick-kustomize/base/kapacitor/resources/service.yaml' must be a directory to be a root

The first part of the error is kind of ok, but the second part does not make any sense here for the user.

Files:


$ cat resources/service.yaml 
---
apiVersion: v1
kind: Service
metadata:
  name: kapacitor
  labels:
    app.kubernetes.io/name: tick-kapacitor
spec:
  selector:
    app.kubernetes.io/name: tick-kapacitor
    - name: http
      port: 9092
      protocol: TCP
  type: ClusterIP
$ cat kustomization.yaml 
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - resources/service.yaml
  - resources/statefulset.yaml

@rdxmb
Copy link

rdxmb commented Jun 18, 2021

@Shell32-Natsu in some cases the error message might be correct. However, it appears also when there are some syntax problems within the files. Then it's very confusing. This seems to be an issue for me :)

@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 Sep 16, 2021
@m-Bilal
Copy link
Member

m-Bilal commented Sep 17, 2021

/assign

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active 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 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 rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Oct 17, 2021
@m-Bilal
Copy link
Member

m-Bilal commented Oct 17, 2021

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Oct 17, 2021
@rdxmb
Copy link

rdxmb commented Oct 18, 2021

@Shell32-Natsu

added the triage/not-an-issue label on Apr 16

Why?

@digihunch
Copy link

In my case, the actual error was duplicate resource name.
This error message is very misleading and it appears before the actual error message.

@m-Bilal
Copy link
Member

m-Bilal commented Jan 26, 2022

The reason why "directory must be a root" error message got appended to the actual error in @rdxmb's case is that we're only checking for HTTP error and proceeding if there's any other error here:

if errF := kt.accumulateFile(ra, path); errF != nil {
// not much we can do if the error is an HTTP error so we bail out
if errors.Is(errF, load.ErrorHTTP) {
return nil, errF
}
ldr, err := kt.ldr.New(path)

Is there a specific reason we're ignoring other errors here?

@m-Bilal
Copy link
Member

m-Bilal commented Jan 26, 2022

Does the error message "path must be a directory so that it can be used as a build root" make more sense?

@natasha41575
Copy link
Contributor

Is there a specific reason we're ignoring other errors here?

What we are trying to do is first try to load the resource as a file. If there is an error, proceed to try to load the resource as a directory.

Perhaps it doesn't make the most sense and there may be a way to restructure the code to provide more specific error messages.

@m-Bilal
Copy link
Member

m-Bilal commented Jan 26, 2022

I think the fix would be to make Read() in kyaml/kio/byteio_reader.go return a specific error type (like MalformedYAMLError / InvalidInputError) so that we can check for it in kusttarget.go's accumulateFile() and return if that is the error type. Is that the correct approach?

Another way I can think of doing this is to check if the path is not a directory and there's an error in kusttarget's accumulateFile(), return the error instead of trying to load the resource as a directory.

@felipetssilva
Copy link

In

"got file '%s', but '%s' must be a directory to be a root",

, what does "must be a directory to be a root" even mean? That's not English!

I am leaving this for future reference:

This error is because we must pass a directory to the kubectl apply -k <kustomization_directory> (or kubectl kustomize <kustomization_directory>) command. For example : this 'k apply -k application/' works! and this k apply -k application/application/kustomize.yaml DOES NOT!!

Error message is confusing but the problem is simple :)

@gocpplua
Copy link

minio
├── argo-server-deployment.yaml
├── argo-server-sa.yaml
├── argo-server-service.yaml
└── kustomization.yaml

/data/kubernetes/k3s$ sudo k3s kubectl apply -k ./minio
serviceaccount/argo-server created
service/argo-server created
deployment.apps/argo-server created

@lugipfupf
Copy link

In case this might help someone else:
Running on a rather old 2.5.5 ArgoCD, we got the same error message. Reason was a kustomization.yaml with quite a lot of yaml references hiding a duplicate entry.

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. triage/not-an-issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.