Skip to content

Commit b4f79d3

Browse files
committed
feat(builder): make the builder pod timeout configurable
1 parent e05345f commit b4f79d3

3 files changed

Lines changed: 58 additions & 19 deletions

File tree

boot.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
const (
1818
serverConfAppName = "deis-builder-server"
1919
gitReceiveConfAppName = "deis-builder-git-receive"
20+
builderPodTick = 100
21+
objectStorageTick = 500
2022
)
2123

2224
func init() {
@@ -59,6 +61,15 @@ func main() {
5961
pkglog.Err("Error getting config for %s [%s]", gitReceiveConfAppName, err)
6062
os.Exit(1)
6163
}
64+
65+
// check for invalid ticks duration
66+
if cnf.BuilderPodTickDurationMSec >= cnf.BuilderPodWaitDurationMSec {
67+
cnf.BuilderPodTickDurationMSec = builderPodTick
68+
}
69+
if cnf.ObjectStorageTickDurationMSec >= cnf.ObjectStorageWaitDurationMSec {
70+
cnf.ObjectStorageTickDurationMSec = objectStorageTick
71+
}
72+
6273
if err := gitreceive.Run(cnf); err != nil {
6374
pkglog.Err("running git receive hook [%s]", err)
6475
os.Exit(1)

pkg/gitreceive/build.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"os/exec"
1111
"path/filepath"
1212
"strings"
13-
"time"
1413

1514
"github.com/aws/aws-sdk-go/service/s3"
1615
"github.com/deis/builder/pkg"
@@ -21,6 +20,7 @@ import (
2120

2221
"k8s.io/kubernetes/pkg/api"
2322
client "k8s.io/kubernetes/pkg/client/unversioned"
23+
"k8s.io/kubernetes/pkg/util/wait"
2424
)
2525

2626
// repoCmd returns exec.Command(first, others...) with its current working directory repoDir
@@ -168,9 +168,7 @@ func build(conf *Config, s3Client *s3.S3, kubeClient *client.Client, builderKey,
168168
return fmt.Errorf("creating builder pod (%s)", err)
169169
}
170170

171-
timeout := time.Duration(5 * time.Minute)
172-
tick := time.Duration(500 * time.Millisecond)
173-
if err := waitForPod(kubeClient, newPod.Namespace, newPod.Name, tick, timeout); err != nil {
171+
if err := waitForPod(kubeClient, newPod.Namespace, newPod.Name, conf.BuilderPodTickDuration(), conf.BuilderPodWaitDuration()); err != nil {
174172
return fmt.Errorf("watching events for builder pod startup (%s)", err)
175173
}
176174

@@ -192,15 +190,16 @@ func build(conf *Config, s3Client *s3.S3, kubeClient *client.Client, builderKey,
192190
log.Debug("size of logs streamed %v", size)
193191

194192
// poll the s3 server to ensure the slug exists
195-
// TODO: time out looking
196-
for {
193+
err = wait.PollImmediate(conf.ObjectStorageTickDuration(), conf.ObjectStorageWaitDuration(), func() (bool, error) {
197194
exists, err := storage.ObjectExists(s3Client, bucketName, slugBuilderInfo.PushKey())
198195
if err != nil {
199-
return fmt.Errorf("Checking if object %s/%s exists (%s)", bucketName, slugBuilderInfo.PushKey(), err)
200-
}
201-
if exists {
202-
break
196+
return false, fmt.Errorf("Checking if object %s/%s exists (%s)", bucketName, slugBuilderInfo.PushKey(), err)
203197
}
198+
return exists, nil
199+
})
200+
201+
if err != nil {
202+
return fmt.Errorf("Timed out waiting for object in storage. Aborting build...")
204203
}
205204

206205
log.Info("Build complete.")

pkg/gitreceive/config.go

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gitreceive
22

33
import (
44
"strings"
5+
"time"
56
)
67

78
type Config struct {
@@ -11,15 +12,19 @@ type Config struct {
1112
RegistryHost string `envconfig:"DEIS_REGISTRY_SERVICE_HOST" required:"true"`
1213
RegistryPort string `envconfig:"DEIS_REGISTRY_SERVICE_PORT" required:"true"`
1314

14-
GitHome string `envconfig:"GIT_HOME" required:"true"`
15-
SSHConnection string `envconfig:"SSH_CONNECTION" required:"true"`
16-
SSHOriginalCommand string `envconfig:"SSH_ORIGINAL_COMMAND" required:"true"`
17-
Repository string `envconfig:"REPOSITORY" required:"true"`
18-
Username string `envconfig:"USERNAME" required:"true"`
19-
Fingerprint string `envconfig:"FINGERPRINT" required:"true"`
20-
PodNamespace string `envconfig:"POD_NAMESPACE" required:"true"`
21-
StorageRegion string `envconfig:"STORAGE_REGION" default:"us-east-1"`
22-
Debug bool `envconfig:"DEBUG" default:"false"`
15+
GitHome string `envconfig:"GIT_HOME" required:"true"`
16+
SSHConnection string `envconfig:"SSH_CONNECTION" required:"true"`
17+
SSHOriginalCommand string `envconfig:"SSH_ORIGINAL_COMMAND" required:"true"`
18+
Repository string `envconfig:"REPOSITORY" required:"true"`
19+
Username string `envconfig:"USERNAME" required:"true"`
20+
Fingerprint string `envconfig:"FINGERPRINT" required:"true"`
21+
PodNamespace string `envconfig:"POD_NAMESPACE" required:"true"`
22+
StorageRegion string `envconfig:"STORAGE_REGION" default:"us-east-1"`
23+
Debug bool `envconfig:"DEBUG" default:"false"`
24+
BuilderPodTickDurationMSec int `envconfig:"BUILDER_POD_TICK_DURATION" default:"100"`
25+
BuilderPodWaitDurationMSec int `envconfig:"BUILDER_POD_WAIT_DURATION" default:"300000"` // 5 minutes
26+
ObjectStorageTickDurationMSec int `envconfing:"OBJECT_STORAGE_TICK_DURATION" default:"500"`
27+
ObjectStorageWaitDurationMSec int `envconfig:"OBJECT_STORAGE_WAIT_DURATION" default:"300000"` // 5 minutes
2328
}
2429

2530
func (c Config) App() string {
@@ -29,3 +34,27 @@ func (c Config) App() string {
2934
}
3035
return c.Repository[0:li]
3136
}
37+
38+
// BuilderPodTickDuration returns the size of the interval used to check for
39+
// the end of the execution of a Pod building an application
40+
func (c Config) BuilderPodTickDuration() time.Duration {
41+
return time.Duration(time.Duration(c.BuilderPodTickDurationMSec) * time.Millisecond)
42+
}
43+
44+
// BuilderPodWaitDuration returns the maximum time to wait for the end
45+
// of the execution of a Pod building an application
46+
func (c Config) BuilderPodWaitDuration() time.Duration {
47+
return time.Duration(time.Duration(c.BuilderPodWaitDurationMSec) * time.Millisecond)
48+
}
49+
50+
// ObjectStorageTickDuration returns the size of the interval used to check for
51+
// the end of an operation that involves the object storage
52+
func (c Config) ObjectStorageTickDuration() time.Duration {
53+
return time.Duration(time.Duration(c.ObjectStorageTickDurationMSec) * time.Millisecond)
54+
}
55+
56+
// ObjectStorageWaitDuration returns the maximum time to wait for the end of an
57+
// operation that involves the object storage
58+
func (c Config) ObjectStorageWaitDuration() time.Duration {
59+
return time.Duration(time.Duration(c.ObjectStorageWaitDurationMSec) * time.Millisecond)
60+
}

0 commit comments

Comments
 (0)