Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
instead of create use apply and do clean up on error
Browse files Browse the repository at this point in the history
  • Loading branch information
surajssd committed Nov 28, 2017
1 parent 1a42e8c commit 2b058e0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,35 @@ func BuildS2I(image, context, builderImage string) error {
log.Debugf("ImageStream for output image: \n%s\n", string(isyaml))
log.Debugf("BuildConfig: \n%s\n", string(bcyaml))

args := []string{"create", "-f", "-"}
args := []string{"apply", "-f", "-"}
err = cmd.RunClusterCommand(args, isyaml, true)
if err != nil {
cleanup(labels)
return err
}
err = cmd.RunClusterCommand(args, bcyaml, true)
if err != nil {
cleanup(labels)
return err
}

log.Infof("Starting build for %q", image)
cmd := []string{"oc", "start-build", image, "--from-dir=" + context, "-F"}
if err := RunCommand(cmd); err != nil {
cleanup(labels)
return err
}
log.Infof("To trigger the build again, just run:\noc start-build %s --from-dir=%s", image, context)

return nil
}

func cleanup(label map[string]string) {
log.Infof("Cleaning up since error occurred while creating")

for k, v := range label {
cmd := []string{"oc", "delete", "all", "-l " + k + "=" + v}
if err := RunCommand(cmd); err != nil {
log.Debugf("error while cleanup: %v", err)
}
}
}

0 comments on commit 2b058e0

Please sign in to comment.