Skip to content

Commit

Permalink
refactor: move non-entry app functions away from app pkg
Browse files Browse the repository at this point in the history
Signed-off-by: davidko <[email protected]>
  • Loading branch information
innobead authored and David Ko committed Dec 13, 2023
1 parent 27101bb commit ac3a130
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions app/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package app
import (
"fmt"
"net/http"
"os"

_ "net/http/pprof" // for runtime profiling
"os"

"github.com/gorilla/handlers"
"github.com/pkg/errors"
Expand All @@ -22,10 +21,12 @@ import (
"github.com/longhorn/longhorn-manager/datastore"
"github.com/longhorn/longhorn-manager/manager"
"github.com/longhorn/longhorn-manager/meta"
"github.com/longhorn/longhorn-manager/recovery_backend"
"github.com/longhorn/longhorn-manager/types"
"github.com/longhorn/longhorn-manager/upgrade"
"github.com/longhorn/longhorn-manager/util"
"github.com/longhorn/longhorn-manager/util/client"
"github.com/longhorn/longhorn-manager/webhook"

metricscollector "github.com/longhorn/longhorn-manager/metrics_collector"
)
Expand Down Expand Up @@ -146,12 +147,12 @@ func startManager(c *cli.Context) error {

webhookTypes := []string{types.WebhookTypeConversion, types.WebhookTypeAdmission}
for _, webhookType := range webhookTypes {
if err := startWebhook(ctx, webhookType, clients); err != nil {
if err := webhook.StartWebhook(ctx, webhookType, clients); err != nil {
return err
}
}

if err := startRecoveryBackend(clients); err != nil {
if err := recoverybackend.StartRecoveryBackend(clients); err != nil {
return err
}

Expand Down Expand Up @@ -220,7 +221,7 @@ func startManager(c *cli.Context) error {
debugAddress := "127.0.0.1:6060"
debugHandler := http.DefaultServeMux
logger.Infof("Debug Server listening on %s", debugAddress)
if err := http.ListenAndServe(debugAddress, debugHandler); err != nil && err != http.ErrServerClosed {
if err := http.ListenAndServe(debugAddress, debugHandler); err != nil && !errors.Is(err, http.ErrServerClosed) {
logger.Errorf(fmt.Sprintf("ListenAndServe: %s", err))
}
}()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app
package recoverybackend

import (
"net/http"
Expand All @@ -9,7 +9,7 @@ import (
"github.com/longhorn/longhorn-manager/util/client"
)

func startRecoveryBackend(clients *client.Clients) error {
func StartRecoveryBackend(clients *client.Clients) error {
logrus.Info("Starting longhorn recovery-backend server")

s := server.New(clients.Namespace, clients.Datastore)
Expand Down
4 changes: 2 additions & 2 deletions app/webhook.go → webhook/webhook.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app
package webhook

import (
"context"
Expand All @@ -19,7 +19,7 @@ var (
defaultStartTimeout = 60 * time.Second
)

func startWebhook(ctx context.Context, webhookType string, clients *client.Clients) error {
func StartWebhook(ctx context.Context, webhookType string, clients *client.Clients) error {
logrus.Infof("Starting longhorn %s webhook server", webhookType)

var webhookPort int
Expand Down

0 comments on commit ac3a130

Please sign in to comment.