From 7b92fa2f9b7f5d48d994df6785f8229a32b951b8 Mon Sep 17 00:00:00 2001 From: Diego Ciangottini Date: Sun, 22 Sep 2024 09:21:01 +0200 Subject: [PATCH] listen on socket Signed-off-by: Diego Ciangottini --- .DS_Store | Bin 0 -> 6148 bytes cmd/main.go | 36 +++++++++++++++++++++++++++++++++--- pkg/.DS_Store | Bin 0 -> 6148 bytes pkg/common/types.go | 1 + 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 .DS_Store create mode 100644 pkg/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..38989cfa6df641bd7e5faf47c0c975149e603d6b GIT binary patch literal 6148 zcmeHKze~eF6nq+ByMqqS;^HE@ z2!c52B>26%tGQ=dM-{mTcVF^;B2sZTqU zP?K7+AH_;Blat~0^RzAc5m{M3le1($74D~iPP){TeFP6##N~f@UmV>NTh~o8-h6Zn z-!xX8fOC&pbRby^uV58%m%CbA8gYNg$vT*nGp3IM_0U6Gc5r&G*R3Nicm29{yjaw~ zMO){tJ0F#Ncep4OX@C{?G4~~B?Mg;n-t*hf`|Z@b+~YGOf1UY%%dls&mC6SF>=p0| zcm+Nc;P*p_!5CRg4eD11CjAKj4B*y=W4(6)Lv{coi>X0)V9JyNO{ub<7|N8xAKJXg zVrtNolhVw%j%8N%3q@&m_(PpeDl+J2uYgxTDo`+|72f~XCx8FTB7f!;@Cy7Z1ym4k z#%oxT-CJ{uKH#l*4nrGaAs+xEi>X0)VE&JQmcdV6fge@i E14TLEX8-^I literal 0 HcmV?d00001 diff --git a/cmd/main.go b/cmd/main.go index 857f038..f873668 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -2,9 +2,13 @@ package main import ( "context" + "net" "net/http" "os" + "os/signal" "strconv" + "strings" + "syscall" "github.com/sirupsen/logrus" "github.com/virtual-kubelet/virtual-kubelet/log" @@ -61,9 +65,35 @@ func main() { mutex.HandleFunc("/create", SidecarAPIs.CreateHandler) mutex.HandleFunc("/delete", SidecarAPIs.DeleteHandler) mutex.HandleFunc("/getLogs", SidecarAPIs.GetLogsHandler) - err = http.ListenAndServe(":"+interLinkConfig.Sidecarport, mutex) - if err != nil { - log.G(Ctx).Fatal(err) + if strings.HasPrefix(interLinkConfig.Socket, "unix://") { + // Create a Unix domain socket and listen for incoming connections. + socket, err := net.Listen("unix", strings.ReplaceAll(interLinkConfig.Socket, "unix://", "")) + if err != nil { + panic(err) + } + + // Cleanup the sockfile. + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) + go func() { + <-c + os.Remove(strings.ReplaceAll(interLinkConfig.Socket, "unix://", "")) + os.Exit(1) + }() + server := http.Server{ + Handler: mutex, + } + + log.G(Ctx).Info(socket) + + if err := server.Serve(socket); err != nil { + log.G(Ctx).Fatal(err) + } + } else { + err = http.ListenAndServe(":"+interLinkConfig.Sidecarport, mutex) + if err != nil { + log.G(Ctx).Fatal(err) + } } } diff --git a/pkg/.DS_Store b/pkg/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0c8885141335ec4fe931b31e71960ae38997f8fd GIT binary patch literal 6148 zcmeHKK~BR!475vxg1GdEIPC`z^ar5|AD|yVO%O;lY*nczE_nb#{D>P*-~qgZ@!Bd$ zL&XiD%8tCV@!A__62&nQ@pN5Jh{i;eLj^}i7=9307ahpREV9UHk4TS;yUDDI&2r%F zhX2TbJi9}xC{lxC@chEd_IeY`a=wUj*z?opv(Jz0{c`A2|LU{6@4hD&*aCUf$e^MJ zx}{bBJ$gFdUhn2{{np8&vquxZ^VsFn&*N3{aB&8l0cT*}89>bz$&VF%bOxLOXJEsC zd>;Z-urO>D)29PNY5{;5%tp9{eM5m&zu2gV6Pb9tello+>+JS!Ocmn s4bU5?i1@XNn-EM=DTc3<;uB~R*n>=fg<-1*3&ei}5)D2$1AofE7b?U|P5=M^ literal 0 HcmV?d00001 diff --git a/pkg/common/types.go b/pkg/common/types.go index 0810681..a0b0ff2 100644 --- a/pkg/common/types.go +++ b/pkg/common/types.go @@ -48,6 +48,7 @@ type InterLinkConfig struct { Scancelpath string `yaml:"ScancelPath"` Squeuepath string `yaml:"SqueuePath"` Interlinkport string `yaml:"InterlinkPort"` + Socket string `yaml:"Socket"` Sidecarport string `yaml:"SidecarPort"` Commandprefix string `yaml:"CommandPrefix"` ExportPodData bool `yaml:"ExportPodData"`