Merge pull request #11391 from Luap99/rootlessport-socket
rootlessport: allow socket paths with more than 108 chars
This commit is contained in:
		
						commit
						fff12da70e
					
				|  | @ -632,16 +632,7 @@ func (c *Container) reloadRootlessRLKPortMapping() error { | ||||||
| 	childIP := getRootlessPortChildIP(c) | 	childIP := getRootlessPortChildIP(c) | ||||||
| 	logrus.Debugf("reloading rootless ports for container %s, childIP is %s", c.config.ID, childIP) | 	logrus.Debugf("reloading rootless ports for container %s, childIP is %s", c.config.ID, childIP) | ||||||
| 
 | 
 | ||||||
| 	var conn net.Conn | 	conn, err := openUnixSocket(filepath.Join(c.runtime.config.Engine.TmpDir, "rp", c.config.ID)) | ||||||
| 	var err error |  | ||||||
| 	// try three times to connect to the socket, maybe it is not ready yet
 |  | ||||||
| 	for i := 0; i < 3; i++ { |  | ||||||
| 		conn, err = net.Dial("unix", filepath.Join(c.runtime.config.Engine.TmpDir, "rp", c.config.ID)) |  | ||||||
| 		if err == nil { |  | ||||||
| 			break |  | ||||||
| 		} |  | ||||||
| 		time.Sleep(250 * time.Millisecond) |  | ||||||
| 	} |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		// This is not a hard error for backwards compatibility. A container started
 | 		// This is not a hard error for backwards compatibility. A container started
 | ||||||
| 		// with an old version did not created the rootlessport socket.
 | 		// with an old version did not created the rootlessport socket.
 | ||||||
|  |  | ||||||
|  | @ -218,10 +218,20 @@ outer: | ||||||
| 
 | 
 | ||||||
| 	// we only need to have a socket to reload ports when we run under rootless cni
 | 	// we only need to have a socket to reload ports when we run under rootless cni
 | ||||||
| 	if cfg.RootlessCNI { | 	if cfg.RootlessCNI { | ||||||
| 		socket, err := net.Listen("unix", filepath.Join(socketDir, cfg.ContainerID)) | 		// workaround to bypass the 108 char socket path limit
 | ||||||
|  | 		// open the fd and use the path to the fd as bind argument
 | ||||||
|  | 		fd, err := unix.Open(socketDir, unix.O_PATH, 0) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
|  | 		socket, err := net.ListenUnix("unixpacket", &net.UnixAddr{Name: fmt.Sprintf("/proc/self/fd/%d/%s", fd, cfg.ContainerID), Net: "unixpacket"}) | ||||||
|  | 		if err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  | 		err = unix.Close(fd) | ||||||
|  | 		if err != nil { | ||||||
|  | 			logrus.Warnf("failed to close the socketDir fd: %v", err) | ||||||
|  | 		} | ||||||
| 		defer socket.Close() | 		defer socket.Close() | ||||||
| 		go serve(socket, driver) | 		go serve(socket, driver) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue