Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove nginx unix sockets #4531

Merged
merged 2 commits into from
Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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