Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Daichi Sakaue <[email protected]>
  • Loading branch information
yokaze committed Apr 1, 2024
1 parent 7b87343 commit e01bfa8
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 17 deletions.
44 changes: 29 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
BIN_DIR := $(shell pwd)/bin

# Tool versions
MDBOOK_VERSION = 0.4.35
MDBOOK := $(BIN_DIR)/mdbook
HELM_VERSION := 3.14.3
KIND_VERSION := 0.22.0

# Test tools
STATICCHECK = $(BIN_DIR)/staticcheck
HELM := $(BIN_DIR)/helm
STATICCHECK := $(BIN_DIR)/staticcheck

.PHONY: all
all: test
all: help

##@ Basic

.PHONY: book
book: $(MDBOOK)
rm -rf docs/book
cd docs; $(MDBOOK) build
.PHONY: help
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) ## Install necessary tools
GOBIN=$(BIN_DIR) go install sigs.k8s.io/kind@v$(KIND_VERSION)
$(HELM) repo add cilium https://helm.cilium.io/
$(HELM) repo update cilium

$(HELM):
mkdir -p $(BIN_DIR)
wget -qO - https://get.helm.sh/helm-v$(HELM_VERSION)-linux-amd64.tar.gz | tar zx -O linux-amd64/helm > $@
chmod +x $@

.PHONY: build
build:
mkdir -p $(BIN_DIR)
go build -o $(BIN_DIR)/cilium-policy main.go

.PHONY: clean
clean:
rm -rf $(BIN_DIR)

.PHONY: test
test:
Expand All @@ -30,13 +49,8 @@ test-go: test-tools
go test -race -v ./...
go vet ./...


##@ Tools

$(MDBOOK):
mkdir -p bin
curl -fsL https://github.com/rust-lang/mdBook/releases/download/v$(MDBOOK_VERSION)/mdbook-v$(MDBOOK_VERSION)-x86_64-unknown-linux-gnu.tar.gz | tar -C bin -xzf -

.PHONY: test-tools
test-tools: $(STATICCHECK)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
[![PkgGoDev](https://pkg.go.dev/badge/github.com/cybozu-go/cilium-policy-viewer?tab=overview)](https://pkg.go.dev/github.com/cybozu-go/cilium-policy-viewer?tab=overview)
[![Go Report Card](https://goreportcard.com/badge/github.com/cybozu-go/cilium-policy-viewer)](https://goreportcard.com/report/github.com/cybozu-go/cilium-policy-viewer)

Template repository for Neco
============================
Cilium Policy Viewer
====================

**Project Status**: Initial development

Expand Down
23 changes: 23 additions & 0 deletions cmd/dump.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var dumpCmd = &cobra.Command{
Use: "dump",
Short: "dump endpoint status",
Long: `Dump endpoint status`,

Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("Hello")
return nil
},
}

func init() {
rootCmd.AddCommand(dumpCmd)
}
17 changes: 17 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
27 changes: 27 additions & 0 deletions e2e/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CILIUM_VERSION := 1.15.3

BIN_DIR := $(shell pwd)/../bin
HELM := $(BIN_DIR)/helm
KIND := $(BIN_DIR)/kind

##@ Basic

.PHONY: help
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)

##@ Environment

.PHONY: start
start:
docker pull quay.io/cilium/cilium:v$(CILIUM_VERSION)
$(KIND) create cluster --config 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

.PHONY: stop
stop:
$(KIND) delete cluster
9 changes: 9 additions & 0 deletions e2e/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker
networking:
disableDefaultCNI: true
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/cybozu-go/cilium-policy-viewer

go 1.22.1

require github.com/spf13/cobra v1.8.0

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"github.com/cybozu-go/cilium-policy-viewer/cmd"
)

func main() {
cmd.Execute()
}

0 comments on commit e01bfa8

Please sign in to comment.