-
Notifications
You must be signed in to change notification settings - Fork 4.8k
refactor build interfaces #760
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package client | ||
|
|
||
| import ( | ||
| buildapi "github.com/openshift/origin/pkg/build/api" | ||
| osclient "github.com/openshift/origin/pkg/client" | ||
| ) | ||
|
|
||
| // BuildConfigGetter provides methods for getting BuildConfigs | ||
| type BuildConfigGetter interface { | ||
| Get(namespace, name string) (*buildapi.BuildConfig, error) | ||
| } | ||
|
|
||
| // BuildConfigUpdater provides methods for updating BuildConfigs | ||
| type BuildConfigUpdater interface { | ||
| Update(buildConfig *buildapi.BuildConfig) error | ||
| } | ||
|
|
||
| // OSClientBuildConfigClient delegates get and update operations to the OpenShift client interface | ||
| type OSClientBuildConfigClient struct { | ||
| Client osclient.Interface | ||
| } | ||
|
|
||
| // NewOSClientBuildConfigClient creates a new build config client that uses an openshift client to create and get BuildConfigs | ||
| func NewOSClientBuildConfigClient(client osclient.Interface) *OSClientBuildConfigClient { | ||
| return &OSClientBuildConfigClient{Client: client} | ||
| } | ||
|
|
||
| // Get returns a BuildConfig using the OpenShift client. | ||
| func (c OSClientBuildConfigClient) Get(namespace, name string) (*buildapi.BuildConfig, error) { | ||
| return c.Client.BuildConfigs(namespace).Get(name) | ||
| } | ||
|
|
||
| // Update updates a BuildConfig using the OpenShift client. | ||
| func (c OSClientBuildConfigClient) Update(buildConfig *buildapi.BuildConfig) error { | ||
| _, err := c.Client.BuildConfigs(buildConfig.Namespace).Update(buildConfig) | ||
| return err | ||
| } | ||
|
|
||
| // BuildCreator provides methods for creating new Builds | ||
| type BuildCreator interface { | ||
| Create(namespace string, build *buildapi.Build) error | ||
| } | ||
|
|
||
| // BuildUpdater provides methods for updating existing Builds. | ||
| type BuildUpdater interface { | ||
| Update(namespace string, build *buildapi.Build) error | ||
| } | ||
|
|
||
| // OSClientBuildClient deletes build create and update operations to the OpenShift client interface | ||
| type OSClientBuildClient struct { | ||
| Client osclient.Interface | ||
| } | ||
|
|
||
| // NewOSClientBuildClient creates a new build client that uses an openshift client to create builds | ||
| func NewOSClientBuildClient(client osclient.Interface) *OSClientBuildClient { | ||
| return &OSClientBuildClient{Client: client} | ||
| } | ||
|
|
||
| // Create creates builds using the OpenShift client. | ||
| func (c OSClientBuildClient) Create(namespace string, build *buildapi.Build) error { | ||
| _, e := c.Client.Builds(namespace).Create(build) | ||
| return e | ||
| } | ||
|
|
||
| // Update updates builds using the OpenShift client. | ||
| func (c OSClientBuildClient) Update(namespace string, build *buildapi.Build) error { | ||
| _, e := c.Client.Builds(namespace).Update(build) | ||
| return e | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,16 +14,17 @@ import ( | |
| "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" | ||
|
|
||
| buildapi "github.com/openshift/origin/pkg/build/api" | ||
| buildclient "github.com/openshift/origin/pkg/build/client" | ||
| controller "github.com/openshift/origin/pkg/build/controller" | ||
| strategy "github.com/openshift/origin/pkg/build/controller/strategy" | ||
| buildutil "github.com/openshift/origin/pkg/build/util" | ||
| osclient "github.com/openshift/origin/pkg/client" | ||
| imageapi "github.com/openshift/origin/pkg/image/api" | ||
| ) | ||
|
|
||
| type BuildControllerFactory struct { | ||
| Client *osclient.Client | ||
| KubeClient *kclient.Client | ||
| OSClient osclient.Interface | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good. |
||
| KubeClient kclient.Interface | ||
| BuildUpdater buildclient.BuildUpdater | ||
| DockerBuildStrategy *strategy.DockerBuildStrategy | ||
| STIBuildStrategy *strategy.STIBuildStrategy | ||
| CustomBuildStrategy *strategy.CustomBuildStrategy | ||
|
|
@@ -35,10 +36,10 @@ type BuildControllerFactory struct { | |
|
|
||
| func (factory *BuildControllerFactory) Create() *controller.BuildController { | ||
| factory.buildStore = cache.NewStore() | ||
| cache.NewReflector(&buildLW{client: factory.Client}, &buildapi.Build{}, factory.buildStore).RunUntil(factory.Stop) | ||
| cache.NewReflector(&buildLW{client: factory.OSClient}, &buildapi.Build{}, factory.buildStore).RunUntil(factory.Stop) | ||
|
|
||
| buildQueue := cache.NewFIFO() | ||
| cache.NewReflector(&buildLW{client: factory.Client}, &buildapi.Build{}, buildQueue).RunUntil(factory.Stop) | ||
| cache.NewReflector(&buildLW{client: factory.OSClient}, &buildapi.Build{}, buildQueue).RunUntil(factory.Stop) | ||
|
|
||
| // Kubernetes does not currently synchronize Pod status in storage with a Pod's container | ||
| // states. Because of this, we can't receive events related to container (and thus Pod) | ||
|
|
@@ -51,10 +52,10 @@ func (factory *BuildControllerFactory) Create() *controller.BuildController { | |
| podQueue := cache.NewFIFO() | ||
| cache.NewPoller(factory.pollPods, 10*time.Second, podQueue).RunUntil(factory.Stop) | ||
|
|
||
| client := ControllerClient{factory.KubeClient, factory.Client} | ||
| client := ControllerClient{factory.KubeClient, factory.OSClient} | ||
| return &controller.BuildController{ | ||
| BuildStore: factory.buildStore, | ||
| BuildUpdater: client, | ||
| BuildUpdater: factory.BuildUpdater, | ||
| ImageRepositoryClient: client, | ||
| PodManager: client, | ||
| NextBuild: func() *buildapi.Build { | ||
|
|
@@ -78,7 +79,9 @@ func (factory *BuildControllerFactory) Create() *controller.BuildController { | |
| // ImageChangeControllerFactory can create an ImageChangeController which obtains ImageRepositories | ||
| // from a queue populated from a watch of all ImageRepositories. | ||
| type ImageChangeControllerFactory struct { | ||
| Client *osclient.Client | ||
| Client osclient.Interface | ||
| BuildCreator buildclient.BuildCreator | ||
| BuildConfigUpdater buildclient.BuildConfigUpdater | ||
| // Stop may be set to allow controllers created by this factory to be terminated. | ||
| Stop <-chan struct{} | ||
| } | ||
|
|
@@ -92,11 +95,10 @@ func (factory *ImageChangeControllerFactory) Create() *controller.ImageChangeCon | |
| store := cache.NewStore() | ||
| cache.NewReflector(&buildConfigLW{client: factory.Client}, &buildapi.BuildConfig{}, store).RunUntil(factory.Stop) | ||
|
|
||
| client := ControllerClient{nil, factory.Client} | ||
| return &controller.ImageChangeController{ | ||
| BuildConfigStore: store, | ||
| BuildConfigUpdater: client, | ||
| BuildCreator: client, | ||
| BuildConfigUpdater: factory.BuildConfigUpdater, | ||
| BuildCreator: factory.BuildCreator, | ||
| NextImageRepository: func() *imageapi.ImageRepository { | ||
| repo := queue.Pop().(*imageapi.ImageRepository) | ||
| panicIfStopped(factory.Stop, "build image change controller stopped") | ||
|
|
@@ -235,30 +237,6 @@ func (c ControllerClient) DeletePod(namespace string, pod *kapi.Pod) error { | |
| return c.KubeClient.Pods(namespace).Delete(pod.Name) | ||
| } | ||
|
|
||
| // UpdateBuild updates build using the OpenShift client. | ||
| func (c ControllerClient) UpdateBuild(namespace string, build *buildapi.Build) (*buildapi.Build, error) { | ||
| return c.Client.Builds(namespace).Update(build) | ||
| } | ||
|
|
||
| // CreateBuild updates build using the OpenShift client. | ||
| func (c ControllerClient) CreateBuild(config *buildapi.BuildConfig, imageSubstitutions map[string]string) error { | ||
| build := buildutil.GenerateBuildFromConfig(config, nil) | ||
| for originalImage, newImage := range imageSubstitutions { | ||
| buildutil.SubstituteImageReferences(build, originalImage, newImage) | ||
| } | ||
| if _, err := c.Client.Builds(config.Namespace).Create(build); err != nil { | ||
| glog.V(2).Infof("Error creating build for buildConfig %v: %v", config.Name, err) | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // UpdateBuildConfig updates buildConfig using the OpenShift client. | ||
| func (c ControllerClient) UpdateBuildConfig(buildConfig *buildapi.BuildConfig) error { | ||
| _, err := c.Client.BuildConfigs(buildConfig.Namespace).Update(buildConfig) | ||
| return err | ||
| } | ||
|
|
||
| // GetImageRepository retrieves an image repository by namespace and name | ||
| func (c ControllerClient) GetImageRepository(namespace, name string) (*imageapi.ImageRepository, error) { | ||
| return c.Client.ImageRepositories(namespace).Get(name) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'd propose renaming the file to
clients.go, similar to what we have inpkg/client/client.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.
since there are multiple clients in this file, i think i prefer it as is.
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.
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.
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.
so as soon as we add a second file to this package, the name would be ok, right?