q-shift / qshift-templates

Backstage templates for the Qshift demo
Apache License 2.0
1 stars 3 forks source link

argocd action Error: Duplicate project detected. Cannot overwrite existing #7

Open cmoulliard opened 5 months ago

cmoulliard commented 5 months ago

Issue

When we replay the scaffolding using the template of the PR #5 then process fails

792024-02-09T11:37:40.000Z Finished step Generating GitOps Resources
802024-02-09T11:37:40.000Z Beginning step Publishing to Code Source Repository - Github
812024-02-09T11:37:41.000Z info: Init git repository {dir=/var/folders/28/g86pgjxj0wl1nkd_85c2krjw0000gn/T/f3344935-b1b0-4e02-8359-ad5c6dfeaf38}
822024-02-09T11:37:41.000Z info: Adding file {dir=/var/folders/28/g86pgjxj0wl1nkd_85c2krjw0000gn/T/f3344935-b1b0-4e02-8359-ad5c6dfeaf38,filepath=.}
832024-02-09T11:37:41.000Z info: Committing file to repo {dir=/var/folders/28/g86pgjxj0wl1nkd_85c2krjw0000gn/T/f3344935-b1b0-4e02-8359-ad5c6dfeaf38,message=initial commit}
842024-02-09T11:37:41.000Z info: Creating new remote {dir=/var/folders/28/g86pgjxj0wl1nkd_85c2krjw0000gn/T/f3344935-b1b0-4e02-8359-ad5c6dfeaf38,remote=origin,url=https://github.com/ch007m/my-quarkus-app.git}
852024-02-09T11:37:41.000Z info: Pushing directory to remote {dir=/var/folders/28/g86pgjxj0wl1nkd_85c2krjw0000gn/T/f3344935-b1b0-4e02-8359-ad5c6dfeaf38,remote=origin}
862024-02-09T11:37:42.000Z Finished step Publishing to Code Source Repository - Github
...
882024-02-09T11:29:00.000Z Error: Duplicate project detected. Cannot overwrite existing.89    at 
ArgoService.createArgoProject (/Users/cmoullia/code/openshift/fork-backstage-playground/node_modules/@roadiehq/backstage-plugin-argo-cd-backend/src/service/argocd.service.ts:264:13)90    at 
process.processTicksAndRejections (node:internal/process/task_queues:95:5)91    at 
ArgoService.createArgoResources (/Users/cmoullia/code/openshift/fork-backstage-playground/node_modules/@roadiehq/backstage-plugin-argo-cd-backend/src/service/argocd.service.ts:686:5)92    at 
Object.handler (/Users/cmoullia/code/openshift/fork-backstage-playground/node_modules/@roadiehq/scaffolder-backend-argocd/src/actions/run/argocd.ts:59:7)93    at 
NunjucksWorkflowRunner.executeStep (/Users/cmoullia/code/openshift/fork-backstage-playground/node_modules/@backstage/plugin-scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts:343:9)94    at 
NunjucksWorkflowRunner.execute (/Users/cmoullia/code/openshift/fork-backstage-playground/node_modules/@backstage/plugin-scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts:431:9)95    at 
TaskWorker.runOneTask (/Users/cmoullia/code/openshift/fork-backstage-playground/node_modules/@backstage/plugin-scaffolder-backend/src/scaffolder/tasks/TaskWorker.ts:145:26)96    at 
async run (/Users/cmoullia/code/openshift/fork-backstage-playground/node_modules/p-queue/dist/index.js:163:29)

Error occurs when the argocd plugin checks if the project already exists

https://github.com/RoadieHQ/roadie-backstage-plugins/blob/f96282c5430fa57f2a1953cf6cc7c66815cdf5ee/plugins/backend/backstage-plugin-argo-cd-backend/src/service/argocd.service.ts#L330-L361
  }: CreateArgoProjectProps): Promise<object> {
    const data = {
      project: this.buildArgoProjectPayload({
        projectName,
        namespace,
        sourceRepo,
        destinationServer,
      }),
    };

    const options: RequestInit = {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Authorization: `Bearer ${argoToken}`,
      },
      body: JSON.stringify(data),
    };
    const resp = await fetch(`${baseUrl}/api/v1/projects`, options);
    const responseData = await resp.json();
    if (resp.status === 403) {
      throw new Error(responseData.message);
    } else if (resp.status === 404) {
      return resp.json();
    } else if (
      JSON.stringify(responseData).includes(
        'existing project spec is different',
      )
    ) {
      throw new Error('Duplicate project detected. Cannot overwrite existing.');
    }
    return responseData;
  }

Screenshot 2024-02-09 at 12 33 08

cmoulliard commented 5 months ago

As this Argocd project my-quarkus-app-bootstrap already exists, then that fails. If we delete it, then the problem is gone.

I'm wondering how such argocd projects have been created as our templates use the default

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: ${{ values.component_id }}-test
  namespace: ${{ values.gitopsNamespace }}
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  project: default