kpt icon indicating copy to clipboard operation
kpt copied to clipboard

kpt alpha rpkg pull on package with subdirectories

Open henderiw opened this issue 1 year ago • 1 comments

Expected behavior

when you perform kpt alpha rpkg pull on a package that contains subdirectories, the files in those subdirectories should be shown.

Actual behavior

when you perform kpt alpha rpkg pull on a package that contains subdirectories, they files in those subdirectories are not shown

Information

k get packagerevisionresources.porch.kpt.dev mgmt-admin-76576dd94bd0ab2027daf8b3e1a8e7345d68de89 -o yaml apiVersion: porch.kpt.dev/v1alpha1 kind: PackageRevisionResources metadata: creationTimestamp: "2022-09-08T06:04:15Z" name: mgmt-admin-76576dd94bd0ab2027daf8b3e1a8e7345d68de89 namespace: default resourceVersion: 65192dea732e43d1c24954ab2d61317401dc73df uid: uid:admin.yndd.io/Tenant/tenant1:v1 spec: packageName: admin.yndd.io/Tenant/tenant1 repository: mgmt-admin resources: Kptfile: | apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: admin.yndd.io/Tenant/tenant1 annotations: config.kubernetes.io/local-config: "true" info: description: admin.yndd.io/Tenant/tenant1 README.md: | # admin.yndd.io/Tenant/tenant1

  ## Description
  admin.yndd.io/Tenant/tenant1

  ## Usage

  ### Fetch the package
  `kpt pkg get REPO_URI[.git]/PKG_PATH[@VERSION] admin.yndd.io/Tenant/tenant1`
  Details: https://kpt.dev/reference/cli/pkg/get/

  ### View package content
  `kpt pkg tree admin.yndd.io/Tenant/tenant1`
  Details: https://kpt.dev/reference/cli/pkg/tree/

  ### Apply the package
  ```
  kpt live init admin.yndd.io/Tenant/tenant1
  kpt live apply admin.yndd.io/Tenant/tenant1 --reconcile-timeout=2m --output=table
  ```
  Details: https://kpt.dev/reference/cli/live/
non-namespaced/tenant1.yaml: |
  apiVersion: v1
  kind: Namespace
  metadata:
    name: tenant1
package-context.yaml: |
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: kptfile.kpt.dev
    annotations:
      config.kubernetes.io/local-config: "true"
  data:
    name: example

revision: v1

kpt alpha rpkg pull mgmt-admin-76576dd94bd0ab2027daf8b3e1a8e7345d68de89 -n default apiVersion: config.kubernetes.io/v1 kind: ResourceList items:

  • apiVersion: kpt.dev/v1 kind: Kptfile metadata: name: admin.yndd.io/Tenant/tenant1 annotations: config.kubernetes.io/local-config: "true" config.kubernetes.io/index: '0' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'Kptfile' config.kubernetes.io/path: 'Kptfile' info: description: admin.yndd.io/Tenant/tenant1
  • apiVersion: v1 kind: ConfigMap metadata: name: kptfile.kpt.dev annotations: config.kubernetes.io/local-config: "true" config.kubernetes.io/index: '0' internal.config.kubernetes.io/index: '0' internal.config.kubernetes.io/path: 'package-context.yaml' config.kubernetes.io/path: 'package-context.yaml' data: name: example

Steps to reproduce the behavior

create a package with subdirectories

possible fix:

FROM: func includeFile(path string) bool { for _, m := range matchResourceContents { if matched, err := filepath.Match(m, path); err == nil && matched { return true } } return false }

TO: func includeFile(path string) bool { for _, m := range matchResourceContents { file := filepath.Base(path) if matched, err := filepath.Match(m, file); err == nil && matched { return true } } return false }

henderiw avatar Sep 09 '22 04:09 henderiw

Yeah, I'm able to reproduce this. It seems like running the kpt alpha rpkg pull command and specifying a destination on disk correctly writes out nested directories and files, but when a destination is not specified, the resulting ResourceList written to stdout does not contain those files. I will look into how we can fix this.

mortent avatar Sep 14 '22 06:09 mortent

@mortent I also see when applying a package with subdirectories to porch does not install any KRM resource in the subdirectories. Is this aligned with what you found?

henderiw avatar Sep 25 '22 15:09 henderiw

@mortent this is one issue I see which is potentially related to this. Here is a scenario I have.

henderiw@nucx:~/nephio-install-mgmt/mgmt-admin/tenant1$ k get packagerevisionresources.porch.kpt.dev yndd-mgmt-app-packages-987876cf01f61e1a10f6e10900bb15f9b5321e95 NAME PACKAGE REVISION REPOSITORY FILES yndd-mgmt-app-packages-987876cf01f61e1a10f6e10900bb15f9b5321e95 topology-app main yndd-mgmt-app-packages 10 henderiw@nucx:~/nephio-install-mgmt/mgmt-admin/tenant1$ kpt alpha rpkg copy yndd-mgmt-app-packages-987876cf01f61e1a10f6e10900bb15f9b5321e95 --revision v15 -n default yndd-mgmt-app-packages-ac189212ce6057c2438afebc41ac4ebcaf3b82db created henderiw@nucx:~/nephio-install-mgmt/mgmt-admin/tenant1$ k get packagerevisionresources.porch.kpt.dev yndd-mgmt-app-packages-ac189212ce6057c2438afebc41ac4ebcaf3b82db NAME PACKAGE REVISION REPOSITORY FILES yndd-mgmt-app-packages-ac189212ce6057c2438afebc41ac4ebcaf3b82db topology-app v15 yndd-mgmt-app-packages 3

henderiw avatar Oct 10 '22 10:10 henderiw

@henderiw Thanks for reporting these. I have a fix for the first issue in https://github.com/GoogleContainerTools/kpt/pull/3609.

Do you have steps to reproduce the second issue you mentioned, where subdirectories are not included when applying a package to porch? Is this about applying a package to the cluster using the Config Sync integration with the kpt alpha sync commands?

I assume the last issue is the same as https://github.com/GoogleContainerTools/kpt/issues/3607? I will take a look at it.

mortent avatar Oct 11 '22 03:10 mortent

I am stuck now with this error. Not sure why it is happening, but this package when we copy the topology-app in a revision I get the error.

I created a public repo with the package, so I hope you can use it as well kpt alpha repo register
--namespace default https://github.com/henderiw-kpt/test-package.git kpt alpha rpkg copy test-package-93515d0d1b6dfa9531096f2bc006b5b9617f6807 --revision v1 -n default Error: Internal error occurred: authentication required

henderiw avatar Oct 11 '22 04:10 henderiw

This seems like a duplicate of #3607. The copy command does however have the issue described in #3599.

mortent avatar Jan 27 '23 23:01 mortent