This reverts commit ba587bc7aa10b8ea2a93b00a97781ce0f17e2a0c.
| ... | ... |
@@ -87,7 +87,6 @@ func TestExampleObjectSchemas(t *testing.T) {
|
| 87 | 87 |
"test-route": &routeapi.Route{},
|
| 88 | 88 |
"test-service": &kapi.Service{},
|
| 89 | 89 |
"test-buildcli": &kapi.List{},
|
| 90 |
- "test-buildcli-beta2": &kapi.List{},
|
|
| 91 | 90 |
}, |
| 92 | 91 |
"../test/templates/fixtures": {
|
| 93 | 92 |
"crunchydata-pod": nil, // Explicitly fails validation, but should pass transformation |
| ... | ... |
@@ -177,25 +177,18 @@ This section covers how to perform all the steps of building, deploying, and upd |
| 177 | 177 |
|
| 178 | 178 |
8. Confirm the registry is accessible (you may need to run this more than once): |
| 179 | 179 |
|
| 180 |
- $ export DOCKER_REGISTRY=`osc get service docker-registry --template="{{ .portalIP}}:{{ .port }}"`
|
|
| 181 |
- $ curl $DOCKER_REGISTRY |
|
| 180 |
+ $ curl `osc get service docker-registry --template="{{ .portalIP}}:{{ .port }}"`
|
|
| 182 | 181 |
|
| 183 | 182 |
You should see: |
| 184 | 183 |
|
| 185 | 184 |
"docker-registry server (dev) (v0.9.0)" |
| 186 | 185 |
|
| 187 | 186 |
|
| 188 |
-9. Push builder image to private docker-registry: |
|
| 189 |
- |
|
| 190 |
- $ docker pull openshift/ruby-20-centos7:latest |
|
| 191 |
- $ docker tag -f openshift/ruby-20-centos7:latest ${DOCKER_REGISTRY}/test/ruby-20-centos7:latest
|
|
| 192 |
- $ docker push ${DOCKER_REGISTRY}/test/ruby-20-centos7:latest
|
|
| 193 |
- |
|
| 194 |
-10. Create a new project in OpenShift. This creates a namespace `test` to contain the builds and app that we will generate below. |
|
| 187 |
+9. Create a new project in OpenShift. This creates a namespace `test` to contain the builds and app that we will generate below. |
|
| 195 | 188 |
|
| 196 | 189 |
$ openshift ex new-project test --display-name="OpenShift 3 Sample" --description="This is an example project to demonstrate OpenShift v3" --admin=anypassword:test-admin |
| 197 | 190 |
|
| 198 |
-11. *Optional:* View the OpenShift web console in your browser by browsing to `https://<host>:8444`. Login using the user `test-admin` and any password. |
|
| 191 |
+10. *Optional:* View the OpenShift web console in your browser by browsing to `https://<host>:8444`. Login using the user `test-admin` and any password. |
|
| 199 | 192 |
|
| 200 | 193 |
* You will need to have the browser accept the certificate at |
| 201 | 194 |
`https://<host>:8443` before the console can consult the OpenShift |
| ... | ... |
@@ -206,7 +199,7 @@ This section covers how to perform all the steps of building, deploying, and upd |
| 206 | 206 |
and run builds. |
| 207 | 207 |
|
| 208 | 208 |
|
| 209 |
-12. *Optional:* Fork the [ruby sample repository](https://github.com/openshift/ruby-hello-world) |
|
| 209 |
+11. *Optional:* Fork the [ruby sample repository](https://github.com/openshift/ruby-hello-world) |
|
| 210 | 210 |
to an OpenShift-visible git account that you control, preferably |
| 211 | 211 |
somewhere that can also reach your OpenShift server with a webhook. |
| 212 | 212 |
A github.com account is an obvious place for this, but an in-house |
| ... | ... |
@@ -219,7 +212,7 @@ This section covers how to perform all the steps of building, deploying, and upd |
| 219 | 219 |
Without your own fork, you can still run the initial build from |
| 220 | 220 |
OpenShift's public repository, just not a changed build. |
| 221 | 221 |
|
| 222 |
-13. *Optional:* Add the following webhook under the settings in your new GitHub repository: |
|
| 222 |
+12. *Optional:* Add the following webhook under the settings in your new GitHub repository: |
|
| 223 | 223 |
|
| 224 | 224 |
$ https://<host>:8443/osapi/v1beta1/buildConfigHooks/ruby-sample-build/secret101/github?namespace=test |
| 225 | 225 |
|
| ... | ... |
@@ -230,12 +223,12 @@ This section covers how to perform all the steps of building, deploying, and upd |
| 230 | 230 |
instance as the certificate chain generated is not publicly verified. |
| 231 | 231 |
|
| 232 | 232 |
|
| 233 |
-14. Edit application-template-stibuild.json which will define the sample application |
|
| 233 |
+13. Edit application-template-stibuild.json which will define the sample application |
|
| 234 | 234 |
|
| 235 | 235 |
* Update the BuildConfig's sourceURI (git://github.com/openshift/ruby-hello-world.git) to point to your forked repository. |
| 236 | 236 |
*Note:* You can skip this step if you did not create a forked repository. |
| 237 | 237 |
|
| 238 |
-15. Submit the application template for processing (generating shared parameters requested in the template) |
|
| 238 |
+14. Submit the application template for processing (generating shared parameters requested in the template) |
|
| 239 | 239 |
and then request creation of the processed template: |
| 240 | 240 |
|
| 241 | 241 |
$ osc process -n test -f application-template-stibuild.json | osc create -n test -f - |
| ... | ... |
@@ -254,13 +247,13 @@ This section covers how to perform all the steps of building, deploying, and upd |
| 254 | 254 |
Note that no build has actually occurred yet, so at this time there |
| 255 | 255 |
is no image to deploy and no application to visit. |
| 256 | 256 |
|
| 257 |
-16. Trigger an initial build of your application |
|
| 257 |
+15. Trigger an initial build of your application |
|
| 258 | 258 |
* If you setup the GitHub webhook, push a change to app.rb in your ruby sample repository. |
| 259 | 259 |
* Otherwise you can request a new build by running: |
| 260 | 260 |
|
| 261 | 261 |
$ osc start-build -n test ruby-sample-build |
| 262 | 262 |
|
| 263 |
-17. Monitor the builds and wait for the status to go to "complete" (this can take a few minutes): |
|
| 263 |
+16. Monitor the builds and wait for the status to go to "complete" (this can take a few minutes): |
|
| 264 | 264 |
|
| 265 | 265 |
$ osc get -n test builds |
| 266 | 266 |
|
| ... | ... |
@@ -290,7 +283,7 @@ This section covers how to perform all the steps of building, deploying, and upd |
| 290 | 290 |
automatically trigger a deployment of the application, creating a |
| 291 | 291 |
pod each for the frontend (your Ruby code) and backend. |
| 292 | 292 |
|
| 293 |
-18. Wait for the application's frontend pod and database pods to be started (this can take a few minutes): |
|
| 293 |
+17. Wait for the application's frontend pod and database pods to be started (this can take a few minutes): |
|
| 294 | 294 |
|
| 295 | 295 |
$ osc get -n test pods |
| 296 | 296 |
|
| ... | ... |
@@ -301,7 +294,7 @@ This section covers how to perform all the steps of building, deploying, and upd |
| 301 | 301 |
1b978f62-605f-11e4-b0db-3c970e3bf0b7 mysql localhost.localdomain/ deploymentConfig=,deploymentID=database,name=database,replicationController=1b960e56-605f-11e4-b0db-3c970e3bf0b7,template=ruby-helloworld-sample Running |
| 302 | 302 |
4a792f55-605f-11e4-b0db-3c970e3bf0b7 172.30.17.3:5001/openshift/origin-ruby-sample:9477bdb99a409b9c747e699361ae7934fd83bb4092627e2ee35f9f0b0869885b localhost.localdomain/ deploymentConfig=frontend,deploymentID=frontend-1,name=frontend,replicationController=4a749831-605f-11e4-b0db-3c970e3bf0b7,template=ruby-helloworld-sample Running |
| 303 | 303 |
|
| 304 |
-19. Determine the IP for the frontend service: |
|
| 304 |
+18. Determine the IP for the frontend service: |
|
| 305 | 305 |
|
| 306 | 306 |
$ osc get -n test services |
| 307 | 307 |
|
| ... | ... |
@@ -317,7 +310,7 @@ This section covers how to perform all the steps of building, deploying, and upd |
| 317 | 317 |
|
| 318 | 318 |
*Note:* you can also get this information from the web console. |
| 319 | 319 |
|
| 320 |
-20. Confirm the application is now accessible via the frontend service on port 5432. Go to http://172.30.17.4:5432 (or whatever IP address was reported above) in your browser if you're running this locally; otherwise you can use curl to see the HTML, or port forward the address to your local workstation to visit it. |
|
| 320 |
+19. Confirm the application is now accessible via the frontend service on port 5432. Go to http://172.30.17.4:5432 (or whatever IP address was reported above) in your browser if you're running this locally; otherwise you can use curl to see the HTML, or port forward the address to your local workstation to visit it. |
|
| 321 | 321 |
|
| 322 | 322 |
- - - |
| 323 | 323 |
**VAGRANT USERS:** |
| ... | ... |
@@ -330,14 +323,14 @@ This section covers how to perform all the steps of building, deploying, and upd |
| 330 | 330 |
|
| 331 | 331 |
You should see a welcome page and a form that allows you to query and update key/value pairs. The keys are stored in the database container running in the database pod. |
| 332 | 332 |
|
| 333 |
-21. Make a change to your ruby sample main.html file, commit, and push it via git. |
|
| 333 |
+20. Make a change to your ruby sample main.html file, commit, and push it via git. |
|
| 334 | 334 |
|
| 335 | 335 |
* If you do not have the webhook enabled, you'll have to manually trigger another build: |
| 336 | 336 |
|
| 337 | 337 |
$ osc start-build -n test ruby-sample-build |
| 338 | 338 |
|
| 339 | 339 |
|
| 340 |
-22. Repeat step 17 (waiting for the build to complete). Once the build is complete, refreshing your browser should show your changes. |
|
| 340 |
+21. Repeat step 16 (waiting for the build to complete). Once the build is complete, refreshing your browser should show your changes. |
|
| 341 | 341 |
|
| 342 | 342 |
Congratulations, you've successfully deployed and updated an application on OpenShift. |
| 343 | 343 |
|
| ... | ... |
@@ -329,14 +329,12 @@ openshift ex new-project recreated-project --admin="anypassword:createuser2" |
| 329 | 329 |
osc describe policybinding master -n recreated-project | grep anypassword:createuser2 |
| 330 | 330 |
echo "ex new-project: ok" |
| 331 | 331 |
|
| 332 |
-# Test running a router |
|
| 333 | 332 |
[ ! "$(openshift ex router | grep 'does not exist')"] |
| 334 | 333 |
[ "$(openshift ex router -o yaml --credentials="${OPENSHIFTCONFIG}" | grep 'openshift/origin-haproxy-')" ]
|
| 335 | 334 |
openshift ex router --create --credentials="${OPENSHIFTCONFIG}"
|
| 336 | 335 |
[ "$(openshift ex router | grep 'service exists')" ] |
| 337 | 336 |
echo "ex router: ok" |
| 338 | 337 |
|
| 339 |
-# Test running a registry |
|
| 340 | 338 |
[ ! "$(openshift ex registry | grep 'does not exist')"] |
| 341 | 339 |
[ "$(openshift ex registry -o yaml --credentials="${OPENSHIFTCONFIG}" | grep 'openshift/origin-docker-registry')" ]
|
| 342 | 340 |
openshift ex registry --create --credentials="${OPENSHIFTCONFIG}"
|
| ... | ... |
@@ -232,11 +232,11 @@ echo "[INFO] Installing the registry" |
| 232 | 232 |
# TODO: add --images="${USE_IMAGES}" when the Docker registry is built alongside OpenShift
|
| 233 | 233 |
openshift ex registry --create --credentials="${CERT_DIR}/openshift-registry/.kubeconfig" --mount-host="/tmp/openshift.local.registry" --images='openshift/origin-${component}:latest'
|
| 234 | 234 |
|
| 235 |
-echo "[INFO] Pre-pulling and pushing ruby-20-centos7" |
|
| 236 |
-docker pull openshift/ruby-20-centos7:latest |
|
| 235 |
+echo "[INFO] Pre-pulling and pushing centos7" |
|
| 236 |
+docker pull centos:centos7 |
|
| 237 | 237 |
# TODO: remove after this becomes part of the build |
| 238 | 238 |
docker pull openshift/origin-docker-registry |
| 239 |
-echo "[INFO] Pulled ruby-20-centos7" |
|
| 239 |
+echo "[INFO] Pulled centos7" |
|
| 240 | 240 |
|
| 241 | 241 |
echo "[INFO] Waiting for Docker registry pod to start" |
| 242 | 242 |
# TODO: simplify when #4702 is fixed upstream |
| ... | ... |
@@ -250,9 +250,9 @@ wait_for_url_timed "http://${DOCKER_REGISTRY}" "[INFO] Docker registry says: " $
|
| 250 | 250 |
|
| 251 | 251 |
[ "$(dig @${API_HOST} "docker-registry.default.local." A)" ]
|
| 252 | 252 |
|
| 253 |
-docker tag -f openshift/ruby-20-centos7:latest ${DOCKER_REGISTRY}/test/ruby-20-centos7:latest
|
|
| 254 |
-docker push ${DOCKER_REGISTRY}/test/ruby-20-centos7:latest
|
|
| 255 |
-echo "[INFO] Pushed ruby-20-centos7" |
|
| 253 |
+docker tag -f centos:centos7 ${DOCKER_REGISTRY}/cached/centos:centos7
|
|
| 254 |
+docker push ${DOCKER_REGISTRY}/cached/centos:centos7
|
|
| 255 |
+echo "[INFO] Pushed centos7" |
|
| 256 | 256 |
|
| 257 | 257 |
# Process template and create |
| 258 | 258 |
echo "[INFO] Submitting application template json for processing..." |
| ... | ... |
@@ -48,7 +48,7 @@ type BuildParameters struct {
|
| 48 | 48 |
Revision *SourceRevision `json:"revision,omitempty"` |
| 49 | 49 |
|
| 50 | 50 |
// Strategy defines how to perform a build. |
| 51 |
- Strategy BuildStrategy `json:"strategy"` |
|
| 51 |
+ Strategy BuildStrategy `json:"strategy,omitempty"` |
|
| 52 | 52 |
|
| 53 | 53 |
// Output describes the Docker image the Strategy should produce. |
| 54 | 54 |
Output BuildOutput `json:"output,omitempty"` |
| ... | ... |
@@ -142,7 +142,7 @@ type SourceControlUser struct {
|
| 142 | 142 |
// BuildStrategy contains the details of how to perform a build. |
| 143 | 143 |
type BuildStrategy struct {
|
| 144 | 144 |
// Type is the kind of build strategy. |
| 145 |
- Type BuildStrategyType `json:"type"` |
|
| 145 |
+ Type BuildStrategyType `json:"type,omitempty"` |
|
| 146 | 146 |
|
| 147 | 147 |
// DockerStrategy holds the parameters to the Docker build strategy. |
| 148 | 148 |
DockerStrategy *DockerBuildStrategy `json:"dockerStrategy,omitempty"` |
| ... | ... |
@@ -209,16 +209,8 @@ type DockerBuildStrategy struct {
|
| 209 | 209 |
// STIBuildStrategy defines input parameters specific to an STI build. |
| 210 | 210 |
type STIBuildStrategy struct {
|
| 211 | 211 |
// Image is the image used to execute the build. |
| 212 |
- // Only valid if From is not present. |
|
| 213 | 212 |
Image string `json:"image,omitempty"` |
| 214 | 213 |
|
| 215 |
- // From is reference to an image repository from where the docker image should be pulled |
|
| 216 |
- From *kapi.ObjectReference `json:"from,omitempty"` |
|
| 217 |
- |
|
| 218 |
- // Tag is the name of image repository tag to be used as the build image, it only |
|
| 219 |
- // applies when From is specified. |
|
| 220 |
- Tag string `json:"tag,omitempty` |
|
| 221 |
- |
|
| 222 | 214 |
// Additional environment variables you want to pass into a builder container |
| 223 | 215 |
Env []kapi.EnvVar `json:"env,omitempty"` |
| 224 | 216 |
|
| ... | ... |
@@ -53,27 +53,11 @@ func init() {
|
| 53 | 53 |
func(in *newer.STIBuildStrategy, out *STIBuildStrategy, s conversion.Scope) error {
|
| 54 | 54 |
out.BuilderImage = in.Image |
| 55 | 55 |
out.Image = in.Image |
| 56 |
- if in.From != nil {
|
|
| 57 |
- out.From = &kapi.ObjectReference{
|
|
| 58 |
- Name: in.From.Name, |
|
| 59 |
- Namespace: in.From.Namespace, |
|
| 60 |
- Kind: "ImageRepository", |
|
| 61 |
- } |
|
| 62 |
- } |
|
| 63 |
- out.Tag = in.Tag |
|
| 64 | 56 |
out.Scripts = in.Scripts |
| 65 | 57 |
out.Clean = !in.Incremental |
| 66 | 58 |
return s.Convert(&in.Env, &out.Env, 0) |
| 67 | 59 |
}, |
| 68 | 60 |
func(in *STIBuildStrategy, out *newer.STIBuildStrategy, s conversion.Scope) error {
|
| 69 |
- if in.From != nil {
|
|
| 70 |
- out.From = &api.ObjectReference{
|
|
| 71 |
- Name: in.From.Name, |
|
| 72 |
- Namespace: in.From.Namespace, |
|
| 73 |
- Kind: "ImageRepository", |
|
| 74 |
- } |
|
| 75 |
- } |
|
| 76 |
- out.Tag = in.Tag |
|
| 77 | 61 |
out.Scripts = in.Scripts |
| 78 | 62 |
out.Incremental = !in.Clean |
| 79 | 63 |
if len(in.Image) != 0 {
|
| ... | ... |
@@ -26,12 +26,6 @@ func TestSTIBuildStrategyConversion(t *testing.T) {
|
| 26 | 26 |
if actual.Image != oldVersion.BuilderImage {
|
| 27 | 27 |
t.Errorf("expected %v, actual %v", oldVersion.BuilderImage, actual.Image)
|
| 28 | 28 |
} |
| 29 |
- if actual.From != nil {
|
|
| 30 |
- t.Errorf("expected %v, actual %v", nil, actual.From)
|
|
| 31 |
- } |
|
| 32 |
- if actual.Tag != oldVersion.Tag {
|
|
| 33 |
- t.Errorf("expected %v, actual %v", oldVersion.Tag, actual.Tag)
|
|
| 34 |
- } |
|
| 35 | 29 |
if actual.Incremental == oldVersion.Clean {
|
| 36 | 30 |
t.Errorf("expected %v, actual %v", oldVersion.Clean, actual.Incremental)
|
| 37 | 31 |
} |
| ... | ... |
@@ -48,7 +48,7 @@ type BuildParameters struct {
|
| 48 | 48 |
Revision *SourceRevision `json:"revision,omitempty"` |
| 49 | 49 |
|
| 50 | 50 |
// Strategy defines how to perform a build. |
| 51 |
- Strategy BuildStrategy `json:"strategy"` |
|
| 51 |
+ Strategy BuildStrategy `json:"strategy,omitempty"` |
|
| 52 | 52 |
|
| 53 | 53 |
// Output describes the Docker image the Strategy should produce. |
| 54 | 54 |
Output BuildOutput `json:"output,omitempty"` |
| ... | ... |
@@ -142,7 +142,7 @@ type SourceControlUser struct {
|
| 142 | 142 |
// BuildStrategy contains the details of how to perform a build. |
| 143 | 143 |
type BuildStrategy struct {
|
| 144 | 144 |
// Type is the kind of build strategy. |
| 145 |
- Type BuildStrategyType `json:"type"` |
|
| 145 |
+ Type BuildStrategyType `json:"type,omitempty"` |
|
| 146 | 146 |
|
| 147 | 147 |
// DockerStrategy holds the parameters to the Docker build strategy. |
| 148 | 148 |
DockerStrategy *DockerBuildStrategy `json:"dockerStrategy,omitempty"` |
| ... | ... |
@@ -214,17 +214,8 @@ type STIBuildStrategy struct {
|
| 214 | 214 |
BuilderImage string `json:"builderImage,omitempty"` |
| 215 | 215 |
|
| 216 | 216 |
// Image is the image used to execute the build. |
| 217 |
- // For BuildConfigs, From takes precedence. |
|
| 218 | 217 |
Image string `json:"image,omitempty"` |
| 219 | 218 |
|
| 220 |
- // Tag is the name of image repository tag to be used as the build image, it only |
|
| 221 |
- // applies when From is specified. |
|
| 222 |
- Tag string `json:"tag,omitempty"` |
|
| 223 |
- |
|
| 224 |
- // From is reference to an image repository from where the docker image should be pulled |
|
| 225 |
- // Only allowed in BuildConfigs, Builds use the Image field exclusively. |
|
| 226 |
- From *kapi.ObjectReference `json:"from,omitempty"` |
|
| 227 |
- |
|
| 228 | 219 |
// Additional environment variables you want to pass into a builder container |
| 229 | 220 |
Env []kapi.EnvVar `json:"env,omitempty"` |
| 230 | 221 |
|
| ... | ... |
@@ -144,22 +144,23 @@ func validateBuildConfigOutput(output *buildapi.BuildOutput) errs.ValidationErro |
| 144 | 144 |
func validateStrategy(strategy *buildapi.BuildStrategy) errs.ValidationErrorList {
|
| 145 | 145 |
allErrs := errs.ValidationErrorList{}
|
| 146 | 146 |
|
| 147 |
- switch {
|
|
| 148 |
- case len(strategy.Type) == 0: |
|
| 147 |
+ if len(strategy.Type) == 0 {
|
|
| 149 | 148 |
allErrs = append(allErrs, errs.NewFieldRequired("type"))
|
| 149 |
+ } |
|
| 150 | 150 |
|
| 151 |
- case strategy.Type == buildapi.STIBuildStrategyType: |
|
| 151 |
+ switch strategy.Type {
|
|
| 152 |
+ case buildapi.STIBuildStrategyType: |
|
| 152 | 153 |
if strategy.STIStrategy == nil {
|
| 153 | 154 |
allErrs = append(allErrs, errs.NewFieldRequired("stiStrategy"))
|
| 154 | 155 |
} else {
|
| 155 | 156 |
allErrs = append(allErrs, validateSTIStrategy(strategy.STIStrategy).Prefix("stiStrategy")...)
|
| 156 | 157 |
} |
| 157 |
- case strategy.Type == buildapi.DockerBuildStrategyType: |
|
| 158 |
+ case buildapi.DockerBuildStrategyType: |
|
| 158 | 159 |
// DockerStrategy is currently optional, initialize it to a default state if it's not set. |
| 159 | 160 |
if strategy.DockerStrategy == nil {
|
| 160 | 161 |
strategy.DockerStrategy = &buildapi.DockerBuildStrategy{}
|
| 161 | 162 |
} |
| 162 |
- case strategy.Type == buildapi.CustomBuildStrategyType: |
|
| 163 |
+ case buildapi.CustomBuildStrategyType: |
|
| 163 | 164 |
if strategy.CustomStrategy == nil {
|
| 164 | 165 |
allErrs = append(allErrs, errs.NewFieldRequired("customStrategy"))
|
| 165 | 166 |
} else {
|
| ... | ... |
@@ -177,11 +178,8 @@ func validateStrategy(strategy *buildapi.BuildStrategy) errs.ValidationErrorList |
| 177 | 177 |
|
| 178 | 178 |
func validateSTIStrategy(strategy *buildapi.STIBuildStrategy) errs.ValidationErrorList {
|
| 179 | 179 |
allErrs := errs.ValidationErrorList{}
|
| 180 |
- if (strategy.From == nil || len(strategy.From.Name) == 0) && len(strategy.Image) == 0 {
|
|
| 181 |
- allErrs = append(allErrs, errs.NewFieldRequired("from"))
|
|
| 182 |
- } |
|
| 183 |
- if (strategy.From != nil && len(strategy.From.Name) != 0) && len(strategy.Image) != 0 {
|
|
| 184 |
- allErrs = append(allErrs, errs.NewFieldInvalid("image", strategy.Image, "only one of 'image' and 'from' may be set"))
|
|
| 180 |
+ if len(strategy.Image) == 0 {
|
|
| 181 |
+ allErrs = append(allErrs, errs.NewFieldRequired("image"))
|
|
| 185 | 182 |
} |
| 186 | 183 |
return allErrs |
| 187 | 184 |
} |
| ... | ... |
@@ -76,9 +76,7 @@ func TestBuildConfigValidationSuccess(t *testing.T) {
|
| 76 | 76 |
Type: buildapi.DockerBuildStrategyType, |
| 77 | 77 |
DockerStrategy: &buildapi.DockerBuildStrategy{},
|
| 78 | 78 |
}, |
| 79 |
- Output: buildapi.BuildOutput{
|
|
| 80 |
- DockerImageReference: "repository/data", |
|
| 81 |
- }, |
|
| 79 |
+ Output: buildapi.BuildOutput{},
|
|
| 82 | 80 |
}, |
| 83 | 81 |
} |
| 84 | 82 |
if result := ValidateBuildConfig(buildConfig); len(result) > 0 {
|
| ... | ... |
@@ -277,7 +275,7 @@ func TestValidateBuildParameters(t *testing.T) {
|
| 277 | 277 |
}, |
| 278 | 278 |
}, |
| 279 | 279 |
{
|
| 280 |
- string(errs.ValidationErrorTypeInvalid) + "strategy.type", |
|
| 280 |
+ string(errs.ValidationErrorTypeRequired) + "strategy.stiStrategy.image", |
|
| 281 | 281 |
&buildapi.BuildParameters{
|
| 282 | 282 |
Source: buildapi.BuildSource{
|
| 283 | 283 |
Type: buildapi.BuildSourceGit, |
| ... | ... |
@@ -285,70 +283,15 @@ func TestValidateBuildParameters(t *testing.T) {
|
| 285 | 285 |
URI: "http://github.com/my/repository", |
| 286 | 286 |
}, |
| 287 | 287 |
}, |
| 288 |
- Strategy: buildapi.BuildStrategy{Type: "classic-joke"},
|
|
| 289 | 288 |
Output: buildapi.BuildOutput{
|
| 290 | 289 |
DockerImageReference: "repository/data", |
| 291 | 290 |
}, |
| 292 |
- }, |
|
| 293 |
- }, |
|
| 294 |
- {
|
|
| 295 |
- string(errs.ValidationErrorTypeRequired) + "strategy.type", |
|
| 296 |
- &buildapi.BuildParameters{
|
|
| 297 |
- Source: buildapi.BuildSource{
|
|
| 298 |
- Type: buildapi.BuildSourceGit, |
|
| 299 |
- Git: &buildapi.GitBuildSource{
|
|
| 300 |
- URI: "http://github.com/my/repository", |
|
| 301 |
- }, |
|
| 302 |
- }, |
|
| 303 |
- Strategy: buildapi.BuildStrategy{},
|
|
| 304 |
- Output: buildapi.BuildOutput{
|
|
| 305 |
- DockerImageReference: "repository/data", |
|
| 306 |
- }, |
|
| 307 |
- }, |
|
| 308 |
- }, |
|
| 309 |
- // invalid because both image and from are specified in the |
|
| 310 |
- // sti strategy definition |
|
| 311 |
- {
|
|
| 312 |
- string(errs.ValidationErrorTypeInvalid) + "strategy.stiStrategy.image", |
|
| 313 |
- &buildapi.BuildParameters{
|
|
| 314 |
- Source: buildapi.BuildSource{
|
|
| 315 |
- Type: buildapi.BuildSourceGit, |
|
| 316 |
- Git: &buildapi.GitBuildSource{
|
|
| 317 |
- URI: "http://github.com/my/repository", |
|
| 318 |
- }, |
|
| 319 |
- }, |
|
| 320 | 291 |
Strategy: buildapi.BuildStrategy{
|
| 321 | 292 |
Type: buildapi.STIBuildStrategyType, |
| 322 | 293 |
STIStrategy: &buildapi.STIBuildStrategy{
|
| 323 |
- Image: "image", |
|
| 324 |
- From: &kapi.ObjectReference{
|
|
| 325 |
- Name: "reponame", |
|
| 326 |
- }, |
|
| 327 |
- }, |
|
| 328 |
- }, |
|
| 329 |
- Output: buildapi.BuildOutput{
|
|
| 330 |
- DockerImageReference: "repository/data", |
|
| 331 |
- }, |
|
| 332 |
- }, |
|
| 333 |
- }, |
|
| 334 |
- // invalid because neither image nor from are specified in the |
|
| 335 |
- // sti strategy definition |
|
| 336 |
- {
|
|
| 337 |
- string(errs.ValidationErrorTypeRequired) + "strategy.stiStrategy.from", |
|
| 338 |
- &buildapi.BuildParameters{
|
|
| 339 |
- Source: buildapi.BuildSource{
|
|
| 340 |
- Type: buildapi.BuildSourceGit, |
|
| 341 |
- Git: &buildapi.GitBuildSource{
|
|
| 342 |
- URI: "http://github.com/my/repository", |
|
| 294 |
+ Image: "", |
|
| 343 | 295 |
}, |
| 344 | 296 |
}, |
| 345 |
- Strategy: buildapi.BuildStrategy{
|
|
| 346 |
- Type: buildapi.STIBuildStrategyType, |
|
| 347 |
- STIStrategy: &buildapi.STIBuildStrategy{},
|
|
| 348 |
- }, |
|
| 349 |
- Output: buildapi.BuildOutput{
|
|
| 350 |
- DockerImageReference: "repository/data", |
|
| 351 |
- }, |
|
| 352 | 297 |
}, |
| 353 | 298 |
}, |
| 354 | 299 |
} |
| ... | ... |
@@ -366,61 +309,6 @@ func TestValidateBuildParameters(t *testing.T) {
|
| 366 | 366 |
} |
| 367 | 367 |
} |
| 368 | 368 |
|
| 369 |
-func TestValidateBuildParametersSuccess(t *testing.T) {
|
|
| 370 |
- testCases := []struct {
|
|
| 371 |
- *buildapi.BuildParameters |
|
| 372 |
- }{
|
|
| 373 |
- {
|
|
| 374 |
- &buildapi.BuildParameters{
|
|
| 375 |
- Source: buildapi.BuildSource{
|
|
| 376 |
- Type: buildapi.BuildSourceGit, |
|
| 377 |
- Git: &buildapi.GitBuildSource{
|
|
| 378 |
- URI: "http://github.com/my/repository", |
|
| 379 |
- }, |
|
| 380 |
- }, |
|
| 381 |
- Strategy: buildapi.BuildStrategy{
|
|
| 382 |
- Type: buildapi.STIBuildStrategyType, |
|
| 383 |
- STIStrategy: &buildapi.STIBuildStrategy{
|
|
| 384 |
- Image: "repository/builder-image", |
|
| 385 |
- }, |
|
| 386 |
- }, |
|
| 387 |
- Output: buildapi.BuildOutput{
|
|
| 388 |
- DockerImageReference: "repository/data", |
|
| 389 |
- }, |
|
| 390 |
- }, |
|
| 391 |
- }, |
|
| 392 |
- {
|
|
| 393 |
- &buildapi.BuildParameters{
|
|
| 394 |
- Source: buildapi.BuildSource{
|
|
| 395 |
- Type: buildapi.BuildSourceGit, |
|
| 396 |
- Git: &buildapi.GitBuildSource{
|
|
| 397 |
- URI: "http://github.com/my/repository", |
|
| 398 |
- }, |
|
| 399 |
- }, |
|
| 400 |
- Strategy: buildapi.BuildStrategy{
|
|
| 401 |
- Type: buildapi.STIBuildStrategyType, |
|
| 402 |
- STIStrategy: &buildapi.STIBuildStrategy{
|
|
| 403 |
- From: &kapi.ObjectReference{
|
|
| 404 |
- Name: "reponame", |
|
| 405 |
- }, |
|
| 406 |
- }, |
|
| 407 |
- }, |
|
| 408 |
- Output: buildapi.BuildOutput{
|
|
| 409 |
- DockerImageReference: "repository/data", |
|
| 410 |
- }, |
|
| 411 |
- }, |
|
| 412 |
- }, |
|
| 413 |
- } |
|
| 414 |
- |
|
| 415 |
- for _, config := range testCases {
|
|
| 416 |
- errors := validateBuildParameters(config.BuildParameters) |
|
| 417 |
- if len(errors) != 0 {
|
|
| 418 |
- t.Errorf("Unexpected validation error: %v", errors)
|
|
| 419 |
- } |
|
| 420 |
- } |
|
| 421 |
- |
|
| 422 |
-} |
|
| 423 |
- |
|
| 424 | 369 |
func TestValidateTrigger(t *testing.T) {
|
| 425 | 370 |
tests := map[string]struct {
|
| 426 | 371 |
trigger buildapi.BuildTriggerPolicy |
| ... | ... |
@@ -8,7 +8,6 @@ import ( |
| 8 | 8 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache" |
| 9 | 9 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" |
| 10 | 10 |
|
| 11 |
- kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
|
| 12 | 11 |
buildapi "github.com/openshift/origin/pkg/build/api" |
| 13 | 12 |
buildclient "github.com/openshift/origin/pkg/build/client" |
| 14 | 13 |
buildutil "github.com/openshift/origin/pkg/build/util" |
| ... | ... |
@@ -38,8 +37,7 @@ type ImageChangeController struct {
|
| 38 | 38 |
// HandleImageRepo processes the next ImageRepository event. |
| 39 | 39 |
func (c *ImageChangeController) HandleImageRepo(repo *imageapi.ImageRepository) error {
|
| 40 | 40 |
glog.V(4).Infof("Build image change controller detected imagerepo change %s", repo.Status.DockerImageRepository)
|
| 41 |
- imageSubs := make(map[string]string) |
|
| 42 |
- repoSubs := make(map[kapi.ObjectReference]string) |
|
| 41 |
+ subs := make(map[string]string) |
|
| 43 | 42 |
|
| 44 | 43 |
// TODO: this is inefficient |
| 45 | 44 |
for _, bc := range c.BuildConfigStore.List() {
|
| ... | ... |
@@ -75,8 +73,7 @@ func (c *ImageChangeController) HandleImageRepo(repo *imageapi.ImageRepository) |
| 75 | 75 |
next = latest.DockerImageReference |
| 76 | 76 |
} |
| 77 | 77 |
if len(last) == 0 || next != last {
|
| 78 |
- imageSubs[change.Image] = latest.DockerImageReference |
|
| 79 |
- repoSubs[change.From] = latest.DockerImageReference |
|
| 78 |
+ subs[change.Image] = latest.DockerImageReference |
|
| 80 | 79 |
change.LastTriggeredImageID = next |
| 81 | 80 |
shouldBuild = true |
| 82 | 81 |
} |
| ... | ... |
@@ -84,7 +81,7 @@ func (c *ImageChangeController) HandleImageRepo(repo *imageapi.ImageRepository) |
| 84 | 84 |
|
| 85 | 85 |
if shouldBuild {
|
| 86 | 86 |
glog.V(4).Infof("Running build for buildConfig %s in namespace %s", config.Name, config.Namespace)
|
| 87 |
- b := buildutil.GenerateBuildFromConfig(config, nil, imageSubs, repoSubs) |
|
| 87 |
+ b := buildutil.GenerateBuildFromConfig(config, nil, subs) |
|
| 88 | 88 |
if err := c.BuildCreator.Create(config.Namespace, b); err != nil {
|
| 89 | 89 |
return fmt.Errorf("error starting build for buildConfig %s: %v", config.Name, err)
|
| 90 | 90 |
} |
| ... | ... |
@@ -255,37 +255,6 @@ func mockBuildConfig() *api.BuildConfig {
|
| 255 | 255 |
} |
| 256 | 256 |
} |
| 257 | 257 |
|
| 258 |
-func mockBuildConfigImageRef() *api.BuildConfig {
|
|
| 259 |
- return &api.BuildConfig{
|
|
| 260 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 261 |
- Name: "data-build", |
|
| 262 |
- Namespace: kapi.NamespaceDefault, |
|
| 263 |
- Labels: map[string]string{
|
|
| 264 |
- "name": "data-build", |
|
| 265 |
- }, |
|
| 266 |
- }, |
|
| 267 |
- Parameters: api.BuildParameters{
|
|
| 268 |
- Source: api.BuildSource{
|
|
| 269 |
- Type: api.BuildSourceGit, |
|
| 270 |
- Git: &api.GitBuildSource{
|
|
| 271 |
- URI: "http://my.build.com/the/build/Dockerfile", |
|
| 272 |
- }, |
|
| 273 |
- }, |
|
| 274 |
- Strategy: api.BuildStrategy{
|
|
| 275 |
- Type: api.STIBuildStrategyType, |
|
| 276 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 277 |
- From: &kapi.ObjectReference{
|
|
| 278 |
- Name: "builder/image", |
|
| 279 |
- }, |
|
| 280 |
- }, |
|
| 281 |
- }, |
|
| 282 |
- Output: api.BuildOutput{
|
|
| 283 |
- DockerImageReference: "repository/data-build", |
|
| 284 |
- }, |
|
| 285 |
- }, |
|
| 286 |
- } |
|
| 287 |
-} |
|
| 288 |
- |
|
| 289 | 258 |
func TestUpdateBuildConfig(t *testing.T) {
|
| 290 | 259 |
mockRegistry := test.BuildConfigRegistry{}
|
| 291 | 260 |
storage := REST{&mockRegistry}
|
| ... | ... |
@@ -321,143 +290,69 @@ func TestUpdateBuildConfigError(t *testing.T) {
|
| 321 | 321 |
func TestBuildConfigRESTValidatesCreate(t *testing.T) {
|
| 322 | 322 |
mockRegistry := test.BuildConfigRegistry{}
|
| 323 | 323 |
storage := REST{&mockRegistry}
|
| 324 |
- failureCases := map[string]struct {
|
|
| 325 |
- expectSuccess bool |
|
| 326 |
- data api.BuildConfig |
|
| 327 |
- }{
|
|
| 324 |
+ failureCases := map[string]api.BuildConfig{
|
|
| 328 | 325 |
"blank sourceURI": {
|
| 329 |
- false, |
|
| 330 |
- api.BuildConfig{
|
|
| 331 |
- ObjectMeta: kapi.ObjectMeta{Name: "abc"},
|
|
| 332 |
- Parameters: api.BuildParameters{
|
|
| 333 |
- Source: api.BuildSource{
|
|
| 334 |
- Type: api.BuildSourceGit, |
|
| 335 |
- Git: &api.GitBuildSource{
|
|
| 336 |
- URI: "", |
|
| 337 |
- }, |
|
| 326 |
+ ObjectMeta: kapi.ObjectMeta{Name: "abc"},
|
|
| 327 |
+ Parameters: api.BuildParameters{
|
|
| 328 |
+ Source: api.BuildSource{
|
|
| 329 |
+ Type: api.BuildSourceGit, |
|
| 330 |
+ Git: &api.GitBuildSource{
|
|
| 331 |
+ URI: "", |
|
| 338 | 332 |
}, |
| 339 |
- Strategy: api.BuildStrategy{
|
|
| 340 |
- Type: api.STIBuildStrategyType, |
|
| 341 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 342 |
- From: &kapi.ObjectReference{
|
|
| 343 |
- Name: "builder/image", |
|
| 344 |
- }, |
|
| 345 |
- }, |
|
| 346 |
- }, |
|
| 347 |
- Output: api.BuildOutput{
|
|
| 348 |
- DockerImageReference: "data/image", |
|
| 333 |
+ }, |
|
| 334 |
+ Strategy: api.BuildStrategy{
|
|
| 335 |
+ Type: api.STIBuildStrategyType, |
|
| 336 |
+ STIStrategy: &api.STIBuildStrategy{
|
|
| 337 |
+ Image: "builder/image", |
|
| 349 | 338 |
}, |
| 350 | 339 |
}, |
| 340 |
+ Output: api.BuildOutput{
|
|
| 341 |
+ DockerImageReference: "data/image", |
|
| 342 |
+ }, |
|
| 351 | 343 |
}, |
| 352 | 344 |
}, |
| 353 | 345 |
"blank DockerImageReference": {
|
| 354 |
- true, |
|
| 355 |
- api.BuildConfig{
|
|
| 356 |
- ObjectMeta: kapi.ObjectMeta{Name: "abc"},
|
|
| 357 |
- Parameters: api.BuildParameters{
|
|
| 358 |
- Source: api.BuildSource{
|
|
| 359 |
- Type: api.BuildSourceGit, |
|
| 360 |
- Git: &api.GitBuildSource{
|
|
| 361 |
- URI: "http://github.com/test/source", |
|
| 362 |
- }, |
|
| 363 |
- }, |
|
| 364 |
- Strategy: api.BuildStrategy{
|
|
| 365 |
- Type: api.STIBuildStrategyType, |
|
| 366 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 367 |
- From: &kapi.ObjectReference{
|
|
| 368 |
- Name: "builder/image", |
|
| 369 |
- }, |
|
| 370 |
- }, |
|
| 371 |
- }, |
|
| 372 |
- Output: api.BuildOutput{
|
|
| 373 |
- DockerImageReference: "", |
|
| 346 |
+ ObjectMeta: kapi.ObjectMeta{Name: "abc"},
|
|
| 347 |
+ Parameters: api.BuildParameters{
|
|
| 348 |
+ Source: api.BuildSource{
|
|
| 349 |
+ Type: api.BuildSourceGit, |
|
| 350 |
+ Git: &api.GitBuildSource{
|
|
| 351 |
+ URI: "http://github.com/test/source", |
|
| 374 | 352 |
}, |
| 375 | 353 |
}, |
| 376 |
- }, |
|
| 377 |
- }, |
|
| 378 |
- "blank From.Name and blank Image": {
|
|
| 379 |
- false, |
|
| 380 |
- api.BuildConfig{
|
|
| 381 |
- ObjectMeta: kapi.ObjectMeta{Name: "abc"},
|
|
| 382 |
- Parameters: api.BuildParameters{
|
|
| 383 |
- Source: api.BuildSource{
|
|
| 384 |
- Type: api.BuildSourceGit, |
|
| 385 |
- Git: &api.GitBuildSource{
|
|
| 386 |
- URI: "http://github.com/test/source", |
|
| 387 |
- }, |
|
| 388 |
- }, |
|
| 389 |
- Strategy: api.BuildStrategy{
|
|
| 390 |
- Type: api.STIBuildStrategyType, |
|
| 391 |
- STIStrategy: &api.STIBuildStrategy{},
|
|
| 392 |
- }, |
|
| 393 |
- Output: api.BuildOutput{
|
|
| 394 |
- DockerImageReference: "data/image", |
|
| 395 |
- }, |
|
| 354 |
+ Output: api.BuildOutput{
|
|
| 355 |
+ DockerImageReference: "", |
|
| 396 | 356 |
}, |
| 397 | 357 |
}, |
| 398 | 358 |
}, |
| 399 |
- "blank From.Name and Image present": {
|
|
| 400 |
- true, |
|
| 401 |
- api.BuildConfig{
|
|
| 402 |
- ObjectMeta: kapi.ObjectMeta{Name: "abc"},
|
|
| 403 |
- Parameters: api.BuildParameters{
|
|
| 404 |
- Source: api.BuildSource{
|
|
| 405 |
- Type: api.BuildSourceGit, |
|
| 406 |
- Git: &api.GitBuildSource{
|
|
| 407 |
- URI: "http://github.com/test/source", |
|
| 408 |
- }, |
|
| 409 |
- }, |
|
| 410 |
- Strategy: api.BuildStrategy{
|
|
| 411 |
- Type: api.STIBuildStrategyType, |
|
| 412 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 413 |
- Image: "builder/image", |
|
| 414 |
- }, |
|
| 415 |
- }, |
|
| 416 |
- Output: api.BuildOutput{
|
|
| 417 |
- DockerImageReference: "data/image", |
|
| 359 |
+ "blank Image": {
|
|
| 360 |
+ ObjectMeta: kapi.ObjectMeta{Name: "abc"},
|
|
| 361 |
+ Parameters: api.BuildParameters{
|
|
| 362 |
+ Source: api.BuildSource{
|
|
| 363 |
+ Type: api.BuildSourceGit, |
|
| 364 |
+ Git: &api.GitBuildSource{
|
|
| 365 |
+ URI: "http://github.com/test/source", |
|
| 418 | 366 |
}, |
| 419 | 367 |
}, |
| 420 |
- }, |
|
| 421 |
- }, |
|
| 422 |
- "blank Image and From.Name present": {
|
|
| 423 |
- true, |
|
| 424 |
- api.BuildConfig{
|
|
| 425 |
- ObjectMeta: kapi.ObjectMeta{Name: "abc"},
|
|
| 426 |
- Parameters: api.BuildParameters{
|
|
| 427 |
- Source: api.BuildSource{
|
|
| 428 |
- Type: api.BuildSourceGit, |
|
| 429 |
- Git: &api.GitBuildSource{
|
|
| 430 |
- URI: "http://github.com/test/source", |
|
| 431 |
- }, |
|
| 432 |
- }, |
|
| 433 |
- Strategy: api.BuildStrategy{
|
|
| 434 |
- Type: api.STIBuildStrategyType, |
|
| 435 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 436 |
- From: &kapi.ObjectReference{
|
|
| 437 |
- Name: "builder/image", |
|
| 438 |
- }, |
|
| 439 |
- }, |
|
| 440 |
- }, |
|
| 441 |
- Output: api.BuildOutput{
|
|
| 442 |
- DockerImageReference: "data/image", |
|
| 368 |
+ Strategy: api.BuildStrategy{
|
|
| 369 |
+ Type: api.STIBuildStrategyType, |
|
| 370 |
+ STIStrategy: &api.STIBuildStrategy{
|
|
| 371 |
+ Image: "", |
|
| 443 | 372 |
}, |
| 444 | 373 |
}, |
| 374 |
+ Output: api.BuildOutput{
|
|
| 375 |
+ DockerImageReference: "data/image", |
|
| 376 |
+ }, |
|
| 445 | 377 |
}, |
| 446 | 378 |
}, |
| 447 | 379 |
} |
| 448 |
- for desc, testCase := range failureCases {
|
|
| 449 |
- c, err := storage.Create(kapi.NewDefaultContext(), &testCase.data) |
|
| 450 |
- if testCase.expectSuccess {
|
|
| 451 |
- if c == nil {
|
|
| 452 |
- t.Errorf("%s: Expected success, got error: %s", desc, err)
|
|
| 453 |
- } |
|
| 454 |
- } else {
|
|
| 455 |
- if c != nil {
|
|
| 456 |
- t.Errorf("%s: Expected nil object", desc)
|
|
| 457 |
- } |
|
| 458 |
- if !errors.IsInvalid(err) {
|
|
| 459 |
- t.Errorf("%s: Expected to get an invalid resource error, got %v", desc, err)
|
|
| 460 |
- } |
|
| 380 |
+ for desc, failureCase := range failureCases {
|
|
| 381 |
+ c, err := storage.Create(kapi.NewDefaultContext(), &failureCase) |
|
| 382 |
+ if c != nil {
|
|
| 383 |
+ t.Errorf("%s: Expected nil object", desc)
|
|
| 384 |
+ } |
|
| 385 |
+ if !errors.IsInvalid(err) {
|
|
| 386 |
+ t.Errorf("%s: Expected to get an invalid resource error, got %v", desc, err)
|
|
| 461 | 387 |
} |
| 462 | 388 |
} |
| 463 | 389 |
} |
| ... | ... |
@@ -465,175 +360,83 @@ func TestBuildConfigRESTValidatesCreate(t *testing.T) {
|
| 465 | 465 |
func TestBuildRESTValidatesUpdate(t *testing.T) {
|
| 466 | 466 |
mockRegistry := test.BuildConfigRegistry{}
|
| 467 | 467 |
storage := REST{&mockRegistry}
|
| 468 |
- failureCases := map[string]struct {
|
|
| 469 |
- expectSuccess bool |
|
| 470 |
- data api.BuildConfig |
|
| 471 |
- }{
|
|
| 468 |
+ failureCases := map[string]api.BuildConfig{
|
|
| 472 | 469 |
"empty ID": {
|
| 473 |
- false, |
|
| 474 |
- api.BuildConfig{
|
|
| 475 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 476 |
- Name: "", |
|
| 477 |
- Namespace: kapi.NamespaceDefault, |
|
| 478 |
- }, |
|
| 479 |
- Parameters: api.BuildParameters{
|
|
| 480 |
- Source: api.BuildSource{
|
|
| 481 |
- Type: api.BuildSourceGit, |
|
| 482 |
- Git: &api.GitBuildSource{
|
|
| 483 |
- URI: "http://github.com/test/source", |
|
| 484 |
- }, |
|
| 485 |
- }, |
|
| 486 |
- Output: api.BuildOutput{
|
|
| 487 |
- DockerImageReference: "data/image", |
|
| 470 |
+ ObjectMeta: kapi.ObjectMeta{Name: ""},
|
|
| 471 |
+ Parameters: api.BuildParameters{
|
|
| 472 |
+ Source: api.BuildSource{
|
|
| 473 |
+ Type: api.BuildSourceGit, |
|
| 474 |
+ Git: &api.GitBuildSource{
|
|
| 475 |
+ URI: "http://github.com/test/source", |
|
| 488 | 476 |
}, |
| 489 | 477 |
}, |
| 478 |
+ Output: api.BuildOutput{
|
|
| 479 |
+ DockerImageReference: "data/image", |
|
| 480 |
+ }, |
|
| 490 | 481 |
}, |
| 491 | 482 |
}, |
| 492 | 483 |
"blank sourceURI": {
|
| 493 |
- false, |
|
| 494 |
- api.BuildConfig{
|
|
| 495 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 496 |
- Name: "abc", |
|
| 497 |
- Namespace: kapi.NamespaceDefault, |
|
| 498 |
- }, |
|
| 499 |
- Parameters: api.BuildParameters{
|
|
| 500 |
- Source: api.BuildSource{
|
|
| 501 |
- Type: api.BuildSourceGit, |
|
| 502 |
- Git: &api.GitBuildSource{
|
|
| 503 |
- URI: "", |
|
| 504 |
- }, |
|
| 505 |
- }, |
|
| 506 |
- Strategy: api.BuildStrategy{
|
|
| 507 |
- Type: api.STIBuildStrategyType, |
|
| 508 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 509 |
- From: &kapi.ObjectReference{
|
|
| 510 |
- Name: "builder/image", |
|
| 511 |
- }, |
|
| 512 |
- }, |
|
| 484 |
+ ObjectMeta: kapi.ObjectMeta{Name: "abc"},
|
|
| 485 |
+ Parameters: api.BuildParameters{
|
|
| 486 |
+ Source: api.BuildSource{
|
|
| 487 |
+ Type: api.BuildSourceGit, |
|
| 488 |
+ Git: &api.GitBuildSource{
|
|
| 489 |
+ URI: "", |
|
| 513 | 490 |
}, |
| 514 |
- Output: api.BuildOutput{
|
|
| 515 |
- DockerImageReference: "data/image", |
|
| 491 |
+ }, |
|
| 492 |
+ Strategy: api.BuildStrategy{
|
|
| 493 |
+ Type: api.STIBuildStrategyType, |
|
| 494 |
+ STIStrategy: &api.STIBuildStrategy{
|
|
| 495 |
+ Image: "builder/image", |
|
| 516 | 496 |
}, |
| 517 | 497 |
}, |
| 498 |
+ Output: api.BuildOutput{
|
|
| 499 |
+ DockerImageReference: "data/image", |
|
| 500 |
+ }, |
|
| 518 | 501 |
}, |
| 519 | 502 |
}, |
| 520 | 503 |
"blank DockerImageReference": {
|
| 521 |
- false, |
|
| 522 |
- api.BuildConfig{
|
|
| 523 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 524 |
- Name: "abc", |
|
| 525 |
- Namespace: kapi.NamespaceDefault, |
|
| 526 |
- }, |
|
| 527 |
- Parameters: api.BuildParameters{
|
|
| 528 |
- Source: api.BuildSource{
|
|
| 529 |
- Type: api.BuildSourceGit, |
|
| 530 |
- Git: &api.GitBuildSource{
|
|
| 531 |
- URI: "http://github.com/test/source", |
|
| 532 |
- }, |
|
| 533 |
- }, |
|
| 534 |
- Output: api.BuildOutput{
|
|
| 535 |
- DockerImageReference: "", |
|
| 504 |
+ ObjectMeta: kapi.ObjectMeta{Name: "abc"},
|
|
| 505 |
+ Parameters: api.BuildParameters{
|
|
| 506 |
+ Source: api.BuildSource{
|
|
| 507 |
+ Type: api.BuildSourceGit, |
|
| 508 |
+ Git: &api.GitBuildSource{
|
|
| 509 |
+ URI: "http://github.com/test/source", |
|
| 536 | 510 |
}, |
| 537 | 511 |
}, |
| 538 |
- }, |
|
| 539 |
- }, |
|
| 540 |
- "blank From.Name and blank Image": {
|
|
| 541 |
- false, |
|
| 542 |
- api.BuildConfig{
|
|
| 543 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 544 |
- Name: "abc", |
|
| 545 |
- Namespace: kapi.NamespaceDefault, |
|
| 546 |
- }, |
|
| 547 |
- Parameters: api.BuildParameters{
|
|
| 548 |
- Source: api.BuildSource{
|
|
| 549 |
- Type: api.BuildSourceGit, |
|
| 550 |
- Git: &api.GitBuildSource{
|
|
| 551 |
- URI: "http://github.com/test/source", |
|
| 552 |
- }, |
|
| 553 |
- }, |
|
| 554 |
- Strategy: api.BuildStrategy{
|
|
| 555 |
- Type: api.STIBuildStrategyType, |
|
| 556 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 557 |
- From: &kapi.ObjectReference{
|
|
| 558 |
- Name: "", |
|
| 559 |
- }, |
|
| 560 |
- }, |
|
| 561 |
- }, |
|
| 562 |
- Output: api.BuildOutput{
|
|
| 563 |
- DockerImageReference: "data/image", |
|
| 564 |
- }, |
|
| 512 |
+ Output: api.BuildOutput{
|
|
| 513 |
+ DockerImageReference: "", |
|
| 565 | 514 |
}, |
| 566 | 515 |
}, |
| 567 | 516 |
}, |
| 568 |
- "blank From.Name and Image present": {
|
|
| 569 |
- true, |
|
| 570 |
- api.BuildConfig{
|
|
| 571 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 572 |
- Name: "abc", |
|
| 573 |
- Namespace: kapi.NamespaceDefault, |
|
| 574 |
- }, |
|
| 575 |
- Parameters: api.BuildParameters{
|
|
| 576 |
- Source: api.BuildSource{
|
|
| 577 |
- Type: api.BuildSourceGit, |
|
| 578 |
- Git: &api.GitBuildSource{
|
|
| 579 |
- URI: "http://github.com/test/source", |
|
| 580 |
- }, |
|
| 581 |
- }, |
|
| 582 |
- Strategy: api.BuildStrategy{
|
|
| 583 |
- Type: api.STIBuildStrategyType, |
|
| 584 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 585 |
- Image: "builder/image", |
|
| 586 |
- }, |
|
| 587 |
- }, |
|
| 588 |
- Output: api.BuildOutput{
|
|
| 589 |
- DockerImageReference: "data/image", |
|
| 517 |
+ "blank Image on STIBuildType": {
|
|
| 518 |
+ ObjectMeta: kapi.ObjectMeta{Name: "abc"},
|
|
| 519 |
+ Parameters: api.BuildParameters{
|
|
| 520 |
+ Source: api.BuildSource{
|
|
| 521 |
+ Type: api.BuildSourceGit, |
|
| 522 |
+ Git: &api.GitBuildSource{
|
|
| 523 |
+ URI: "http://github.com/test/source", |
|
| 590 | 524 |
}, |
| 591 | 525 |
}, |
| 592 |
- }, |
|
| 593 |
- }, |
|
| 594 |
- "blank Image and From.Name present": {
|
|
| 595 |
- true, |
|
| 596 |
- api.BuildConfig{
|
|
| 597 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 598 |
- Name: "abc", |
|
| 599 |
- Namespace: kapi.NamespaceDefault, |
|
| 600 |
- }, |
|
| 601 |
- Parameters: api.BuildParameters{
|
|
| 602 |
- Source: api.BuildSource{
|
|
| 603 |
- Type: api.BuildSourceGit, |
|
| 604 |
- Git: &api.GitBuildSource{
|
|
| 605 |
- URI: "http://github.com/test/source", |
|
| 606 |
- }, |
|
| 607 |
- }, |
|
| 608 |
- Strategy: api.BuildStrategy{
|
|
| 609 |
- Type: api.STIBuildStrategyType, |
|
| 610 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 611 |
- From: &kapi.ObjectReference{
|
|
| 612 |
- Name: "imagerepo", |
|
| 613 |
- }, |
|
| 614 |
- }, |
|
| 615 |
- }, |
|
| 616 |
- Output: api.BuildOutput{
|
|
| 617 |
- DockerImageReference: "data/image", |
|
| 526 |
+ Strategy: api.BuildStrategy{
|
|
| 527 |
+ Type: api.STIBuildStrategyType, |
|
| 528 |
+ STIStrategy: &api.STIBuildStrategy{
|
|
| 529 |
+ Image: "", |
|
| 618 | 530 |
}, |
| 619 | 531 |
}, |
| 532 |
+ Output: api.BuildOutput{
|
|
| 533 |
+ DockerImageReference: "data/image", |
|
| 534 |
+ }, |
|
| 620 | 535 |
}, |
| 621 | 536 |
}, |
| 622 | 537 |
} |
| 623 |
- |
|
| 624 |
- for desc, testCase := range failureCases {
|
|
| 625 |
- c, created, err := storage.Update(kapi.NewDefaultContext(), &testCase.data) |
|
| 626 |
- if testCase.expectSuccess {
|
|
| 627 |
- if c == nil {
|
|
| 628 |
- t.Errorf("%s: Expected success, error: %s", desc, err)
|
|
| 629 |
- } |
|
| 630 |
- } else {
|
|
| 631 |
- if c != nil || created {
|
|
| 632 |
- t.Errorf("%s: Expected nil object", desc)
|
|
| 633 |
- } |
|
| 634 |
- if !errors.IsInvalid(err) {
|
|
| 635 |
- t.Errorf("%s: Expected to get an invalid resource error, got %v", desc, err)
|
|
| 636 |
- } |
|
| 538 |
+ for desc, failureCase := range failureCases {
|
|
| 539 |
+ c, created, err := storage.Update(kapi.NewDefaultContext(), &failureCase) |
|
| 540 |
+ if c != nil || created {
|
|
| 541 |
+ t.Errorf("%s: Expected nil object", desc)
|
|
| 542 |
+ } |
|
| 543 |
+ if !errors.IsInvalid(err) {
|
|
| 544 |
+ t.Errorf("%s: Expected to get an invalid resource error, got %v", desc, err)
|
|
| 637 | 545 |
} |
| 638 | 546 |
} |
| 639 | 547 |
} |
| ... | ... |
@@ -682,4 +485,5 @@ func checkExpectedNamespaceError(t *testing.T, err error) {
|
| 682 | 682 |
t.Errorf("Expected '"+expectedError+"' error, got '%v'", err.Error())
|
| 683 | 683 |
} |
| 684 | 684 |
} |
| 685 |
+ |
|
| 685 | 686 |
} |
| ... | ... |
@@ -110,63 +110,6 @@ func TestEtcdCreateBuild(t *testing.T) {
|
| 110 | 110 |
Strategy: api.BuildStrategy{
|
| 111 | 111 |
Type: api.STIBuildStrategyType, |
| 112 | 112 |
STIStrategy: &api.STIBuildStrategy{
|
| 113 |
- From: &kapi.ObjectReference{
|
|
| 114 |
- Name: "builder/image", |
|
| 115 |
- }, |
|
| 116 |
- }, |
|
| 117 |
- }, |
|
| 118 |
- Output: api.BuildOutput{
|
|
| 119 |
- DockerImageReference: "repository/dataBuild", |
|
| 120 |
- }, |
|
| 121 |
- }, |
|
| 122 |
- Status: api.BuildStatusPending, |
|
| 123 |
- PodName: "-the-pod-id", |
|
| 124 |
- }) |
|
| 125 |
- if err != nil {
|
|
| 126 |
- t.Fatalf("unexpected error: %v", err)
|
|
| 127 |
- } |
|
| 128 |
- |
|
| 129 |
- resp, err := fakeClient.Get(makeTestDefaultBuildKey("foo"), false, false)
|
|
| 130 |
- if err != nil {
|
|
| 131 |
- t.Fatalf("Unexpected error %v", err)
|
|
| 132 |
- } |
|
| 133 |
- var build api.Build |
|
| 134 |
- err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &build) |
|
| 135 |
- if err != nil {
|
|
| 136 |
- t.Errorf("unexpected error: %v", err)
|
|
| 137 |
- } |
|
| 138 |
- |
|
| 139 |
- if build.Name != "foo" {
|
|
| 140 |
- t.Errorf("Unexpected build: %#v %s", build, resp.Node.Value)
|
|
| 141 |
- } |
|
| 142 |
-} |
|
| 143 |
- |
|
| 144 |
-func TestEtcdCreateBuildUsingImage(t *testing.T) {
|
|
| 145 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 146 |
- fakeClient.TestIndex = true |
|
| 147 |
- fakeClient.Data[makeTestDefaultBuildKey("foo")] = tools.EtcdResponseWithError{
|
|
| 148 |
- R: &etcd.Response{
|
|
| 149 |
- Node: nil, |
|
| 150 |
- }, |
|
| 151 |
- E: tools.EtcdErrorNotFound, |
|
| 152 |
- } |
|
| 153 |
- registry := NewTestEtcd(fakeClient) |
|
| 154 |
- err := registry.CreateBuild(kapi.NewDefaultContext(), &api.Build{
|
|
| 155 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 156 |
- Name: "foo", |
|
| 157 |
- Labels: map[string]string{
|
|
| 158 |
- "name": "dataBuild", |
|
| 159 |
- }, |
|
| 160 |
- }, |
|
| 161 |
- Parameters: api.BuildParameters{
|
|
| 162 |
- Source: api.BuildSource{
|
|
| 163 |
- Git: &api.GitBuildSource{
|
|
| 164 |
- URI: "http://my.build.com/the/build/Dockerfile", |
|
| 165 |
- }, |
|
| 166 |
- }, |
|
| 167 |
- Strategy: api.BuildStrategy{
|
|
| 168 |
- Type: api.STIBuildStrategyType, |
|
| 169 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 170 | 113 |
Image: "builder/image", |
| 171 | 114 |
}, |
| 172 | 115 |
}, |
| ... | ... |
@@ -389,61 +332,6 @@ func TestEtcdCreateBuildConfig(t *testing.T) {
|
| 389 | 389 |
Strategy: api.BuildStrategy{
|
| 390 | 390 |
Type: api.STIBuildStrategyType, |
| 391 | 391 |
STIStrategy: &api.STIBuildStrategy{
|
| 392 |
- From: &kapi.ObjectReference{
|
|
| 393 |
- Name: "builder/image", |
|
| 394 |
- }, |
|
| 395 |
- }, |
|
| 396 |
- }, |
|
| 397 |
- Output: api.BuildOutput{
|
|
| 398 |
- DockerImageReference: "repository/dataBuild", |
|
| 399 |
- }, |
|
| 400 |
- }, |
|
| 401 |
- }) |
|
| 402 |
- if err != nil {
|
|
| 403 |
- t.Fatalf("unexpected error: %v", err)
|
|
| 404 |
- } |
|
| 405 |
- |
|
| 406 |
- resp, err := fakeClient.Get(makeTestDefaultBuildConfigKey("foo"), false, false)
|
|
| 407 |
- if err != nil {
|
|
| 408 |
- t.Fatalf("Unexpected error %v", err)
|
|
| 409 |
- } |
|
| 410 |
- var buildConfig api.BuildConfig |
|
| 411 |
- err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &buildConfig) |
|
| 412 |
- if err != nil {
|
|
| 413 |
- t.Errorf("unexpected error: %v", err)
|
|
| 414 |
- } |
|
| 415 |
- |
|
| 416 |
- if buildConfig.Name != "foo" {
|
|
| 417 |
- t.Errorf("Unexpected buildConfig: %#v %s", buildConfig, resp.Node.Value)
|
|
| 418 |
- } |
|
| 419 |
-} |
|
| 420 |
- |
|
| 421 |
-func TestEtcdCreateBuildConfigUsingImage(t *testing.T) {
|
|
| 422 |
- fakeClient := tools.NewFakeEtcdClient(t) |
|
| 423 |
- fakeClient.TestIndex = true |
|
| 424 |
- fakeClient.Data[makeTestDefaultBuildConfigKey("foo")] = tools.EtcdResponseWithError{
|
|
| 425 |
- R: &etcd.Response{
|
|
| 426 |
- Node: nil, |
|
| 427 |
- }, |
|
| 428 |
- E: tools.EtcdErrorNotFound, |
|
| 429 |
- } |
|
| 430 |
- registry := NewTestEtcd(fakeClient) |
|
| 431 |
- err := registry.CreateBuildConfig(kapi.NewDefaultContext(), &api.BuildConfig{
|
|
| 432 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 433 |
- Name: "foo", |
|
| 434 |
- Labels: map[string]string{
|
|
| 435 |
- "name": "dataBuildConfig", |
|
| 436 |
- }, |
|
| 437 |
- }, |
|
| 438 |
- Parameters: api.BuildParameters{
|
|
| 439 |
- Source: api.BuildSource{
|
|
| 440 |
- Git: &api.GitBuildSource{
|
|
| 441 |
- URI: "http://my.build.com/the/build/Dockerfile", |
|
| 442 |
- }, |
|
| 443 |
- }, |
|
| 444 |
- Strategy: api.BuildStrategy{
|
|
| 445 |
- Type: api.STIBuildStrategyType, |
|
| 446 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 447 | 392 |
Image: "builder/image", |
| 448 | 393 |
}, |
| 449 | 394 |
}, |
| ... | ... |
@@ -1,7 +1,6 @@ |
| 1 | 1 |
package util |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "fmt" |
|
| 5 | 4 |
"github.com/golang/glog" |
| 6 | 5 |
|
| 7 | 6 |
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
| ... | ... |
@@ -14,8 +13,7 @@ import ( |
| 14 | 14 |
// GenerateBuildFromConfig creates a new build based on a given BuildConfig. Optionally a SourceRevision for the new |
| 15 | 15 |
// build can be specified. Also optionally a list of image names to be substituted can be supplied. Values in the BuildConfig |
| 16 | 16 |
// that have a substitution provided will be replaced in the resulting Build |
| 17 |
-func GenerateBuildFromConfig(bc *buildapi.BuildConfig, ref *buildapi.SourceRevision, imageSubstitutions map[string]string, |
|
| 18 |
- imageRepoSubstitutions map[kapi.ObjectReference]string) (build *buildapi.Build) {
|
|
| 17 |
+func GenerateBuildFromConfig(bc *buildapi.BuildConfig, r *buildapi.SourceRevision, imageSubstitutions map[string]string) (build *buildapi.Build) {
|
|
| 19 | 18 |
// Need to copy the buildConfig here so that it doesn't share pointers with |
| 20 | 19 |
// the build object which could be (will be) modified later. |
| 21 | 20 |
obj, _ := kapi.Scheme.Copy(bc) |
| ... | ... |
@@ -26,7 +24,7 @@ func GenerateBuildFromConfig(bc *buildapi.BuildConfig, ref *buildapi.SourceRevis |
| 26 | 26 |
Source: bcCopy.Parameters.Source, |
| 27 | 27 |
Strategy: bcCopy.Parameters.Strategy, |
| 28 | 28 |
Output: bcCopy.Parameters.Output, |
| 29 |
- Revision: ref, |
|
| 29 |
+ Revision: r, |
|
| 30 | 30 |
}, |
| 31 | 31 |
ObjectMeta: kapi.ObjectMeta{
|
| 32 | 32 |
Labels: bcCopy.Labels, |
| ... | ... |
@@ -41,14 +39,6 @@ func GenerateBuildFromConfig(bc *buildapi.BuildConfig, ref *buildapi.SourceRevis |
| 41 | 41 |
glog.V(4).Infof("Substituting %s for %s", newImage, originalImage)
|
| 42 | 42 |
SubstituteImageReferences(b, originalImage, newImage) |
| 43 | 43 |
} |
| 44 |
- for imageRepo, newImage := range imageRepoSubstitutions {
|
|
| 45 |
- if len(imageRepo.Namespace) != 0 {
|
|
| 46 |
- glog.V(4).Infof("Substituting repository %s for %s/%s", newImage, imageRepo.Namespace, imageRepo.Name)
|
|
| 47 |
- } else {
|
|
| 48 |
- glog.V(4).Infof("Substituting repository %s for %s", newImage, imageRepo.Name)
|
|
| 49 |
- } |
|
| 50 |
- SubstituteImageRepoReferences(b, imageRepo, newImage) |
|
| 51 |
- } |
|
| 52 | 44 |
return b |
| 53 | 45 |
} |
| 54 | 46 |
|
| ... | ... |
@@ -72,65 +62,10 @@ func GenerateBuildFromBuild(build *buildapi.Build) *buildapi.Build {
|
| 72 | 72 |
// the image tag from the corresponding image repo rather than the image field from the buildconfig |
| 73 | 73 |
// as the base image for the build. |
| 74 | 74 |
func GenerateBuildWithImageTag(config *buildapi.BuildConfig, revision *buildapi.SourceRevision, imageRepoGetter osclient.ImageRepositoryNamespaceGetter) (*buildapi.Build, error) {
|
| 75 |
- var build *buildapi.Build |
|
| 76 |
- var err error |
|
| 77 |
- glog.V(4).Infof("Generating tagged build for config %s", config.Name)
|
|
| 78 |
- |
|
| 79 |
- switch {
|
|
| 80 |
- case config.Parameters.Strategy.Type == buildapi.STIBuildStrategyType: |
|
| 81 |
- if config.Parameters.Strategy.STIStrategy.From != nil && config.Parameters.Strategy.STIStrategy.From.Name != "" {
|
|
| 82 |
- build, err = GenerateBuildUsingObjectReference(config, revision, imageRepoGetter) |
|
| 83 |
- } else {
|
|
| 84 |
- build, err = GenerateBuildUsingImageTriggerTag(config, revision, imageRepoGetter) |
|
| 85 |
- } |
|
| 86 |
- case config.Parameters.Strategy.Type == buildapi.DockerBuildStrategyType: |
|
| 87 |
- build, err = GenerateBuildUsingImageTriggerTag(config, revision, imageRepoGetter) |
|
| 88 |
- case config.Parameters.Strategy.Type == buildapi.CustomBuildStrategyType: |
|
| 89 |
- build, err = GenerateBuildUsingImageTriggerTag(config, revision, imageRepoGetter) |
|
| 90 |
- default: |
|
| 91 |
- return nil, fmt.Errorf("Build strategy type must be set")
|
|
| 92 |
- } |
|
| 93 |
- return build, err |
|
| 94 |
-} |
|
| 95 |
- |
|
| 96 |
-// GenerateBuildUsingObjectReference examines the ImageRepo referenced by the BuildConfig and resolves it to |
|
| 97 |
-// an imagespec, it then returns a Build object that uses that imagespec. |
|
| 98 |
-func GenerateBuildUsingObjectReference(config *buildapi.BuildConfig, revision *buildapi.SourceRevision, imageRepoGetter osclient.ImageRepositoryNamespaceGetter) (*buildapi.Build, error) {
|
|
| 99 |
- imageRepoSubstitutions := make(map[kapi.ObjectReference]string) |
|
| 100 |
- from := config.Parameters.Strategy.STIStrategy.From |
|
| 101 |
- namespace := from.Namespace |
|
| 102 |
- if len(namespace) == 0 {
|
|
| 103 |
- namespace = config.Namespace |
|
| 104 |
- } |
|
| 105 |
- tag := config.Parameters.Strategy.STIStrategy.Tag |
|
| 106 |
- if len(tag) == 0 {
|
|
| 107 |
- tag = buildapi.DefaultImageTag |
|
| 108 |
- } |
|
| 109 |
- |
|
| 110 |
- imageRepo, err := imageRepoGetter.GetByNamespace(namespace, from.Name) |
|
| 111 |
- if err != nil {
|
|
| 112 |
- return nil, err |
|
| 113 |
- } |
|
| 114 |
- if imageRepo == nil || imageRepo.Status.DockerImageRepository == "" {
|
|
| 115 |
- return nil, fmt.Errorf("Docker Image Repository %s missing in namespace %s", from.Name, namespace)
|
|
| 116 |
- } |
|
| 117 |
- glog.V(4).Infof("Found image repo %s", imageRepo.Name)
|
|
| 118 |
- latest, err := imageapi.LatestTaggedImage(imageRepo, tag) |
|
| 119 |
- if err == nil {
|
|
| 120 |
- glog.V(4).Infof("Using image %s for image repository %s in namespace %s", latest.DockerImageReference, from.Name, from.Namespace)
|
|
| 121 |
- imageRepoSubstitutions[*from] = latest.DockerImageReference |
|
| 122 |
- } else {
|
|
| 123 |
- return nil, fmt.Errorf("Docker Image Repository %s has no tag %s", from.Name, tag)
|
|
| 124 |
- } |
|
| 125 |
- glog.V(4).Infof("Generating build from config for build config %s", config.Name)
|
|
| 126 |
- return GenerateBuildFromConfig(config, revision, nil, imageRepoSubstitutions), nil |
|
| 127 |
-} |
|
| 128 | 75 |
|
| 129 |
-// GenerateBuildUsingTriggerTag examines the ImageChangeTriggers associated with the BuildConfig |
|
| 130 |
-// and uses them to determine the current imagespec that should be used to run this build, it then |
|
| 131 |
-// returns a Build object that uses that imagespec. |
|
| 132 |
-func GenerateBuildUsingImageTriggerTag(config *buildapi.BuildConfig, revision *buildapi.SourceRevision, imageRepoGetter osclient.ImageRepositoryNamespaceGetter) (*buildapi.Build, error) {
|
|
| 133 | 76 |
imageSubstitutions := make(map[string]string) |
| 77 |
+ glog.V(4).Infof("Generating tagged build for config %s", config.Name)
|
|
| 78 |
+ |
|
| 134 | 79 |
for _, trigger := range config.Triggers {
|
| 135 | 80 |
if trigger.Type != buildapi.ImageChangeBuildTriggerType {
|
| 136 | 81 |
continue |
| ... | ... |
@@ -176,7 +111,7 @@ func GenerateBuildUsingImageTriggerTag(config *buildapi.BuildConfig, revision *b |
| 176 | 176 |
imageSubstitutions[icTrigger.Image] = imageRef |
| 177 | 177 |
} |
| 178 | 178 |
glog.V(4).Infof("Generating build from config for build config %s", config.Name)
|
| 179 |
- build := GenerateBuildFromConfig(config, revision, imageSubstitutions, nil) |
|
| 179 |
+ build := GenerateBuildFromConfig(config, revision, imageSubstitutions) |
|
| 180 | 180 |
return build, nil |
| 181 | 181 |
} |
| 182 | 182 |
|
| ... | ... |
@@ -189,7 +124,6 @@ func SubstituteImageReferences(build *buildapi.Build, oldImage string, newImage |
| 189 | 189 |
build.Parameters.Strategy.DockerStrategy.Image = newImage |
| 190 | 190 |
case build.Parameters.Strategy.Type == buildapi.STIBuildStrategyType && |
| 191 | 191 |
build.Parameters.Strategy.STIStrategy != nil && |
| 192 |
- (build.Parameters.Strategy.STIStrategy.From == nil || build.Parameters.Strategy.STIStrategy.From.Name == "") && |
|
| 193 | 192 |
build.Parameters.Strategy.STIStrategy.Image == oldImage: |
| 194 | 193 |
build.Parameters.Strategy.STIStrategy.Image = newImage |
| 195 | 194 |
case build.Parameters.Strategy.Type == buildapi.CustomBuildStrategyType: |
| ... | ... |
@@ -221,18 +155,3 @@ func SubstituteImageReferences(build *buildapi.Build, oldImage string, newImage |
| 221 | 221 |
} |
| 222 | 222 |
} |
| 223 | 223 |
} |
| 224 |
- |
|
| 225 |
-// SubstituteImageRepoReferences uses references to an image repository to set an actual image name |
|
| 226 |
-// It also clears the ImageRepo reference from the BuildStrategy, if one was set. The imagereference |
|
| 227 |
-// field will be used explicitly. |
|
| 228 |
-func SubstituteImageRepoReferences(build *buildapi.Build, imageRepo kapi.ObjectReference, newImage string) {
|
|
| 229 |
- switch {
|
|
| 230 |
- case build.Parameters.Strategy.Type == buildapi.STIBuildStrategyType && |
|
| 231 |
- build.Parameters.Strategy.STIStrategy != nil && |
|
| 232 |
- build.Parameters.Strategy.STIStrategy.From != nil && |
|
| 233 |
- build.Parameters.Strategy.STIStrategy.From.Name == imageRepo.Name && |
|
| 234 |
- build.Parameters.Strategy.STIStrategy.From.Namespace == imageRepo.Namespace: |
|
| 235 |
- build.Parameters.Strategy.STIStrategy.Image = newImage |
|
| 236 |
- build.Parameters.Strategy.STIStrategy.From = nil |
|
| 237 |
- } |
|
| 238 |
-} |
| ... | ... |
@@ -22,7 +22,6 @@ const ( |
| 22 | 22 |
|
| 23 | 23 |
imageRepoName = "testRepo" |
| 24 | 24 |
unmatchedImageRepoName = "unmatchedRepo" |
| 25 |
- imageRepoNamespace = "testns" |
|
| 26 | 25 |
) |
| 27 | 26 |
|
| 28 | 27 |
func TestGenerateBuildFromConfig(t *testing.T) {
|
| ... | ... |
@@ -53,7 +52,7 @@ func TestGenerateBuildFromConfig(t *testing.T) {
|
| 53 | 53 |
Commit: "abcd", |
| 54 | 54 |
}, |
| 55 | 55 |
} |
| 56 |
- build := GenerateBuildFromConfig(bc, revision, nil, nil) |
|
| 56 |
+ build := GenerateBuildFromConfig(bc, revision, nil) |
|
| 57 | 57 |
if !reflect.DeepEqual(source, build.Parameters.Source) {
|
| 58 | 58 |
t.Errorf("Build source does not match BuildConfig source")
|
| 59 | 59 |
} |
| ... | ... |
@@ -74,7 +73,7 @@ func TestGenerateBuildFromConfig(t *testing.T) {
|
| 74 | 74 |
} |
| 75 | 75 |
} |
| 76 | 76 |
|
| 77 |
-func TestGenerateBuildWithImageTagForDockerStrategy(t *testing.T) {
|
|
| 77 |
+func TestGenerateBuildWithImageTag(t *testing.T) {
|
|
| 78 | 78 |
source := mockSource() |
| 79 | 79 |
strategy := mockDockerStrategy() |
| 80 | 80 |
strategy.DockerStrategy.Image = originalImage |
| ... | ... |
@@ -242,82 +241,6 @@ func TestGenerateBuildWithImageTagUnmatchedTag(t *testing.T) {
|
| 242 | 242 |
} |
| 243 | 243 |
} |
| 244 | 244 |
|
| 245 |
-func TestGenerateBuildWithImageTagForSTIStrategyImage(t *testing.T) {
|
|
| 246 |
- source := mockSource() |
|
| 247 |
- strategy := mockSTIStrategyForImage() |
|
| 248 |
- output := mockOutput() |
|
| 249 |
- imageRepoGetter := &mockImageRepositoryNamespaceGetter{"", imageRepoName}
|
|
| 250 |
- |
|
| 251 |
- bc := &buildapi.BuildConfig{
|
|
| 252 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 253 |
- Name: "test-build-config", |
|
| 254 |
- }, |
|
| 255 |
- Parameters: buildapi.BuildParameters{
|
|
| 256 |
- Source: source, |
|
| 257 |
- Revision: &buildapi.SourceRevision{
|
|
| 258 |
- Type: buildapi.BuildSourceGit, |
|
| 259 |
- Git: &buildapi.GitSourceRevision{
|
|
| 260 |
- Commit: "1234", |
|
| 261 |
- }, |
|
| 262 |
- }, |
|
| 263 |
- Strategy: strategy, |
|
| 264 |
- Output: output, |
|
| 265 |
- }, |
|
| 266 |
- Triggers: []buildapi.BuildTriggerPolicy{
|
|
| 267 |
- {
|
|
| 268 |
- Type: buildapi.ImageChangeBuildTriggerType, |
|
| 269 |
- ImageChange: &buildapi.ImageChangeTrigger{
|
|
| 270 |
- Image: originalImage, |
|
| 271 |
- From: kapi.ObjectReference{
|
|
| 272 |
- Name: imageRepoName, |
|
| 273 |
- }, |
|
| 274 |
- Tag: tagName, |
|
| 275 |
- }, |
|
| 276 |
- }, |
|
| 277 |
- }, |
|
| 278 |
- } |
|
| 279 |
- |
|
| 280 |
- build, err := GenerateBuildWithImageTag(bc, nil, imageRepoGetter) |
|
| 281 |
- if err != nil {
|
|
| 282 |
- t.Errorf("Unexpected error %v", err)
|
|
| 283 |
- } |
|
| 284 |
- if build.Parameters.Strategy.STIStrategy.Image != newImage {
|
|
| 285 |
- t.Errorf("STI base image value %s does not match expected value %s", build.Parameters.Strategy.STIStrategy.Image, newImage)
|
|
| 286 |
- } |
|
| 287 |
-} |
|
| 288 |
- |
|
| 289 |
-func TestGenerateBuildWithImageTagForSTIStrategyImageRepository(t *testing.T) {
|
|
| 290 |
- source := mockSource() |
|
| 291 |
- strategy := mockSTIStrategyForImageRepository() |
|
| 292 |
- output := mockOutput() |
|
| 293 |
- imageRepoGetter := &mockImageRepositoryNamespaceGetter{imageRepoNamespace, imageRepoName}
|
|
| 294 |
- |
|
| 295 |
- bc := &buildapi.BuildConfig{
|
|
| 296 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 297 |
- Name: "test-build-config", |
|
| 298 |
- }, |
|
| 299 |
- Parameters: buildapi.BuildParameters{
|
|
| 300 |
- Source: source, |
|
| 301 |
- Revision: &buildapi.SourceRevision{
|
|
| 302 |
- Type: buildapi.BuildSourceGit, |
|
| 303 |
- Git: &buildapi.GitSourceRevision{
|
|
| 304 |
- Commit: "1234", |
|
| 305 |
- }, |
|
| 306 |
- }, |
|
| 307 |
- Strategy: strategy, |
|
| 308 |
- Output: output, |
|
| 309 |
- }, |
|
| 310 |
- } |
|
| 311 |
- |
|
| 312 |
- build, err := GenerateBuildWithImageTag(bc, nil, imageRepoGetter) |
|
| 313 |
- if err != nil {
|
|
| 314 |
- t.Errorf("Unexpected error %v", err)
|
|
| 315 |
- } |
|
| 316 |
- if build.Parameters.Strategy.STIStrategy.Image != newImage {
|
|
| 317 |
- t.Errorf("STI base image value %s does not match expected value %s", build.Parameters.Strategy.STIStrategy.Image, newImage)
|
|
| 318 |
- } |
|
| 319 |
-} |
|
| 320 |
- |
|
| 321 | 245 |
func TestGenerateBuildFromBuild(t *testing.T) {
|
| 322 | 246 |
source := mockSource() |
| 323 | 247 |
strategy := mockDockerStrategy() |
| ... | ... |
@@ -353,7 +276,7 @@ func TestSubstituteImageDockerNil(t *testing.T) {
|
| 353 | 353 |
strategy := mockDockerStrategy() |
| 354 | 354 |
output := mockOutput() |
| 355 | 355 |
bc := mockBuildConfig(source, strategy, output) |
| 356 |
- build := GenerateBuildFromConfig(bc, nil, nil, nil) |
|
| 356 |
+ build := GenerateBuildFromConfig(bc, nil, nil) |
|
| 357 | 357 |
|
| 358 | 358 |
// Docker build with nil base image |
| 359 | 359 |
// base image should still be nil |
| ... | ... |
@@ -368,7 +291,7 @@ func TestSubstituteImageDockerMatch(t *testing.T) {
|
| 368 | 368 |
strategy := mockDockerStrategy() |
| 369 | 369 |
output := mockOutput() |
| 370 | 370 |
bc := mockBuildConfig(source, strategy, output) |
| 371 |
- build := GenerateBuildFromConfig(bc, nil, nil, nil) |
|
| 371 |
+ build := GenerateBuildFromConfig(bc, nil, nil) |
|
| 372 | 372 |
|
| 373 | 373 |
// Docker build with a matched base image |
| 374 | 374 |
// base image should be replaced. |
| ... | ... |
@@ -387,7 +310,7 @@ func TestSubstituteImageDockerMismatch(t *testing.T) {
|
| 387 | 387 |
strategy := mockDockerStrategy() |
| 388 | 388 |
output := mockOutput() |
| 389 | 389 |
bc := mockBuildConfig(source, strategy, output) |
| 390 |
- build := GenerateBuildFromConfig(bc, nil, nil, nil) |
|
| 390 |
+ build := GenerateBuildFromConfig(bc, nil, nil) |
|
| 391 | 391 |
|
| 392 | 392 |
// Docker build with an unmatched base image |
| 393 | 393 |
// base image should not be replaced. |
| ... | ... |
@@ -399,10 +322,10 @@ func TestSubstituteImageDockerMismatch(t *testing.T) {
|
| 399 | 399 |
|
| 400 | 400 |
func TestSubstituteImageSTIMatch(t *testing.T) {
|
| 401 | 401 |
source := mockSource() |
| 402 |
- strategy := mockSTIStrategyForImage() |
|
| 402 |
+ strategy := mockSTIStrategy() |
|
| 403 | 403 |
output := mockOutput() |
| 404 | 404 |
bc := mockBuildConfig(source, strategy, output) |
| 405 |
- build := GenerateBuildFromConfig(bc, nil, nil, nil) |
|
| 405 |
+ build := GenerateBuildFromConfig(bc, nil, nil) |
|
| 406 | 406 |
|
| 407 | 407 |
// STI build with a matched base image |
| 408 | 408 |
// base image should be replaced |
| ... | ... |
@@ -413,33 +336,15 @@ func TestSubstituteImageSTIMatch(t *testing.T) {
|
| 413 | 413 |
if bc.Parameters.Strategy.STIStrategy.Image != originalImage {
|
| 414 | 414 |
t.Errorf("STI BuildConfig was updated when Build was modified")
|
| 415 | 415 |
} |
| 416 |
-} |
|
| 417 |
- |
|
| 418 |
-func TestSubstituteImageRepositorySTIMatch(t *testing.T) {
|
|
| 419 |
- source := mockSource() |
|
| 420 |
- strategy := mockSTIStrategyForImageRepository() |
|
| 421 |
- repoRef := *strategy.STIStrategy.From |
|
| 422 |
- output := mockOutput() |
|
| 423 |
- bc := mockBuildConfig(source, strategy, output) |
|
| 424 |
- build := GenerateBuildFromConfig(bc, nil, nil, nil) |
|
| 425 | 416 |
|
| 426 |
- // STI build with a matched base image |
|
| 427 |
- // base image should be replaced |
|
| 428 |
- SubstituteImageRepoReferences(build, repoRef, newImage) |
|
| 429 |
- if build.Parameters.Strategy.STIStrategy.Image != newImage {
|
|
| 430 |
- t.Errorf("Base image name was not substituted in sti strategy")
|
|
| 431 |
- } |
|
| 432 |
- if bc.Parameters.Strategy.STIStrategy.Image != "" {
|
|
| 433 |
- t.Errorf("STI BuildConfig was updated when Build was modified")
|
|
| 434 |
- } |
|
| 435 | 417 |
} |
| 436 | 418 |
|
| 437 | 419 |
func TestSubstituteImageSTIMismatch(t *testing.T) {
|
| 438 | 420 |
source := mockSource() |
| 439 |
- strategy := mockSTIStrategyForImage() |
|
| 421 |
+ strategy := mockSTIStrategy() |
|
| 440 | 422 |
output := mockOutput() |
| 441 | 423 |
bc := mockBuildConfig(source, strategy, output) |
| 442 |
- build := GenerateBuildFromConfig(bc, nil, nil, nil) |
|
| 424 |
+ build := GenerateBuildFromConfig(bc, nil, nil) |
|
| 443 | 425 |
|
| 444 | 426 |
// STI build with an unmatched base image |
| 445 | 427 |
// base image should not be replaced |
| ... | ... |
@@ -449,30 +354,12 @@ func TestSubstituteImageSTIMismatch(t *testing.T) {
|
| 449 | 449 |
} |
| 450 | 450 |
} |
| 451 | 451 |
|
| 452 |
-func TestSubstituteImageRepositorySTIMismatch(t *testing.T) {
|
|
| 453 |
- source := mockSource() |
|
| 454 |
- strategy := mockSTIStrategyForImage() |
|
| 455 |
- output := mockOutput() |
|
| 456 |
- bc := mockBuildConfig(source, strategy, output) |
|
| 457 |
- imageRepoRef := kapi.ObjectReference{
|
|
| 458 |
- Name: "unmatched", |
|
| 459 |
- } |
|
| 460 |
- build := GenerateBuildFromConfig(bc, nil, nil, nil) |
|
| 461 |
- |
|
| 462 |
- // STI build with an unmatched image repository |
|
| 463 |
- // base image should not be set |
|
| 464 |
- SubstituteImageRepoReferences(build, imageRepoRef, "dummy") |
|
| 465 |
- if build.Parameters.Strategy.STIStrategy.Image == "dummy" {
|
|
| 466 |
- t.Errorf("Base image name was improperly set in STI strategy")
|
|
| 467 |
- } |
|
| 468 |
-} |
|
| 469 |
- |
|
| 470 | 452 |
func TestSubstituteImageCustomAllMatch(t *testing.T) {
|
| 471 | 453 |
source := mockSource() |
| 472 | 454 |
strategy := mockCustomStrategy() |
| 473 | 455 |
output := mockOutput() |
| 474 | 456 |
bc := mockBuildConfig(source, strategy, output) |
| 475 |
- build := GenerateBuildFromConfig(bc, nil, nil, nil) |
|
| 457 |
+ build := GenerateBuildFromConfig(bc, nil, nil) |
|
| 476 | 458 |
|
| 477 | 459 |
// Full custom build with a Image and a well defined environment variable image value, |
| 478 | 460 |
// both should be replaced. Additional environment variables should not be touched. |
| ... | ... |
@@ -506,7 +393,7 @@ func TestSubstituteImageCustomAllMismatch(t *testing.T) {
|
| 506 | 506 |
strategy := mockCustomStrategy() |
| 507 | 507 |
output := mockOutput() |
| 508 | 508 |
bc := mockBuildConfig(source, strategy, output) |
| 509 |
- build := GenerateBuildFromConfig(bc, nil, nil, nil) |
|
| 509 |
+ build := GenerateBuildFromConfig(bc, nil, nil) |
|
| 510 | 510 |
|
| 511 | 511 |
// Full custom build with base image that is not matched |
| 512 | 512 |
// Base image name should be unchanged |
| ... | ... |
@@ -521,7 +408,7 @@ func TestSubstituteImageCustomBaseMatchEnvMismatch(t *testing.T) {
|
| 521 | 521 |
strategy := mockCustomStrategy() |
| 522 | 522 |
output := mockOutput() |
| 523 | 523 |
bc := mockBuildConfig(source, strategy, output) |
| 524 |
- build := GenerateBuildFromConfig(bc, nil, nil, nil) |
|
| 524 |
+ build := GenerateBuildFromConfig(bc, nil, nil) |
|
| 525 | 525 |
|
| 526 | 526 |
// Full custom build with a Image and a well defined environment variable image value that does not match the new image |
| 527 | 527 |
// Only base image should be replaced. Environment variables should not be touched. |
| ... | ... |
@@ -548,7 +435,7 @@ func TestSubstituteImageCustomBaseMatchEnvMissing(t *testing.T) {
|
| 548 | 548 |
strategy := mockCustomStrategy() |
| 549 | 549 |
output := mockOutput() |
| 550 | 550 |
bc := mockBuildConfig(source, strategy, output) |
| 551 |
- build := GenerateBuildFromConfig(bc, nil, nil, nil) |
|
| 551 |
+ build := GenerateBuildFromConfig(bc, nil, nil) |
|
| 552 | 552 |
|
| 553 | 553 |
// Custom build with a base Image but no image environment variable. |
| 554 | 554 |
// base image should be replaced, new image environment variable should be added, |
| ... | ... |
@@ -575,7 +462,7 @@ func TestSubstituteImageCustomBaseMatchEnvNil(t *testing.T) {
|
| 575 | 575 |
strategy := mockCustomStrategy() |
| 576 | 576 |
output := mockOutput() |
| 577 | 577 |
bc := mockBuildConfig(source, strategy, output) |
| 578 |
- build := GenerateBuildFromConfig(bc, nil, nil, nil) |
|
| 578 |
+ build := GenerateBuildFromConfig(bc, nil, nil) |
|
| 579 | 579 |
|
| 580 | 580 |
// Custom build with a base Image but no environment variables |
| 581 | 581 |
// base image should be replaced, new image environment variable should be added |
| ... | ... |
@@ -610,7 +497,7 @@ func mockDockerStrategy() buildapi.BuildStrategy {
|
| 610 | 610 |
} |
| 611 | 611 |
} |
| 612 | 612 |
|
| 613 |
-func mockSTIStrategyForImage() buildapi.BuildStrategy {
|
|
| 613 |
+func mockSTIStrategy() buildapi.BuildStrategy {
|
|
| 614 | 614 |
return buildapi.BuildStrategy{
|
| 615 | 615 |
Type: buildapi.STIBuildStrategyType, |
| 616 | 616 |
STIStrategy: &buildapi.STIBuildStrategy{
|
| ... | ... |
@@ -619,19 +506,6 @@ func mockSTIStrategyForImage() buildapi.BuildStrategy {
|
| 619 | 619 |
} |
| 620 | 620 |
} |
| 621 | 621 |
|
| 622 |
-func mockSTIStrategyForImageRepository() buildapi.BuildStrategy {
|
|
| 623 |
- return buildapi.BuildStrategy{
|
|
| 624 |
- Type: buildapi.STIBuildStrategyType, |
|
| 625 |
- STIStrategy: &buildapi.STIBuildStrategy{
|
|
| 626 |
- From: &kapi.ObjectReference{
|
|
| 627 |
- Name: imageRepoName, |
|
| 628 |
- Namespace: imageRepoNamespace, |
|
| 629 |
- }, |
|
| 630 |
- Tag: tagName, |
|
| 631 |
- }, |
|
| 632 |
- } |
|
| 633 |
-} |
|
| 634 |
- |
|
| 635 | 622 |
func mockCustomStrategy() buildapi.BuildStrategy {
|
| 636 | 623 |
return buildapi.BuildStrategy{
|
| 637 | 624 |
Type: buildapi.CustomBuildStrategyType, |
| ... | ... |
@@ -15,28 +15,13 @@ import ( |
| 15 | 15 |
type okImageRepositoryNamespaceGetter struct{}
|
| 16 | 16 |
|
| 17 | 17 |
func (m *okImageRepositoryNamespaceGetter) GetByNamespace(namespace, name string) (*imageapi.ImageRepository, error) {
|
| 18 |
- return &imageapi.ImageRepository{
|
|
| 19 |
- Status: imageapi.ImageRepositoryStatus{
|
|
| 20 |
- DockerImageRepository: "repository/image", |
|
| 21 |
- }, |
|
| 22 |
- Tags: map[string]string{
|
|
| 23 |
- "latest": "latest", |
|
| 24 |
- }, |
|
| 25 |
- }, nil |
|
| 18 |
+ return nil, nil |
|
| 26 | 19 |
} |
| 27 | 20 |
|
| 28 | 21 |
type okBuildConfigGetter struct{}
|
| 29 | 22 |
|
| 30 | 23 |
func (*okBuildConfigGetter) Get(namespace, name string) (*api.BuildConfig, error) {
|
| 31 | 24 |
return &api.BuildConfig{
|
| 32 |
- Parameters: api.BuildParameters{
|
|
| 33 |
- Strategy: api.BuildStrategy{
|
|
| 34 |
- Type: "STI", |
|
| 35 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 36 |
- Image: "repository/builder-image", |
|
| 37 |
- }, |
|
| 38 |
- }, |
|
| 39 |
- }, |
|
| 40 | 25 |
Triggers: []api.BuildTriggerPolicy{
|
| 41 | 26 |
{
|
| 42 | 27 |
Type: api.GithubWebHookBuildTriggerType, |
| ... | ... |
@@ -249,14 +234,7 @@ func (i *testBuildConfigInterface) Get(namespace, name string) (*api.BuildConfig |
| 249 | 249 |
func TestInvokeWebhookOk(t *testing.T) {
|
| 250 | 250 |
var buildRequest *api.Build |
| 251 | 251 |
buildConfig := &api.BuildConfig{
|
| 252 |
- Parameters: api.BuildParameters{
|
|
| 253 |
- Strategy: api.BuildStrategy{
|
|
| 254 |
- Type: "STI", |
|
| 255 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 256 |
- Image: "repository/builder-image", |
|
| 257 |
- }, |
|
| 258 |
- }, |
|
| 259 |
- }, |
|
| 252 |
+ Parameters: api.BuildParameters{},
|
|
| 260 | 253 |
} |
| 261 | 254 |
|
| 262 | 255 |
server := httptest.NewServer(NewController( |
| ... | ... |
@@ -8,19 +8,9 @@ import ( |
| 8 | 8 |
"strings" |
| 9 | 9 |
"testing" |
| 10 | 10 |
|
| 11 |
- kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
|
| 12 | 11 |
"github.com/openshift/origin/pkg/build/api" |
| 13 | 12 |
) |
| 14 | 13 |
|
| 15 |
-var mockBuildStrategy api.BuildStrategy = api.BuildStrategy{
|
|
| 16 |
- Type: "STI", |
|
| 17 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 18 |
- From: &kapi.ObjectReference{
|
|
| 19 |
- Name: "repository/image", |
|
| 20 |
- }, |
|
| 21 |
- }, |
|
| 22 |
-} |
|
| 23 |
- |
|
| 24 | 14 |
func GivenRequest(method string) *http.Request {
|
| 25 | 15 |
req, _ := http.NewRequest(method, "http://someurl.com", nil) |
| 26 | 16 |
return req |
| ... | ... |
@@ -116,7 +106,7 @@ func TestExtractWithEmptyPayload(t *testing.T) {
|
| 116 | 116 |
Ref: "master", |
| 117 | 117 |
}, |
| 118 | 118 |
}, |
| 119 |
- Strategy: mockBuildStrategy, |
|
| 119 |
+ Strategy: api.BuildStrategy{},
|
|
| 120 | 120 |
}, |
| 121 | 121 |
} |
| 122 | 122 |
plugin := New() |
| ... | ... |
@@ -150,7 +140,7 @@ func TestExtractWithUnmatchedRefGitPayload(t *testing.T) {
|
| 150 | 150 |
Ref: "asdfkasdfasdfasdfadsfkjhkhkh", |
| 151 | 151 |
}, |
| 152 | 152 |
}, |
| 153 |
- Strategy: mockBuildStrategy, |
|
| 153 |
+ Strategy: api.BuildStrategy{},
|
|
| 154 | 154 |
}, |
| 155 | 155 |
} |
| 156 | 156 |
plugin := New() |
| ... | ... |
@@ -185,7 +175,7 @@ func TestExtractWithGitPayload(t *testing.T) {
|
| 185 | 185 |
Ref: "master", |
| 186 | 186 |
}, |
| 187 | 187 |
}, |
| 188 |
- Strategy: mockBuildStrategy, |
|
| 188 |
+ Strategy: api.BuildStrategy{},
|
|
| 189 | 189 |
}, |
| 190 | 190 |
} |
| 191 | 191 |
plugin := New() |
| ... | ... |
@@ -16,14 +16,7 @@ import ( |
| 16 | 16 |
type okImageRepositoryNamespaceGetter struct{}
|
| 17 | 17 |
|
| 18 | 18 |
func (m *okImageRepositoryNamespaceGetter) GetByNamespace(namespace, name string) (*imageapi.ImageRepository, error) {
|
| 19 |
- return &imageapi.ImageRepository{
|
|
| 20 |
- Status: imageapi.ImageRepositoryStatus{
|
|
| 21 |
- DockerImageRepository: "repository/image", |
|
| 22 |
- }, |
|
| 23 |
- Tags: map[string]string{
|
|
| 24 |
- "latest": "latest", |
|
| 25 |
- }, |
|
| 26 |
- }, nil |
|
| 19 |
+ return nil, nil |
|
| 27 | 20 |
} |
| 28 | 21 |
|
| 29 | 22 |
type okBuildConfigGetter struct{}
|
| ... | ... |
@@ -45,18 +38,10 @@ func (c *okBuildConfigGetter) Get(namespace, name string) (*api.BuildConfig, err |
| 45 | 45 |
URI: "git://github.com/my/repo.git", |
| 46 | 46 |
}, |
| 47 | 47 |
}, |
| 48 |
- Strategy: mockBuildStrategy, |
|
| 49 | 48 |
}, |
| 50 | 49 |
}, nil |
| 51 | 50 |
} |
| 52 | 51 |
|
| 53 |
-var mockBuildStrategy api.BuildStrategy = api.BuildStrategy{
|
|
| 54 |
- Type: "STI", |
|
| 55 |
- STIStrategy: &api.STIBuildStrategy{
|
|
| 56 |
- Image: "repository/image", |
|
| 57 |
- }, |
|
| 58 |
-} |
|
| 59 |
- |
|
| 60 | 52 |
type okBuildCreator struct{}
|
| 61 | 53 |
|
| 62 | 54 |
func (c *okBuildCreator) Create(namespace string, build *api.Build) error {
|
| ... | ... |
@@ -222,7 +207,6 @@ func setup(t *testing.T, filename, eventType string) *testContext {
|
| 222 | 222 |
URI: "git://github.com/my/repo.git", |
| 223 | 223 |
}, |
| 224 | 224 |
}, |
| 225 |
- Strategy: mockBuildStrategy, |
|
| 226 | 225 |
}, |
| 227 | 226 |
}, |
| 228 | 227 |
path: "/foobar", |
| ... | ... |
@@ -78,54 +78,7 @@ func (d *BuildDescriber) DescribeUser(out *tabwriter.Writer, label string, u bui |
| 78 | 78 |
} |
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 |
-func (d *BuildDescriber) Describe(namespace, name string) (string, error) {
|
|
| 82 |
- c := d.Builds(namespace) |
|
| 83 |
- build, err := c.Get(name) |
|
| 84 |
- if err != nil {
|
|
| 85 |
- return "", err |
|
| 86 |
- } |
|
| 87 |
- return tabbedString(func(out *tabwriter.Writer) error {
|
|
| 88 |
- formatMeta(out, build.ObjectMeta) |
|
| 89 |
- formatString(out, "Status", bold(build.Status)) |
|
| 90 |
- if build.StartTimestamp != nil {
|
|
| 91 |
- formatString(out, "Started", build.StartTimestamp.Time) |
|
| 92 |
- } |
|
| 93 |
- if build.CompletionTimestamp != nil {
|
|
| 94 |
- formatString(out, "Finished", build.CompletionTimestamp.Time) |
|
| 95 |
- } |
|
| 96 |
- // Create the time object with second-level precision so we don't get |
|
| 97 |
- // output like "duration: 1.2724395728934s" |
|
| 98 |
- t := util.Now().Rfc3339Copy() |
|
| 99 |
- if build.StartTimestamp != nil && build.CompletionTimestamp != nil {
|
|
| 100 |
- // time a build ran from pod creation to build finish or cancel |
|
| 101 |
- formatString(out, "Duration", build.CompletionTimestamp.Sub(build.StartTimestamp.Rfc3339Copy().Time)) |
|
| 102 |
- } else if build.CompletionTimestamp != nil && build.Status == buildapi.BuildStatusCancelled {
|
|
| 103 |
- // time a build waited for its pod before ultimately being canceled before that pod was created |
|
| 104 |
- formatString(out, "Duration", fmt.Sprintf("waited for %s", build.CompletionTimestamp.Sub(build.CreationTimestamp.Rfc3339Copy().Time)))
|
|
| 105 |
- } else if build.CompletionTimestamp != nil && build.Status != buildapi.BuildStatusCancelled {
|
|
| 106 |
- // for some reason we never saw the pod enter the running state, so we don't know when it |
|
| 107 |
- // "started", so instead print out the time from creation to completion. |
|
| 108 |
- formatString(out, "Duration", build.CompletionTimestamp.Sub(build.CreationTimestamp.Rfc3339Copy().Time)) |
|
| 109 |
- } else if build.StartTimestamp == nil && build.Status != buildapi.BuildStatusCancelled {
|
|
| 110 |
- // time a new build has been waiting for its pod to be created so it can run |
|
| 111 |
- formatString(out, "Duration", fmt.Sprintf("waiting for %s", t.Sub(build.CreationTimestamp.Rfc3339Copy().Time)))
|
|
| 112 |
- } else if build.CompletionTimestamp == nil {
|
|
| 113 |
- // time a still running build has been running in a pod |
|
| 114 |
- formatString(out, "Duration", fmt.Sprintf("running for %s", t.Sub(build.StartTimestamp.Rfc3339Copy().Time)))
|
|
| 115 |
- } |
|
| 116 |
- formatString(out, "Build Pod", build.PodName) |
|
| 117 |
- describeBuildParameters(build.Parameters, out) |
|
| 118 |
- return nil |
|
| 119 |
- }) |
|
| 120 |
-} |
|
| 121 |
- |
|
| 122 |
-// BuildConfigDescriber generates information about a buildConfig |
|
| 123 |
-type BuildConfigDescriber struct {
|
|
| 124 |
- client.Interface |
|
| 125 |
- host string |
|
| 126 |
-} |
|
| 127 |
- |
|
| 128 |
-func describeBuildParameters(p buildapi.BuildParameters, out *tabwriter.Writer) {
|
|
| 81 |
+func (d *BuildDescriber) DescribeParameters(p buildapi.BuildParameters, out *tabwriter.Writer) {
|
|
| 129 | 82 |
formatString(out, "Strategy", p.Strategy.Type) |
| 130 | 83 |
switch p.Strategy.Type {
|
| 131 | 84 |
case buildapi.DockerBuildStrategyType: |
| ... | ... |
@@ -136,7 +89,10 @@ func describeBuildParameters(p buildapi.BuildParameters, out *tabwriter.Writer) |
| 136 | 136 |
formatString(out, "Image", p.Strategy.DockerStrategy.Image) |
| 137 | 137 |
} |
| 138 | 138 |
case buildapi.STIBuildStrategyType: |
| 139 |
- describeSTIStrategy(p.Strategy.STIStrategy, out) |
|
| 139 |
+ formatString(out, "Image", p.Strategy.STIStrategy.Image) |
|
| 140 |
+ if p.Strategy.STIStrategy.Incremental {
|
|
| 141 |
+ formatString(out, "Incremental Build", "yes") |
|
| 142 |
+ } |
|
| 140 | 143 |
case buildapi.CustomBuildStrategyType: |
| 141 | 144 |
formatString(out, "Image", p.Strategy.CustomStrategy.Image) |
| 142 | 145 |
if p.Strategy.CustomStrategy.ExposeDockerSocket {
|
| ... | ... |
@@ -166,36 +122,62 @@ func describeBuildParameters(p buildapi.BuildParameters, out *tabwriter.Writer) |
| 166 | 166 |
|
| 167 | 167 |
formatString(out, "Output Spec", p.Output.DockerImageReference) |
| 168 | 168 |
if p.Revision != nil && p.Revision.Type == buildapi.BuildSourceGit && p.Revision.Git != nil {
|
| 169 |
- buildDescriber := &BuildDescriber{}
|
|
| 170 |
- |
|
| 171 | 169 |
formatString(out, "Git Commit", p.Revision.Git.Commit) |
| 172 |
- buildDescriber.DescribeUser(out, "Revision Author", p.Revision.Git.Author) |
|
| 173 |
- buildDescriber.DescribeUser(out, "Revision Committer", p.Revision.Git.Committer) |
|
| 170 |
+ d.DescribeUser(out, "Revision Author", p.Revision.Git.Author) |
|
| 171 |
+ d.DescribeUser(out, "Revision Committer", p.Revision.Git.Committer) |
|
| 174 | 172 |
if len(p.Revision.Git.Message) > 0 {
|
| 175 | 173 |
formatString(out, "Revision Message", p.Revision.Git.Message) |
| 176 | 174 |
} |
| 177 | 175 |
} |
| 178 | 176 |
} |
| 179 | 177 |
|
| 180 |
-func describeSTIStrategy(s *buildapi.STIBuildStrategy, out *tabwriter.Writer) {
|
|
| 181 |
- if s.From != nil && s.From.Name != "" {
|
|
| 182 |
- if s.From.Namespace != "" {
|
|
| 183 |
- formatString(out, "Image Repository", fmt.Sprintf("%s/%s", s.From.Name, s.From.Namespace))
|
|
| 184 |
- } else {
|
|
| 185 |
- formatString(out, "Image Repository", s.From.Name) |
|
| 178 |
+func (d *BuildDescriber) Describe(namespace, name string) (string, error) {
|
|
| 179 |
+ c := d.Builds(namespace) |
|
| 180 |
+ build, err := c.Get(name) |
|
| 181 |
+ if err != nil {
|
|
| 182 |
+ return "", err |
|
| 183 |
+ } |
|
| 184 |
+ |
|
| 185 |
+ return tabbedString(func(out *tabwriter.Writer) error {
|
|
| 186 |
+ formatMeta(out, build.ObjectMeta) |
|
| 187 |
+ formatString(out, "Status", bold(build.Status)) |
|
| 188 |
+ if build.StartTimestamp != nil {
|
|
| 189 |
+ formatString(out, "Started", build.StartTimestamp.Time) |
|
| 186 | 190 |
} |
| 187 |
- if s.Tag != "" {
|
|
| 188 |
- formatString(out, "Image Repository Tag", s.Tag) |
|
| 191 |
+ if build.CompletionTimestamp != nil {
|
|
| 192 |
+ formatString(out, "Finished", build.CompletionTimestamp.Time) |
|
| 189 | 193 |
} |
| 190 |
- } else {
|
|
| 191 |
- formatString(out, "Builder Image", s.Image) |
|
| 192 |
- } |
|
| 193 |
- if s.Scripts != "" {
|
|
| 194 |
- formatString(out, "Scripts", s.Scripts) |
|
| 195 |
- } |
|
| 196 |
- if s.Incremental {
|
|
| 197 |
- formatString(out, "Incremental Build", "yes") |
|
| 198 |
- } |
|
| 194 |
+ // Create the time object with second-level precision so we don't get |
|
| 195 |
+ // output like "duration: 1.2724395728934s" |
|
| 196 |
+ t := util.Now().Rfc3339Copy() |
|
| 197 |
+ if build.StartTimestamp != nil && build.CompletionTimestamp != nil {
|
|
| 198 |
+ // time a build ran from pod creation to build finish or cancel |
|
| 199 |
+ formatString(out, "Duration", build.CompletionTimestamp.Sub(build.StartTimestamp.Rfc3339Copy().Time)) |
|
| 200 |
+ } else if build.CompletionTimestamp != nil && build.Status == buildapi.BuildStatusCancelled {
|
|
| 201 |
+ // time a build waited for its pod before ultimately being canceled before that pod was created |
|
| 202 |
+ formatString(out, "Duration", fmt.Sprintf("waited for %s", build.CompletionTimestamp.Sub(build.CreationTimestamp.Rfc3339Copy().Time)))
|
|
| 203 |
+ } else if build.CompletionTimestamp != nil && build.Status != buildapi.BuildStatusCancelled {
|
|
| 204 |
+ // for some reason we never saw the pod enter the running state, so we don't know when it |
|
| 205 |
+ // "started", so instead print out the time from creation to completion. |
|
| 206 |
+ formatString(out, "Duration", build.CompletionTimestamp.Sub(build.CreationTimestamp.Rfc3339Copy().Time)) |
|
| 207 |
+ } else if build.StartTimestamp == nil && build.Status != buildapi.BuildStatusCancelled {
|
|
| 208 |
+ // time a new build has been waiting for its pod to be created so it can run |
|
| 209 |
+ formatString(out, "Duration", fmt.Sprintf("waiting for %s", t.Sub(build.CreationTimestamp.Rfc3339Copy().Time)))
|
|
| 210 |
+ } else if build.CompletionTimestamp == nil {
|
|
| 211 |
+ // time a still running build has been running in a pod |
|
| 212 |
+ formatString(out, "Duration", fmt.Sprintf("running for %s", t.Sub(build.StartTimestamp.Rfc3339Copy().Time)))
|
|
| 213 |
+ } |
|
| 214 |
+ |
|
| 215 |
+ formatString(out, "Build Pod", build.PodName) |
|
| 216 |
+ d.DescribeParameters(build.Parameters, out) |
|
| 217 |
+ return nil |
|
| 218 |
+ }) |
|
| 219 |
+} |
|
| 220 |
+ |
|
| 221 |
+// BuildConfigDescriber generates information about a buildConfig |
|
| 222 |
+type BuildConfigDescriber struct {
|
|
| 223 |
+ client.Interface |
|
| 224 |
+ host string |
|
| 199 | 225 |
} |
| 200 | 226 |
|
| 201 | 227 |
// DescribeTriggers generates information about the triggers associated with a buildconfig |
| ... | ... |
@@ -227,9 +209,11 @@ func (d *BuildConfigDescriber) Describe(namespace, name string) (string, error) |
| 227 | 227 |
return "", err |
| 228 | 228 |
} |
| 229 | 229 |
|
| 230 |
+ buildDescriber := &BuildDescriber{}
|
|
| 231 |
+ |
|
| 230 | 232 |
return tabbedString(func(out *tabwriter.Writer) error {
|
| 231 | 233 |
formatMeta(out, buildConfig.ObjectMeta) |
| 232 |
- describeBuildParameters(buildConfig.Parameters, out) |
|
| 234 |
+ buildDescriber.DescribeParameters(buildConfig.Parameters, out) |
|
| 233 | 235 |
d.DescribeTriggers(buildConfig, d.host, out) |
| 234 | 236 |
return nil |
| 235 | 237 |
}) |
| 236 | 238 |
deleted file mode 100644 |
| ... | ... |
@@ -1,107 +0,0 @@ |
| 1 |
-{
|
|
| 2 |
- "apiVersion": "v1beta1", |
|
| 3 |
- "items": [ |
|
| 4 |
- {
|
|
| 5 |
- "apiVersion": "v1beta1", |
|
| 6 |
- "dockerImageRepository": "openshift/ruby-20-centos", |
|
| 7 |
- "kind": "ImageRepository", |
|
| 8 |
- "metadata": {
|
|
| 9 |
- "name": "ruby-20-centos-buildcli" |
|
| 10 |
- }, |
|
| 11 |
- "tags": {
|
|
| 12 |
- "valid": "success" |
|
| 13 |
- } |
|
| 14 |
- }, |
|
| 15 |
- {
|
|
| 16 |
- "apiVersion": "v1beta1", |
|
| 17 |
- "kind": "BuildConfig", |
|
| 18 |
- "labels": {
|
|
| 19 |
- "name": "ruby-sample-build" |
|
| 20 |
- }, |
|
| 21 |
- "metadata": {
|
|
| 22 |
- "name": "ruby-sample-build-validtag" |
|
| 23 |
- }, |
|
| 24 |
- "parameters": {
|
|
| 25 |
- "output": {
|
|
| 26 |
- "to": {
|
|
| 27 |
- "name": "origin-ruby-sample" |
|
| 28 |
- } |
|
| 29 |
- }, |
|
| 30 |
- "source": {
|
|
| 31 |
- "git": {
|
|
| 32 |
- "uri": "git://github.com/openshift/ruby-hello-world.git" |
|
| 33 |
- }, |
|
| 34 |
- "type": "Git" |
|
| 35 |
- }, |
|
| 36 |
- "strategy": {
|
|
| 37 |
- "stiStrategy": {
|
|
| 38 |
- "from": {
|
|
| 39 |
- "name": "ruby-20-centos-buildcli" |
|
| 40 |
- }, |
|
| 41 |
- "tag": "valid", |
|
| 42 |
- "scripts": "https://raw.githubusercontent.com/openshift/ruby-20-centos/master/.sti/bin" |
|
| 43 |
- }, |
|
| 44 |
- "type": "STI" |
|
| 45 |
- } |
|
| 46 |
- }, |
|
| 47 |
- "triggers": [ |
|
| 48 |
- {
|
|
| 49 |
- "imageChange": {
|
|
| 50 |
- "from": {
|
|
| 51 |
- "name": "ruby-20-centos-buildcli" |
|
| 52 |
- }, |
|
| 53 |
- "image": "openshift/ruby-20-centos", |
|
| 54 |
- "tag": "valid" |
|
| 55 |
- }, |
|
| 56 |
- "type": "imageChange" |
|
| 57 |
- } |
|
| 58 |
- ] |
|
| 59 |
- }, |
|
| 60 |
- {
|
|
| 61 |
- "apiVersion": "v1beta1", |
|
| 62 |
- "kind": "BuildConfig", |
|
| 63 |
- "labels": {
|
|
| 64 |
- "name": "ruby-sample-build" |
|
| 65 |
- }, |
|
| 66 |
- "metadata": {
|
|
| 67 |
- "name": "ruby-sample-build-invalidtag" |
|
| 68 |
- }, |
|
| 69 |
- "parameters": {
|
|
| 70 |
- "output": {
|
|
| 71 |
- "to": {
|
|
| 72 |
- "name": "origin-ruby-sample" |
|
| 73 |
- } |
|
| 74 |
- }, |
|
| 75 |
- "source": {
|
|
| 76 |
- "git": {
|
|
| 77 |
- "uri": "git://github.com/openshift/ruby-hello-world.git" |
|
| 78 |
- }, |
|
| 79 |
- "type": "Git" |
|
| 80 |
- }, |
|
| 81 |
- "strategy": {
|
|
| 82 |
- "stiStrategy": {
|
|
| 83 |
- "from": {
|
|
| 84 |
- "name": "ruby-20-centos-buildcli" |
|
| 85 |
- }, |
|
| 86 |
- "tag": "invalid", |
|
| 87 |
- "scripts": "https://raw.githubusercontent.com/openshift/ruby-20-centos/master/.sti/bin" |
|
| 88 |
- }, |
|
| 89 |
- "type": "STI" |
|
| 90 |
- } |
|
| 91 |
- }, |
|
| 92 |
- "triggers": [ |
|
| 93 |
- {
|
|
| 94 |
- "imageChange": {
|
|
| 95 |
- "from": {
|
|
| 96 |
- "name": "ruby-20-centos-buildcli" |
|
| 97 |
- }, |
|
| 98 |
- "image": "openshift/ruby-20-centos", |
|
| 99 |
- "tag": "invalid" |
|
| 100 |
- }, |
|
| 101 |
- "type": "imageChange" |
|
| 102 |
- } |
|
| 103 |
- ] |
|
| 104 |
- } |
|
| 105 |
- ], |
|
| 106 |
- "kind": "List" |
|
| 107 |
-} |
| ... | ... |
@@ -106,6 +106,13 @@ func TestSimpleImageChangeBuildTrigger(t *testing.T) {
|
| 106 | 106 |
}); err != nil {
|
| 107 | 107 |
t.Fatalf("unexpected error: %v", err)
|
| 108 | 108 |
} |
| 109 |
+ /* |
|
| 110 |
+ // update the image tag to ref-2 in the imagerepo so we get another build event using that tag. |
|
| 111 |
+ imageRepo.Tags["latest"] = "ref-2" |
|
| 112 |
+ if _, err = openshift.Client.ImageRepositories(testutil.Namespace()).Update(imageRepo); err != nil {
|
|
| 113 |
+ t.Fatalf("Error updating imageRepo: %v", err)
|
|
| 114 |
+ } |
|
| 115 |
+ */ |
|
| 109 | 116 |
event = <-watch.ResultChan() |
| 110 | 117 |
if e, a := watchapi.Added, event.Type; e != a {
|
| 111 | 118 |
t.Fatalf("expected watch event type %s, got %s", e, a)
|
| ... | ... |
@@ -128,126 +135,7 @@ func TestSimpleImageChangeBuildTrigger(t *testing.T) {
|
| 128 | 128 |
t.Fatalf("Expected build with label %s=%s from build config got %s=%s", "testlabel", "testvalue", "testlabel", newBuild.Labels["testlabel"])
|
| 129 | 129 |
} |
| 130 | 130 |
|
| 131 |
- <-watch2.ResultChan() |
|
| 132 |
- updatedConfig, err = openshift.Client.BuildConfigs(testutil.Namespace()).Get(config.Name) |
|
| 133 |
- if err != nil {
|
|
| 134 |
- t.Fatalf("Couldn't get BuildConfig: %v", err)
|
|
| 135 |
- } |
|
| 136 |
- if updatedConfig.Triggers[0].ImageChange.LastTriggeredImageID != "ref-2-random" {
|
|
| 137 |
- t.Errorf("unexpected trigger id: %#v", updatedConfig.Triggers[0].ImageChange)
|
|
| 138 |
- } |
|
| 139 |
-} |
|
| 140 |
- |
|
| 141 |
-func TestSimpleImageChangeBuildTriggerFromRef(t *testing.T) {
|
|
| 142 |
- testutil.DeleteAllEtcdKeys() |
|
| 143 |
- openshift := NewTestOpenshift(t) |
|
| 144 |
- defer openshift.Close() |
|
| 145 |
- |
|
| 146 |
- imageRepo := &imageapi.ImageRepository{
|
|
| 147 |
- ObjectMeta: kapi.ObjectMeta{Name: "test-image-trigger-repo"},
|
|
| 148 |
- DockerImageRepository: "registry:8080/openshift/test-image-trigger", |
|
| 149 |
- Tags: map[string]string{
|
|
| 150 |
- "latest": "latest", |
|
| 151 |
- }, |
|
| 152 |
- } |
|
| 153 |
- |
|
| 154 |
- config := imageChangeBuildConfigFromRef() |
|
| 155 |
- |
|
| 156 |
- created, err := openshift.Client.BuildConfigs(testutil.Namespace()).Create(config) |
|
| 157 |
- if err != nil {
|
|
| 158 |
- t.Fatalf("Couldn't create BuildConfig: %v", err)
|
|
| 159 |
- } |
|
| 160 |
- |
|
| 161 |
- watch, err := openshift.Client.Builds(testutil.Namespace()).Watch(labels.Everything(), fields.Everything(), created.ResourceVersion) |
|
| 162 |
- if err != nil {
|
|
| 163 |
- t.Fatalf("Couldn't subscribe to Builds %v", err)
|
|
| 164 |
- } |
|
| 165 |
- defer watch.Stop() |
|
| 166 |
- |
|
| 167 |
- watch2, err := openshift.Client.BuildConfigs(testutil.Namespace()).Watch(labels.Everything(), fields.Everything(), created.ResourceVersion) |
|
| 168 |
- if err != nil {
|
|
| 169 |
- t.Fatalf("Couldn't subscribe to BuildConfigs %v", err)
|
|
| 170 |
- } |
|
| 171 |
- defer watch2.Stop() |
|
| 172 |
- |
|
| 173 |
- imageRepo, err = openshift.Client.ImageRepositories(testutil.Namespace()).Create(imageRepo) |
|
| 174 |
- if err != nil {
|
|
| 175 |
- t.Fatalf("Couldn't create ImageRepository: %v", err)
|
|
| 176 |
- } |
|
| 177 |
- |
|
| 178 |
- // wait for initial build event from the creation of the imagerepo with tag latest |
|
| 179 |
- event := <-watch.ResultChan() |
|
| 180 |
- if e, a := watchapi.Added, event.Type; e != a {
|
|
| 181 |
- t.Fatalf("expected watch event type %s, got %s", e, a)
|
|
| 182 |
- } |
|
| 183 |
- newBuild := event.Object.(*buildapi.Build) |
|
| 184 |
- if newBuild.Parameters.Strategy.STIStrategy.Image != "registry:8080/openshift/test-image-trigger:latest" {
|
|
| 185 |
- i, _ := openshift.Client.ImageRepositories(testutil.Namespace()).Get(imageRepo.Name) |
|
| 186 |
- bc, _ := openshift.Client.BuildConfigs(testutil.Namespace()).Get(config.Name) |
|
| 187 |
- t.Fatalf("Expected build with base image %s, got %s\n, imagerepo is %v\ntrigger is %s\n", "registry:8080/openshift/test-image-trigger:latest", newBuild.Parameters.Strategy.STIStrategy.Image, i, bc.Triggers[0].ImageChange)
|
|
| 188 |
- } |
|
| 189 |
- event = <-watch.ResultChan() |
|
| 190 |
- if e, a := watchapi.Modified, event.Type; e != a {
|
|
| 191 |
- t.Fatalf("expected watch event type %s, got %s", e, a)
|
|
| 192 |
- } |
|
| 193 |
- newBuild = event.Object.(*buildapi.Build) |
|
| 194 |
- if newBuild.Parameters.Output.DockerImageReference != "registry:8080/openshift/test-image-trigger:outputtag" {
|
|
| 195 |
- t.Fatalf("Expected build with output image %s, got %s", "registry:8080/openshift/test-image-trigger:outputtag", newBuild.Parameters.Output.DockerImageReference)
|
|
| 196 |
- } |
|
| 197 |
- if newBuild.Labels["testlabel"] != "testvalue" {
|
|
| 198 |
- t.Fatalf("Expected build with label %s=%s from build config got %s=%s", "testlabel", "testvalue", "testlabel", newBuild.Labels["testlabel"])
|
|
| 199 |
- } |
|
| 200 |
- |
|
| 201 |
- // wait for build config to be updated |
|
| 202 |
- <-watch2.ResultChan() |
|
| 203 |
- updatedConfig, err := openshift.Client.BuildConfigs(testutil.Namespace()).Get(config.Name) |
|
| 204 |
- if err != nil {
|
|
| 205 |
- t.Fatalf("Couldn't get BuildConfig: %v", err)
|
|
| 206 |
- } |
|
| 207 |
- // the first tag did not have an image id, so the last trigger field is the pull spec |
|
| 208 |
- if updatedConfig.Triggers[0].ImageChange.LastTriggeredImageID != "registry:8080/openshift/test-image-trigger:latest" {
|
|
| 209 |
- t.Errorf("Expected imageID equal to pull spec, got %s", updatedConfig.Triggers[0].ImageChange)
|
|
| 210 |
- } |
|
| 211 |
- |
|
| 212 |
- // trigger a build by posting a new image |
|
| 213 |
- if err := openshift.Client.ImageRepositoryMappings(testutil.Namespace()).Create(&imageapi.ImageRepositoryMapping{
|
|
| 214 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 215 |
- Namespace: testutil.Namespace(), |
|
| 216 |
- Name: imageRepo.Name, |
|
| 217 |
- }, |
|
| 218 |
- Tag: "latest", |
|
| 219 |
- Image: imageapi.Image{
|
|
| 220 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 221 |
- Name: "ref-2-random", |
|
| 222 |
- }, |
|
| 223 |
- DockerImageReference: "registry:8080/openshift/test-image-trigger:ref-2", |
|
| 224 |
- }, |
|
| 225 |
- }); err != nil {
|
|
| 226 |
- t.Fatalf("unexpected error: %v", err)
|
|
| 227 |
- } |
|
| 228 |
- event = <-watch.ResultChan() |
|
| 229 |
- if e, a := watchapi.Added, event.Type; e != a {
|
|
| 230 |
- t.Fatalf("expected watch event type %s, got %s", e, a)
|
|
| 231 |
- } |
|
| 232 |
- newBuild = event.Object.(*buildapi.Build) |
|
| 233 |
- if newBuild.Parameters.Strategy.STIStrategy.Image != "registry:8080/openshift/test-image-trigger:ref-2" {
|
|
| 234 |
- i, _ := openshift.Client.ImageRepositories(testutil.Namespace()).Get(imageRepo.Name) |
|
| 235 |
- bc, _ := openshift.Client.BuildConfigs(testutil.Namespace()).Get(config.Name) |
|
| 236 |
- t.Fatalf("Expected build with base image %s, got %s\n, imagerepo is %v\trigger is %s\n", "registry:8080/openshift/test-image-trigger:ref-2", newBuild.Parameters.Strategy.STIStrategy.Image, i, bc.Triggers[0].ImageChange)
|
|
| 237 |
- } |
|
| 238 |
- event = <-watch.ResultChan() |
|
| 239 |
- if e, a := watchapi.Modified, event.Type; e != a {
|
|
| 240 |
- t.Fatalf("expected watch event type %s, got %s", e, a)
|
|
| 241 |
- } |
|
| 242 |
- newBuild = event.Object.(*buildapi.Build) |
|
| 243 |
- if newBuild.Parameters.Output.DockerImageReference != "registry:8080/openshift/test-image-trigger:outputtag" {
|
|
| 244 |
- t.Fatalf("Expected build with output image %s, got %s", "registry:8080/openshift/test-image-trigger:outputtag", newBuild.Parameters.Output.DockerImageReference)
|
|
| 245 |
- } |
|
| 246 |
- if newBuild.Labels["testlabel"] != "testvalue" {
|
|
| 247 |
- t.Fatalf("Expected build with label %s=%s from build config got %s=%s", "testlabel", "testvalue", "testlabel", newBuild.Labels["testlabel"])
|
|
| 248 |
- } |
|
| 249 |
- |
|
| 250 |
- <-watch2.ResultChan() |
|
| 131 |
+ event = <-watch2.ResultChan() |
|
| 251 | 132 |
updatedConfig, err = openshift.Client.BuildConfigs(testutil.Namespace()).Get(config.Name) |
| 252 | 133 |
if err != nil {
|
| 253 | 134 |
t.Fatalf("Couldn't get BuildConfig: %v", err)
|
| ... | ... |
@@ -299,48 +187,3 @@ func imageChangeBuildConfig() *buildapi.BuildConfig {
|
| 299 | 299 |
} |
| 300 | 300 |
return buildcfg |
| 301 | 301 |
} |
| 302 |
- |
|
| 303 |
-func imageChangeBuildConfigFromRef() *buildapi.BuildConfig {
|
|
| 304 |
- buildcfg := &buildapi.BuildConfig{
|
|
| 305 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 306 |
- Name: "test-build-cfg", |
|
| 307 |
- Labels: map[string]string{"testlabel": "testvalue"},
|
|
| 308 |
- }, |
|
| 309 |
- Parameters: buildapi.BuildParameters{
|
|
| 310 |
- Source: buildapi.BuildSource{
|
|
| 311 |
- Type: "Git", |
|
| 312 |
- Git: &buildapi.GitBuildSource{
|
|
| 313 |
- URI: "git://github.com/openshift/ruby-hello-world.git", |
|
| 314 |
- }, |
|
| 315 |
- ContextDir: "contextimage", |
|
| 316 |
- }, |
|
| 317 |
- Strategy: buildapi.BuildStrategy{
|
|
| 318 |
- Type: buildapi.STIBuildStrategyType, |
|
| 319 |
- STIStrategy: &buildapi.STIBuildStrategy{
|
|
| 320 |
- From: &kapi.ObjectReference{
|
|
| 321 |
- Name: "test-image-trigger-repo", |
|
| 322 |
- }, |
|
| 323 |
- }, |
|
| 324 |
- }, |
|
| 325 |
- Output: buildapi.BuildOutput{
|
|
| 326 |
- To: &kapi.ObjectReference{
|
|
| 327 |
- Name: "test-image-trigger-repo", |
|
| 328 |
- }, |
|
| 329 |
- Tag: "outputtag", |
|
| 330 |
- }, |
|
| 331 |
- }, |
|
| 332 |
- Triggers: []buildapi.BuildTriggerPolicy{
|
|
| 333 |
- {
|
|
| 334 |
- Type: buildapi.ImageChangeBuildTriggerType, |
|
| 335 |
- ImageChange: &buildapi.ImageChangeTrigger{
|
|
| 336 |
- Image: "registry:8080/openshift/test-image-trigger", |
|
| 337 |
- From: kapi.ObjectReference{
|
|
| 338 |
- Name: "test-image-trigger-repo", |
|
| 339 |
- }, |
|
| 340 |
- Tag: "latest", |
|
| 341 |
- }, |
|
| 342 |
- }, |
|
| 343 |
- }, |
|
| 344 |
- } |
|
| 345 |
- return buildcfg |
|
| 346 |
-} |
| ... | ... |
@@ -92,48 +92,6 @@ func TestWebhookGithubPushWithImageTag(t *testing.T) {
|
| 92 | 92 |
} |
| 93 | 93 |
} |
| 94 | 94 |
|
| 95 |
-func TestWebhookGithubPushWithImageTagRef(t *testing.T) {
|
|
| 96 |
- testutil.DeleteAllEtcdKeys() |
|
| 97 |
- openshift := NewTestBuildOpenshift(t) |
|
| 98 |
- defer openshift.Close() |
|
| 99 |
- |
|
| 100 |
- // create imagerepo |
|
| 101 |
- imageRepo := &imageapi.ImageRepository{
|
|
| 102 |
- ObjectMeta: kapi.ObjectMeta{Name: "imageRepo"},
|
|
| 103 |
- Tags: map[string]string{"validTag": "success"},
|
|
| 104 |
- } |
|
| 105 |
- if _, err := openshift.Client.ImageRepositories(testutil.Namespace()).Create(imageRepo); err != nil {
|
|
| 106 |
- t.Fatalf("Unexpected error: %v", err)
|
|
| 107 |
- } |
|
| 108 |
- |
|
| 109 |
- // create buildconfig |
|
| 110 |
- buildConfig := mockBuildConfigRefParms("originalImage", "imageRepo", "validTag")
|
|
| 111 |
- |
|
| 112 |
- if _, err := openshift.Client.BuildConfigs(testutil.Namespace()).Create(buildConfig); err != nil {
|
|
| 113 |
- t.Fatalf("Unexpected error: %v", err)
|
|
| 114 |
- } |
|
| 115 |
- |
|
| 116 |
- watch, err := openshift.Client.Builds(testutil.Namespace()).Watch(labels.Everything(), fields.Everything(), "0") |
|
| 117 |
- if err != nil {
|
|
| 118 |
- t.Fatalf("Couldn't subscribe to builds: %v", err)
|
|
| 119 |
- } |
|
| 120 |
- defer watch.Stop() |
|
| 121 |
- |
|
| 122 |
- // trigger build event sending push notification |
|
| 123 |
- postFile("push", "pushevent.json", openshift.server.URL+openshift.whPrefix+"pushbuild/secret101/github?namespace="+testutil.Namespace(), http.StatusOK, t)
|
|
| 124 |
- |
|
| 125 |
- event := <-watch.ResultChan() |
|
| 126 |
- actual := event.Object.(*buildapi.Build) |
|
| 127 |
- |
|
| 128 |
- if actual.Status != buildapi.BuildStatusNew {
|
|
| 129 |
- t.Errorf("Expected %s, got %s", buildapi.BuildStatusNew, actual.Status)
|
|
| 130 |
- } |
|
| 131 |
- |
|
| 132 |
- if actual.Parameters.Strategy.STIStrategy.Image != "registry:3000/integration/imageRepo:success" {
|
|
| 133 |
- t.Errorf("Expected %s, got %s", "registry:3000/integration-test/imageRepo:success", actual.Parameters.Strategy.STIStrategy.Image)
|
|
| 134 |
- } |
|
| 135 |
-} |
|
| 136 |
- |
|
| 137 | 95 |
func TestWebhookGithubPushWithImageTagUnmatched(t *testing.T) {
|
| 138 | 96 |
testutil.DeleteAllEtcdKeys() |
| 139 | 97 |
openshift := NewTestBuildOpenshift(t) |
| ... | ... |
@@ -314,50 +272,3 @@ func mockBuildConfigParms(imageName, imageRepo, imageTag string) *buildapi.Build |
| 314 | 314 |
}, |
| 315 | 315 |
} |
| 316 | 316 |
} |
| 317 |
- |
|
| 318 |
-func mockBuildConfigRefParms(imageName, imageRepo, imageTag string) *buildapi.BuildConfig {
|
|
| 319 |
- return &buildapi.BuildConfig{
|
|
| 320 |
- ObjectMeta: kapi.ObjectMeta{
|
|
| 321 |
- Name: "pushbuild", |
|
| 322 |
- }, |
|
| 323 |
- Triggers: []buildapi.BuildTriggerPolicy{
|
|
| 324 |
- {
|
|
| 325 |
- Type: buildapi.GithubWebHookBuildTriggerType, |
|
| 326 |
- GithubWebHook: &buildapi.WebHookTrigger{
|
|
| 327 |
- Secret: "secret101", |
|
| 328 |
- }, |
|
| 329 |
- }, |
|
| 330 |
- {
|
|
| 331 |
- Type: buildapi.ImageChangeBuildTriggerType, |
|
| 332 |
- ImageChange: &buildapi.ImageChangeTrigger{
|
|
| 333 |
- Image: imageName, |
|
| 334 |
- From: kapi.ObjectReference{
|
|
| 335 |
- Name: imageRepo, |
|
| 336 |
- }, |
|
| 337 |
- Tag: imageTag, |
|
| 338 |
- }, |
|
| 339 |
- }, |
|
| 340 |
- }, |
|
| 341 |
- Parameters: buildapi.BuildParameters{
|
|
| 342 |
- Source: buildapi.BuildSource{
|
|
| 343 |
- Type: buildapi.BuildSourceGit, |
|
| 344 |
- Git: &buildapi.GitBuildSource{
|
|
| 345 |
- URI: "http://my.docker/build", |
|
| 346 |
- }, |
|
| 347 |
- ContextDir: "context", |
|
| 348 |
- }, |
|
| 349 |
- Strategy: buildapi.BuildStrategy{
|
|
| 350 |
- Type: buildapi.STIBuildStrategyType, |
|
| 351 |
- STIStrategy: &buildapi.STIBuildStrategy{
|
|
| 352 |
- From: &kapi.ObjectReference{
|
|
| 353 |
- Name: imageRepo, |
|
| 354 |
- }, |
|
| 355 |
- Tag: imageTag, |
|
| 356 |
- }, |
|
| 357 |
- }, |
|
| 358 |
- Output: buildapi.BuildOutput{
|
|
| 359 |
- DockerImageReference: "namespace/builtimage", |
|
| 360 |
- }, |
|
| 361 |
- }, |
|
| 362 |
- } |
|
| 363 |
-} |