Create pidns for rootless

pull/1343/head
Darren Shepherd 2020-01-22 10:53:24 -07:00
parent 0374c4f63d
commit 782004bec9
4 changed files with 17 additions and 5 deletions

View File

@ -17,6 +17,8 @@ func setupMounts(stateDir string) error {
{"/var/run", ""}, {"/var/run", ""},
{"/var/log", filepath.Join(stateDir, "logs")}, {"/var/log", filepath.Join(stateDir, "logs")},
{"/var/lib/cni", filepath.Join(stateDir, "cni")}, {"/var/lib/cni", filepath.Join(stateDir, "cni")},
{"/var/lib/kubelet", filepath.Join(stateDir, "kubelet")},
{"/etc/rancher", filepath.Join(stateDir, "etc", "rancher")},
} }
for _, v := range mountMap { for _, v := range mountMap {

View File

@ -89,7 +89,8 @@ func createParentOpt(stateDir string) (*parent.Opt, error) {
} }
opt := &parent.Opt{ opt := &parent.Opt{
StateDir: stateDir, StateDir: stateDir,
CreatePIDNS: true,
} }
mtu := 0 mtu := 0
@ -102,7 +103,7 @@ func createParentOpt(stateDir string) (*parent.Opt, error) {
if _, err := exec.LookPath(binary); err != nil { if _, err := exec.LookPath(binary); err != nil {
return nil, err return nil, err
} }
opt.NetworkDriver = slirp4netns.NewParentDriver(binary, mtu, ipnet, disableHostLoopback, "") opt.NetworkDriver = slirp4netns.NewParentDriver(binary, mtu, ipnet, disableHostLoopback, "", false, false)
opt.PortDriver, err = portbuiltin.NewParentDriver(&logrusDebugWriter{}, stateDir) opt.PortDriver, err = portbuiltin.NewParentDriver(&logrusDebugWriter{}, stateDir)
if err != nil { if err != nil {
return nil, err return nil, err
@ -130,5 +131,7 @@ func createChildOpt() (*child.Opt, error) {
opt.PortDriver = portbuiltin.NewChildDriver(&logrusDebugWriter{}) opt.PortDriver = portbuiltin.NewChildDriver(&logrusDebugWriter{})
opt.CopyUpDirs = []string{"/etc", "/run", "/var/lib"} opt.CopyUpDirs = []string{"/etc", "/run", "/var/lib"}
opt.CopyUpDriver = tmpfssymlink.NewChildDriver() opt.CopyUpDriver = tmpfssymlink.NewChildDriver()
opt.MountProcfs = true
opt.Reaper = true
return opt, nil return opt, nil
} }

View File

@ -17,7 +17,7 @@ var (
all = "_all_" all = "_all_"
) )
func Register(ctx context.Context, serviceController coreClients.ServiceController, httpsPort int) error { func Register(ctx context.Context, serviceController coreClients.ServiceController, enabled bool, httpsPort int) error {
var ( var (
err error err error
rootlessClient client.Client rootlessClient client.Client
@ -41,6 +41,7 @@ func Register(ctx context.Context, serviceController coreClients.ServiceControll
} }
h := &handler{ h := &handler{
enabled: enabled,
rootlessClient: rootlessClient, rootlessClient: rootlessClient,
serviceClient: serviceController, serviceClient: serviceController,
serviceCache: serviceController.Cache(), serviceCache: serviceController.Cache(),
@ -54,6 +55,7 @@ func Register(ctx context.Context, serviceController coreClients.ServiceControll
} }
type handler struct { type handler struct {
enabled bool
rootlessClient client.Client rootlessClient client.Client
serviceClient coreClients.ServiceController serviceClient coreClients.ServiceController
serviceCache coreClients.ServiceCache serviceCache coreClients.ServiceCache
@ -122,6 +124,11 @@ func (h *handler) toBindPorts() (map[int]int, error) {
toBindPorts := map[int]int{ toBindPorts := map[int]int{
h.httpsPort: h.httpsPort, h.httpsPort: h.httpsPort,
} }
if !h.enabled {
return toBindPorts, nil
}
for _, svc := range svcs { for _, svc := range svcs {
for _, ingress := range svc.Status.LoadBalancer.Ingress { for _, ingress := range svc.Status.LoadBalancer.Ingress {
if ingress.IP == "" { if ingress.IP == "" {

View File

@ -151,8 +151,8 @@ func masterControllers(ctx context.Context, sc *Context, config *Config) error {
return err return err
} }
if !config.DisableServiceLB && config.Rootless { if config.Rootless {
return rootlessports.Register(ctx, sc.Core.Core().V1().Service(), config.ControlConfig.HTTPSPort) return rootlessports.Register(ctx, sc.Core.Core().V1().Service(), !config.DisableServiceLB, config.ControlConfig.HTTPSPort)
} }
return nil return nil