-
Notifications
You must be signed in to change notification settings - Fork 142
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
Refactor install #1284
Refactor install #1284
Conversation
Added function to convert from Manifest to CommitFile
Removed AssociateCluster method from GitOpsDirectoryWriter
# Conflicts: # pkg/services/gitops/install.go # pkg/services/gitops/install_test.go
Co-authored-by: Jordan Pellizzari <jordan@weave.works>
…e-gitops into refactor-install
A function was renamed but their calls were not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Any extra comments that you could add to the code about future plans or why certain things might seem weird would be good.
A function was renamed but their calls were not
… kustomization of the expected file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just a few suggested changes and a few nits.
pkg/services/install/install_test.go
Outdated
}) | ||
|
||
It("should fail getting default branch", func() { | ||
fakeKubeClient.GetClusterStatusReturns(kube.Unmodified) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 8 lines appear to be repeated in quite of few of these tests, consider either move to setup or make a function that each could call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@palemtnrider Can't do that. Each test uses specific setup lines. Not all lines appear in all tests and not all are the same. Let me know if I'm missing something. This another approach where I would be duplicate any single line but seems a bit confusing. The huge advantage I see is that if I need to make a change somewhere it would be in a single place only. Let me know if you want to discuss this in a call.
Context("error paths2", func() {
someError := errors.New("some error")
It("should fail validating wego installation", func() {
fakeKubeClient.GetClusterStatusReturns(kube.Unknown)
err := installer.Install(testNamespace, configRepo, true)
Expect(err).Should(MatchError("failed validating wego installation: Weave GitOps cannot talk to the cluster"))
})
Context("return unmodified on GetClusterStatus and valid wego config", func() {
fakeKubeClient.GetClusterStatusReturns(kube.Unmodified)
fakeKubeClient.GetWegoConfigReturns(&kube.WegoConfig{
FluxNamespace: testNamespace,
WegoNamespace: testNamespace,
}, nil)
It("should fail getting cluster name", func() {
fakeKubeClient.GetClusterNameReturns("", someError)
err := installer.Install(testNamespace, configRepo, true)
Expect(err).Should(MatchError(fmt.Sprintf("failed getting cluster name: %s", someError)))
})
Context("return valid cluster name", func() {
fakeKubeClient.GetClusterNameReturns(clusterName, nil)
It("should fail installing flux", func() {
fakeFluxClient.InstallReturns(nil, someError)
err := installer.Install(testNamespace, configRepo, true)
Expect(err).Should(MatchError(fmt.Sprintf("failed installing flux: %s", someError)))
})
Context("do not return error on flux install", func() {
fakeFluxClient.InstallReturnsOnCall(0, nil, nil)
It("should fail getting bootstrap manifests", func() {
fakeFluxClient.InstallReturnsOnCall(1, nil, someError)
err := installer.Install(testNamespace, configRepo, true)
Expect(err).Should(MatchError(fmt.Sprintf("failed getting bootstrap manifests: failed getting runtime manifests: %s", someError)))
})
Context("do not return error on flux install", func() {
fakeFluxClient.InstallReturnsOnCall(1, nil, nil)
It("should fail getting default branch", func() {
fakeGitProvider.GetDefaultBranchReturnsOnCall(0, "", someError)
err := installer.Install(testNamespace, configRepo, true)
Expect(err).Should(MatchError(fmt.Sprintf("failed getting default branch: %s", someError)))
})
Context("return valid default branch", func() {
fakeGitProvider.GetDefaultBranchReturnsOnCall(0, "main", nil)
It("should fail getting config repo git source", func() {
fakeGitProvider.GetRepoVisibilityReturns(nil, someError)
err := installer.Install(testNamespace, configRepo, true)
Expect(err).Should(MatchError(fmt.Sprintf("failed getting git source: failed getting ref secret: %s", someError)))
})
Context("return private repo visibility", func() {
privateVisibility := gitprovider.RepositoryVisibilityPrivate
fakeGitProvider.GetRepoVisibilityReturns(&privateVisibility, nil)
It("should fail applying bootstrap manifests", func() {
fakeKubeClient.ApplyReturns(someError)
err := installer.Install(testNamespace, configRepo, true)
Expect(err).Should(MatchError(fmt.Sprintf("error applying manifest .weave-gitops/clusters/test-cluster/system/wego-system.yaml: %s", someError)))
})
Context("do not fail when applying manifests", func() {
fakeKubeClient.ApplyReturns(nil)
It("should fail getting gitops manifests", func() {
fakeFluxClient.InstallReturnsOnCall(2, nil, someError)
err := installer.Install(testNamespace, configRepo, true)
Expect(err).Should(MatchError(fmt.Sprintf("failed generating gitops manifests: failed getting runtime manifests: %s", someError)))
})
Context("do not fail when calling install for second time", func() {
fakeFluxClient.InstallReturnsOnCall(2, nil, nil)
It("should fail writing directly to branch", func() {
fakeGitClient.CloneReturns(false, someError)
err := installer.Install(testNamespace, configRepo, true)
Expect(err).Should(MatchError(fmt.Sprintf("failed writting to default branch failed to clone repo: failed cloning user repo: ssh://git@github.com/test-user/test-repo.git: %s", someError)))
})
It("should fail creating a pull requests", func() {
fakeGitProvider.CreatePullRequestReturns(nil, someError)
err := installer.Install(testNamespace, configRepo, false)
Expect(err).Should(MatchError(fmt.Sprintf("failed creating pull request: %s", someError)))
})
})
})
})
})
})
})
})
})
})
# Conflicts: # cmd/gitops/install/cmd.go # pkg/services/auth/auth_test.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work!
Closes:
What changed?
Initial work to refactor installer
Why?
To make it more API/CLI friendly and to align with the latest architecture ADR.
How did you test it?
Added unit tests and fixed all acceptance tests related to the install command.
Release notes
N/A
Documentation Changes
N/A