Skip to content

Commit 4f77b16

Browse files
author
nikimanoledaki
committed
Address Add Profile review comments part 2
1 parent 842aa64 commit 4f77b16

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

pkg/services/profiles/add.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ type AddOptions struct {
3535
// Add installs an available profile in a cluster's namespace by appending a HelmRelease to the profile manifest in the config repo,
3636
// provided that such a HelmRelease does not exist with the same profile name and version in the same namespace and cluster.
3737
func (s *ProfilesSvc) Add(ctx context.Context, gitProvider gitproviders.GitProvider, opts AddOptions) error {
38-
configRepoUrl, err := gitproviders.NewRepoURL(opts.ConfigRepo)
38+
configRepoURL, err := gitproviders.NewRepoURL(opts.ConfigRepo)
3939
if err != nil {
4040
return fmt.Errorf("failed to parse url: %w", err)
4141
}
4242

43-
repoExists, err := gitProvider.RepositoryExists(ctx, configRepoUrl)
43+
repoExists, err := gitProvider.RepositoryExists(ctx, configRepoURL)
4444
if err != nil {
4545
return fmt.Errorf("failed to check whether repository exists: %w", err)
4646
} else if !repoExists {
47-
return fmt.Errorf("repository '%v' could not be found", configRepoUrl.String())
47+
return fmt.Errorf("repository %q could not be found", configRepoURL)
4848
}
4949

50-
defaultBranch, err := gitProvider.GetDefaultBranch(ctx, configRepoUrl)
50+
defaultBranch, err := gitProvider.GetDefaultBranch(ctx, configRepoURL)
5151
if err != nil {
5252
return fmt.Errorf("failed to get default branch: %w", err)
5353
}
@@ -74,17 +74,17 @@ func (s *ProfilesSvc) Add(ctx context.Context, gitProvider gitproviders.GitProvi
7474

7575
newRelease := helm.MakeHelmRelease(opts.Name, version, opts.Cluster, opts.Namespace, helmRepo)
7676

77-
files, err := gitProvider.GetRepoDirFiles(ctx, configRepoUrl, git.GetSystemPath(opts.Cluster), defaultBranch)
77+
files, err := gitProvider.GetRepoDirFiles(ctx, configRepoURL, git.GetSystemPath(opts.Cluster), defaultBranch)
7878
if err != nil {
79-
return fmt.Errorf("failed to get files in '%s' for config repository '%s': %s", git.GetSystemPath(opts.Cluster), configRepoUrl.String(), err)
79+
return fmt.Errorf("failed to get files in '%s' for config repository %q: %s", git.GetSystemPath(opts.Cluster), configRepoURL, err)
8080
}
8181

8282
file, err := AppendProfileToFile(files, newRelease, git.GetProfilesPath(opts.Cluster, models.WegoProfilesPath))
8383
if err != nil {
8484
return fmt.Errorf("failed to append HelmRelease to profiles file: %w", err)
8585
}
8686

87-
pr, err := gitProvider.CreatePullRequest(ctx, configRepoUrl, gitproviders.PullRequestInfo{
87+
pr, err := gitProvider.CreatePullRequest(ctx, configRepoURL, gitproviders.PullRequestInfo{
8888
Title: fmt.Sprintf("GitOps add %s", opts.Name),
8989
Description: fmt.Sprintf("Add manifest for %s profile", opts.Name),
9090
CommitMessage: AddCommitMessage,
@@ -101,7 +101,7 @@ func (s *ProfilesSvc) Add(ctx context.Context, gitProvider gitproviders.GitProvi
101101
if opts.AutoMerge {
102102
s.Logger.Actionf("auto-merge=true; merging PR number %v", pr.Get().Number)
103103

104-
if err := gitProvider.MergePullRequest(ctx, configRepoUrl, pr.Get().Number, AddCommitMessage); err != nil {
104+
if err := gitProvider.MergePullRequest(ctx, configRepoURL, pr.Get().Number, AddCommitMessage); err != nil {
105105
return fmt.Errorf("error auto-merging PR: %w", err)
106106
}
107107
}
@@ -146,6 +146,7 @@ func AppendProfileToFile(files []*gitprovider.CommitFile, newRelease *v2beta1.He
146146
}
147147

148148
content = *f.Content
149+
break
149150
}
150151
}
151152

pkg/services/profiles/add_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ var _ = Describe("Add", func() {
178178
It("fails if the config repo does not exist", func() {
179179
gitProviders.RepositoryExistsReturns(false, nil)
180180
err := profilesSvc.Add(context.TODO(), gitProviders, addOptions)
181-
Expect(err).To(MatchError("repository 'ssh://[email protected]/owner/config-repo.git' could not be found"))
181+
Expect(err).To(MatchError("repository \"ssh://[email protected]/owner/config-repo.git\" could not be found"))
182182
Expect(gitProviders.RepositoryExistsCallCount()).To(Equal(1))
183183
})
184184
})

tools/testcrds/helm.toolkit.fluxcd.io_helmreleases.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ spec:
432432
description: Optional marks this ValuesReference as optional. When set, a not found error for the values reference is ignored, but any ValuesKey, targetPath or transient error will still result in a reconciliation failure.
433433
type: boolean
434434
targetPath:
435-
description: targetPath is the YAML dot notation path the value should be merged at. When set, the ValuesKey is expected to be a single flat value. Defaults to 'None', which results in the values getting merged at the root.
435+
description: TargetPath is the YAML dot notation path the value should be merged at. When set, the ValuesKey is expected to be a single flat value. Defaults to 'None', which results in the values getting merged at the root.
436436
type: string
437437
valuesKey:
438438
description: ValuesKey is the data key where the values.yaml or a specific value can be found at. Defaults to 'values.yaml'.

0 commit comments

Comments
 (0)