Skip to content

Commit

Permalink
refactor ict to remove from/image parameters
Browse files Browse the repository at this point in the history
also adds from reference support to docker and custom strategies
and updates to use DockerImage kind instead of Image fields internally
  • Loading branch information
bparees committed Apr 29, 2015
1 parent a0646bc commit 8f01437
Show file tree
Hide file tree
Showing 48 changed files with 2,236 additions and 1,794 deletions.
16 changes: 12 additions & 4 deletions assets/app/scripts/filters/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,20 @@ angular.module('openshiftConsole')
};
})
.filter('imageRepoReference', function(){
return function(objectRef, tag){
tag = tag || "latest";
return function(objectRef, kind, tag){
var ns = objectRef.namespace || "";
ns = ns == "" ? ns : ns + "/";
ns = ns === "" ? ns : ns + "/";

if (kind === "ImageStreamTag" || kind === "ImageStreamImage") {
return ns+objectRef.name;
}
var ref = ns + objectRef.name;
ref += " [" + tag + "]";
// until v1beta2, the ImageStreamImage Kind isn't being set so we need to
// manually check if the name looks like an ImageStreamImage
if (objectRef.name.indexOf("@") === -1) {
tag = tag || "latest";
ref += " [" + tag + "]";
}
return ref;
};
});
8 changes: 1 addition & 7 deletions assets/app/scripts/services/applicationGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,7 @@ angular.module("openshiftConsole")
}
if(input.buildConfig.buildOnImageChange){
triggers.push({
imageChange: {
image: dockerSpec,
from:{
name: input.imageName
},
tag: input.imageTag
},
imageChange: {},
type: "imageChange"
});
}
Expand Down
70 changes: 57 additions & 13 deletions assets/app/views/builds.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ <h2>{{buildConfigName}}</h2>
</div>
<div ng-if="buildConfig.parameters.strategy.stiStrategy.from">
<dl class="dl-horizontal">
<dt>Builder image repo [tag]:</dt>
<dd>{{buildConfig.parameters.strategy.stiStrategy.from | imageRepoReference : buildConfig.parameters.strategy.stiStrategy.tag}}
<dt>Builder image stream:</dt>
<dd>{{buildConfig.parameters.strategy.stiStrategy.from | imageRepoReference : buildConfig.parameters.strategy.stiStrategy.from.kind : buildConfig.parameters.strategy.stiStrategy.Tag}}
</dd>
</dl>
</div>
Expand All @@ -40,12 +40,28 @@ <h2>{{buildConfigName}}</h2>
<dd>{{buildConfig.parameters.strategy.dockerStrategy.image}}</dd>
</dl>
</div>
<div ng-if="buildConfig.parameters.strategy.dockerStrategy.from">
<dl class="dl-horizontal">
<dt>Builder image stream:</dt>
<dd>{{buildConfig.parameters.strategy.dockerStrategy.from | imageRepoReference : buildConfig.parameters.strategy.dockerStrategy.from.kind : buildConfig.parameters.strategy.dockerStrategy.Tag}}
</dd>
</dl>
</div>
</div>
<div ng-switch-when="Custom">
<dl class="dl-horizontal">
<dt>Builder image:</dt>
<dd>{{buildConfig.parameters.strategy.customStrategy.image}}</dd>
</dl>
<div ng-if="buildConfig.parameters.strategy.customStrategy.image">
<dl class="dl-horizontal">
<dt>Builder image:</dt>
<dd>{{buildConfig.parameters.strategy.customStrategy.image}}</dd>
</dl>
</div>
<div ng-if="buildConfig.parameters.strategy.customStrategy.from">
<dl class="dl-horizontal">
<dt>Builder image stream:</dt>
<dd>{{buildConfig.parameters.strategy.customStrategy.from | imageRepoReference : buildConfig.parameters.strategy.customStrategy.from.kind : buildConfig.parameters.strategy.customStrategy.Tag}}
</dd>
</dl>
</div>
</div>
</div>
<div ng-if="buildConfig.parameters.source">
Expand Down Expand Up @@ -106,8 +122,41 @@ <h3>Triggers:</h3>
</dd>
</dl>
</span>
<span ng-switch-when="imageChange">
Image change on image repository {{trigger.imageChange.from.name}}:{{trigger.imageChange.tag}}
<span ng-switch-when="imageChange">
<div ng-switch="buildConfig.parameters.strategy.type">
<div ng-switch-when="STI">
<dl class="dl-horizontal" ng-if="buildConfig.parameters.strategy.stiStrategy.from&& buildConfig.parameters.strategy.stiStrategy.from.kind!='ImageStreamImage'">
<dt>
New image for:
</dt>
<dd>
Image stream {{buildConfig.parameters.strategy.stiStrategy.from | imageRepoReference : buildConfig.parameters.strategy.stiStrategy.from.kind : buildConfig.parameters.strategy.stiStrategy.Tag}}
</dd>
</dl>
</div>
<div ng-switch-when="Docker">
<dl class="dl-horizontal" ng-if="buildConfig.parameters.strategy.dockerStrategy.from && buildConfig.parameters.strategy.dockerStrategy.from.kind!='ImageStreamImage'">
<dt>
New image for:
</dt>
<dd>
Image stream {{buildConfig.parameters.strategy.dockerStrategy.from | imageRepoReference : buildConfig.parameters.strategy.dockerStrategy.from.kind : buildConfig.parameters.strategy.dockerStrategy.Tag}}
</dd>
<br>
</dl>
</div>
<div ng-switch-when="Custom">
<dl class="dl-horizontal" ng-if="buildConfig.parameters.strategy.customStrategy.from && buildConfig.parameters.strategy.customStrategy.from.kind!='ImageStreamImage'">
<dt>
New image for:
</dt>
<dd>
Image stream {{buildConfig.parameters.strategy.customStrategy.from | imageRepoReference : buildConfig.parameters.strategy.customStrategy.from.kind : buildConfig.parameters.strategy.customStrategy.Tag}}
</dd>
<br>
</dl>
</div>
</div>
</span>
<span ng-switch-default>{{trigger.type}}</span>
</span>
Expand Down Expand Up @@ -192,11 +241,6 @@ <h3>{{build.metadata.name}}</h3>
</div>
</div>
</div>





