Skip to content

Conversation

@bparees
Copy link
Contributor

@bparees bparees commented Jan 27, 2015

Attempting to bring some structure to the build interfaces we had scattered about the code... the intent is to define all the interfaces and the "standard" implementation in the util.go file, define the mock impls in the test cases that use them, and reduce the number of interfaces (rather than having an interface per build operation, have an interface that aggregates all the build operations).

this makes it slightly harder to mock the interface since you have to provide more dummy implementations, but it makes it much easier (imho) to understand the set of interfaces involved in the build process and where they're implemented.

@bparees bparees force-pushed the immutable_builds branch 2 times, most recently from d56638c to c2a804b Compare January 27, 2015 22:18
@bparees
Copy link
Contributor Author

bparees commented Jan 27, 2015

@soltysh @mfojtik @csrwng PTAL

i think there is more that can be done here, but again i'd like to get this iteration in to avoid rebase/merge conflict nightmares

@bparees
Copy link
Contributor Author

bparees commented Jan 27, 2015

[test]

@bparees bparees force-pushed the immutable_builds branch 2 times, most recently from c14eeb6 to fda1363 Compare January 27, 2015 22:42
Copy link
Contributor

Choose a reason for hiding this comment

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

godoc? (same for interface below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@csrwng
Copy link
Contributor

csrwng commented Jan 28, 2015

The builder package seems like an odd place to put the interfaces, maybe they should go in their own client package?

Copy link
Contributor

Choose a reason for hiding this comment

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

So we don't do this for a reason - to make local testability easier. This is kind of going against the conventions we're using in both Kubernetes and Origin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

having seen what that has wrought, i really disagree with that convention. it has created a nightmare of interfaces that make it really hard to follow what is being implemented, not to mention redundant logic all over the place.

I also don't really see that this reduces local testability, as you can see in the PR i've retained all the existing tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually Ben's refactor matches upstream conventions, see https://github.com/GoogleCloudPlatform/kubernetes/blob/master/pkg/controller/replication_controller.go#L46-L51. The only problem I can see here, there's too much create build methods we're using.

Copy link
Contributor

Choose a reason for hiding this comment

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

This interface purpose is to provide external services to the controller. I'd propose moving CreateBuildFromConfig and CreateBuildWithImmutableId methods to the controller, because they contain logic that should be part of the controller. The only interaction with other parts of the system I see there is CreateBuild which is part of that interface and all the rest should happen inside controller IMHO.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking more into it, I haven't noticed this interface landed in util.go, sorry. I see a BuildInterface here which should contain create and update methods and the other two methods (CreateBuildFromConfig, CreateBuildWithImmutableId) are just plain util methods, that should not be part of that interface.

Copy link
Contributor

Choose a reason for hiding this comment

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

@soltysh +1 i think the interfaces should be 'clean'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CreateBuildFromConfig and CreateBuildWithImmutableId need to be interfaces somewhere so they can be mocked... I might be inclined to agree that the methods that "just" create the object w/ no other logic should be separated from the more sophisticated paths, though.

@smarterclayton
Copy link
Contributor

I'm not in favor of this change given our existing conventions.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be more effective to implement a "real" implementation of ClientWebhookInterface that wraps a client in webhook.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no good reason for "ClientWebhookInterface" to exist, all it did was provide CreateBuild methods, there's nothing unique about that that demands the webhook component have its own version of the interface. Which is why i've removed it and replaced it with the more generic BuildClient interface to be used by things that want to create/manipulate Builds and BuildConfigClient interface for things that want to create/manipulate BuildConfigs

@soltysh
Copy link
Contributor

soltysh commented Jan 28, 2015

I'm leaning towards @smarterclayton idea of not changing what we have here. What I'd propose is to come up with reasonable naming scheme for case such as here. In there we have 3 different interfaces serving similar purpose, they differ only in the resource type they serve. I'd suggest renaming all of them to <resource>Manager, <resource>Client or whatever else as long as it'll be consistent in this file and among other controllers, my 0.02 💲

Copy link
Contributor

Choose a reason for hiding this comment

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

godoc does not match

@bparees
Copy link
Contributor Author

bparees commented Jan 28, 2015

i've addressed the non controversial comments (will squash later), will see if i can find a compromise on the interface debate after some discussion with @mfojtik and @soltysh

@bparees
Copy link
Contributor Author

bparees commented Jan 28, 2015

@smarterclayton let me add my next commit reworking the interface definitions before we continue this discussion, i think it will alleviate at least some of your concerns.

@bparees bparees force-pushed the immutable_builds branch 2 times, most recently from 8da4d9b to 520251f Compare January 28, 2015 21:38
@bparees
Copy link
Contributor Author

bparees commented Jan 28, 2015

The refactor has been refactored.
Things I suspect @smarterclayton will still not like:

  1. There is still a BuildClient and BuildConfigClient aggregate interface, though what they contain has been greatly stripped down. However I did introduce individual interfaces for test mocking, so tests do not need to implement the full Build(Config)Client interface.

  2. BuildControllerFactory still has an explicit BuildUpdater field rather than creating a BuildUpdater from the OSClient, as is being done for the "PodManager" and "ImageRepositoryClient". I prefer my approach because (although not currently used for testing) it enabled one to create factories that will create BuildControllers that use the OSClient, but use an alternate implementation of BuildUpdater. I don't really see any meaningful downside to having this be a part of the Factory (I would do it for PodManager and ImageRepositoryClient too, if it were up to me). I also think "ControllerClient" is a pretty unclear concept/term, so that was another motivation to not follow that pattern here.

  3. ImageChangeControllerFactory follows the same pattern as Add alpha API documentation #2

  4. I moved the Build(Config)Client interfaces into a new package, "client". I think you wanted that part, but you may not like that i left the canonical implementations in that package. I think they make more sense there than anywhere else I might put them (eg putting them in "factory" which is the primary place they're used). util.go is back to what it was. it should probably go away completely, but that's beyond what i want to do here.

  5. We also still have a "util" package as well, which should probably go away, but it was not introduced by this refactor.

@bparees bparees force-pushed the immutable_builds branch 3 times, most recently from e74721b to 72e217c Compare January 28, 2015 23:32
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, buildclient.BuilderUpdater would make me feel like you want me to be happy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i find it helpful when things are clearly spelled out as being interfaces w/o having to dig into them. it tells me immediately that the implementation might be flexible and i need to consider why and how it changes, and tells me i can potentially change it if needed. Having to jump to the definition to determine that is an extra step.

but again, i'll change it, i'm not that hung up on it, but i do think there are multiple valid schools of thought here.

@smarterclayton
Copy link
Contributor

I like this version much better, a few name things and the client stuff left.

@bparees bparees force-pushed the immutable_builds branch 2 times, most recently from ae42450 to 2beb1ff Compare January 29, 2015 08:28
@bparees
Copy link
Contributor Author

bparees commented Jan 29, 2015

Made the final changes in a separate commit, will squash if you're content.

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_openshift3/898/)

Copy link
Contributor

Choose a reason for hiding this comment

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

Was this change intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, global search/replace error.

@bparees bparees force-pushed the immutable_builds branch 2 times, most recently from 0fb103a to cfb5343 Compare January 29, 2015 09:17
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd propose renaming the file to clients.go, similar to what we have in pkg/client/client.go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since there are multiple clients in this file, i think i prefer it as is.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is more of a convention thing. If you have one file in a package, and you want to call the package a certain something, you generally call the only file in the package the same as the package. That's usually the stronger convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so as soon as we add a second file to this package, the name would be ok, right?

@mfojtik
Copy link
Contributor

mfojtik commented Jan 29, 2015

LGTM 👍

@soltysh
Copy link
Contributor

soltysh commented Jan 29, 2015

One small nit, other than that LGTM 🎱

@bparees
Copy link
Contributor Author

bparees commented Jan 29, 2015

---->squashed<----

@bparees
Copy link
Contributor Author

bparees commented Jan 29, 2015

@smarterclayton merge at will.

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 have BuildControllerClients, why do you need BuildControllerClient?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because I don't want both and in the interest of your implied pending abstraction of these methods, I didn't think using the method that returned both and then assuming one of the two return values would always be the one i wanted, was the right thing to do.

@bparees
Copy link
Contributor Author

bparees commented Jan 29, 2015

@smarterclayton removed the BuildControllerClient method.

@smarterclayton
Copy link
Contributor

LGTM [merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin up to 87233e7

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_openshift3/730/) (Image: devenv-fedora_624)

openshift-bot pushed a commit that referenced this pull request Jan 29, 2015
@openshift-bot openshift-bot merged commit e457f04 into openshift:master Jan 29, 2015
@bparees bparees deleted the immutable_builds branch February 2, 2015 17:57
sjenning pushed a commit to sjenning/origin that referenced this pull request Jan 5, 2018
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.

6 participants