Skip to content

Commit

Permalink
WIP Remove nginx unix sockets (kubernetes#4531)
Browse files Browse the repository at this point in the history
* Remove nginx unix sockets
* Use an emptyDir volume for /tmp in PSP e2e tests
  • Loading branch information
aledbf authored Sep 8, 2019
1 parent 76e2a5d commit ce3e3d5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
8 changes: 4 additions & 4 deletions internal/ingress/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,10 +795,10 @@ type TemplateConfig struct {
PublishService *apiv1.Service
EnableMetrics bool

PID string
StatusPath string
StatusPort int
StreamSocket string
PID string
StatusPath string
StatusPort int
StreamPort int
}

// ListenPorts describe the ports required to run the
Expand Down
16 changes: 8 additions & 8 deletions internal/ingress/controller/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,11 @@ func (n NGINXController) generateTemplate(cfg ngx_config.Configuration, ingressC
PublishService: n.GetPublishService(),
EnableMetrics: n.cfg.EnableMetrics,

HealthzURI: nginx.HealthPath,
PID: nginx.PID,
StatusPath: nginx.StatusPath,
StatusPort: nginx.StatusPort,
StreamSocket: nginx.StreamSocket,
HealthzURI: nginx.HealthPath,
PID: nginx.PID,
StatusPath: nginx.StatusPath,
StatusPort: nginx.StatusPort,
StreamPort: nginx.StreamPort,
}

tc.Cfg.Checksum = ingressCfg.ConfigurationChecksum
Expand Down Expand Up @@ -923,16 +923,16 @@ func updateStreamConfiguration(TCPEndpoints []ingress.L4Service, UDPEndpoints []
})
}

conn, err := net.Dial("unix", nginx.StreamSocket)
buf, err := json.Marshal(streams)
if err != nil {
return err
}
defer conn.Close()

buf, err := json.Marshal(streams)
conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%v", nginx.StreamPort))
if err != nil {
return err
}
defer conn.Close()

_, err = conn.Write(buf)
if err != nil {
Expand Down
14 changes: 6 additions & 8 deletions internal/ingress/controller/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,15 @@ func TestIsDynamicConfigurationEnough(t *testing.T) {
func TestConfigureDynamically(t *testing.T) {
listener, err := net.Listen("tcp", fmt.Sprintf(":%v", nginx.StatusPort))
if err != nil {
t.Fatalf("crating unix listener: %s", err)
t.Fatalf("crating tcp listener: %s", err)
}
defer listener.Close()

streamListener, err := net.Listen("unix", nginx.StreamSocket)
streamListener, err := net.Listen("tcp", fmt.Sprintf(":%v", nginx.StreamPort))
if err != nil {
t.Fatalf("crating unix listener: %s", err)
t.Fatalf("crating tcp listener: %s", err)
}
defer streamListener.Close()
defer os.Remove(nginx.StreamSocket)

endpointStats := map[string]int{"/configuration/backends": 0, "/configuration/general": 0, "/configuration/servers": 0}
resetEndpointStats := func() {
Expand Down Expand Up @@ -321,16 +320,15 @@ func TestConfigureDynamically(t *testing.T) {
func TestConfigureCertificates(t *testing.T) {
listener, err := net.Listen("tcp", fmt.Sprintf(":%v", nginx.StatusPort))
if err != nil {
t.Fatalf("crating unix listener: %s", err)
t.Fatalf("crating tcp listener: %s", err)
}
defer listener.Close()

streamListener, err := net.Listen("unix", nginx.StreamSocket)
streamListener, err := net.Listen("tcp", fmt.Sprintf(":%v", nginx.StreamPort))
if err != nil {
t.Fatalf("crating unix listener: %s", err)
t.Fatalf("crating tcp listener: %s", err)
}
defer streamListener.Close()
defer os.Remove(nginx.StreamSocket)

servers := []*ingress.Server{{
Hostname: "myapp.fake",
Expand Down
6 changes: 2 additions & 4 deletions internal/nginx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ var HealthCheckTimeout = 10 * time.Second
// http://nginx.org/en/docs/http/ngx_http_stub_status_module.html
var StatusPath = "/nginx_status"

// StreamSocket defines the location of the unix socket used by NGINX for the NGINX stream configuration socket
var StreamSocket = "/tmp/ingress-stream.sock"

var statusLocation = "nginx-status"
// StreamPort defines the port used by NGINX for the NGINX stream configuration socket
var StreamPort = 10257

// NewGetStatusRequest creates a new GET request to the internal NGINX status server
func NewGetStatusRequest(path string) (int, []byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ stream {
}

server {
listen unix:{{ .StreamSocket }};
listen 127.0.0.1:{{ .StreamPort }};

access_log off;

Expand Down
8 changes: 8 additions & 0 deletions test/e2e/settings/pod_security_policy_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ var _ = framework.IngressNginxDescribe("Pod Security Policies with volumes", fun
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
},
{
Name: "tmp", VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
},
}

fsGroup := int64(33)
Expand All @@ -82,6 +87,9 @@ var _ = framework.IngressNginxDescribe("Pod Security Policies with volumes", fun
{
Name: "ssl", MountPath: "/etc/ingress-controller",
},
{
Name: "tmp", MountPath: "/tmp",
},
}

_, err := f.KubeClientSet.AppsV1().Deployments(f.Namespace).Update(deployment)
Expand Down

0 comments on commit ce3e3d5

Please sign in to comment.