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

porch: packagevariant bug "Internal error occurred: error applying patch: conflict: fragment line does not match src line" #469

Open
johnbelamaric opened this issue Jan 4, 2024 · 8 comments
Labels
area/platform area/porch Porch related issues bug Something isn't working triaged
Milestone

Comments

@johnbelamaric
Copy link
Member

See kptdev/kpt#4110

cc @SamarSidharth

@SamarSidharth
Copy link

Hi @johnbelamaric,

Is there any workaround for this issue or an alternative way to update a published package managed by package variant

Thanks a lot for your time and efforts

@johnbelamaric
Copy link
Member Author

Ok, so I pulled down your package and pasted in the pipeline, I get this trying kpt fn render on the CLI:

jbelamaric@jbelamaric-glaptop:~/Downloads/nrf_2/nrf$ kpt fn render
Error: Kptfile at "/home/jbelamaric/Downloads/nrf_2/nrf" can't be read.

Details:
yaml: unmarshal errors:
  line 9: field pipeline not found in type v1.PackageInfo 

Looking at the Kptfile, pasting in your exact snippet from above, I get that result. The problem is that the pipeline stanza is indented under info and should not be. Using the below Kptfile instead, which just un-indents pipeline, the kpt fn render works.

apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
  name: nrf
  annotations:
    config.kubernetes.io/local-config: "true"
info:
  description: sample description
pipeline:
  mutators:
  - configMap:
      by-path: spec.kubeConfig.secretRef.name
      put-value: cluster2-kubeconfig
    image: gcr.io/kpt-fn/search-replace:v0.2.0
    selectors:
    - kind: HelmRelease

So, can you try that and see if it fixes the problem? If so, then the primary issue is in our error handling we should have rejected the package with an appropriate message.

@SamarSidharth
Copy link

Thanks a lot @johnbelamaric, I will test and let you know

@SamarSidharth
Copy link

Hi John, I had a look at the upstream kptfile and it doesn't contain the pipeline keyword initially as it is added by the packagevariant.

  1. The packagevariant is created successfully and the package is published.
  2. Update the values in the pipeline mutator function of the package variant created in step 1, this triggers the creation of new package from the already published package. --> The failure happens at this step, also one more point to note is that it worked well few times the new packagevariant was getting created in draft when the package variant was editted.

Controller logs:

0c7fbe386b", resources unchanged
I0122 10:11:22.726279       1 packagevariant_controller.go:826] PackageVariant "nrf-india-nif", PackageRevision "downstream-nif-5200b69beade9e7a0ceaa9499cc45e0c7fbe386b", resources unchanged
I0122 10:12:15.184284       1 packagevariant_controller.go:819] PackageVariant "nrf-india-nif", PackageRevision "downstream-nif-5200b69beade9e7a0ceaa9499cc45e0c7fbe386b", resources changed: "Kptfile" different
I0122 10:12:15.184335       1 packagevariant_controller.go:413] package variant "nrf-india-nif" needs to mutate to package revision "downstream-nif-5200b69beade9e7a0ceaa9499cc45e0c7fbe386b", creating new draft
I0122 10:12:15.184350       1 packagevariant_controller.go:637] package variant "nrf-india-nif" is creating package revision ""
E0122 10:12:15.248538       1 packagevariant_controller.go:417] package variant "nrf-india-nif" failed to copy "downstream-nif-5200b69beade9e7a0ceaa9499cc45e0c7fbe386b": Internal error occurred: error applying patch: conflict: fragment line does not match src line

Packagerevisionresources output of the published package:

apiVersion: porch.kpt.dev/v1alpha1
kind: PackageRevisionResources
metadata:
  creationTimestamp: "2024-01-22T08:28:37Z"
  name: downstream-nif-5200b69beade9e7a0ceaa9499cc45e0c7fbe386b
  namespace: nrf
  resourceVersion: 396729c2ab1bf82a503a58c71cb825b9347b08a4
  uid: uid:nrf-india:packagevariant-1
spec:
  packageName: nrf-india
  repository: downstream-nif
  resources:
    Kptfile: |
      apiVersion: kpt.dev/v1
      kind: Kptfile
      metadata: # kpt-merge: /nrf-india
        name: nrf-india
        annotations:
          config.kubernetes.io/local-config: "true"
          internal.kpt.dev/upstream-identifier: 'kpt.dev|Kptfile|default|nrf-india'
      upstream:
        type: git
        git:
          repo: https://gitlab.tech.orange/asc/rom-nif.git
          directory: nrf
          ref: nrf/upstream
      upstreamLock:
        type: git
        git:
          repo: https://gitlab.tech.orange/asc/rom-nif.git
          directory: nrf
          ref: nrf/upstream
          commit: 46c69c01313f32530b8b9ea54f0b3514e59781bf
      info:
        readinessGates:
        - conditionType: config.injection.ConfigMap.nrf-overrides-values
        description: sample description
      pipeline:
        mutators:
        - name: PackageVariant.nrf-india-nif..0
          image: docker.io/uemk/replace-by-paths:v0.1.0
          configMap:
            spec.chart.spec.version: 0.2.7
            spec.kubeConfig.secretRef.name: free5gc-cluster
            spec.targetNamespace: nrf
          selectors:
          - kind: HelmRelease
        - name: PackageVariant.nrf-india-nif..1
          image: docker.io/uemk/replace-by-paths:v0.1.0
          configMap:
            metadata.name: nrf
            spec.url: https://raw.githubusercontent.com/Orange-OpenSource/towards5gs-helm/main/repo/
          selectors:
          - kind: HelmRepository
      status:
        conditions:
        - type: config.injection.ConfigMap.nrf-overrides-values
          status: "True"
          message: injected resource "nrf-overrides" from cluster
          reason: ConfigInjected
    README.md: |
      # nrf

      ## Description
      sample description

      ## Usage

      ### Fetch the package
      `kpt pkg get REPO_URI[.git]/PKG_PATH[@VERSION] nrf`
      Details: https://kpt.dev/reference/cli/pkg/get/

      ### View package content
      `kpt pkg tree nrf`
      Details: https://kpt.dev/reference/cli/pkg/tree/

      ### Apply the package
      ```
      kpt live init nrf
      kpt live apply nrf --reconcile-timeout=2m --output=table
      ```
      Details: https://kpt.dev/reference/cli/live/
    base/namespace.yaml: |
      apiVersion: v1
      kind: Namespace
      metadata: # kpt-merge: /nrf
        name: nrf
        annotations:
          internal.kpt.dev/upstream-identifier: '|Namespace|default|nrf'
    kustomization.yml: |
      apiVersion: kustomize.config.k8s.io/v1beta1
      kind: Kustomization
      resources:
      - ./base/namespace.yaml
      - nrf-overrides-cm.yaml
      - nrf-helmrepository.yml
      - nrf-release.yaml
    nrf-helmrepository.yml: |
      apiVersion: source.toolkit.fluxcd.io/v1beta2
      kind: HelmRepository
      metadata: # kpt-merge: nrf/nrf-test
        name: nrf
        namespace: nrf
        annotations:
          internal.kpt.dev/upstream-identifier: 'source.toolkit.fluxcd.io|HelmRepository|nrf|nrf-test'
      spec:
        interval: 1m0s
        url: https://raw.githubusercontent.com/Orange-OpenSource/towards5gs-helm/main/repo/
    nrf-overrides-cm.yaml: |
      apiVersion: v1
      kind: ConfigMap
      metadata: # kpt-merge: nrf/nrf-overrides-values
        name: nrf-overrides-values
        namespace: nrf
        annotations:
          kpt.dev/config-injection: required
          internal.kpt.dev/upstream-identifier: '|ConfigMap|nrf|nrf-overrides-values'
          kpt.dev/injected-resource: nrf-overrides
      data:
        nrf-values.yaml: |
          nrf:
            readinessProbe:
              initialDelaySeconds: 0
              periodSeconds: 1
              timeoutSeconds: 1
              failureThreshold: 100
              successThreshold: 1
            image:
              tag: latest
              pullpolicy: IfNotPresent
            resources:
              requests:
    nrf-release.yaml: |
      apiVersion: helm.toolkit.fluxcd.io/v2beta1
      kind: HelmRelease
      metadata: # kpt-merge: nrf/nrf
        name: nrf
        namespace: nrf
        annotations:
          internal.kpt.dev/upstream-identifier: 'helm.toolkit.fluxcd.io|HelmRelease|nrf|nrf'
      spec:
        chart:
          spec:
            chart: free5gc-nrf
            interval: 5m
            sourceRef:
              kind: HelmRepository
              name: nrf
              namespace: nrf
            version: 0.2.7
        kubeConfig:
          secretRef:
            name: free5gc-cluster
        install:
          createNamespace: true
          crds: CreateReplace
          remediation:
            retries: 1
        interval: 5m
        storageNamespace: nrf
        targetNamespace: nrf
        upgrade:
          crds: CreateReplace
          remediation:
            retries: 1
        valuesFrom:
        - kind: ConfigMap
          name: nrf-overrides-values
          valuesKey: nrf-values.yaml
          optional: true
    package-context.yaml: |
      apiVersion: v1
      kind: ConfigMap
      metadata: # kpt-merge: /kptfile.kpt.dev
        name: kptfile.kpt.dev
        annotations:
          config.kubernetes.io/local-config: "true"
          internal.kpt.dev/upstream-identifier: '|ConfigMap|default|kptfile.kpt.dev'
      data:
        name: nrf-india
        package-path: nrf-india
  revision: v1
  workspaceName: packagevariant-1
status:
  renderStatus:
    error: ""
    result:
      exitCode: 0
      metadata:
        creationTimestamp: null

@johnbelamaric
Copy link
Member Author

Thanks. So, yes, definitely a bug, and I don't know of a workaround.

This error comes from here:

https://github.com/nephio-project/porch/blob/main/pkg/engine/patchgen.go#L118

which in turn is getting it from:

https://github.com/bluekeyes/go-gitdiff/blob/master/gitdiff/apply_text.go#L130

So, my suspicion is that patchgen.go is producing an invalid patch somehow. It may be there is a simple fix in there somewhere; or perhaps we are using an older version of that library and an update would help. I am not sure.

Now, in #450 I describe eliminating the "tasks" code. This would make this bug obsolete. Right now, I suspect "clone" is replaying all the tasks - I think that's where patchgen.go comes in. If we stopped doing that, and simply copied the package as-is, this would be a lot simpler and the problem would go away.

@liamfallon liamfallon added the area/porch Porch related issues label Mar 26, 2024
@liamfallon
Copy link
Member

Same root cause as #604

@liamfallon liamfallon added the bug Something isn't working label May 17, 2024
@liamfallon
Copy link
Member

Triaged
Triage Comment: To do with tasks in Porch, could be difficult to fix

@liamfallon liamfallon added this to the R3 milestone May 17, 2024
@liamfallon
Copy link
Member

Closed #604 as it is a duplicate of this.

Original issue URL: kptdev/kpt#3694
Original issue user: https://github.com/johnbelamaric
Original issue created at: 2022-12-14T21:37:36Z
Original issue last updated at: 2022-12-14T21:41:23Z
Original issue body: ### Expected behavior
rpkg edit creates a new draft package

Actual behavior

ubuntu@nephio-poc-004:~$ kpt --kubeconfig ~/.kube/nephio.config alpha rpkg edit edge-1-03644cdb5e035f49d209641a1763704042546aa2 -n default --workspace v3
Error: Internal error occurred: error applying patch: conflict: fragment line does not match src line 
ubuntu@nephio-poc-004:~$ kpt --kubeconfig ~/.kube/nephio.config alpha rpkg edit edge-1-03644cdb5e035f49d209641a1763704042546aa2 -n default 
Error: --workspace is required to specify downstream workspaceName 
ubuntu@nephio-poc-004:~$

Information

ubuntu@nephio-poc-004:~$ kpt --kubeconfig ~/.kube/nephio.config alpha rpkg list
NAME                                                        PACKAGE                  WORKSPACENAME         REVISION   LATEST   LIFECYCLE   REPOSITORY
...snipped...
edge-1-03644cdb5e035f49d209641a1763704042546aa2             free5gc-operator         packagedeployment-1   v1         true     Published   edge-1
...snipped...
ubuntu@nephio-poc-004:~$ 

Note that this revision v1 from repo https://github.com/nephio-test/nephio-poc-004-edge-1

Steps to reproduce the behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/platform area/porch Porch related issues bug Something isn't working triaged
Projects
Status: No status
Development

No branches or pull requests

4 participants