Skip to content

Commit 887ed38

Browse files
authored
Merge pull request #6 from interTwin-eu/socket
enable listen on socket
2 parents 7d68646 + 7b92fa2 commit 887ed38

4 files changed

Lines changed: 34 additions & 3 deletions

File tree

.DS_Store

6 KB
Binary file not shown.

cmd/main.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ package main
22

33
import (
44
"context"
5+
"net"
56
"net/http"
67
"os"
8+
"os/signal"
79
"strconv"
10+
"strings"
11+
"syscall"
812

913
"github.com/sirupsen/logrus"
1014
"github.com/virtual-kubelet/virtual-kubelet/log"
@@ -61,9 +65,35 @@ func main() {
6165
mutex.HandleFunc("/create", SidecarAPIs.CreateHandler)
6266
mutex.HandleFunc("/delete", SidecarAPIs.DeleteHandler)
6367
mutex.HandleFunc("/getLogs", SidecarAPIs.GetLogsHandler)
64-
err = http.ListenAndServe(":"+interLinkConfig.Sidecarport, mutex)
6568

66-
if err != nil {
67-
log.G(Ctx).Fatal(err)
69+
if strings.HasPrefix(interLinkConfig.Socket, "unix://") {
70+
// Create a Unix domain socket and listen for incoming connections.
71+
socket, err := net.Listen("unix", strings.ReplaceAll(interLinkConfig.Socket, "unix://", ""))
72+
if err != nil {
73+
panic(err)
74+
}
75+
76+
// Cleanup the sockfile.
77+
c := make(chan os.Signal, 1)
78+
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
79+
go func() {
80+
<-c
81+
os.Remove(strings.ReplaceAll(interLinkConfig.Socket, "unix://", ""))
82+
os.Exit(1)
83+
}()
84+
server := http.Server{
85+
Handler: mutex,
86+
}
87+
88+
log.G(Ctx).Info(socket)
89+
90+
if err := server.Serve(socket); err != nil {
91+
log.G(Ctx).Fatal(err)
92+
}
93+
} else {
94+
err = http.ListenAndServe(":"+interLinkConfig.Sidecarport, mutex)
95+
if err != nil {
96+
log.G(Ctx).Fatal(err)
97+
}
6898
}
6999
}

pkg/.DS_Store

6 KB
Binary file not shown.

pkg/common/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type InterLinkConfig struct {
4848
Scancelpath string `yaml:"ScancelPath"`
4949
Squeuepath string `yaml:"SqueuePath"`
5050
Interlinkport string `yaml:"InterlinkPort"`
51+
Socket string `yaml:"Socket"`
5152
Sidecarport string `yaml:"SidecarPort"`
5253
Commandprefix string `yaml:"CommandPrefix"`
5354
ExportPodData bool `yaml:"ExportPodData"`

0 commit comments

Comments
 (0)