</div>
<!-- render any builds whose build configs no longer exist -->
<div class="tile" ng-repeat="(buildConfigName, blds) in buildsByBuildConfig" ng-if="!buildConfigs[buildConfigName]">
Expand Down
8 changes: 1 addition & 7 deletions assets/test/spec/services/applicationGeneratorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,7 @@ describe("ApplicationGenerator", function(){
"type": "github"
},
{
"imageChange" : {
"image" : "172.30.17.58:5000/test/origin-ruby-sample:latest",
"from" : {
"name" : "origin-ruby-sample"
},
"tag" : "latest"
},
"imageChange" : {},
"type" : "imageChange"
}
]
Expand Down
14 changes: 6 additions & 8 deletions examples/sample-app/application-template-custombuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@
}
],
"exposeDockerSocket": true,
"image": "openshift/origin-custom-docker-builder"
"customStrategy": {
"from": {
"name":"origin-custom-docker-builder"
}
}
},
"type": "Custom"
}
Expand All @@ -93,13 +97,7 @@
"type": "generic"
},
{
"imageChange": {
"from": {
"name": "origin-custom-docker-builder"
},
"image": "openshift/origin-custom-docker-builder",
"tag": "latest"
},
"imageChange": {},
"type": "imageChange"
}
]
Expand Down
15 changes: 7 additions & 8 deletions examples/sample-app/application-template-dockerbuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@
"type": "Git"
},
"strategy": {
"type": "Docker"
"type": "Docker",
"dockerStrategy": {
"from": {
"name":"ruby-20-centos7"
}
}
}
},
"triggers": [
Expand All @@ -83,13 +88,7 @@
"type": "generic"
},
{
"imageChange": {
"from": {
"name": "ruby-20-centos7"
},
"image": "openshift/ruby-20-centos7",
"tag": "latest"
},
"imageChange": {},
"type": "imageChange"
}
]
Expand Down
12 changes: 4 additions & 8 deletions examples/sample-app/application-template-stibuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
},
"strategy": {
"stiStrategy": {
"image": "openshift/ruby-20-centos7"
"from": {
"name":"ruby-20-centos7"
}
},
"type": "STI"
}
Expand All @@ -86,13 +88,7 @@
"type": "generic"
},
{
"imageChange": {
"from": {
"name": "ruby-20-centos7"
},
"image": "openshift/ruby-20-centos7",
"tag": "latest"
},
"imageChange": {},
"type": "imageChange"
}
]
Expand Down
9 changes: 1 addition & 8 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ osc process -f examples/sample-app/application-template-dockerbuild.json | osc c
osc get buildConfigs
osc get bc
osc get builds

[[ $(osc describe buildConfigs ruby-sample-build | grep --text "Webhook Github") =~ "${API_SCHEME}://${API_HOST}:${API_PORT}/osapi/v1beta1/buildConfigHooks/ruby-sample-build/secret101/github" ]]
[[ $(osc describe buildConfigs ruby-sample-build | grep --text "Webhook Generic") =~ "${API_SCHEME}://${API_HOST}:${API_PORT}/osapi/v1beta1/buildConfigHooks/ruby-sample-build/secret101/generic" ]]
echo "buildConfig: ok"
Expand All @@ -412,14 +413,6 @@ started=$(osc start-build ruby-sample-build-invalidtag)
echo "start-build: ok"
osc describe build ${started} | grep openshift/ruby-20-centos7$

osc cancel-build "${started}" --dump-logs --restart
# a build for which there is an upstream tag in the corresponding imagerepo, so
# the build should use that specific tag of the image instead of the image field
# as defined in the buildconfig
started=$(osc start-build ruby-sample-build-validtag)
osc describe imagestream ruby-20-centos7-buildcli
osc describe build ${started}
osc describe build ${started} | grep openshift/ruby-20-centos7:success$
osc cancel-build "${started}" --dump-logs --restart
echo "cancel-build: ok"

