From 6a8413a5d7b124e5cfc05d0da47a8bc897056e99 Mon Sep 17 00:00:00 2001 From: Luuk van den Maagdenberg Date: Sun, 27 Nov 2022 16:51:30 +0100 Subject: [PATCH 1/2] restructured the project files --- .github/workflows/docker-publish.yml | 1 + Makefile | 24 +++++++++---------- Dockerfile => src/cmd/cnfuzz/Dockerfile | 0 {hack => src/cmd/cnfuzz}/local.Dockerfile | 0 src/{ => cmd/cnfuzz}/main.go | 4 +--- src/{ => internal}/cmd/root.go | 10 ++++---- src/{ => internal}/model/container_image.go | 4 ++-- .../model/container_image_test.go | 2 +- src/{ => internal}/persistence/cache.go | 10 ++++---- .../persistence/in_memory/container_image.go | 4 ++-- .../in_memory/container_image_test.go | 2 +- .../persistence/redis/container_image.go | 6 ++--- .../persistence/redis/container_image_test.go | 0 .../persistence/storage_type.go | 0 src/{ => pkg}/auth/apikey_token_source.go | 0 .../auth/apikey_token_source_test.go | 0 src/{ => pkg}/auth/basic_token_source.go | 0 src/{ => pkg}/auth/basic_token_source_test.go | 0 src/{ => pkg}/auth/oauth_client.go | 5 ++-- src/{ => pkg}/auth/oauth_token_source.go | 0 src/{ => pkg}/auth/token.go | 2 +- src/{ => pkg}/auth/token_source.go | 5 ++-- src/{ => pkg}/auth/token_source_test.go | 4 ++-- src/{ => pkg}/config/config.go | 2 +- src/{ => pkg}/config/overwrite.go | 0 src/{ => pkg}/discovery/api_information.go | 0 src/{ => pkg}/discovery/openapi/fetch_doc.go | 5 ++-- src/{ => pkg}/discovery/openapi/parser.go | 4 ++-- src/{ => pkg}/health/checker.go | 2 +- src/{ => pkg}/health/checker_test.go | 2 +- src/{ => pkg}/health/health.go | 0 src/{ => pkg}/health/serv.go | 0 src/{ => pkg}/health/serv_test.go | 2 +- src/{ => pkg}/health/test_checker.go | 0 src/{ => pkg}/k8s/annotations.go | 0 src/{ => pkg}/k8s/annotations_test.go | 0 src/{ => pkg}/k8s/client_set.go | 2 +- src/{ => pkg}/k8s/controller.go | 22 ++++++++--------- src/{ => pkg}/k8s/controller_test.go | 10 ++++---- src/{ => pkg}/k8s/fuzz_job.go | 10 ++++---- src/{ => pkg}/k8s/job/restler.go | 8 +++---- src/{ => pkg}/k8s/util/container_image.go | 2 +- .../k8s/util/container_image_test.go | 2 +- src/{ => pkg}/k8s/util/exist.go | 2 +- src/{ => pkg}/k8s/util/exist_test.go | 2 +- src/{ => pkg}/k8s/util/meta.go | 0 src/{ => pkg}/k8s/util/meta_test.go | 0 src/{ => pkg}/logger/exit.go | 0 src/{ => pkg}/logger/logger.go | 0 src/{ => pkg}/logger/logger_test.go | 0 src/{ => pkg}/logger/test_util.go | 0 51 files changed, 78 insertions(+), 82 deletions(-) rename Dockerfile => src/cmd/cnfuzz/Dockerfile (100%) rename {hack => src/cmd/cnfuzz}/local.Dockerfile (100%) rename src/{ => cmd/cnfuzz}/main.go (91%) rename src/{ => internal}/cmd/root.go (93%) rename src/{ => internal}/model/container_image.go (97%) rename src/{ => internal}/model/container_image_test.go (98%) rename src/{ => internal}/persistence/cache.go (84%) rename src/{ => internal}/persistence/in_memory/container_image.go (94%) rename src/{ => internal}/persistence/in_memory/container_image_test.go (98%) rename src/{ => internal}/persistence/redis/container_image.go (94%) rename src/{ => internal}/persistence/redis/container_image_test.go (100%) rename src/{ => internal}/persistence/storage_type.go (100%) rename src/{ => pkg}/auth/apikey_token_source.go (100%) rename src/{ => pkg}/auth/apikey_token_source_test.go (100%) rename src/{ => pkg}/auth/basic_token_source.go (100%) rename src/{ => pkg}/auth/basic_token_source_test.go (100%) rename src/{ => pkg}/auth/oauth_client.go (97%) rename src/{ => pkg}/auth/oauth_token_source.go (100%) rename src/{ => pkg}/auth/token.go (98%) rename src/{ => pkg}/auth/token_source.go (96%) rename src/{ => pkg}/auth/token_source_test.go (95%) rename src/{ => pkg}/config/config.go (98%) rename src/{ => pkg}/config/overwrite.go (100%) rename src/{ => pkg}/discovery/api_information.go (100%) rename src/{ => pkg}/discovery/openapi/fetch_doc.go (97%) rename src/{ => pkg}/discovery/openapi/parser.go (98%) rename src/{ => pkg}/health/checker.go (97%) rename src/{ => pkg}/health/checker_test.go (98%) rename src/{ => pkg}/health/health.go (100%) rename src/{ => pkg}/health/serv.go (100%) rename src/{ => pkg}/health/serv_test.go (98%) rename src/{ => pkg}/health/test_checker.go (100%) rename src/{ => pkg}/k8s/annotations.go (100%) rename src/{ => pkg}/k8s/annotations_test.go (100%) rename src/{ => pkg}/k8s/client_set.go (96%) rename src/{ => pkg}/k8s/controller.go (90%) rename src/{ => pkg}/k8s/controller_test.go (93%) rename src/{ => pkg}/k8s/fuzz_job.go (92%) rename src/{ => pkg}/k8s/job/restler.go (98%) rename src/{ => pkg}/k8s/util/container_image.go (98%) rename src/{ => pkg}/k8s/util/container_image_test.go (98%) rename src/{ => pkg}/k8s/util/exist.go (97%) rename src/{ => pkg}/k8s/util/exist_test.go (97%) rename src/{ => pkg}/k8s/util/meta.go (100%) rename src/{ => pkg}/k8s/util/meta_test.go (100%) rename src/{ => pkg}/logger/exit.go (100%) rename src/{ => pkg}/logger/logger.go (100%) rename src/{ => pkg}/logger/logger_test.go (100%) rename src/{ => pkg}/logger/test_util.go (100%) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 218eab1..07cc6ef 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -72,6 +72,7 @@ jobs: uses: docker/build-push-action@v3 with: context: . + file: src/cmd/cnfuzz/Dockerfile push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Makefile b/Makefile index 76908ac..9063afb 100644 --- a/Makefile +++ b/Makefile @@ -27,13 +27,13 @@ helm-init: run: - go run src/main.go $(RUN_ARGS) + go run src/cmd/cnfuzz/main.go $(RUN_ARGS) build: init - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(BIN_DIR)/$(BIN_NAME) src/main.go + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(BIN_DIR)/$(BIN_NAME) src/cmd/cnfuzz/main.go build-debug: init - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-N -l" -o dist/cnfuzz-debug src/main.go + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-N -l" -o dist/cnfuzz-debug src/cmd/cnfuzz/main.go test: go test ./... @@ -47,17 +47,17 @@ format: gofmt -s -l -w $(SRCS) image: - docker build -t $(IMAGE) . + docker build -t $(IMAGE) -f src/cmd/cnfuzz/Dockerfile . image.local: build - docker build -t $(IMAGE) -f hack/local.Dockerfile . + docker build -t $(IMAGE) -f src/cmd/cnfuzz/local.Dockerfile . image-debug: - docker build -t $(DEV_IMAGE) -f Dockerfile . + docker build -t $(DEV_IMAGE) -f src/cmd/cnfuzz/Dockerfile . kind-init: build - cd example && docker build -t $(KIND_EXAMPLE_IMAGE) -f Dockerfile . && cd .. - docker build -t $(CNFUZZ_IMAGE) -f hack/local.Dockerfile . + cd example && docker build -t $(KIND_EXAMPLE_IMAGE) -f src/cmd/cnfuzz/Dockerfile . && cd .. + docker build -t $(CNFUZZ_IMAGE) -f src/cmd/cnfuzz/local.Dockerfile . kind load docker-image $(CNFUZZ_IMAGE) && kind load docker-image $(KIND_EXAMPLE_IMAGE) helm install --wait --timeout 10m0s dev chart/cnfuzz $(DEFAULT_HELM_DEV_ARGS) $(if $(GIT_COMMIT),--set image.tag=$(subst /,-,$(GIT_COMMIT))) kubectl apply -f example/deployment.yaml @@ -65,7 +65,7 @@ kind-init: build kubectl scale deployment --replicas=1 todo-api kind-build: build - docker build -t $(CNFUZZ_IMAGE) -f hack/local.Dockerfile . + docker build -t $(CNFUZZ_IMAGE) -f src/cmd/cnfuzz/local.Dockerfile . kind load docker-image $(CNFUZZ_IMAGE) helm upgrade --install dev chart/cnfuzz $(DEFAULT_HELM_DEV_ARGS) $(if $(GIT_COMMIT),--set image.tag=$(subst /,-,$(GIT_COMMIT))) @@ -75,15 +75,15 @@ k8s-clean: kubectl delete deployment todo-api rancher-init: build - cd example && nerdctl -n k8s.io build -t $(KIND_EXAMPLE_IMAGE) -f Dockerfile . && cd .. - nerdctl -n k8s.io build -t $(CNFUZZ_IMAGE) -f hack/local.Dockerfile . + cd example && nerdctl -n k8s.io build -t $(KIND_EXAMPLE_IMAGE) -f src/cmd/cnfuzz/Dockerfile . && cd .. + nerdctl -n k8s.io build -t $(CNFUZZ_IMAGE) -f src/cmd/cnfuzz/local.Dockerfile . helm install --wait --timeout 10m0s dev chart/cnfuzz $(DEFAULT_HELM_DEV_ARGS) $(if $(GIT_COMMIT),--set image.tag=$(subst /,-,$(GIT_COMMIT))) kubectl apply -f example/deployment.yaml kubectl set image deployment/todo-api todoapi=$(KIND_EXAMPLE_IMAGE) kubectl scale deployment --replicas=1 todo-api rancher-build: build - nerdctl -n k8s.io build -t $(CNFUZZ_IMAGE) -f hack/local.Dockerfile . + nerdctl -n k8s.io build -t $(CNFUZZ_IMAGE) -f src/cmd/cnfuzz/local.Dockerfile . helm upgrade --install dev chart/cnfuzz $(DEFAULT_HELM_DEV_ARGS) $(if $(GIT_COMMIT),--set image.tag=$(subst /,-,$(GIT_COMMIT))) kill-jobs: diff --git a/Dockerfile b/src/cmd/cnfuzz/Dockerfile similarity index 100% rename from Dockerfile rename to src/cmd/cnfuzz/Dockerfile diff --git a/hack/local.Dockerfile b/src/cmd/cnfuzz/local.Dockerfile similarity index 100% rename from hack/local.Dockerfile rename to src/cmd/cnfuzz/local.Dockerfile diff --git a/src/main.go b/src/cmd/cnfuzz/main.go similarity index 91% rename from src/main.go rename to src/cmd/cnfuzz/main.go index 0ad69e5..11dfe63 100644 --- a/src/main.go +++ b/src/cmd/cnfuzz/main.go @@ -16,9 +16,7 @@ package main -import ( - "github.com/suecodelabs/cnfuzz/src/cmd" -) +import "github.com/suecodelabs/cnfuzz/src/internal/cmd" func main() { cmd.Execute() diff --git a/src/cmd/root.go b/src/internal/cmd/root.go similarity index 93% rename from src/cmd/root.go rename to src/internal/cmd/root.go index 04e4d68..729bbc2 100644 --- a/src/cmd/root.go +++ b/src/internal/cmd/root.go @@ -18,11 +18,11 @@ package cmd import ( "github.com/spf13/cobra" - "github.com/suecodelabs/cnfuzz/src/config" - "github.com/suecodelabs/cnfuzz/src/health" - "github.com/suecodelabs/cnfuzz/src/k8s" - "github.com/suecodelabs/cnfuzz/src/logger" - "github.com/suecodelabs/cnfuzz/src/persistence" + "github.com/suecodelabs/cnfuzz/src/internal/persistence" + "github.com/suecodelabs/cnfuzz/src/pkg/config" + "github.com/suecodelabs/cnfuzz/src/pkg/health" + "github.com/suecodelabs/cnfuzz/src/pkg/k8s" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "log" ) diff --git a/src/model/container_image.go b/src/internal/model/container_image.go similarity index 97% rename from src/model/container_image.go rename to src/internal/model/container_image.go index b8579a8..c7e6200 100644 --- a/src/model/container_image.go +++ b/src/internal/model/container_image.go @@ -19,8 +19,8 @@ package model import ( "errors" "fmt" - kutil "github.com/suecodelabs/cnfuzz/src/k8s/util" - "github.com/suecodelabs/cnfuzz/src/logger" + kutil "github.com/suecodelabs/cnfuzz/src/pkg/k8s/util" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" apiv1 "k8s.io/api/core/v1" "strconv" "strings" diff --git a/src/model/container_image_test.go b/src/internal/model/container_image_test.go similarity index 98% rename from src/model/container_image_test.go rename to src/internal/model/container_image_test.go index e8a277c..0fc73ac 100644 --- a/src/model/container_image_test.go +++ b/src/internal/model/container_image_test.go @@ -19,7 +19,7 @@ package model import ( "fmt" "github.com/stretchr/testify/assert" - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" apiv1 "k8s.io/api/core/v1" "strconv" "testing" diff --git a/src/persistence/cache.go b/src/internal/persistence/cache.go similarity index 84% rename from src/persistence/cache.go rename to src/internal/persistence/cache.go index fe92440..e5e2aa4 100644 --- a/src/persistence/cache.go +++ b/src/internal/persistence/cache.go @@ -19,11 +19,11 @@ package persistence import ( "context" "fmt" - "github.com/suecodelabs/cnfuzz/src/health" - "github.com/suecodelabs/cnfuzz/src/logger" - "github.com/suecodelabs/cnfuzz/src/model" - "github.com/suecodelabs/cnfuzz/src/persistence/in_memory" - "github.com/suecodelabs/cnfuzz/src/persistence/redis" + "github.com/suecodelabs/cnfuzz/src/internal/model" + "github.com/suecodelabs/cnfuzz/src/internal/persistence/in_memory" + "github.com/suecodelabs/cnfuzz/src/internal/persistence/redis" + "github.com/suecodelabs/cnfuzz/src/pkg/health" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" ) type Cache[T any] interface { diff --git a/src/persistence/in_memory/container_image.go b/src/internal/persistence/in_memory/container_image.go similarity index 94% rename from src/persistence/in_memory/container_image.go rename to src/internal/persistence/in_memory/container_image.go index aff6c04..4c8a4de 100644 --- a/src/persistence/in_memory/container_image.go +++ b/src/internal/persistence/in_memory/container_image.go @@ -19,8 +19,8 @@ package in_memory import ( "context" "errors" - "github.com/suecodelabs/cnfuzz/src/logger" - "github.com/suecodelabs/cnfuzz/src/model" + "github.com/suecodelabs/cnfuzz/src/internal/model" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" ) type containerImageMem struct { diff --git a/src/persistence/in_memory/container_image_test.go b/src/internal/persistence/in_memory/container_image_test.go similarity index 98% rename from src/persistence/in_memory/container_image_test.go rename to src/internal/persistence/in_memory/container_image_test.go index f5b3cda..0a25e23 100644 --- a/src/persistence/in_memory/container_image_test.go +++ b/src/internal/persistence/in_memory/container_image_test.go @@ -19,7 +19,7 @@ package in_memory import ( "context" "github.com/stretchr/testify/assert" - "github.com/suecodelabs/cnfuzz/src/model" + "github.com/suecodelabs/cnfuzz/src/internal/model" "testing" ) diff --git a/src/persistence/redis/container_image.go b/src/internal/persistence/redis/container_image.go similarity index 94% rename from src/persistence/redis/container_image.go rename to src/internal/persistence/redis/container_image.go index e777bb8..d0f83d0 100644 --- a/src/persistence/redis/container_image.go +++ b/src/internal/persistence/redis/container_image.go @@ -18,12 +18,12 @@ package redis import ( "context" - "github.com/suecodelabs/cnfuzz/src/health" - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/internal/model" + "github.com/suecodelabs/cnfuzz/src/pkg/health" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "time" "github.com/go-redis/redis/v9" - "github.com/suecodelabs/cnfuzz/src/model" ) type containerImageRedis struct { diff --git a/src/persistence/redis/container_image_test.go b/src/internal/persistence/redis/container_image_test.go similarity index 100% rename from src/persistence/redis/container_image_test.go rename to src/internal/persistence/redis/container_image_test.go diff --git a/src/persistence/storage_type.go b/src/internal/persistence/storage_type.go similarity index 100% rename from src/persistence/storage_type.go rename to src/internal/persistence/storage_type.go diff --git a/src/auth/apikey_token_source.go b/src/pkg/auth/apikey_token_source.go similarity index 100% rename from src/auth/apikey_token_source.go rename to src/pkg/auth/apikey_token_source.go diff --git a/src/auth/apikey_token_source_test.go b/src/pkg/auth/apikey_token_source_test.go similarity index 100% rename from src/auth/apikey_token_source_test.go rename to src/pkg/auth/apikey_token_source_test.go diff --git a/src/auth/basic_token_source.go b/src/pkg/auth/basic_token_source.go similarity index 100% rename from src/auth/basic_token_source.go rename to src/pkg/auth/basic_token_source.go diff --git a/src/auth/basic_token_source_test.go b/src/pkg/auth/basic_token_source_test.go similarity index 100% rename from src/auth/basic_token_source_test.go rename to src/pkg/auth/basic_token_source_test.go diff --git a/src/auth/oauth_client.go b/src/pkg/auth/oauth_client.go similarity index 97% rename from src/auth/oauth_client.go rename to src/pkg/auth/oauth_client.go index 538c5f1..83074dc 100644 --- a/src/auth/oauth_client.go +++ b/src/pkg/auth/oauth_client.go @@ -20,9 +20,8 @@ import ( "context" "errors" "fmt" - "github.com/suecodelabs/cnfuzz/src/logger" - - "github.com/suecodelabs/cnfuzz/src/discovery" + "github.com/suecodelabs/cnfuzz/src/pkg/discovery" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "golang.org/x/oauth2" "golang.org/x/oauth2/clientcredentials" ) diff --git a/src/auth/oauth_token_source.go b/src/pkg/auth/oauth_token_source.go similarity index 100% rename from src/auth/oauth_token_source.go rename to src/pkg/auth/oauth_token_source.go diff --git a/src/auth/token.go b/src/pkg/auth/token.go similarity index 98% rename from src/auth/token.go rename to src/pkg/auth/token.go index f6e09d3..daa4f96 100644 --- a/src/auth/token.go +++ b/src/pkg/auth/token.go @@ -18,7 +18,7 @@ package auth import ( "fmt" - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "net/http" "strings" "time" diff --git a/src/auth/token_source.go b/src/pkg/auth/token_source.go similarity index 96% rename from src/auth/token_source.go rename to src/pkg/auth/token_source.go index fd0718b..53cc249 100644 --- a/src/auth/token_source.go +++ b/src/pkg/auth/token_source.go @@ -18,9 +18,8 @@ package auth import ( "fmt" - "github.com/suecodelabs/cnfuzz/src/logger" - - "github.com/suecodelabs/cnfuzz/src/discovery" + "github.com/suecodelabs/cnfuzz/src/pkg/discovery" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" ) // ITokenSource interface for creating new auth tokens diff --git a/src/auth/token_source_test.go b/src/pkg/auth/token_source_test.go similarity index 95% rename from src/auth/token_source_test.go rename to src/pkg/auth/token_source_test.go index c6da0e1..a7458e8 100644 --- a/src/auth/token_source_test.go +++ b/src/pkg/auth/token_source_test.go @@ -20,8 +20,8 @@ import ( "encoding/base64" "fmt" "github.com/stretchr/testify/assert" - "github.com/suecodelabs/cnfuzz/src/discovery" - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/discovery" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "testing" ) diff --git a/src/config/config.go b/src/pkg/config/config.go similarity index 98% rename from src/config/config.go rename to src/pkg/config/config.go index ab8c1cd..66156b5 100644 --- a/src/config/config.go +++ b/src/pkg/config/config.go @@ -17,7 +17,7 @@ package config import ( - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "gopkg.in/yaml.v2" "os" "path/filepath" diff --git a/src/config/overwrite.go b/src/pkg/config/overwrite.go similarity index 100% rename from src/config/overwrite.go rename to src/pkg/config/overwrite.go diff --git a/src/discovery/api_information.go b/src/pkg/discovery/api_information.go similarity index 100% rename from src/discovery/api_information.go rename to src/pkg/discovery/api_information.go diff --git a/src/discovery/openapi/fetch_doc.go b/src/pkg/discovery/openapi/fetch_doc.go similarity index 97% rename from src/discovery/openapi/fetch_doc.go rename to src/pkg/discovery/openapi/fetch_doc.go index ddf23e7..4ac8525 100644 --- a/src/discovery/openapi/fetch_doc.go +++ b/src/pkg/discovery/openapi/fetch_doc.go @@ -18,14 +18,13 @@ package openapi import ( "fmt" - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/discovery" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "io" "net/http" "net/url" "strconv" "time" - - "github.com/suecodelabs/cnfuzz/src/discovery" ) const UserAgent = "cnfuzz" diff --git a/src/discovery/openapi/parser.go b/src/pkg/discovery/openapi/parser.go similarity index 98% rename from src/discovery/openapi/parser.go rename to src/pkg/discovery/openapi/parser.go index 26b9c76..f829fad 100644 --- a/src/discovery/openapi/parser.go +++ b/src/pkg/discovery/openapi/parser.go @@ -19,14 +19,14 @@ package openapi import ( "encoding/json" "fmt" - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/discovery" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "net/url" "strconv" "github.com/getkin/kin-openapi/openapi2" conv "github.com/getkin/kin-openapi/openapi2conv" "github.com/getkin/kin-openapi/openapi3" - "github.com/suecodelabs/cnfuzz/src/discovery" ) // UnMarshalOpenApiDoc unmarshal OpenAPI doc represented as a byte array diff --git a/src/health/checker.go b/src/pkg/health/checker.go similarity index 97% rename from src/health/checker.go rename to src/pkg/health/checker.go index a4a2ad5..56317f8 100644 --- a/src/health/checker.go +++ b/src/pkg/health/checker.go @@ -18,7 +18,7 @@ package health import ( "context" - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "time" ) diff --git a/src/health/checker_test.go b/src/pkg/health/checker_test.go similarity index 98% rename from src/health/checker_test.go rename to src/pkg/health/checker_test.go index adadaba..1c64a92 100644 --- a/src/health/checker_test.go +++ b/src/pkg/health/checker_test.go @@ -18,7 +18,7 @@ package health import ( "github.com/stretchr/testify/assert" - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "go.uber.org/zap/zapcore" "testing" ) diff --git a/src/health/health.go b/src/pkg/health/health.go similarity index 100% rename from src/health/health.go rename to src/pkg/health/health.go diff --git a/src/health/serv.go b/src/pkg/health/serv.go similarity index 100% rename from src/health/serv.go rename to src/pkg/health/serv.go diff --git a/src/health/serv_test.go b/src/pkg/health/serv_test.go similarity index 98% rename from src/health/serv_test.go rename to src/pkg/health/serv_test.go index 2250f3a..c76c9c5 100644 --- a/src/health/serv_test.go +++ b/src/pkg/health/serv_test.go @@ -19,7 +19,7 @@ package health import ( "encoding/json" "github.com/stretchr/testify/assert" - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "io" "net/http" "net/http/httptest" diff --git a/src/health/test_checker.go b/src/pkg/health/test_checker.go similarity index 100% rename from src/health/test_checker.go rename to src/pkg/health/test_checker.go diff --git a/src/k8s/annotations.go b/src/pkg/k8s/annotations.go similarity index 100% rename from src/k8s/annotations.go rename to src/pkg/k8s/annotations.go diff --git a/src/k8s/annotations_test.go b/src/pkg/k8s/annotations_test.go similarity index 100% rename from src/k8s/annotations_test.go rename to src/pkg/k8s/annotations_test.go diff --git a/src/k8s/client_set.go b/src/pkg/k8s/client_set.go similarity index 96% rename from src/k8s/client_set.go rename to src/pkg/k8s/client_set.go index 8938dbc..c2360d8 100644 --- a/src/k8s/client_set.go +++ b/src/pkg/k8s/client_set.go @@ -17,7 +17,7 @@ package k8s import ( - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" ctrl "sigs.k8s.io/controller-runtime" diff --git a/src/k8s/controller.go b/src/pkg/k8s/controller.go similarity index 90% rename from src/k8s/controller.go rename to src/pkg/k8s/controller.go index 9baa667..e15a9fc 100644 --- a/src/k8s/controller.go +++ b/src/pkg/k8s/controller.go @@ -18,11 +18,11 @@ package k8s import ( "context" - "github.com/suecodelabs/cnfuzz/src/config" - "github.com/suecodelabs/cnfuzz/src/k8s/util" - "github.com/suecodelabs/cnfuzz/src/logger" - "github.com/suecodelabs/cnfuzz/src/model" - "github.com/suecodelabs/cnfuzz/src/persistence" + "github.com/suecodelabs/cnfuzz/src/internal/model" + "github.com/suecodelabs/cnfuzz/src/internal/persistence" + config3 "github.com/suecodelabs/cnfuzz/src/pkg/config" + "github.com/suecodelabs/cnfuzz/src/pkg/k8s/util" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" apiv1 "k8s.io/api/core/v1" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" @@ -36,12 +36,12 @@ type controller struct { log logger.Logger client kubernetes.Interface storage *persistence.Storage - config *config.CnFuzzConfig - overwrites config.Overwrites - handleFunc func(l logger.Logger, clientSet kubernetes.Interface, storage *persistence.Storage, config *config.CnFuzzConfig, overwrites config.Overwrites, pod *apiv1.Pod) + config *config3.CnFuzzConfig + overwrites config3.Overwrites + handleFunc func(l logger.Logger, clientSet kubernetes.Interface, storage *persistence.Storage, config *config3.CnFuzzConfig, overwrites config3.Overwrites, pod *apiv1.Pod) } -func NewController(l logger.Logger, client kubernetes.Interface, storage *persistence.Storage, config *config.CnFuzzConfig, overwrites config.Overwrites) *controller { +func NewController(l logger.Logger, client kubernetes.Interface, storage *persistence.Storage, config *config3.CnFuzzConfig, overwrites config3.Overwrites) *controller { return &controller{ log: l, client: client, @@ -57,7 +57,7 @@ func (c controller) handleEvent(pod *apiv1.Pod) { } // StartController start informers that listen for Kubernetes events and let the EventHandler react on the events -func StartController(l logger.Logger, storage *persistence.Storage, config *config.CnFuzzConfig, overwrites config.Overwrites, client kubernetes.Interface) (err error) { +func StartController(l logger.Logger, storage *persistence.Storage, config *config3.CnFuzzConfig, overwrites config3.Overwrites, client kubernetes.Interface) (err error) { myEventHandler := NewController(l, client, storage, config, overwrites) factory := informers.NewSharedInformerFactory(client, time.Hour*24) @@ -117,7 +117,7 @@ func (c controller) OnDelete(obj any) { // handlePodEvent method that handles an event for a pod // it decides if the pod needs to be fuzzed and can start the fuzzing process when the pod is ready -func handlePodEvent(l logger.Logger, client kubernetes.Interface, storage *persistence.Storage, config *config.CnFuzzConfig, overwrites config.Overwrites, pod *apiv1.Pod) { +func handlePodEvent(l logger.Logger, client kubernetes.Interface, storage *persistence.Storage, config *config3.CnFuzzConfig, overwrites config3.Overwrites, pod *apiv1.Pod) { annos := GetAnnotations(&pod.ObjectMeta) // Skip events generated by internal Kubernetes components diff --git a/src/k8s/controller_test.go b/src/pkg/k8s/controller_test.go similarity index 93% rename from src/k8s/controller_test.go rename to src/pkg/k8s/controller_test.go index 08e6347..eb07a4c 100644 --- a/src/k8s/controller_test.go +++ b/src/pkg/k8s/controller_test.go @@ -20,11 +20,11 @@ import ( "context" "fmt" "github.com/stretchr/testify/assert" - "github.com/suecodelabs/cnfuzz/src/config" - "github.com/suecodelabs/cnfuzz/src/logger" - "github.com/suecodelabs/cnfuzz/src/model" - "github.com/suecodelabs/cnfuzz/src/persistence" - "github.com/suecodelabs/cnfuzz/src/persistence/in_memory" + "github.com/suecodelabs/cnfuzz/src/internal/model" + "github.com/suecodelabs/cnfuzz/src/internal/persistence" + "github.com/suecodelabs/cnfuzz/src/internal/persistence/in_memory" + "github.com/suecodelabs/cnfuzz/src/pkg/config" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" apiv1 "k8s.io/api/core/v1" "k8s.io/client-go/kubernetes" "log" diff --git a/src/k8s/fuzz_job.go b/src/pkg/k8s/fuzz_job.go similarity index 92% rename from src/k8s/fuzz_job.go rename to src/pkg/k8s/fuzz_job.go index 228c139..68fe8e6 100644 --- a/src/k8s/fuzz_job.go +++ b/src/pkg/k8s/fuzz_job.go @@ -19,11 +19,11 @@ package k8s import ( "context" "fmt" - "github.com/suecodelabs/cnfuzz/src/auth" - "github.com/suecodelabs/cnfuzz/src/config" - "github.com/suecodelabs/cnfuzz/src/discovery/openapi" - "github.com/suecodelabs/cnfuzz/src/k8s/job" - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/auth" + "github.com/suecodelabs/cnfuzz/src/pkg/config" + "github.com/suecodelabs/cnfuzz/src/pkg/discovery/openapi" + "github.com/suecodelabs/cnfuzz/src/pkg/k8s/job" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" diff --git a/src/k8s/job/restler.go b/src/pkg/k8s/job/restler.go similarity index 98% rename from src/k8s/job/restler.go rename to src/pkg/k8s/job/restler.go index b5dfff5..fff3985 100644 --- a/src/k8s/job/restler.go +++ b/src/pkg/k8s/job/restler.go @@ -18,12 +18,12 @@ package job import ( "fmt" - "github.com/suecodelabs/cnfuzz/src/discovery" - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/auth" + "github.com/suecodelabs/cnfuzz/src/pkg/config" + "github.com/suecodelabs/cnfuzz/src/pkg/discovery" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "time" - "github.com/suecodelabs/cnfuzz/src/auth" - "github.com/suecodelabs/cnfuzz/src/config" batchv1 "k8s.io/api/batch/v1" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" diff --git a/src/k8s/util/container_image.go b/src/pkg/k8s/util/container_image.go similarity index 98% rename from src/k8s/util/container_image.go rename to src/pkg/k8s/util/container_image.go index 164b228..ce37f53 100644 --- a/src/k8s/util/container_image.go +++ b/src/pkg/k8s/util/container_image.go @@ -17,7 +17,7 @@ package util import ( - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "strings" ) diff --git a/src/k8s/util/container_image_test.go b/src/pkg/k8s/util/container_image_test.go similarity index 98% rename from src/k8s/util/container_image_test.go rename to src/pkg/k8s/util/container_image_test.go index 53abe03..3ecad36 100644 --- a/src/k8s/util/container_image_test.go +++ b/src/pkg/k8s/util/container_image_test.go @@ -19,7 +19,7 @@ package util import ( "fmt" "github.com/stretchr/testify/assert" - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "testing" ) diff --git a/src/k8s/util/exist.go b/src/pkg/k8s/util/exist.go similarity index 97% rename from src/k8s/util/exist.go rename to src/pkg/k8s/util/exist.go index bce32b2..80a2072 100644 --- a/src/k8s/util/exist.go +++ b/src/pkg/k8s/util/exist.go @@ -18,7 +18,7 @@ package util import ( "context" - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" "strings" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/src/k8s/util/exist_test.go b/src/pkg/k8s/util/exist_test.go similarity index 97% rename from src/k8s/util/exist_test.go rename to src/pkg/k8s/util/exist_test.go index 5fa9e1f..5d535fa 100644 --- a/src/k8s/util/exist_test.go +++ b/src/pkg/k8s/util/exist_test.go @@ -20,7 +20,7 @@ import ( "context" "fmt" "github.com/stretchr/testify/assert" - "github.com/suecodelabs/cnfuzz/src/logger" + "github.com/suecodelabs/cnfuzz/src/pkg/logger" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/fake" diff --git a/src/k8s/util/meta.go b/src/pkg/k8s/util/meta.go similarity index 100% rename from src/k8s/util/meta.go rename to src/pkg/k8s/util/meta.go diff --git a/src/k8s/util/meta_test.go b/src/pkg/k8s/util/meta_test.go similarity index 100% rename from src/k8s/util/meta_test.go rename to src/pkg/k8s/util/meta_test.go diff --git a/src/logger/exit.go b/src/pkg/logger/exit.go similarity index 100% rename from src/logger/exit.go rename to src/pkg/logger/exit.go diff --git a/src/logger/logger.go b/src/pkg/logger/logger.go similarity index 100% rename from src/logger/logger.go rename to src/pkg/logger/logger.go diff --git a/src/logger/logger_test.go b/src/pkg/logger/logger_test.go similarity index 100% rename from src/logger/logger_test.go rename to src/pkg/logger/logger_test.go diff --git a/src/logger/test_util.go b/src/pkg/logger/test_util.go similarity index 100% rename from src/logger/test_util.go rename to src/pkg/logger/test_util.go From 8777603a022ce9a7dcd6bcad2f4212cca0f78a8e Mon Sep 17 00:00:00 2001 From: Luuk van den Maagdenberg Date: Sun, 27 Nov 2022 17:02:40 +0100 Subject: [PATCH 2/2] fixed makefile because, accidentally changed docker file path for example api --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9063afb..61ef207 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ image-debug: docker build -t $(DEV_IMAGE) -f src/cmd/cnfuzz/Dockerfile . kind-init: build - cd example && docker build -t $(KIND_EXAMPLE_IMAGE) -f src/cmd/cnfuzz/Dockerfile . && cd .. + cd example && docker build -t $(KIND_EXAMPLE_IMAGE) . && cd .. docker build -t $(CNFUZZ_IMAGE) -f src/cmd/cnfuzz/local.Dockerfile . kind load docker-image $(CNFUZZ_IMAGE) && kind load docker-image $(KIND_EXAMPLE_IMAGE) helm install --wait --timeout 10m0s dev chart/cnfuzz $(DEFAULT_HELM_DEV_ARGS) $(if $(GIT_COMMIT),--set image.tag=$(subst /,-,$(GIT_COMMIT)))