From 6928c03f2fa85be32fb2c23115986c9fe13a6d65 Mon Sep 17 00:00:00 2001 From: Bence Csati Date: Sun, 8 Sep 2024 10:48:59 +0200 Subject: [PATCH] fix: interview revision Signed-off-by: Bence Csati --- Makefile | 19 ++++++++++++------- internal/config/config.go | 7 +++++-- internal/k8s/client.go | 8 ++++---- internal/server/server.go | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 449d082..d957337 100644 --- a/Makefile +++ b/Makefile @@ -89,9 +89,6 @@ fmt: ## Format code ##@ Dependencies -deps: bin/golangci-lint bin/kind -deps: ## Install dependencies - # Dependency versions GOLANGCI_LINT_VERSION = 1.60.3 KIND_VERSION = 0.24.0 @@ -101,16 +98,24 @@ GOLANGCI_LINT_BIN := golangci-lint KIND_BIN := kind HELM_BIN := helm -bin/golangci-lint: +deps: bin/golangci-lint-${GOLANGCI_LINT_VERSION} bin/kind-${KIND_VERSION} bin/helm +deps: ## Install dependencies + @ln -sf golangci-lint-${GOLANGCI_LINT_VERSION} bin/golangci-lint + @ln -sf kind-${KIND_VERSION} bin/kind + +bin/golangci-lint-${GOLANGCI_LINT_VERSION}: @mkdir -p bin curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- v${GOLANGCI_LINT_VERSION} + @mv bin/golangci-lint $@ -bin/kind: +bin/kind-${KIND_VERSION}: @mkdir -p bin curl -Lo bin/kind https://kind.sigs.k8s.io/dl/v${KIND_VERSION}/kind-$(shell uname -s | tr '[:upper:]' '[:lower:]')-$(shell uname -m | sed -e "s/aarch64/arm64/; s/x86_64/amd64/") - @chmod +x bin/kind + @mv bin/kind $@ + @chmod +x $@ bin/helm: @mkdir -p bin curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | USE_SUDO=false HELM_INSTALL_DIR=bin bash - @chmod +x bin/helm + @mv bin/helm $@ + @chmod +x $@ diff --git a/internal/config/config.go b/internal/config/config.go index c7b3718..e1512cb 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -20,7 +20,8 @@ type Config struct { Mode string `mapstructure:"mode"` LogLevel string `mapstructure:"log_level"` JSONLog bool `mapstructure:"json_log"` - LogServerAddress string `mapstructure:"log_server"` + LogServerAddress string `mapstructure:"log_server_address"` + LogServerNetwork string `mapstructure:"log_server_network"` } func LoadConfig() (*Config, error) { @@ -47,7 +48,9 @@ func LoadConfig() (*Config, error) { _ = v.BindEnv("json_log") - _ = v.BindEnv("log_server") + _ = v.BindEnv("log_server_address") + + _ = v.BindEnv("log_server_network") config := &Config{} if err := v.Unmarshal(config); err != nil { diff --git a/internal/k8s/client.go b/internal/k8s/client.go index ca29ae1..3183df4 100644 --- a/internal/k8s/client.go +++ b/internal/k8s/client.go @@ -31,12 +31,12 @@ func NewClient() (*Client, error) { return &Client{clientset: clientset}, nil } -func (c *Client) ListResource(ctx context.Context, resource common.Resources) (common.Resources, error) { - switch resource.(type) { - case common.ResourceType: +func (c *Client) ListResource(ctx context.Context, resource common.ResourceType) (common.Resources, error) { + switch resource { + case common.PodResourceType: return c.listPods(ctx) default: - return nil, fmt.Errorf("unsupported resource type: %T", resource) + return nil, fmt.Errorf("unsupported resource type: %s", resource) } } diff --git a/internal/server/server.go b/internal/server/server.go index 0a87ad4..36e09e7 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -24,7 +24,7 @@ func New(config *config.Config) (*Server, error) { gin.SetMode(config.Mode) if config.LogServerAddress != "" { - writer, err := net.Dial("udp", config.LogServerAddress) + writer, err := net.Dial(config.LogServerNetwork, config.LogServerAddress) if err != nil { return nil, fmt.Errorf("failed to connect to log server: %w", err) }