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

Allow specifying SSH key for the Git repository where to fetch private Helm charts #2863

Merged
merged 6 commits into from
Nov 29, 2021

Conversation

nghialv
Copy link
Member

@nghialv nghialv commented Nov 29, 2021

What this PR does / why we need it:

Basically, the same SSH key should be used for simplicity but users can specify another SSH key for the Git repositories where to fetch private Helm charts.

In that case, the path file of the private SSH key file must be specified in chartRepositories field of Piped configuration.

Which issue(s) this PR fixes:

Fixes #2759

Does this PR introduce a user-facing change?:

Allow specifying SSH key for the Git repository where used to fetch private Helm charts

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.72%. This pull request increases coverage by 0.01%.

File Function Base Head Diff
pkg/config/piped.go HelmChartRepository.IsHTTPRepository -- 100.00% +100.00%
pkg/config/piped.go HelmChartRepository.IsGitRepository -- 100.00% +100.00%
pkg/config/piped.go HelmChartRepository.Validate -- 55.56% +55.56%
pkg/config/piped.go PipedSpec.HTTPHelmChartRepositories -- 0.00% +0.00%
pkg/config/piped.go PipedSpec.GitHelmChartRepositories -- 0.00% +0.00%
pkg/config/piped.go PipedSpec.Validate 57.14% 58.33% +1.19%

pkg/config/piped.go Outdated Show resolved Hide resolved
pkg/config/piped.go Outdated Show resolved Hide resolved
nghialv and others added 2 commits November 29, 2021 16:15
Co-authored-by: Khanh Tran <32532742+khanhtc1202@users.noreply.github.com>
}
}

return errors.New("either HTTP repository or Git repository must be configured")
Copy link
Member

Choose a reason for hiding this comment

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

I think this is not right, since in case both or one of HTTP or GitRemote pattern are provided, the error will be returned too. We may need to add a return after L293 or change the implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Get your point. Fixed it!

Copy link
Member Author

Choose a reason for hiding this comment

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

Or should we add a type field, which should be either HTTP or GIT?

Copy link
Member

Choose a reason for hiding this comment

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

That's nice too 👍
Just want to confirm one point: do we only allow one of those types to be configured, not both at the same time for one chartRepo, right?

Copy link
Member

Choose a reason for hiding this comment

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

In such case, the current implementation is LGTM, may be we don't need to add type to keep the configuration simple 😄

Copy link
Member

Choose a reason for hiding this comment

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

In that case, the validation logic is easier for us but looks like it's not simple for our users. Since to keep support for running applications, we need to make the type field default to HTTP, and if users want to use type Git they have to explicitly specify that value in the configuration. But I don't have a strong opinion on this, just feel like it will be easier for me if I'm going to configure this without the type field.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. Exactly as what you said. But the GIT type is only needed when user wants to specify a different SSH key for that repository, so I guess that won't cause much trouble for the user.
Btw, I added the type field. PTAL.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I guess the type field is a bit tedious as well, I also don't have any strong opinion though.

I see. Just feel weird when seeing this check.

I feel like just adding a comment can make it clear.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, we may add more types value to that field. In that case, adding type field and making type default to HTTP is good for future addition 👍

Copy link
Member

Choose a reason for hiding this comment

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

Alright.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.70%. This pull request decreases coverage by -0.01%.

File Function Base Head Diff
pkg/config/piped.go HelmChartRepository.IsHTTPRepository -- 100.00% +100.00%
pkg/config/piped.go HelmChartRepository.IsGitRepository -- 0.00% +0.00%
pkg/config/piped.go HelmChartRepository.Validate -- 36.36% +36.36%
pkg/config/piped.go PipedSpec.HTTPHelmChartRepositories -- 0.00% +0.00%
pkg/config/piped.go PipedSpec.GitHelmChartRepositories -- 0.00% +0.00%
pkg/config/piped.go PipedSpec.Validate 57.14% 58.33% +1.19%

@pipecd-bot pipecd-bot added size/L and removed size/M labels Nov 29, 2021
@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.70%. This pull request decreases coverage by -0.01%.

File Function Base Head Diff
pkg/config/piped.go HelmChartRepository.IsHTTPRepository -- 100.00% +100.00%
pkg/config/piped.go HelmChartRepository.IsGitRepository -- 0.00% +0.00%
pkg/config/piped.go HelmChartRepository.Validate -- 36.36% +36.36%
pkg/config/piped.go PipedSpec.HTTPHelmChartRepositories -- 0.00% +0.00%
pkg/config/piped.go PipedSpec.GitHelmChartRepositories -- 0.00% +0.00%
pkg/config/piped.go PipedSpec.Validate 57.14% 58.33% +1.19%

}

func (r *HelmChartRepository) IsHTTPRepository() bool {
return r.Type == HTTPHelmChartRepository
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return r.Type == HTTPHelmChartRepository
return strings.ToUpper(r.Type) == HTTPHelmChartRepository

nits, users may insert HTTP, http or Http as well. Or we may need to check for the type field in the validation function at L293.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that we should allow that. Like, KubernetesApp not K8sApp or kubernetesApp.

Copy link
Member

@nakabonne nakabonne Nov 29, 2021

Choose a reason for hiding this comment

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

I also think we should distinguish between lowercase and uppercase.

Copy link
Member

Choose a reason for hiding this comment

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

You're right, in that case, we may need to add validate r.Type to the validate function at line L293, and the current error message (at L311) return Git instead of GIT
https://github.com/pipe-cd/pipe/pull/2863/files#diff-49258a851400c4bc54c40491b440d7edf1dd45eda52c9eccd3f5371af15e8409R311

Copy link
Member

Choose a reason for hiding this comment

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

Yep, that should be:

return fmt.Errorf("either %s repository or %s repository must be configured", HTTPHelmChartRepository, GITHelmChartRepository)

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch!
Fixed it.

@nakabonne
Copy link
Member

Way to go 👍
/lgtm

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.70%. This pull request decreases coverage by -0.01%.

File Function Base Head Diff
pkg/config/piped.go HelmChartRepository.IsHTTPRepository -- 100.00% +100.00%
pkg/config/piped.go HelmChartRepository.IsGitRepository -- 0.00% +0.00%
pkg/config/piped.go HelmChartRepository.Validate -- 36.36% +36.36%
pkg/config/piped.go PipedSpec.HTTPHelmChartRepositories -- 0.00% +0.00%
pkg/config/piped.go PipedSpec.GitHelmChartRepositories -- 0.00% +0.00%
pkg/config/piped.go PipedSpec.Validate 57.14% 58.33% +1.19%

@khanhtc1202
Copy link
Member

Nice work
/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by khanhtc1202.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

@pipecd-bot pipecd-bot merged commit b69a3cb into master Nov 29, 2021
@pipecd-bot pipecd-bot deleted the helm-git branch November 29, 2021 09:12
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.

Allow using another SSH key for the Git repository where used to fetch Helm chart
4 participants