Skip to content

Commit

Permalink
chore: fix some nitpicks
Browse files Browse the repository at this point in the history
Signed-off-by: Bence Csati <csatib02@gmail.com>
  • Loading branch information
csatib02 committed Sep 4, 2024
1 parent fb65c55 commit 6464616
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
3 changes: 1 addition & 2 deletions e2e/kpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ func TestKPAEndpoints(t *testing.T) {

require.Equal(t, http.StatusOK, resp.StatusCode)

autocompleteUrl := fmt.Sprintf(autocompleteURL, "localhost", 8080, "pods")
resp, err = http.Get(autocompleteUrl)
resp, err = http.Get(fmt.Sprintf(autocompleteURL, "localhost", 8080, "pods"))
require.NoError(t, err)
defer resp.Body.Close()

Expand Down
4 changes: 2 additions & 2 deletions internal/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package handlers

import "github.com/gin-gonic/gin"

// SetupRouter initializes the router and registers all the handlers
func SetupRouter(router *gin.Engine) {
// SetupRoutes registers all the handlers on the router
func SetupRoutes(router *gin.Engine) {
router.GET("/search/autocomplete/:resource", AutocompleteHandler)
router.GET("/health", HealthHandler)
}
14 changes: 4 additions & 10 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func New(config *config.Config) (*Server, error) {
// NOTE: Add Auth middleware if required
router := gin.New()
router.Use(gin.Recovery(), cors.Default())
gin.SetMode(config.Mode)

if config.LogServerAddress != "" {
writer, err := net.Dial("udp", config.LogServerAddress)
Expand All @@ -33,24 +34,17 @@ func New(config *config.Config) (*Server, error) {
router.Use(gin.Logger())
}

// Set the mode of the gin router, default is debug
if config.Mode == gin.ReleaseMode {
gin.SetMode(gin.ReleaseMode)
}

// Add trusted proxies e.g. when running KPA behind a reverse proxy or a load balancer
if err := router.SetTrustedProxies(config.TrustedProxies); err != nil {
return nil, fmt.Errorf("failed to set trusted proxies: %w", err)
}

handlers.SetupRouter(router)
handlers.SetupRoutes(router)

server := &Server{
return &Server{
router: router,
config: config,
}

return server, nil
}, nil
}

func (s *Server) Run() error {
Expand Down
16 changes: 16 additions & 0 deletions internal/services/autocomplete/model/field.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package model

import "github.com/csatib02/kube-pod-autocomplete/pkg/common"

type FieldType int

const (
ListFilter FieldType = iota
MapFilter
)

type FieldFilter struct {
ResourceType common.ResourceType
Type FieldType
Extractor FieldExtractor
}
3 changes: 1 addition & 2 deletions pkg/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ func InitLogger(config *config.Config) {
router = router.Add(slogsyslog.Option{Level: slog.LevelInfo, Writer: writer}.NewSyslogHandler())
}

logger := slog.New(router.Handler())
logger = logger.With(slog.String("app", "kube-pod-autocomplete"))
logger := slog.New(router.Handler()).With(slog.String("app", "kube-pod-autocomplete"))

// Set the default logger to the configured logger,
// enabling direct usage of the slog package for logging.
Expand Down

0 comments on commit 6464616

Please sign in to comment.