From 5ac9016b5be70b8466b7d377a1f5f17a914c0ce1 Mon Sep 17 00:00:00 2001 From: Daichi Sakaue Date: Fri, 5 Apr 2024 10:24:11 +0900 Subject: [PATCH] Add linter and move test data to testdata Signed-off-by: Daichi Sakaue --- .github/workflows/ci.yaml | 2 + Makefile | 49 +++++++++++++++------- e2e/Makefile | 4 +- e2e/{ => testdata}/cilium-agent-proxy.yaml | 0 e2e/{ => testdata}/cluster.yaml | 1 - e2e/{ => testdata}/envoy-config.yaml | 0 e2e/{ => testdata}/kustomization.yaml | 0 e2e/{ => testdata}/ubuntu.yaml | 0 8 files changed, 38 insertions(+), 18 deletions(-) rename e2e/{ => testdata}/cilium-agent-proxy.yaml (100%) rename e2e/{ => testdata}/cluster.yaml (89%) rename e2e/{ => testdata}/envoy-config.yaml (100%) rename e2e/{ => testdata}/kustomization.yaml (100%) rename e2e/{ => testdata}/ubuntu.yaml (100%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3993dea..ad500ef 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,6 +24,8 @@ jobs: - name: Setup tools if: steps.cache-tools.outputs.cache-hit != 'true' run: make setup + - name: Run lint + run: make lint - name: Run environment run: make start working-directory: e2e diff --git a/Makefile b/Makefile index 8f7896b..d4cf123 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,21 @@ BIN_DIR := $(shell pwd)/bin TOOLS_DIR := $(BIN_DIR)/download HELM_VERSION := 3.14.3 +JQ_VERSION := 1.7.1 KIND_VERSION := 0.22.0 KUBECTL_VERSION := 1.29.3 KUSTOMIZE_VERSION := 5.3.0 +YQ_VERSION := 4.43.1 # Test tools +CILIUM := $(TOOLS_DIR)/cilium +CUSTOMCHECKER := $(TOOLS_DIR)/custom-checker HELM := $(TOOLS_DIR)/helm +JQ := $(TOOLS_DIR)/jq KUBECTL := $(TOOLS_DIR)/kubectl KUSTOMIZE := $(TOOLS_DIR)/kustomize STATICCHECK := $(TOOLS_DIR)/staticcheck +YQ := $(TOOLS_DIR)/yq .PHONY: all all: help @@ -21,37 +27,50 @@ help: ## Display this help @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) .PHONY: setup -setup: $(HELM) $(KUBECTL) $(KUSTOMIZE) ## Install necessary tools +setup: $(CILIUM) $(HELM) $(JQ) $(KUBECTL) $(KUSTOMIZE) $(YQ) ## Install necessary tools GOBIN=$(TOOLS_DIR) go install sigs.k8s.io/kind@v$(KIND_VERSION) + GOBIN=$(TOOLS_DIR) go install honnef.co/go/tools/cmd/staticcheck@latest + GOBIN=$(TOOLS_DIR) go install github.com/cybozu-go/golang-custom-analyzer/cmd/custom-checker@latest $(HELM) repo add cilium https://helm.cilium.io/ $(HELM) repo update cilium -$(HELM): +$(TOOLS_DIR): mkdir -p $(TOOLS_DIR) + +$(HELM): $(TOOLS_DIR) wget -qO - https://get.helm.sh/helm-v$(HELM_VERSION)-linux-amd64.tar.gz | tar zx -O linux-amd64/helm > $@ chmod +x $@ -$(KUBECTL): - mkdir -p $(TOOLS_DIR) +$(JQ): $(TOOLS_DIR) + wget -qO $@ https://github.com/jqlang/jq/releases/download/jq-$(JQ_VERSION)/jq-linux-amd64 + chmod +x $@ + +$(KUBECTL): $(TOOLS_DIR) wget -qO $@ https://storage.googleapis.com/kubernetes-release/release/v$(KUBECTL_VERSION)/bin/linux/amd64/kubectl chmod +x $@ -$(KUSTOMIZE): - mkdir -p $(TOOLS_DIR) +$(KUSTOMIZE): $(TOOLS_DIR) wget -qO - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv$(KUSTOMIZE_VERSION)/kustomize_v$(KUSTOMIZE_VERSION)_linux_amd64.tar.gz | tar zx -O kustomize > $@ chmod +x $@ -.PHONY: build -build: - mkdir -p $(BIN_DIR) - go build -o $(BIN_DIR)/cilium-policy main.go +$(YQ): $(TOOLS_DIR) + wget -qO $@ https://github.com/mikefarah/yq/releases/download/v$(YQ_VERSION)/yq_linux_amd64 + chmod +x $@ .PHONY: clean clean: rm -rf $(BIN_DIR) -.PHONY: test -test: - if find . -name go.mod | grep -q go.mod; then \ - $(MAKE) test-go; \ - fi +##@ Development + +.PHONY: build +build: ## Build cilium-policy-viewer + mkdir -p $(BIN_DIR) + go build -o $(BIN_DIR)/cilium-policy main.go + +.PHONY: lint +lint: ## Run lint tools + go vet ./... + test -z "$$(gofmt -s -l . | tee /dev/stderr)" + $(STATICCHECK) ./... + test -z "$$($(CUSTOMCHECKER) -restrictpkg.packages=html/template,log ./... 2>&1 | tee /dev/stderr)" diff --git a/e2e/Makefile b/e2e/Makefile index 369a3e1..1a004fc 100644 --- a/e2e/Makefile +++ b/e2e/Makefile @@ -19,13 +19,13 @@ help: ## Display this help .PHONY: start start: docker pull quay.io/cilium/cilium:v$(CILIUM_VERSION) - $(KIND) create cluster --config cluster.yaml + $(KIND) create cluster --config testdata/cluster.yaml $(KIND) load docker-image quay.io/cilium/cilium:v$(CILIUM_VERSION) $(HELM) install cilium cilium/cilium --version $(CILIUM_VERSION) \ --namespace kube-system \ --set image.pullPolicy=IfNotPresent \ --set ipam.mode=kubernetes - $(KUSTOMIZE) build . | $(KUBECTL) apply -f - + $(KUSTOMIZE) build testdata | $(KUBECTL) apply -f - $(KUBECTL) wait --for=condition=Available --all deployments --all-namespaces --timeout=1h $(KUBECTL) wait --for=condition=Ready --all pods --all-namespaces --timeout=1h diff --git a/e2e/cilium-agent-proxy.yaml b/e2e/testdata/cilium-agent-proxy.yaml similarity index 100% rename from e2e/cilium-agent-proxy.yaml rename to e2e/testdata/cilium-agent-proxy.yaml diff --git a/e2e/cluster.yaml b/e2e/testdata/cluster.yaml similarity index 89% rename from e2e/cluster.yaml rename to e2e/testdata/cluster.yaml index 31f1ab9..cbf8e01 100644 --- a/e2e/cluster.yaml +++ b/e2e/testdata/cluster.yaml @@ -4,6 +4,5 @@ nodes: - role: control-plane - role: worker - role: worker - - role: worker networking: disableDefaultCNI: true diff --git a/e2e/envoy-config.yaml b/e2e/testdata/envoy-config.yaml similarity index 100% rename from e2e/envoy-config.yaml rename to e2e/testdata/envoy-config.yaml diff --git a/e2e/kustomization.yaml b/e2e/testdata/kustomization.yaml similarity index 100% rename from e2e/kustomization.yaml rename to e2e/testdata/kustomization.yaml diff --git a/e2e/ubuntu.yaml b/e2e/testdata/ubuntu.yaml similarity index 100% rename from e2e/ubuntu.yaml rename to e2e/testdata/ubuntu.yaml