Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jpellizzari committed Jan 21, 2022
1 parent 5713073 commit 1a40240
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 37 deletions.
18 changes: 9 additions & 9 deletions cmd/gitops/install/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func installRunCmd(cmd *cobra.Command, args []string) error {
ctx := context.Background()
namespace, _ := cmd.Parent().Flags().GetString("namespace")

configURL, err := gitproviders.NewRepoURL(installParams.ConfigRepo, true)
configURL, err := gitproviders.NewRepoURL(gitopsParams.ConfigRepo, true)
if err != nil {
return err
}
Expand Down Expand Up @@ -97,19 +97,19 @@ func installRunCmd(cmd *cobra.Command, args []string) error {
var gitClient git.Git
var gitProvider gitproviders.GitProvider

factory := services.NewFactory(flux, log)
factory := services.NewFactory(runner, log)

if err != nil {
return fmt.Errorf("failed getting kube service: %w", err)
}

if installParams.DryRun {
if gitopsParams.DryRun {
gitProvider, err = gitproviders.NewDryRun()
if err != nil {
return fmt.Errorf("error creating git provider for dry run: %w", err)
}
} else {
_, err = flux.Install(namespace, false)
_, err = runner.Install(namespace, false)
if err != nil {
return err
}
Expand All @@ -118,10 +118,10 @@ func installRunCmd(cmd *cobra.Command, args []string) error {

gitClient, gitProvider, err = factory.GetGitClients(context.Background(), providerClient, services.GitConfigParams{
// We need to set URL and ConfigRepo to the same value so a deploy key is created for public config repos
URL: installParams.ConfigRepo,
ConfigRepo: installParams.ConfigRepo,
URL: gitopsParams.ConfigRepo,
ConfigRepo: gitopsParams.ConfigRepo,
Namespace: namespace,
DryRun: installParams.DryRun,
DryRun: gitopsParams.DryRun,
FluxHTTPSUsername: gitopsParams.FluxHTTPSUsername,
FluxHTTPSPassword: gitopsParams.FluxHTTPSPassword,
})
Expand All @@ -133,7 +133,7 @@ func installRunCmd(cmd *cobra.Command, args []string) error {

cluster := models.Cluster{Name: clusterName}
repoWriter := gitrepo.NewRepoWriter(configURL, gitProvider, gitClient, log)
automationGen := automation.NewAutomationGenerator(gitProvider, flux, log)
automationGen := automation.NewAutomationGenerator(gitProvider, runner, log)
gitOpsDirWriter := gitopswriter.NewGitOpsDirectoryWriter(automationGen, repoWriter, osysClient, log)

clusterAutomation, err := automationGen.GenerateClusterAutomation(ctx, cluster, configURL, namespace)
Expand Down Expand Up @@ -161,7 +161,7 @@ func installRunCmd(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed applying manifest: %w", err)
}

err = gitOpsDirWriter.AssociateCluster(ctx, cluster, configURL, namespace, namespace, installParams.AutoMerge)
err = gitOpsDirWriter.AssociateCluster(ctx, cluster, configURL, namespace, namespace, gitopsParams.AutoMerge)
if err != nil {
return fmt.Errorf("failed associating cluster: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/flux/flux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ var _ = Describe("CreateSourceGit", func() {
return []byte("out"), nil
}

repoUrl, err := gitproviders.NewRepoURL("https://gitlab.com/foo/my-name")
repoUrl, err := gitproviders.NewRepoURL("https://gitlab.com/foo/my-name", false)
Expect(err).ShouldNot(HaveOccurred())
out, err := fluxClient.CreateSourceGit("my-name", repoUrl, "main", "", wego.DefaultNamespace, &flux.HTTPSCreds{Username: "test", Password: "password"})
Expect(err).ShouldNot(HaveOccurred())
Expand Down Expand Up @@ -283,7 +283,7 @@ var _ = Describe("CreateSecretGit", func() {
return []byte(`ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCh...`), nil
}

repoUrl, err := gitproviders.NewRepoURL("ssh://git@github.com/foo/bar.git")
repoUrl, err := gitproviders.NewRepoURL("ssh://git@github.com/foo/bar.git", false)
Expect(err).ShouldNot(HaveOccurred())
out, err := fluxClient.CreateSecretGit("my-secret", repoUrl, wego.DefaultNamespace, &flux.HTTPSCreds{Username: "test", Password: "password"})
Expect(err).ShouldNot(HaveOccurred())
Expand Down
36 changes: 20 additions & 16 deletions pkg/flux/fluxfakes/fake_flux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/gitproviders/repo_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewRepoURL(uri string, isConfigRepo bool) (RepoURL, error) {
}

return RepoURL{
repoName: utils.UrlToRepoName(uri),
repoName: utils.URLToRepoName(uri),
owner: owner,
url: u,
normalized: normalized,
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/app/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ var _ = Describe("Add Gitlab", func() {

Expect(fluxClient.CreateSourceGitCallCount()).To(Equal(1))

name, url, branch, secretRef, namespace := fluxClient.CreateSourceGitArgsForCall(0)
name, url, branch, secretRef, namespace, _ := fluxClient.CreateSourceGitArgsForCall(0)
Expect(name).To(Equal("bar"))
Expect(url.String()).To(Equal("ssh://git@gitlab.com/foo/bar.git"))
Expect(branch).To(Equal("main"))
Expand Down
8 changes: 4 additions & 4 deletions pkg/services/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = Describe("auth", func() {
repoUrlString := "ssh://git@github.com/my-org/my-repo.git"
configRepoUrl, err := gitproviders.NewRepoURL(repoUrlString, true)
Expect(err).NotTo(HaveOccurred())
repoUrl, err := gitproviders.NewRepoURL(repoUrlString, false)
repoURL, err := gitproviders.NewRepoURL(repoUrlString, false)
Expect(err).NotTo(HaveOccurred())

BeforeEach(func() {
Expand Down Expand Up @@ -90,7 +90,7 @@ var _ = Describe("auth", func() {
gp.DeployKeyExistsReturns(true, nil)
sn := SecretName{Name: secretName, Namespace: namespace.Name}
// using `generateDeployKey` as a helper for the test setup.
_, secret, err := (&authSvc{fluxClient: fluxClient}).generateDeployKey(testClustername, sn, repoURL, nil)
_, secret, err := (&authSvc{fluxClient: fluxClient}).generateRepoAuthSecret(testClustername, sn, repoURL, nil)
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient.Create(ctx, secret)).To(Succeed())

Expand All @@ -115,14 +115,14 @@ var _ = Describe("auth", func() {
It("avoids deploying key for non config repos", func() {
gp.GetRepoVisibilityReturns(gitprovider.RepositoryVisibilityVar(gitprovider.RepositoryVisibilityPublic), nil)

_, err = as.CreateGitClient(ctx, repoUrl, testClustername, namespace.Name, false, nil)
_, err = as.CreateGitClient(ctx, repoURL, testClustername, namespace.Name, false, nil)
Expect(err).NotTo(HaveOccurred())

Expect(gp.UploadDeployKeyCallCount()).To(Equal(0))
})

It("does not create a deploy key when using https", func() {
repoURL, err := gitproviders.NewRepoURL("https://github.com/my-org/my-repo.git", false)
repoURL, err = gitproviders.NewRepoURL("https://github.com/my-org/my-repo.git", false)
Expect(err).NotTo(HaveOccurred())
_, err := as.CreateGitClient(ctx, repoURL, testClustername, namespace.Name, false, &flux.HTTPSCreds{Username: "test", Password: "topsecret"})
Expect(err).NotTo(HaveOccurred())
Expand Down
6 changes: 3 additions & 3 deletions pkg/services/automation/automation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var _ = Describe("Generate manifests", func() {

Expect(fluxClient.CreateSourceGitCallCount()).To(Equal(1))

name, url, branch, secretRef, namespace := fluxClient.CreateSourceGitArgsForCall(0)
name, url, branch, secretRef, namespace, _ := fluxClient.CreateSourceGitArgsForCall(0)
Expect(name).To(Equal("bar"))
Expect(url.String()).To(Equal("ssh://git@github.com/foo/bar.git"))
Expect(branch).To(Equal("main"))
Expand Down Expand Up @@ -191,9 +191,9 @@ var _ = Describe("Generate manifests", func() {

Expect(fluxClient.CreateSourceGitCallCount()).To(Equal(1))

name, url, branch, secretRef, namespace := fluxClient.CreateSourceGitArgsForCall(0)
name, url, branch, secretRef, namespace, _ := fluxClient.CreateSourceGitArgsForCall(0)
Expect(name).To(Equal("bar"))
Expect(url.String()).To(Equal("ssh://git@github.com/user/repo.git"))
Expect(url.String()).To(Equal("https://github.com/user/repo.git"))
Expect(branch).To(Equal("main"))
Expect(secretRef).To(Equal("wego-github-repo"))
Expect(namespace).To(Equal(wego.DefaultNamespace))
Expand Down
1 change: 1 addition & 0 deletions pkg/services/gitops/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type InstallParams struct {
Namespace string
DryRun bool
ConfigRepo string
AutoMerge bool
FluxHTTPSUsername string
FluxHTTPSPassword string
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/gitopswriter/writer_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ var _ = Describe("Add", func() {
_, repoDir, url, branch := gitClient.CloneArgsForCall(0)

Expect(repoDir).To(ContainSubstring("user-repo-"))
Expect(url).To(Equal("ssh://git@github.com/foo/bar.git"))
Expect(url).To(Equal("https://github.com/foo/bar.git"))
Expect(branch).To(Equal("main"))
})

Expand Down

0 comments on commit 1a40240

Please sign in to comment.