Skip to content

Commit

Permalink
fix: interview revision
Browse files Browse the repository at this point in the history
Signed-off-by: Bence Csati <csatib02@gmail.com>

fix: interview revision

Signed-off-by: Bence Csati <csatib02@gmail.com>

fix: interview revision

Signed-off-by: Bence Csati <csatib02@gmail.com>
  • Loading branch information
csatib02 committed Sep 8, 2024
1 parent 61f7a55 commit e57ec00
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 48 deletions.
76 changes: 41 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
export PATH := $(abspath bin/):${PATH}

# Project variables
PROJECT_NAME = kube-pod-autocomplete
CONTAINER_IMAGE_REF = ghcr.io/csatib02/${PROJECT_NAME}:dev
CONTAINER_IMAGE_REF = ghcr.io/csatib02/$(PROJECT_NAME):dev

# Dependency versions
GOLANGCI_LINT_VERSION = 1.60.3
KIND_VERSION = 0.24.0

# Dependency binaries
BIN_DIR := bin
GOLANGCI_LINT_BIN := golangci-lint
KIND_BIN := kind
HELM_BIN := helm

##@ General

Expand All @@ -17,17 +28,17 @@ help: ## Display this help

.PHONY: up
up: ## Start development environment
${KIND_BIN} create cluster --name ${PROJECT_NAME}
$(BIN_DIR)/$(KIND_BIN) create cluster --name $(PROJECT_NAME)

.PHONY: down
down: ## Stop development environment
${KIND_BIN} delete cluster --name ${PROJECT_NAME}
$(BIN_DIR)/$(KIND_BIN) delete cluster --name $(PROJECT_NAME)

.PHONY: deploy
deploy: container-image ## Deploy kube-pod-autocomplete to the development environment
kind load docker-image ${CONTAINER_IMAGE_REF} --name ${PROJECT_NAME}
kubectl create ns ${PROJECT_NAME}
${HELM_BIN} upgrade --install ${PROJECT_NAME} deploy/charts/${PROJECT_NAME} --namespace ${PROJECT_NAME} --set image.tag=dev
$(BIN_DIR)/$(KIND_BIN) load docker-image $(CONTAINER_IMAGE_REF) --name $(PROJECT_NAME)
kubectl create ns $(PROJECT_NAME)
$(BIN_DIR)/$(HELM_BIN) upgrade --install $(PROJECT_NAME) deploy/charts/$(PROJECT_NAME) --namespace $(PROJECT_NAME) --set image.tag=dev

.PHONY: deploy-testdata
deploy-testdata: ## Deploy testdata to the development environment
Expand All @@ -40,20 +51,19 @@ deploy-testdata: ## Deploy testdata to the development environment
.PHONY: build
build: ## Build binary
@mkdir -p build
go build -race -o build/${PROJECT_NAME} .
go build -race -o build/$(PROJECT_NAME) .

.PHONY: artifacts
artifacts: container-image helm-chart
artifacts: ## Build artifacts
artifacts: container-image helm-chart ## Build artifacts

.PHONY: container-image
container-image: ## Build container image
docker build -t ${CONTAINER_IMAGE_REF} .
docker build -t $(CONTAINER_IMAGE_REF) .

.PHONY: helm-chart
helm-chart: ## Build Helm chart
@mkdir -p build
$(HELM_BIN) package -d build/ deploy/charts/${PROJECT_NAME}
$(BIN_DIR)/$(HELM_BIN) package -d build/ deploy/charts/$(PROJECT_NAME)

##@ Checks

Expand All @@ -70,47 +80,43 @@ test-e2e: ## Run end-to-end tests

.PHONY: test-e2e-local
test-e2e-local: container-image ## Run e2e tests locally
LOAD_IMAGE=${CONTAINER_IMAGE_REF} VERSION=dev ${MAKE} test-e2e
LOAD_IMAGE=$(CONTAINER_IMAGE_REF) VERSION=dev ${MAKE} test-e2e

.PHONY: lint
lint: lint-go lint-helm ## Run linters

.PHONY: lint-go
lint-go:
$(GOLANGCI_LINT_BIN) run $(if ${CI},--out-format github-actions,)
$(BIN_DIR)/$(GOLANGCI_LINT_BIN) run $(if ${CI},--out-format github-actions,)

.PHONY: lint-helm
lint-helm:
$(HELM_BIN) lint deploy/charts/${PROJECT_NAME}
$(BIN_DIR)/$(HELM_BIN) lint deploy/charts/$(PROJECT_NAME)

.PHONY: fmt
fmt: ## Format code
$(GOLANGCI_LINT_BIN) run --fix
$(BIN_DIR)/$(GOLANGCI_LINT_BIN) run --fix

##@ Dependencies

deps: bin/golangci-lint bin/kind
deps: bin/golangci-lint-$(GOLANGCI_LINT_VERSION) bin/kind-$(KIND_VERSION) bin/helm
deps: ## Install dependencies
@ln -sf golangci-lint-$(GOLANGCI_LINT_VERSION) $(BIN_DIR)/golangci-lint
@ln -sf kind-$(KIND_VERSION) $(BIN_DIR)/kind

# Dependency versions
GOLANGCI_LINT_VERSION = 1.60.3
KIND_VERSION = 0.24.0

# Dependency binaries
GOLANGCI_LINT_BIN := golangci-lint
KIND_BIN := kind
HELM_BIN := helm

bin/golangci-lint:
@mkdir -p bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- v${GOLANGCI_LINT_VERSION}
bin/golangci-lint-$(GOLANGCI_LINT_VERSION):
@mkdir -p $(BIN_DIR)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- v$(GOLANGCI_LINT_VERSION)
@mv $(BIN_DIR)/golangci-lint $@

bin/kind:
@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
bin/kind-$(KIND_VERSION):
@mkdir -p $(BIN_DIR)
curl -Lo $(BIN_DIR)/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/")
@mv $(BIN_DIR)/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
@mkdir -p $(BIN_DIR)
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | USE_SUDO=false HELM_INSTALL_DIR=$(BIN_DIR) bash
@mv $(BIN_DIR)/helm $@
@chmod +x $@
7 changes: 5 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func TestLoadConfig(t *testing.T) {
{
name: "Custom values",
envVars: map[string]string{
"KPA_LISTEN_ADDRESS": "127.0.0.1:9090",
"KPA_TRUSTED_PROXIES": "192.168.1.1,192.168.1.2",
"KPA_MODE": gin.ReleaseMode,
"KPA_LOG_LEVEL": "debug",
"KPA_JSON_LOG": "true",
"KPA_LOG_SERVER": "logserver.local",
"KPA_LISTEN_ADDRESS": "127.0.0.1:9090",
"KPA_TRUSTED_PROXIES": "192.168.1.1,192.168.1.2",
"KPA_MODE": gin.ReleaseMode,
"KPA_LOG_LEVEL": "debug",
"KPA_JSON_LOG": "true",
"KPA_LOG_SERVER_ADDRESS": "logserver.local",
},
wantConfig: &Config{
ListenAddress: "127.0.0.1:9090",
Expand Down
8 changes: 4 additions & 4 deletions internal/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit e57ec00

Please sign in to comment.