diff --git a/e2e/kpa_test.go b/e2e/kpa_test.go index b26d6cd..287a42d 100644 --- a/e2e/kpa_test.go +++ b/e2e/kpa_test.go @@ -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() diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index aa2d432..b62b7e8 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -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) } diff --git a/internal/server/server.go b/internal/server/server.go index 6f6d5bb..0a87ad4 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -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) @@ -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 { diff --git a/internal/services/autocomplete/model/field.go b/internal/services/autocomplete/model/field.go new file mode 100644 index 0000000..3a0d446 --- /dev/null +++ b/internal/services/autocomplete/model/field.go @@ -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 +} diff --git a/pkg/log/logger.go b/pkg/log/logger.go index 3d7dbed..e12ee08 100644 --- a/pkg/log/logger.go +++ b/pkg/log/logger.go @@ -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.