Skip to content

Commit

Permalink
Merge pull request openshift#1275 from soltysh/build_rework
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Mar 27, 2015
2 parents 8bbe6e1 + 1d84438 commit b65ab38
Show file tree
Hide file tree
Showing 54 changed files with 1,554 additions and 689 deletions.
32 changes: 16 additions & 16 deletions assets/app/scripts/controllers/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ angular.module('openshiftConsole')
// All deployments
// "" service key for deployments not under any service
// Only being built to improve efficiency in the podRelationships method, not used by the view
$scope.deploymentsByService = {};
$scope.deploymentsByService = {};
// All deployment configs
// "" service key for deployment configs not under any service
$scope.deploymentConfigsByService = {};

$scope.labelSuggestions = {};
$scope.alerts = $scope.alerts || {};
$scope.alerts = $scope.alerts || {};
$scope.emptyMessage = "Loading...";
var watches = [];

Expand Down Expand Up @@ -80,15 +80,15 @@ angular.module('openshiftConsole')
angular.forEach($scope.unfilteredServices, function(service, svcName){
svcSelectors[svcName] = new LabelSelector(service.spec.selector);
$scope.podsByService[svcName] = {};
});
});


angular.forEach($scope.pods, function(pod, name){
var deployments = [];
var services = [];
angular.forEach($scope.deployments, function(deployment, depName){
var ls = depSelectors[depName];
if (ls.matches(pod)) {
if (ls.matches(pod)) {
deployments.push(depName);
$scope.podsByDeployment[depName][name] = pod;
}
Expand All @@ -115,9 +115,9 @@ angular.module('openshiftConsole')
}
});

Logger.log("podsByDeployment", $scope.podsByDeployment);
Logger.log("podsByService", $scope.podsByService);
Logger.log("monopodsByService", $scope.monopodsByService);
Logger.log("podsByDeployment", $scope.podsByDeployment);
Logger.log("podsByService", $scope.podsByService);
Logger.log("monopodsByService", $scope.monopodsByService);
};

// Filter out monopods we know we don't want to see
Expand All @@ -132,11 +132,11 @@ angular.module('openshiftConsole')
// appears.
if (pod.metadata.annotations && pod.metadata.annotations.deployment) {
return false;
}
}
// Hide our build pods since we are already showing details for currently running or recently
// run builds under the appropriate areas
for (var id in $scope.builds) {
if ($scope.builds[id].podName == pod.metadata.name) {
if ($scope.builds[id].metadata.name == pod.metadata.name) {
return false;
}
}
Expand Down Expand Up @@ -269,7 +269,7 @@ angular.module('openshiftConsole')
if (triggerTag !== buildTag) {
continue;
}

trigger.builds = trigger.builds || {};
trigger.builds[build.metadata.name] = build;
}
Expand All @@ -283,7 +283,7 @@ angular.module('openshiftConsole')
angular.forEach($scope.deploymentConfigs, function(depConfig) {
angular.forEach($scope.builds, function(build) {
associateDeploymentConfigTriggersToBuild(depConfig, build);
});
});
});
}
else if (action !== 'DELETED') {
Expand All @@ -292,7 +292,7 @@ angular.module('openshiftConsole')
});
}

deploymentConfigsByService();
deploymentConfigsByService();

Logger.log("deploymentConfigs (subscribe)", $scope.deploymentConfigs);
}));
Expand All @@ -306,7 +306,7 @@ angular.module('openshiftConsole')
associateDeploymentConfigTriggersToBuild(depConfig, bld);
});
});
}
}
else if (action === 'ADDED' || action === 'MODIFIED') {
angular.forEach($scope.deploymentConfigs, function(depConfig) {
associateDeploymentConfigTriggersToBuild(depConfig, build);
Expand All @@ -327,7 +327,7 @@ angular.module('openshiftConsole')
}
else {
delete $scope.alerts["services"];
}
}
};

LabelFilter.onActiveFiltersChanged(function(labelSelector) {
Expand All @@ -340,5 +340,5 @@ angular.module('openshiftConsole')

$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
});
});
});
2 changes: 1 addition & 1 deletion pkg/assets/bindata.go
Original file line number Diff line number Diff line change
Expand Up @@ -14267,7 +14267,7 @@ j = j || a.deploymentsByService[h] && a.deploymentsByService[h][b];
}, i = function(b) {
if ("Succeeded" == b.status.phase || "Terminated" == b.status.phase) return !1;
if (b.metadata.annotations && b.metadata.annotations.deployment) return !1;
for (var c in a.builds) if (a.builds[c].podName == b.metadata.name) return !1;
for (var c in a.builds) if (a.builds[c].metadata.name == b.metadata.name) return !1;
return !0;
}, j = function() {
a.deploymentConfigsByService = {
Expand Down
2 changes: 2 additions & 0 deletions pkg/build/api/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func init() {
&BuildConfig{},
&BuildConfigList{},
&BuildLog{},
&BuildRequest{},
)
}

Expand All @@ -19,3 +20,4 @@ func (*BuildList) IsAnAPIObject() {}
func (*BuildConfig) IsAnAPIObject() {}
func (*BuildConfigList) IsAnAPIObject() {}
func (*BuildLog) IsAnAPIObject() {}
func (*BuildRequest) IsAnAPIObject() {}
18 changes: 15 additions & 3 deletions pkg/build/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)

