kubernetes: show Kubernetes Pods as buildx "Nodes" in docker buildx inspect

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda
2019-11-12 19:10:39 +09:00
parent 6b65b0c982
commit c6f8de90aa
5 changed files with 54 additions and 11 deletions

View File

@ -3,6 +3,7 @@ package driver
import (
"context"
"github.com/docker/buildx/store"
"github.com/docker/buildx/util/progress"
"github.com/moby/buildkit/client"
"github.com/pkg/errors"
@ -39,6 +40,8 @@ func (s Status) String() string {
type Info struct {
Status Status
// DynamicNodes must be empty if the actual nodes are statically listed in the store
DynamicNodes []store.Node
}
type Driver interface {

View File

@ -9,10 +9,10 @@ import (
"github.com/docker/buildx/driver"
"github.com/docker/buildx/driver/kubernetes/execconn"
"github.com/docker/buildx/driver/kubernetes/podchooser"
"github.com/docker/buildx/store"
"github.com/docker/buildx/util/progress"
"github.com/moby/buildkit/client"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
@ -94,13 +94,26 @@ func (d *Driver) Info(ctx context.Context) (*driver.Info, error) {
Status: driver.Inactive,
}, nil
}
if depl.Status.ReadyReplicas > 0 {
if depl.Status.ReadyReplicas <= 0 {
return &driver.Info{
Status: driver.Running,
Status: driver.Stopped,
}, nil
}
pods, err := podchooser.ListRunningPods(d.podClient, depl)
if err != nil {
return nil, err
}
var dynNodes []store.Node
for _, p := range pods {
node := store.Node{
Name: p.Name,
// Other fields are unset (TODO: detect real platforms)
}
dynNodes = append(dynNodes, node)
}
return &driver.Info{
Status: driver.Stopped,
Status: driver.Running,
DynamicNodes: dynNodes,
}, nil
}
@ -126,7 +139,6 @@ func (d *Driver) Client(ctx context.Context) (*client.Client, error) {
if err != nil {
return nil, err
}
logrus.Infof("Using pod %q", pod.Name)
if len(pod.Spec.Containers) == 0 {
return nil, errors.Errorf("pod %s does not have any container", pod.Name)
}