carvel-dev / vendir

Easy way to vendor portions of git repos, github releases, helm charts, docker image contents, etc. declaratively
https://carvel.dev/vendir
Apache License 2.0
269 stars 47 forks source link

fix: Add validation to not fail on same secret #239

Closed odinnordico closed 1 year ago

odinnordico commented 1 year ago

Add validation when getting the secret to not fail if more than two secrets with the same name and same data are provided in the config yaml.

Fixes #238

Test output:

VENDIR_GITHUB_API_TOKEN=ghp_*** ./hack/build.sh && ./hack/test-all.sh

vendir version 0.0.0+develop
+ ./vendir version
vendir version 0.0.0+develop

Succeeded
+ go test --exec=echo ./...
+ echo Success
Success
...
+ echo UNIT SUCCESS
UNIT SUCCESS
...
+ echo E2E SUCCESS
E2E SUCCESS
+ echo ALL SUCCESS
ALL SUCCESS

Local Test:

vendir.yml

apiVersion: vendir.k14s.io/v1alpha1
kind: Config
directories:
- path: "repo"
  contents:
  - path: "1"
    git:
      url: git@github.com:odinnordico/kapp-controller-private-test.git
      secretRef:
          name: ssh-key-secret
      ref: origin/main
    includePaths:
    - cm/**/*
  - path: "2"
    git:
      url: git@github.com:odinnordico/kapp-controller-private-test.git
      secretRef:
          name: ssh-key-secret
      ref: origin/main
    includePaths:
    - secret/**/*
---
apiVersion: v1
data:
  ssh-privatekey: LS---o=
kind: Secret
metadata:
  name: ssh-key-secret
---
apiVersion: v1
data:
  ssh-privatekey: LS...o=
kind: Secret
metadata:
  name: ssh-key-secret
---
apiVersion: v1
data:
  ssh-privatekey: LS...o=
kind: Secret
metadata:
  name: ssh-key-secret

Output

Fetching: repo + 1 (git from git@github.com:odinnordico/kapp-controller-private-test.git@origin/main)

  --> git init
  Initialized empty Git repository in /home/diego/workspace/test/vendir-secrets/.vendir-tmp/incoming/git/.git/
  --> git config credential.helper store --file /home/diego/workspace/test/vendir-secrets/.vendir-tmp/incoming/git-auth/.git-credentials
  --> git remote add origin git@github.com:odinnordico/kapp-controller-private-test.git
  --> git config remote.origin.tagOpt --tags
  --> git fetch origin
  From github.com:odinnordico/kapp-controller-private-test
   * [new branch]      main       -> origin/main
  --> git -c advice.detachedHead=false checkout origin/main
  HEAD is now at f7c4e58 Fix secret
  --> git submodule update --init --recursive
  --> git rev-parse HEAD
  f7c4e58e3e3a1d7b1180e6f8288a76746b1bea8c
  --> git describe --tags f7c4e58e3e3a1d7b1180e6f8288a76746b1bea8c
  fatal: No names found, cannot describe anything.
  --> git log -n 1 --pretty=%B f7c4e58e3e3a1d7b1180e6f8288a76746b1bea8c
  Fix secret

Fetching: repo + 2 (git from git@github.com:odinnordico/kapp-controller-private-test.git@origin/main)

  --> git init
  Initialized empty Git repository in /home/diego/workspace/test/vendir-secrets/.vendir-tmp/incoming/git/.git/
  --> git config credential.helper store --file /home/diego/workspace/test/vendir-secrets/.vendir-tmp/incoming/git-auth/.git-credentials
  --> git remote add origin git@github.com:odinnordico/kapp-controller-private-test.git
  --> git config remote.origin.tagOpt --tags
  --> git fetch origin
  From github.com:odinnordico/kapp-controller-private-test
   * [new branch]      main       -> origin/main
  --> git -c advice.detachedHead=false checkout origin/main
  HEAD is now at f7c4e58 Fix secret
  --> git submodule update --init --recursive
  --> git rev-parse HEAD
  f7c4e58e3e3a1d7b1180e6f8288a76746b1bea8c
  --> git describe --tags f7c4e58e3e3a1d7b1180e6f8288a76746b1bea8c
  fatal: No names found, cannot describe anything.
  --> git log -n 1 --pretty=%B f7c4e58e3e3a1d7b1180e6f8288a76746b1bea8c
  Fix secret

Lock config

apiVersion: vendir.k14s.io/v1alpha1
directories:
- contents:
  - git:
      commitTitle: Fix secret
      sha: f7c4e58e3e3a1d7b1180e6f8288a76746b1bea8c
    path: "1"
  - git:
      commitTitle: Fix secret
      sha: f7c4e58e3e3a1d7b1180e6f8288a76746b1bea8c
    path: "2"
  path: repo
kind: LockConfig

Succeeded

Tree

tree .                                                                                                                
.
├── repo
│   ├── 1
│   │   └── cm
│   │       └── cm.yaml
│   └── 2
│       └── secret
│           └── secret.yaml
├── vendir.lock.yml
└── vendir.yml

6 directories, 4 files

Additional Notes