// BuildLabel is the key of a Pod label whose value is the Name of a Build which is run.
const BuildLabel = "build"

// Build encapsulates the inputs needed to produce a new deployable image, as well as
// the status of the execution and a reference to the Pod which executed the build.
type Build struct {
Expand All @@ -20,9 +23,6 @@ type Build struct {
// A human readable message indicating details about why the build has this status
Message string `json:"message,omitempty"`

// PodName is the name of the pod that is used to execute the build
PodName string `json:"podName,omitempty"`

// Cancelled describes if a cancelling event was triggered for the build.
Cancelled bool `json:"cancelled,omitempty"`

Expand Down Expand Up @@ -268,6 +268,9 @@ type BuildConfig struct {
// are defined, a new build can only occur as a result of an explicit client build creation.
Triggers []BuildTriggerPolicy `json:"triggers,omitempty"`

// LastVersion is used to inform about number of last triggered build.
LastVersion int `json:"lastVersion,omitempty"`

// Parameters holds all the input necessary to produce a new build. A build config may only
// define either the Output.To or Output.DockerImageReference fields, but not both.
Parameters BuildParameters `json:"parameters,omitempty"`
Expand Down Expand Up @@ -363,3 +366,12 @@ type BuildLog struct {
kapi.TypeMeta `json:",inline"`
kapi.ListMeta `json:"metadata,omitempty"`
}

// BuildRequest is the resource used to pass parameters to build generator
type BuildRequest struct {
kapi.TypeMeta `json:",inline"`
kapi.ObjectMeta `json:"metadata,omitempty"`

// Revision is the information from the source for a specific repo snapshot.
Revision *SourceRevision `json:"revision,omitempty"`
}
2 changes: 2 additions & 0 deletions pkg/build/api/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func init() {
&BuildConfig{},
&BuildConfigList{},
&BuildLog{},
&BuildRequest{},
)
}

Expand All @@ -19,3 +20,4 @@ func (*BuildList) IsAnAPIObject() {}
func (*BuildConfig) IsAnAPIObject() {}
func (*BuildConfigList) IsAnAPIObject() {}
func (*BuildLog) IsAnAPIObject() {}
func (*BuildRequest) IsAnAPIObject() {}
18 changes: 15 additions & 3 deletions pkg/build/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)

// BuildLabel is the key of a Pod label whose value is the Name of a Build which is run.
const BuildLabel = "build"

// Build encapsulates the inputs needed to produce a new deployable image, as well as
// the status of the execution and a reference to the Pod which executed the build.
type Build struct {
Expand All @@ -20,9 +23,6 @@ type Build struct {
// A human readable message indicating details about why the build has this status
Message string `json:"message,omitempty"`

// PodName is the name of the pod that is used to execute the build
PodName string `json:"podName,omitempty"`

// Cancelled describes if a cancelling event was triggered for the build.
Cancelled bool `json:"cancelled,omitempty"`

Expand Down Expand Up @@ -284,6 +284,9 @@ type BuildConfig struct {
// are defined, a new build can only occur as a result of an explicit client build creation.
Triggers []BuildTriggerPolicy `json:"triggers,omitempty"`

// LastVersion is used to inform about number of last triggered build.
LastVersion int `json:"lastVersion,omitempty"`

// Parameters holds all the input necessary to produce a new build. A build config may only
// define either the Output.To or Output.DockerImageReference fields, but not both.
Parameters BuildParameters `json:"parameters,omitempty"`
Expand Down Expand Up @@ -383,3 +386,12 @@ type BuildLog struct {
kapi.TypeMeta `json:",inline"`
kapi.ListMeta `json:"metadata,omitempty"`
}

// BuildRequest is the resource used to pass parameters to build generator
type BuildRequest struct {
kapi.TypeMeta `json:",inline"`
kapi.ObjectMeta `json:"metadata,omitempty"`

// Revision is the information from the source for a specific repo snapshot.
Revision *SourceRevision `json:"revision,omitempty"`
}
11 changes: 11 additions & 0 deletions pkg/build/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ func ValidateBuildConfig(config *buildapi.BuildConfig) errs.ValidationErrorList
return allErrs
}

func ValidateBuildRequest(request *buildapi.BuildRequest) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
if len(request.Name) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("name"))
}
if request.Revision != nil {
allErrs = append(allErrs, validateRevision(request.Revision).Prefix("revision")...)
}
return allErrs
}

func validateBuildParameters(params *buildapi.BuildParameters) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
isCustomBuild := params.Strategy.Type == buildapi.CustomBuildStrategyType
Expand Down
24 changes: 24 additions & 0 deletions pkg/build/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,30 @@ func TestBuildConfigValidationOutputFailure(t *testing.T) {
}
}