Expand Down
16 changes: 7 additions & 9 deletions pkg/api/graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,16 @@ func TestGraph(t *testing.T) {
ObjectMeta: kapi.ObjectMeta{Namespace: "default", Name: "build1"},
Triggers: []build.BuildTriggerPolicy{
{
ImageChange: &build.ImageChangeTrigger{
From: kapi.ObjectReference{Name: "test"},
Tag: "base-image",
},
},
{
ImageChange: &build.ImageChangeTrigger{
From: kapi.ObjectReference{},
},
ImageChange: &build.ImageChangeTrigger{},
},
},
Parameters: build.BuildParameters{
Strategy: build.BuildStrategy{
Type: build.STIBuildStrategyType,
STIStrategy: &build.STIBuildStrategy{
From: &kapi.ObjectReference{Kind: "ImageStreamTag", Name: "test:base-image"},
},
},
Output: build.BuildOutput{
To: &kapi.ObjectReference{Name: "other"},
Tag: "tag1",
Expand Down
65 changes: 29 additions & 36 deletions pkg/api/graph/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"fmt"
"sort"
"strconv"
"strings"

"github.com/golang/glog"
"github.com/gonum/graph"

kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"

build "github.com/openshift/origin/pkg/build/api"
buildutil "github.com/openshift/origin/pkg/build/util"
deploy "github.com/openshift/origin/pkg/deploy/api"
image "github.com/openshift/origin/pkg/image/api"
)
Expand Down Expand Up @@ -222,8 +224,9 @@ func ImageStreamTag(g MutableUniqueGraph, namespace, name, tag string) graph.Nod
if len(tag) == 0 {
tag = image.DefaultImageTag
}
uname := UniqueName(fmt.Sprintf("%d|%s/%s:%s", ImageStreamGraphKind, namespace, name, tag))
return EnsureUnique(g,
UniqueName(fmt.Sprintf("%d|%s/%s:%s", ImageStreamGraphKind, namespace, name, tag)),
uname,
func(node Node) graph.Node {
return &ImageStreamTagNode{node, &image.ImageStream{
ObjectMeta: kapi.ObjectMeta{
Expand Down Expand Up @@ -267,43 +270,33 @@ func BuildConfig(g MutableUniqueGraph, config *build.BuildConfig) graph.Node {
g.AddEdge(in, node, BuildInputGraphEdgeKind)
}

// TODO: this belongs in a utility class, and the internal model needs to be simplified
covered := util.StringSet{}
for _, trigger := range config.Triggers {
if trigger.ImageChange != nil {
t := trigger.ImageChange
from := t.From
if len(from.Name) == 0 {
continue
from := buildutil.GetImageStreamForStrategy(config)
if from != nil {
for _, trigger := range config.Triggers {
if trigger.ImageChange != nil {
if len(from.Name) == 0 || from.Kind != "ImageStreamTag" {
continue
}
tag := strings.Split(from.Name, ":")[1]
in := ImageStreamTag(g, defaultNamespace(from.Namespace, config.Namespace), from.Name, tag)
g.AddEdge(in, node, BuildInputImageGraphEdgeKind)
}
covered.Insert(t.Image)
in := ImageStreamTag(g, defaultNamespace(from.Namespace, config.Namespace), from.Name, t.Tag)
g.AddEdge(in, node, BuildInputImageGraphEdgeKind)
}
}
var imageName, tag string
var from *kapi.ObjectReference
switch s := config.Parameters.Strategy; {
case s.DockerStrategy != nil:
imageName = s.DockerStrategy.Image
case s.DockerStrategy != nil:
imageName = s.CustomStrategy.Image
case s.STIStrategy != nil:
imageName, from, tag = s.STIStrategy.Image, s.STIStrategy.From, s.STIStrategy.Tag
if from != nil && len(from.Name) == 0 {
from = nil
}
}
switch {
case from != nil:
in := ImageStreamTag(g, defaultNamespace(from.Namespace, config.Namespace), from.Name, tag)
g.AddEdge(in, node, BuildInputImageGraphEdgeKind)
case len(imageName) > 0 && !covered.Has(imageName):
if ref, err := image.ParseDockerImageReference(imageName); err == nil {
tag := ref.Tag
ref.Tag = ""
in := DockerRepository(g, ref.String(), tag)

switch from.Kind {
case "DockerImage":
if ref, err := image.ParseDockerImageReference(from.Name); err == nil {
tag := ref.Tag
ref.Tag = ""
in := DockerRepository(g, ref.String(), tag)
g.AddEdge(in, node, BuildInputImageGraphEdgeKind)
}
case "ImageStreamTag":
tag := strings.Split(from.Name, ":")[1]
in := ImageStreamTag(g, defaultNamespace(from.Namespace, config.Namespace), from.Name, tag)
g.AddEdge(in, node, BuildInputImageGraphEdgeKind)
case "ImageStreamImage":
glog.V(4).Infof("Ignoring ImageStreamImage reference in buildconfig %s/%s", config.Namespace, config.Name)
}
}
return node
Expand Down
Loading

0 comments on commit 8f01437

Please sign in to comment.