mirror of
https://github.com/moby/buildkit.git
synced 2026-06-30 19:57:39 +00:00
cniprovider: pass hostname as K8S_POD_NAME arg
Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
This commit is contained in:
@@ -146,7 +146,7 @@ func (w *containerdExecutor) Run(ctx context.Context, id string, root executor.M
|
||||
if !ok {
|
||||
return errors.Errorf("unknown network mode %s", meta.NetMode)
|
||||
}
|
||||
namespace, err := provider.New()
|
||||
namespace, err := provider.New(meta.Hostname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ func (w *runcExecutor) Run(ctx context.Context, id string, root executor.Mount,
|
||||
if !ok {
|
||||
return errors.Errorf("unknown network mode %s", meta.NetMode)
|
||||
}
|
||||
namespace, err := provider.New()
|
||||
namespace, err := provider.New(meta.Hostname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -67,32 +67,42 @@ func (c *cniProvider) initNetwork() error {
|
||||
}
|
||||
defer l.Unlock()
|
||||
}
|
||||
ns, err := c.New()
|
||||
ns, err := c.New("test")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ns.Close()
|
||||
}
|
||||
|
||||
func (c *cniProvider) New() (network.Namespace, error) {
|
||||
func (c *cniProvider) New(hostname string) (network.Namespace, error) {
|
||||
id := identity.NewID()
|
||||
nativeID, err := createNetNS(c, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := c.CNI.Setup(context.TODO(), id, nativeID); err != nil {
|
||||
nsOpts := []cni.NamespaceOpts{
|
||||
// NB: K8S_POD_NAME is a semi-well-known arg set by k8s and podman and
|
||||
// leveraged by the dnsname CNI plugin. a more generic name would be nice.
|
||||
cni.WithArgs("K8S_POD_NAME", hostname),
|
||||
|
||||
// must be set for plugins that don't understand K8S_POD_NAME
|
||||
cni.WithArgs("IgnoreUnknown", "1"),
|
||||
}
|
||||
|
||||
if _, err := c.CNI.Setup(context.TODO(), id, nativeID, nsOpts...); err != nil {
|
||||
deleteNetNS(nativeID)
|
||||
return nil, errors.Wrap(err, "CNI setup error")
|
||||
}
|
||||
|
||||
return &cniNS{nativeID: nativeID, id: id, handle: c.CNI}, nil
|
||||
return &cniNS{nativeID: nativeID, id: id, handle: c.CNI, opts: nsOpts}, nil
|
||||
}
|
||||
|
||||
type cniNS struct {
|
||||
handle cni.CNI
|
||||
id string
|
||||
nativeID string
|
||||
opts []cni.NamespaceOpts
|
||||
}
|
||||
|
||||
func (ns *cniNS) Set(s *specs.Spec) error {
|
||||
@@ -100,7 +110,7 @@ func (ns *cniNS) Set(s *specs.Spec) error {
|
||||
}
|
||||
|
||||
func (ns *cniNS) Close() error {
|
||||
err := ns.handle.Remove(context.TODO(), ns.id, ns.nativeID)
|
||||
err := ns.handle.Remove(context.TODO(), ns.id, ns.nativeID, ns.opts...)
|
||||
if err1 := unmountNetNS(ns.nativeID); err1 != nil && err == nil {
|
||||
err = err1
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func NewHostProvider() Provider {
|
||||
type host struct {
|
||||
}
|
||||
|
||||
func (h *host) New() (Namespace, error) {
|
||||
func (h *host) New(hostname string) (Namespace, error) {
|
||||
return &hostNS{}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
// Provider interface for Network
|
||||
type Provider interface {
|
||||
New() (Namespace, error)
|
||||
New(hostname string) (Namespace, error)
|
||||
}
|
||||
|
||||
// Namespace of network for workers
|
||||
|
||||
@@ -11,7 +11,7 @@ func NewNoneProvider() Provider {
|
||||
type none struct {
|
||||
}
|
||||
|
||||
func (h *none) New() (Namespace, error) {
|
||||
func (h *none) New(hostname string) (Namespace, error) {
|
||||
return &noneNS{}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user