Skip to content

Commit

Permalink
listen on socket
Browse files Browse the repository at this point in the history
Signed-off-by: Diego Ciangottini <diego.ciangottini@pg.infn.it>
  • Loading branch information
dciangot committed Sep 22, 2024
1 parent 7d68646 commit 7b92fa2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Binary file added .DS_Store
Binary file not shown.
36 changes: 33 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
}
Binary file added pkg/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions pkg/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 7b92fa2

Please sign in to comment.