argoproj / applicationset

The ApplicationSet controller manages multiple Argo CD Applications as a single ApplicationSet unit, supporting deployments to large numbers of clusters, deployments of large monorepos, and enabling secure Application self-service.
https://argocd-applicationset.readthedocs.io/
Apache License 2.0
584 stars 278 forks source link

scmProvider for gitlab should export a Normalized version of the organization value #640

Closed prune998 closed 1 year ago

prune998 commented 1 year ago

In Gitlab it is possible to use sub-folders for organizations, like /orgA/teamB/projectC.

In that cas you would git clone git@gitlab.server/orgA/teamB/projectC.git

When using An AppSet searching for all matching repos under the orgA, the returned organization contains / like orgA/teamB.

Here's a sample Appset:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  annotations:
  labels:
  name: org-a
  namespace: argocd
spec:
  generators:
  - matrix:
      generators:
      - clusters:
          selector:
            matchLabels:
              argocd.argoproj.io/secret-type: cluster
              environment: qa
          values:
            environment: qa
      - scmProvider:
          cloneProtocol: https
          filters:
          - branchMatch: deployment
            pathsExist:
            - deployments/argocd/qa.yaml
          gitlab:
            allBranches: false
            api: https://gitlab.server.net/
            group: "orga"
            includeSubgroups: true
            tokenRef:
              key: token
              secretName: my-gitlab-token
  template:
    metadata:
      name: '{{ organization }}-{{ repository }}-{{ nameNormalized }}'
    spec:
      destination:
        namespace: orga
        server: '{{server}}'
...

Here the template name will be orgaA/teamB-projectC-cluster_name, which is not a valid name.

Appset Controler does log an error:

applicationset-controller 
time="2023-07-27T20:15:35Z" 
level=error 
msg="failed to unchanged Application" 
action=unchanged 
app=orgaA/teamB-projectC-cluster_name 
appSet=orga 
error="Application.argoproj.io \"orgaA/teamB-projectC-cluster_name\" is invalid: 
  metadata.name: Invalid 
  value: \"orgaA/teamB-projectC-cluster_name\": 
      a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')"

I'm trying to dig in the code, but help will be much appreciated. For example, the cluster name provided by the clusters generator does provide a normalized version of the name as nameNormalized

jessebot commented 1 year ago

@prune998 this code base has moved to https://github.com/argoproj/argo-cd/tree/master/applicationset :) This repo needs to be publically archived.

prune998 commented 1 year ago

yeah I moved the PR :)