Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Support retrieving modules in private git repo through SSH #349

Merged
merged 15 commits into from Dec 9, 2022

Conversation

motilayo
Copy link
Contributor

@motilayo motilayo commented Nov 14, 2022

This is a PR to Support SSH for retrieving terraform modules in private git repo for this issue: #292
There is a corresponding PR in kubevela repo: kubevela/kubevela#5059

This change require a secret which hold the SSH private key and known hosts for the git repo:
known_hosts can be generated using ssh-keyscan <git-url>

apiVersion: v1
kind: Secret
metadata:
  name: git-ssh
  namespace: vela-system
type: kubernetes.io/ssh-auth
stringData:
  ssh-privatekey: |
   <SSH Private Key> # the ssh private key used for authenticating git
  known_hosts: |
   <SSH known_hosts>  # use `ssh-keyscan github.com`  to generate known_hosts

Signed-off-by: motilayo <joshuaagboola@live.ca>
Signed-off-by: motilayo <joshuaagboola@live.ca>
Signed-off-by: motilayo <joshuaagboola@live.ca>
Signed-off-by: motilayo <joshuaagboola@live.ca>
Signed-off-by: motilayo <joshuaagboola@live.ca>
@codecov
Copy link

codecov bot commented Nov 16, 2022

Codecov Report

Base: 79.31% // Head: 79.19% // Decreases project coverage by -0.12% ⚠️

Coverage data is based on head (7e1eeb5) compared to base (3a96f68).
Patch coverage: 76.47% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #349      +/-   ##
==========================================
- Coverage   79.31%   79.19%   -0.13%     
==========================================
  Files          23       23              
  Lines        1750     1807      +57     
==========================================
+ Hits         1388     1431      +43     
- Misses        278      290      +12     
- Partials       84       86       +2     
Flag Coverage Δ
e2e ?
unit 79.19% <76.47%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
controllers/configuration_controller.go 77.24% <76.47%> (-0.12%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@chivalryq
Copy link
Member

chivalryq commented Nov 16, 2022

Let's add some e2e test. Maybe this repo will helps: https://github.com/isomorphic-git/git-http-mock-server
Also please fix the CI.

Signed-off-by: motilayo <joshuaagboola@live.ca>
Signed-off-by: motilayo <joshuaagboola@live.ca>
@motilayo motilayo force-pushed the master branch 2 times, most recently from f0e4d98 to 724a8a6 Compare November 27, 2022 22:57
…e-comments' & 'exported' lint errors

Signed-off-by: motilayo <joshuaagboola@live.ca>
@motilayo motilayo force-pushed the master branch 10 times, most recently from b93f19a to e64a353 Compare November 28, 2022 18:37
@motilayo motilayo force-pushed the master branch 6 times, most recently from 1f2bae3 to aacbae4 Compare November 29, 2022 13:13
Signed-off-by: motilayo <joshuaagboola@live.ca>
@motilayo
Copy link
Contributor Author

Let's add some e2e test. Maybe this repo will helps: https://github.com/isomorphic-git/git-http-mock-server Also please fix the CI.

Couldn't get https://github.com/isomorphic-git/git-http-mock-server to work. Looked into different options, did not find anything lightweight to use. Decided to go with creating a private git server in a pod, with a terraform module repo in that git.
e2e test output:

❯ go test -v ./e2e/normal/... -run TestGitCredentialsSecretReference
=== RUN   TestGitCredentialsSecretReference
I1129 12:05:53.773202    6759 configuration_test.go:71] random-e2e-git-creds-secret-ref test begins……
I1129 12:05:53.774256    6759 configuration_test.go:94] 1. Applying Configuration
I1129 12:05:53.925994    6759 configuration_test.go:311] - Checking git-server pod status
I1129 12:05:53.937536    6759 configuration_test.go:319] - pod=git-server Ready=True
I1129 12:05:54.467514    6759 configuration_test.go:102] 2. Checking Configuration status
I1129 12:06:40.326000    6759 configuration_test.go:125] 3. Checking the status of Configs and Secrets
I1129 12:06:40.326021    6759 configuration_test.go:127] - Checking ConfigMap which stores .tf
I1129 12:06:40.328671    6759 configuration_test.go:132] - Checking Secret which stores Backend
I1129 12:06:40.331256    6759 configuration_test.go:137] - Checking Secret which stores outputs
I1129 12:06:40.333018    6759 configuration_test.go:141] - Checking Secret which stores variables
I1129 12:06:40.334731    6759 configuration_test.go:145] 4. Deleting Configuration
I1129 12:06:40.336358    6759 configuration_test.go:150] 5. Checking Configuration is deleted
I1129 12:06:55.744077    6759 configuration_test.go:182] 6. Checking Secrets and ConfigMap which should all be deleted
I1129 12:06:55.749020    6759 configuration_test.go:198] random-e2e-git-creds-secret-ref test ends……
--- PASS: TestGitCredentialsSecretReference (62.08s)
PASS

.golangci.yml Show resolved Hide resolved
controllers/configuration_controller.go Outdated Show resolved Hide resolved
e2e/normal/configuration_test.go Outdated Show resolved Hide resolved
examples/git-credentials/git-ssh-auth-secret.yaml Outdated Show resolved Hide resolved
examples/git-credentials/git-push-job.yaml Show resolved Hide resolved
examples/git-credentials/ssh-keys-secret.yaml Show resolved Hide resolved
@chivalryq
Copy link
Member

@motilayo You did a very great job! The test methods is impressive. And can you explain some of the files which is not used in test?
Don't worry about the code coverage CI item. It seems not to calculate the e2e test correctly.

… for configuration state

Signed-off-by: motilayo <joshuaagboola@live.ca>
@motilayo
Copy link
Contributor Author

motilayo commented Dec 2, 2022

Those files in examples/git-credentials are prereqs for support git ssh credentials test. The git-server which requires ssh auth for git push & pull. The git-push job which will push the terraform module to a repo on the git server pod, the secret with the ssh public key & private key. The public key is added to authorized_keys file on the git server, the private key is added to the git-push for the initial repo push. Then a generated secret which holds the private key & known_hosts - this secret is mounted to the terraform apply/destroy job so that it can pull the terraform module from a private repo.
Best effort to keep everything self contained for e2e test.

Signed-off-by: motilayo <joshuaagboola@live.ca>
Signed-off-by: motilayo <joshuaagboola@live.ca>
…ls secret has issue

Signed-off-by: motilayo <joshuaagboola@live.ca>
Signed-off-by: motilayo <joshuaagboola@live.ca>
@motilayo
Copy link
Contributor Author

motilayo commented Dec 7, 2022

Hi @chivalryq & @wonderflow , hoping for a review. I've made the suggested changes and added some tests. Let me know if there's any pending tasks for me to do.
Thanks!

Copy link
Member

@chivalryq chivalryq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after some code cleanup

.github/workflows/e2e-test.yml Outdated Show resolved Hide resolved
controllers/configuration_controller.go Outdated Show resolved Hide resolved
controllers/configuration_controller_test.go Outdated Show resolved Hide resolved
Signed-off-by: motilayo <joshuaagboola@live.ca>
@chivalryq chivalryq changed the title Feat: Support SSH for retrieving terraform modules in private git repo Feat: Support retrieving modules in private git repo through SSH Dec 9, 2022
@chivalryq chivalryq merged commit 841b0d1 into kubevela:master Dec 9, 2022
@chivalryq
Copy link
Member

chivalryq commented Dec 9, 2022

@motilayo Great Job! You can fix the conflicts within PR in vela's repo and we try to merge it into master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants