Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linter and move test data to testdata #3

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 33 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
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
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
Expand All @@ -21,37 +26,50 @@ help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\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: $(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)"
4 changes: 2 additions & 2 deletions e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion e2e/cluster.yaml → e2e/testdata/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker
networking:
disableDefaultCNI: true
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading