akuity / kargo

Application lifecycle orchestration
https://kargo.akuity.io/
Apache License 2.0
1.59k stars 137 forks source link

Gitlab merge request are broken #2763

Open koushyk opened 3 days ago

koushyk commented 3 days ago

Checklist

Description

When promoting a fright to stage which has merge request creation enabled I'm getting an error

error executing Git-based promotion mechanisms: error executing Kargo Render promotion mechanism: error preparing PR branch "https://<gitlab_url>/deploy/service.git": error checking out branch "master\n" from repo "https://<gitlab_url>//deploy/service.git": error executing cmd [/usr/bin/git checkout master --]: fatal: invalid reference: master

but for stages without merge request features promotions are working as they should.

Screenshots

Снимок экрана 2024-10-17 в 15 51 06

Steps to Reproduce

  1. Create a warehouse with helm and image in different repositories.
  2. Create stage
    kind: Warehouse
    spec:
    freightCreationPolicy: Automatic
    interval: 5m0s
    subscriptions:
    - git:
        branch: master
        commitSelectionStrategy: NewestFromBranch
        discoveryLimit: 20
        includePaths:
          - service
        repoURL: https://<gitlab_url>/service.git
        strictSemvers: true
    - image:
        allowTags: ^[^sha256].*$
        discoveryLimit: 20
        gitRepoURL: https://<gitlab_url>/service.git
        imageSelectionStrategy: NewestBuild
        repoURL: <registry_url>/service
        strictSemvers: true
    ---
    apiVersion: kargo.akuity.io/v1alpha1
    kind: Stage
    metadata:
    name: <stage-name>
    spec:
    promotionMechanisms:
    argoCDAppUpdates:
      - appName: <argocd_app_name>
    gitRepoUpdates:
      - render: {}
        repoURL: https://<gitlab_url>/service.git
        writeBranch: env/<env-name>/<service-name>
    requestedFreight:
    - origin:
        kind: Warehouse
        name: <service-name>-wh
      sources:
        direct: true
    shard: stage
    ---
    apiVersion: kargo.akuity.io/v1alpha1 
    kind: Stage
    metadata:
    name: <stage-name>
    spec:
    promotionMechanisms:
    gitRepoUpdates:
      - render: {}
        repoURL: https://<gitlab_url>/deploy/service.git
        writeBranch: env/<env>/<service-name>
        pullRequest:
          gitlab: {}
    requestedFreight:
    - origin:
        kind: Warehouse
        name: <service-name>-wh
      sources:
        stages:
          - <stage-name>
  3. Promote fright

Version

{
  "Version": "v0.9.1",
  "BuildDate": "2024-10-11T04:59:22Z",
  "GitCommit": "a1a43b7c59780e726b6438fd41cc74597dd442b6",
  "GitTreeDirty": false,
  "GoVersion": "go1.23.2",
  "Compiler": "gc",
  "Platform": "linux/amd64"
}

Logs

Paste any relevant application logs here.
krancour commented 3 days ago

@koushyk is <gitlab_url> on gitlab.com or self-hosted GitLab?

koushyk commented 3 days ago

@krancour self-hosted

krancour commented 2 days ago

I'm perplexed by why it's attempting to checkout master in the first place.

It has reason to check out a specific commit from master as well as the env/<env>/<service-name> branch you intend to write to, but no reason that I can spot that master should be checked out here.

Would you possibly be able to enable debug logging and see if there's any useful details about what exactly it was doing leading up to this?

Edit: These legacy promotion mechanisms were deprecated in v0.9.0 and will be fully removed in v1.0.0. I suspect the issue here isn't with the gitlab bits, but with the more general git bits preceding the opening of an MR. It would also be interesting to see if the equivalent workflow using a promotion template is prone to the same issue or not.

koushyk commented 2 days ago

I've updated manifests to promotion templates and merge requests are creating fine, so I have to switch to promotion templates anyway.

krancour commented 2 days ago

Thank you for doing that. It's a good data point. While we're not investing in further development of the old promotion mechanisms, we still plan to fix bugs in them for some time so that we can extend the life of v0.9.x while people make the transition to the promotion templates. This has really helped to narrow down where I need to be looking. Thanks again.