func TestValidateBuildRequest(t *testing.T) {
testCases := map[string]*buildapi.BuildRequest{
"": {ObjectMeta: kapi.ObjectMeta{Name: "requestName"}},
string(errs.ValidationErrorTypeRequired) + "name": {},
}

for desc, tc := range testCases {
errors := ValidateBuildRequest(tc)
if len(desc) == 0 && len(errors) > 0 {
t.Errorf("%s: Unexpected validation result: %v", desc, errors)
}
if len(desc) > 0 && len(errors) != 1 {
t.Errorf("%s: Unexpected validation result: %v", desc, errors)
}
if len(desc) > 0 {
err := errors[0].(*errs.ValidationError)
errDesc := string(err.Type) + err.Field
if desc != errDesc {
t.Errorf("Unexpected validation result for %s: expected %s, got %s", err.Field, desc, errDesc)
}
}
}
}

func TestValidateSource(t *testing.T) {
errorCases := map[string]*buildapi.BuildSource{
string(errs.ValidationErrorTypeRequired) + "git.uri": {
Expand Down
53 changes: 41 additions & 12 deletions pkg/build/client/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ func (c OSClientBuildConfigClient) Update(buildConfig *buildapi.BuildConfig) err
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
Expand All @@ -51,19 +46,53 @@ type OSClientBuildClient struct {
Client osclient.Interface
}

// NewOSClientBuildClient creates a new build client that uses an openshift client to create builds
// NewOSClientBuildClient creates a new build client that uses an openshift client to update 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
}

// BuildCloner provides methods for cloning builds
type BuildCloner interface {
Clone(namespace string, request *buildapi.BuildRequest) (*buildapi.Build, error)
}

// OSClientBuildClonerClient creates a new build client that uses an openshift client to clone builds
type OSClientBuildClonerClient struct {
Client osclient.Interface
}

// NewOSClientBuildClonerClient creates a new build client that uses an openshift client to clone builds
func NewOSClientBuildClonerClient(client osclient.Interface) *OSClientBuildClonerClient {
return &OSClientBuildClonerClient{Client: client}
}

// Clone generates new build for given build name
func (c OSClientBuildClonerClient) Clone(namespace string, request *buildapi.BuildRequest) (*buildapi.Build, error) {
return c.Client.Builds(namespace).Clone(request)
}

// BuildConfigInstantiator provides methods for instantiating builds from build configs
type BuildConfigInstantiator interface {
Instantiate(namespace string, request *buildapi.BuildRequest) (*buildapi.Build, error)
}

// OSClientBuildConfigInstantiatorClient creates a new build client that uses an openshift client to create builds
type OSClientBuildConfigInstantiatorClient struct {
Client osclient.Interface
}

// NewOSClientBuildConfigInstantiatorClient creates a new build client that uses an openshift client to create builds
func NewOSClientBuildConfigInstantiatorClient(client osclient.Interface) *OSClientBuildConfigInstantiatorClient {
return &OSClientBuildConfigInstantiatorClient{Client: client}
}

// Instantiate generates new build for given buildConfig
func (c OSClientBuildConfigInstantiatorClient) Instantiate(namespace string, request *buildapi.BuildRequest) (*buildapi.Build, error) {
return c.Client.BuildConfigs(namespace).Instantiate(request)
}
12 changes: 5 additions & 7 deletions pkg/build/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (

buildapi "github.com/openshift/origin/pkg/build/api"
buildclient "github.com/openshift/origin/pkg/build/client"
buildutil "github.com/openshift/origin/pkg/build/util"
imageapi "github.com/openshift/origin/pkg/image/api"
)

// BuildController watches build resources and manages their state
type BuildController struct {
BuildUpdater buildclient.BuildUpdater
PodManager podManager
BuildStrategy BuildStrategy

BuildUpdater buildclient.BuildUpdater
PodManager podManager
BuildStrategy BuildStrategy
ImageRepositoryClient imageRepositoryClient
}

Expand Down Expand Up @@ -100,8 +100,6 @@ func (bc *BuildController) nextBuildStatus(build *buildapi.Build) error {

// set the expected build parameters, which will be saved if no error occurs
build.Status = buildapi.BuildStatusPending
build.PodName = fmt.Sprintf("build-%s", build.Name)

// override DockerImageReference in the strategy for the copy we send to the server
build.Parameters.Output.DockerImageReference = spec

Expand Down Expand Up @@ -141,7 +139,7 @@ func (bc *BuildPodController) HandlePod(pod *kapi.Pod) error {
var build *buildapi.Build
for _, obj := range bc.BuildStore.List() {
b := obj.(*buildapi.Build)
if b.PodName == pod.Name {
if buildutil.GetBuildPodName(b) == pod.Name {
build = b
break
}
Expand Down
Loading

0 comments on commit b65ab38

Please sign in to comment.