applicationset icon indicating copy to clipboard operation
applicationset copied to clipboard

[Proposal]: Git Branch generator

Open Segflow opened this issue 3 years ago • 9 comments

We recently started to use Argo CD as a deployment tool. After checking the application set, we believe it's a nice addition to have "Git Branch" generator.

I can work on the implementation myself, and I believe this will be a nice good first contribution. This issue is more to discuss the spec and the behavior (as well as how we should name things).

Similar to file and directory generator, we propose to have branch generator, could looks something like this:

  generators:
  - git:
      repoURL: [email protected]:something/something.git
      revision: "HEAD"
      branches:
      - dev-*
      - feat/*

This generator should yield a param for each branch that matches the glob.

For example, if the repository contains these branches:

  • main
  • dev-test1
  • dev-tes2
  • feat/new_feature

For each branch that matches the glob, the generator should yield these parameters:

  • branch.fullname: The full branch name, e.g dev-test1 and feat/new_feature
  • glob (help with better name): The piece that matches the asterisk, e.g test1 and new_feature

The generator should yield:

{"branch.fullname": "dev-test1", "glob": "test1"}
{"branch.fullname": "dev-test2", "glob": "test2"}
{"branch.fullname": "feat/new_feature", "glob": "new_feature"}

Sanitize branch name

We can also do something similar to cluster generator https://github.com/argoproj-labs/applicationset/pull/237 and just sanitize the branch name and yield it (along with the original name)

{"branch.fullname": "feat/new_feature", "branch.sanitizedName": "feat-new-feature"}

Use case:

This allows developer to create a new Argo CD application by creating a new branch.

Full example

apiVersion: argoproj.io/v1alpha2 # Notice the v1alpha2 ;)
kind: ApplicationSet
metadata:
  name: dev-envs
spec:
  generators:
  - git:
      repoURL: [email protected]:something/something.git
      revision: "HEAD"   # Not really needed for this generator, but it's a required field.
      branches:
      - deploy/product/dev-*
  template:
    metadata:
      name: '{{glob}}'  # We use `glob` instead of `branch.fullname` as the fullname can contain invalid characters
    spec:
      project: myproject
      source:
        repoURL: [email protected]:something/something.git
        targetRevision: '{{branch.fullname}}'
        path: 'charts/product'
        helm:
          valueFiles:
            - values.yaml
      destination:
        server: https://kubernetes.default.svc
        namespace: 'product-{{glob}}'

I would appreciate any feedback on this. I already have a working example as a POC, getting your feedback on the parameter names, what else we can yield is appreciated.

Segflow avatar Aug 29 '21 09:08 Segflow

I think this awesome idea. So this makes applicationset a perfect tool to create/delete preview environments!

alexmt avatar Sep 07 '21 19:09 alexmt

Agree with @alexmt, this sounds very useful.

I think my only suggestions would be:

  • glob -> globMatch (just to make it clear that the user is getting the value that the glob matched)
  • branch.sanitizedName => branch.normalizedName (normalized, as the verb, rather than sanitized. We do use sanitized in the code itself, but I think normalized is probably a bit better here)

jgwest avatar Sep 13 '21 15:09 jgwest

This would be awesome!

benjamink avatar Oct 06 '21 23:10 benjamink

Agree @benjamink! Game changer for our workflow

elocke avatar Oct 16 '21 02:10 elocke

I would also love this!

bobertrublik avatar Nov 03 '21 08:11 bobertrublik

This would be perfect and exactly what I am looking for! Any idea of when this can be available?

jstdips avatar Nov 22 '21 16:11 jstdips

Seems like a dup of #200

OmerKahani avatar Jan 21 '22 11:01 OmerKahani

Could this be achieved by adding a branch name filter to the SCM provider generator? https://github.com/argoproj/applicationset/blob/master/docs/Generators-SCM-Provider.md#filters

crenshaw-dev avatar Jan 21 '22 14:01 crenshaw-dev

@crenshaw-dev yes, but kinda overkill with scanning for all the repos matching repositoryMatch and easy to get rate limited unless #565 which fixes credentials is implemented

iamstarkov avatar Jul 20 '22 15:07 iamstarkov

Hi all! Any news about this one? I assumed that this was implemented already when reading about git generator, and right now it only supports listing directories and files. That would be amazing as it will allow to implement ephemeral environments for feature branches very easily.

yevon avatar Apr 07 '23 08:04 yevon

@crenshaw-dev yes, but kinda overkill with scanning for all the repos matching repositoryMatch and easy to get rate limited unless #565 which fixes credentials is implemented

Looks that this is implemented already!

yevon avatar Apr 07 '23 08:04 yevon

Hi @Segflow, did you close this because you managed to get this working with the SCM provider generator? The git generator allows you to template based on directories within the repo which I don't think the SCM provider does, so I'm curious if you managed to overcome this

JS-Jake avatar Apr 14 '23 09:04 JS-Jake

@JS-Jake I think it's a dup of #200

keithharvey avatar Sep 08 '23 16:09 keithharvey