Skip to content

Commit

Permalink
remove http server healthchecks
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Stefurishin <aleksandr.stefurishin@flant.com>
  • Loading branch information
astef committed Dec 28, 2024
1 parent 4af64e4 commit a908a64
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 48 deletions.
18 changes: 0 additions & 18 deletions images/sds-local-volume-csi/src/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"syscall"
Expand Down Expand Up @@ -52,14 +51,6 @@ var (
}
)

func healthHandler(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, err := fmt.Fprint(w, "OK")
if err != nil {
klog.Fatalf("Error while generating healthcheck, err: %s", err.Error())
}
}

func main() {
ctx, cancel := context.WithCancel(context.Background())

Expand Down Expand Up @@ -98,15 +89,6 @@ func main() {
Scheme: scheme,
})

http.HandleFunc("/healthz", healthHandler)
http.HandleFunc("/readyz", healthHandler)
go func() {
err = http.ListenAndServe(cfgParams.HealthProbeBindAddress, nil)
if err != nil {
log.Error(err, "[main] create probes")
}
}()

drv, err := driver.NewDriver(cfgParams.CsiAddress, cfgParams.DriverName, cfgParams.Address, &cfgParams.NodeName, log, cl)
if err != nil {
log.Error(err, "[main] create NewDriver")
Expand Down
32 changes: 2 additions & 30 deletions images/sds-local-volume-csi/src/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ package driver

import (
"context"
"errors"
"fmt"
"net"
"net/http"
"net/url"
"os"
"path"
Expand Down Expand Up @@ -62,9 +60,8 @@ type Driver struct {
hostID string
waitActionTimeout time.Duration

srv *grpc.Server
httpSrv http.Server
log *logger.Logger
srv *grpc.Server
log *logger.Logger

readyMu sync.Mutex // protects ready
ready bool
Expand Down Expand Up @@ -147,28 +144,10 @@ func (d *Driver) Run(ctx context.Context) error {
csi.RegisterControllerServer(d.srv, d)
csi.RegisterNodeServer(d.srv, d)

httpListener, err := net.Listen("tcp", d.address)
if err != nil {
return fmt.Errorf("failed to listen: %v", err)
}

mux := http.NewServeMux()
mux.HandleFunc("/health", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
})

d.httpSrv = http.Server{
Handler: mux,
}

d.ready = true
d.log.Info(fmt.Sprintf("grpc_addr %s http_addr %s starting server", grpcAddr, d.address))

var eg errgroup.Group
eg.Go(func() error {
<-ctx.Done()
return d.httpSrv.Shutdown(context.Background())
})
eg.Go(func() error {
go func() {
<-ctx.Done()
Expand All @@ -180,13 +159,6 @@ func (d *Driver) Run(ctx context.Context) error {
}()
return d.srv.Serve(grpcListener)
})
eg.Go(func() error {
err := d.httpSrv.Serve(httpListener)
if errors.Is(err, http.ErrServerClosed) {
return nil
}
return err
})

return eg.Wait()
}

0 comments on commit a908a64

Please sign in to comment.