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

Only add deploy key when needed #1334

Merged
merged 16 commits into from Feb 1, 2022
Merged

Only add deploy key when needed #1334

merged 16 commits into from Feb 1, 2022

Conversation

J-Thompson12
Copy link
Contributor

@J-Thompson12 J-Thompson12 commented Jan 21, 2022

Closes: #1323

What changed?
Refactored deploy key code and removed quick fix. This adds a deploy key on install for a config repo and then on add it only adds a deploy key if the repo is private.

Why?

How did you test it?
Manually and current tests cover it

Release notes

Documentation Changes

@J-Thompson12 J-Thompson12 added bug Something isn't working exclude from release notes and removed bug Something isn't working labels Jan 21, 2022
case isExternalConfig:
providerUrl = params.ConfigRepo
default:
return nil, nil, nil
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not really sure when we will ever hit this default option. I believe with the new directory structure we will always have a config-repo. I also deleted the two tests associated with this.

@J-Thompson12 J-Thompson12 marked this pull request as ready for review January 24, 2022 22:58
Copy link
Contributor

@jpellizzari jpellizzari left a comment

Choose a reason for hiding this comment

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

One question:

pkg/services/factory.go Outdated Show resolved Hide resolved
configRepoClient, configRepoErr := authSvc.CreateGitClient(ctx, normalizedConfigRepo, targetName, params.Namespace, params.DryRun)
if configRepoErr != nil {
return nil, nil, configRepoErr
if *repoVisibility == gitprovider.RepositoryVisibilityPrivate {
Copy link
Contributor

Choose a reason for hiding this comment

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

A comment here about why we are doing this would be helpful. I try to leave comments wherever a non-obvious if statement appears.

Copy link
Contributor

Choose a reason for hiding this comment

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

@J-Thompson12 Can you elaborate on your comment? Why only for a private repo? If I read the code, I can see what is happening; I don't need a comment to tell me that.

Write a message to the next person who is going to wonder why this is the way it is.

pkg/services/factory.go Show resolved Hide resolved
return nil, nil, nil
// This is temporary. When config repo is always present in the config map this can be removed.
if params.ConfigRepo == "" && !params.IsHelmRepository {
params.ConfigRepo = params.URL
Copy link
Contributor

Choose a reason for hiding this comment

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

At this point we might want to get rid of the field ConfigRepo and just leave URL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is only in the case someone has the same config repo as the app they are adding. So running gitops add app . would hit this.

Namespace: params.Namespace,
}

_, err = authSvc.SetupDeployKey(ctx, secretName, targetName, normalizedUrl)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just so I understand it, this was split out from the other func and is called discretely now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes thats exactly what is happening now.

configRepoClient, configRepoErr := authSvc.CreateGitClient(ctx, normalizedConfigRepo, targetName, params.Namespace, params.DryRun)
if configRepoErr != nil {
return nil, nil, configRepoErr
if *repoVisibility == gitprovider.RepositoryVisibilityPrivate {
Copy link
Contributor

Choose a reason for hiding this comment

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

@J-Thompson12 Can you elaborate on your comment? Why only for a private repo? If I read the code, I can see what is happening; I don't need a comment to tell me that.

Write a message to the next person who is going to wonder why this is the way it is.

Copy link
Contributor

@luizbafilho luizbafilho 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 addressing other folks comments

@J-Thompson12 J-Thompson12 merged commit 48bff5f into main Feb 1, 2022
@J-Thompson12 J-Thompson12 deleted the fix-deploy-key branch February 11, 2022 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add deploy key only when needed
4 participants