Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ spec:
| username | string | Username used for the repository backed by HTTP basic authentication. | No |
| password | string | Password used for the repository backed by HTTP basic authentication. | No |
| insecure | bool | Whether to skip TLS certificate checks for the repository or not. | No |
| gitRemote | string | Remote address of the Git repository used to clone Helm charts. | No |
| sshKeyFile | string | The path to the private ssh key file used while cloning Helm charts from above Git repository. | No |

## CloudProvider

Expand Down
24 changes: 15 additions & 9 deletions pkg/app/piped/cmd/piped/piped.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,15 @@ func (p *piped) run(ctx context.Context, input cli.Input) (runErr error) {
}

// Add configured Helm chart repositories.
if len(cfg.ChartRepositories) > 0 {
if repos := cfg.HTTPHelmChartRepositories(); len(repos) > 0 {
reg := toolregistry.DefaultRegistry()
if err := chartrepo.Add(ctx, cfg.ChartRepositories, reg, input.Logger); err != nil {
if err := chartrepo.Add(ctx, repos, reg, input.Logger); err != nil {
input.Logger.Error("failed to add configured chart repositories", zap.Error(err))
return err
}
if len(cfg.ChartRepositories) > 0 {
if err := chartrepo.Update(ctx, reg, input.Logger); err != nil {
input.Logger.Error("failed to update Helm chart repositories", zap.Error(err))
return err
}
if err := chartrepo.Update(ctx, reg, input.Logger); err != nil {
input.Logger.Error("failed to update Helm chart repositories", zap.Error(err))
return err
}
}

Expand Down Expand Up @@ -229,11 +227,19 @@ func (p *piped) run(ctx context.Context, input cli.Input) (runErr error) {
}

// Initialize git client.
gitClient, err := git.NewClient(
gitOptions := []git.Option{
git.WithUserName(cfg.Git.Username),
git.WithEmail(cfg.Git.Email),
git.WithLogger(input.Logger),
)
}
for _, repo := range cfg.GitHelmChartRepositories() {
if f := repo.SSHKeyFile; f != "" {
// Configure git client to use the specified SSH key while fetching private Helm charts.
env := fmt.Sprintf("GIT_SSH_COMMAND=ssh -i %s -o StrictHostKeyChecking=no -F /dev/null", f)
gitOptions = append(gitOptions, git.WithGitEnvForRepo(repo.GitRemote, env))
}
}
gitClient, err := git.NewClient(gitOptions...)
if err != nil {
input.Logger.Error("failed to initialize git client", zap.Error(err))
return err
Expand Down
58 changes: 58 additions & 0 deletions pkg/config/piped.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func (s *PipedSpec) Validate() error {
if s.SyncInterval < 0 {
return errors.New("syncInterval must be greater than or equal to 0")
}
for _, r := range s.ChartRepositories {
if err := r.Validate(); err != nil {
return err
}
}
if s.SecretManagement != nil {
if err := s.SecretManagement.Validate(); err != nil {
return err
Expand Down Expand Up @@ -256,6 +261,59 @@ type HelmChartRepository struct {
Password string `json:"password"`
// Whether to skip TLS certificate checks for the repository or not.
Insecure bool `json:"insecure"`

// Remote address of the Git repository used to clone Helm charts.
// e.g. [email protected]:org/repo.git
GitRemote string `json:"gitRemote"`
// The path to the private ssh key file used while cloning Helm charts from above Git repository.
SSHKeyFile string `json:"sshKeyFile"`
}

func (r *HelmChartRepository) IsHTTPRepository() bool {
return r.Name != "" && r.Address != ""
}

func (r *HelmChartRepository) IsGitRepository() bool {
return r.GitRemote != ""
}

func (r *HelmChartRepository) Validate() error {
if r.IsHTTPRepository() {
if r.Name == "" {
return errors.New("name must be set")
}
if r.Address == "" {
return errors.New("address must be set")
}
}

if r.IsGitRepository() {
if r.GitRemote == "" {
return errors.New("gitRemote must be set")
}
}

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

@khanhtc1202 khanhtc1202 Nov 29, 2021

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.

}

func (s *PipedSpec) HTTPHelmChartRepositories() []HelmChartRepository {
repos := make([]HelmChartRepository, 0, len(s.ChartRepositories))
for _, r := range s.ChartRepositories {
if r.IsHTTPRepository() {
repos = append(repos, r)
}
}
return repos
}

func (s *PipedSpec) GitHelmChartRepositories() []HelmChartRepository {
repos := make([]HelmChartRepository, 0, len(s.ChartRepositories))
for _, r := range s.ChartRepositories {
if r.IsGitRepository() {
repos = append(repos, r)
}
}
return repos
}

type PipedCloudProvider struct {
Expand Down