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

Support all three config modes #253

Merged
merged 31 commits into from
Jun 7, 2021
Merged

Conversation

jrryjcksn
Copy link
Contributor

What changed?

  • We no longer create a wego repository
    • no more "private" flag
  • We have three automation config options:
    • none (only place automation in cluster; no persistent storage)
    • URL (place automation in external repository -- like our old default but no auto-creation),
    • "" (use the user's app repository)
  • Dry run test correctly handles new git client

Why?
This is the design favored by the CTO that she will demo at GitOps days

How did you test it?

  • Tested locally
  • Added unit tests

Release notes
N/A

Documentation Changes
Yes, the getting started guide will need to be updated

@jrryjcksn jrryjcksn marked this pull request as ready for review June 6, 2021 22:49
@pzfreo
Copy link
Contributor

pzfreo commented Jun 7, 2021

I have concerns about the --app-config-url name.

I would prefer --gitops-config-location or --gitops-automation-location

@markramm thoughts?

}

var ignoreGitClient = gitfakes.FakeGit{
CloneStub: func(ctx context.Context, a, b, c string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless you explicitly want to see the print, there is no set all methods, it defaults to noop

@@ -171,17 +171,75 @@ func handleGitLsRemote(arglist ...interface{}) ([]byte, []byte, error) {
return nil, nil, fmt.Errorf("NO!")
}

var fakeGitClient = gitfakes.FakeGit{}
var failGitClient = gitfakes.FakeGit{
CloneStub: func(ctx context.Context, a, b, c string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

a failure would probably be returning an error instead of exiting the process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is so that any use of the code anywhere downstream will fail the test w/o trying to propagate the failure to ensure dry run is working. Returning an error wouldn't work.

Copy link
Contributor

Choose a reason for hiding this comment

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

the use of invalid/non-existent repo addresses would probably accomplish the same, without requiring you to implement those, but I'm fine with it. It's up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense; I was just trying to be consistent across all the overrides and that was the simplest way. Not wedded to it :-)

@@ -216,7 +319,7 @@ var _ = Describe("Dry Run Add Test", func() {
_ = override.WithOverrides(
func() override.Result {
deps := &AddDependencies{
GitClient: &fakeGitClient,
GitClient: &failGitClient,
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to exemplify the previous comment, this could be just GitClient: &gitfakes.FakeGit{}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not for dry run


_, err = fluxops.CallFlux(cmd)
func getUrls(client git.Git, remote string) ([]string, error) {
if _, ok := client.(*git.GoGit); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you do this you won't be able to mock it in the test. It will ignore it every time.

With this, you should be able to mock that

GitClient: &gitfakes.FakeGit{
	OpenStub: func(s string) (*gogit.Repository, error) {
		r, err := gogit.Init(memory.NewStorage(), memfs.New())
		Expect(err).ShouldNot(HaveOccurred())

		_, err = r.CreateRemote(&config.RemoteConfig{
			Name: "origin",
			URLs: []string{"http://foo/foo.git"},
		})
		Expect(err).ShouldNot(HaveOccurred())
		return r, nil
	},
},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without a remote, everything panicked. I had no way to fake the remote at the time so I upleveled it. I'd be very happy to do something better later

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good

@jrryjcksn jrryjcksn force-pushed the support-all-three-config-modes branch from ccf5870 to 1c91135 Compare June 7, 2021 17:41
@luizbafilho luizbafilho self-requested a review June 7, 2021 21:58
Copy link
Contributor

@palemtnrider palemtnrider left a comment

Choose a reason for hiding this comment

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

LGTM - Just a handful of nits you can choose to make or not.

@@ -38,8 +38,8 @@ func init() {
Cmd.Flags().StringVar(&params.Branch, "branch", "main", "Branch to watch within git repository")
Cmd.Flags().StringVar(&params.DeploymentType, "deployment-type", "kustomize", "deployment type [kustomize, helm]")
Cmd.Flags().StringVar(&params.PrivateKey, "private-key", filepath.Join(os.Getenv("HOME"), ".ssh", "id_rsa"), "Private key that provides access to git repository")
Cmd.Flags().StringVar(&params.AppConfigUrl, "app-config-url", "", "URL of external repository (if any) which will hold automation manifests; NONE to store only in the cluster")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit - "URL of external repository" -> "URL of an external repository"

@@ -32,13 +31,12 @@ var _ = Describe("Weave GitOps Add Tests", func() {
defaultSshKeyPath := os.Getenv("HOME") + "/.ssh/id_rsa"
addCommand := "app add . "
appRepoName := "wego-test-app-" + RandString(8)
wegoRepoName := getClusterName() + "-wego"
appName := wegoRepoName + "-" + appRepoName
appName := appRepoName
Copy link
Contributor

Choose a reason for hiding this comment

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

NIt: It string says command is wego add and should bewego app add

if err != nil {
return wrapError(err, "could not get flux repo name")
return wrapError(err, fmt.Sprintf("could not create GitOps automation for '%s'", params.Name))
Copy link
Contributor

Choose a reason for hiding this comment

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

error message is using a different value than what is passed to generateApplicationGoat

pkg/cmdimpl/add.go Show resolved Hide resolved
if err := writeAppYaml(gitClient, appYaml, ".wego"); err != nil {
return err
}
if err := writeGoats(gitClient, ".wego", applicationGoat); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

NIt: Since writeAppYaml and writeGoats are performing similar operations, I'd prefer to have the arguments in the same order. i.e. base path then the manifests.

pkg/cmdimpl/add.go Outdated Show resolved Hide resolved
if err != nil {
return wrapError(err, "could not generate wego source manifest")
}
func generateSource(repoName, repoUrl string, sourceType SourceType) ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We aren't using sourceType in the function. (I suspect it's because we have a different PR that will add the helm support)

@jrryjcksn jrryjcksn force-pushed the support-all-three-config-modes branch from 72bedc6 to 5064b05 Compare June 7, 2021 23:17
@jrryjcksn jrryjcksn merged commit 233d9b5 into main Jun 7, 2021
@jrryjcksn jrryjcksn deleted the support-all-three-config-modes branch June 7, 2021 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants