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

Commit

Permalink
Harden pod chooser for no running pods
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Hiltgen committed Dec 3, 2020
1 parent 9438b36 commit 4993b42
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ If you want to run a single suite of tests while working on a specific area of t
```
make integration EXTRA_GO_TEST_FLAGS="-run TestConfigMapSuite -v"
```
Hint: find the current test suites with `grep "func Test" integration/suites/*.go`

To check your code for **lint/style consistency**, run
```
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ kubectl apply -f ./examples/local-registry.yaml
kubectl buildkit create --config ./examples/local-registry-buildkitd.toml
```

You can then build using the registry cache with something like
You can then build using the registry cache with the command:
```
kubectl build -t myimage --cache-to=type=registry,ref=registry:5000/cache --cache-from=type=registry,ref=registry:5000/cache .
```
Expand Down
13 changes: 8 additions & 5 deletions pkg/driver/kubernetes/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/vmware-tanzu/buildkit-cli-for-kubectl/pkg/store"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
kubeerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
clientappsv1 "k8s.io/client-go/kubernetes/typed/apps/v1"
Expand Down Expand Up @@ -80,9 +81,11 @@ func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error {
return progress.Wrap("[internal] booting buildkit", l, func(sub progress.SubLogger) error {
_, err := d.configMapClient.Get(ctx, d.configMap.Name, metav1.GetOptions{})

if err != nil {
if err != nil && kubeerrors.IsNotFound(err) {
// Doesn't exist, create it
_, err = d.configMapClient.Create(ctx, d.configMap, metav1.CreateOptions{})
} else if err != nil {
return errors.Wrapf(err, "configmap get error for %q", d.configMap.Name)
} else if d.userSpecifiedConfig {
// err was nil, thus it already exists, and user passed a new config, so update it
_, err = d.configMapClient.Update(ctx, d.configMap, metav1.UpdateOptions{})
Expand Down Expand Up @@ -273,11 +276,11 @@ func (d *Driver) wait(ctx context.Context, sub progress.SubLogger) error {
if err != nil {
return err
}
// Instead of updating, we'll just delete and re-create
err = d.Rm(ctx, true)
if err != nil {
return err
// Instead of updating, we'll just delete the deployment and re-create
if err := d.deploymentClient.Delete(ctx, d.deployment.Name, metav1.DeleteOptions{}); err != nil {
return errors.Wrapf(err, "error while calling deploymentClient.Delete for %q", d.deployment.Name)
}

// Wait for the pods to wind down before re-deploying...
for ; try < 100; try++ {
remainingPods := 0
Expand Down
4 changes: 4 additions & 0 deletions pkg/driver/kubernetes/podchooser/podchooser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package podchooser

import (
"context"
"fmt"
"math/rand"
"sort"
"time"
Expand Down Expand Up @@ -31,6 +32,9 @@ func (pc *RandomPodChooser) ChoosePod(ctx context.Context) (*corev1.Pod, error)
if err != nil {
return nil, err
}
if len(pods) == 0 {
return nil, fmt.Errorf("no builder pods are running")
}
randSource := pc.RandSource
if randSource == nil {
randSource = rand.NewSource(time.Now().Unix())
Expand Down

0 comments on commit 4993b42

Please sign in to comment.