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

Restructured the project files #129

Merged
merged 2 commits into from
Nov 27, 2022
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
1 change: 1 addition & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
24 changes: 12 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand All @@ -47,25 +47,25 @@ 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) . && 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
kubectl set image deployment/todo-api todoapi=$(KIND_EXAMPLE_IMAGE)
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)))

Expand All @@ -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:
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 1 addition & 3 deletions src/main.go → src/cmd/cnfuzz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/root.go → src/internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions src/persistence/cache.go → src/internal/persistence/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions src/auth/oauth_client.go → src/pkg/auth/oauth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/auth/token.go → src/pkg/auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions src/auth/token_source.go → src/pkg/auth/token_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion src/config/config.go → src/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/health/checker.go → src/pkg/health/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package health

import (
"context"
"github.com/suecodelabs/cnfuzz/src/logger"
"github.com/suecodelabs/cnfuzz/src/pkg/logger"
"time"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/health/serv_test.go → src/pkg/health/serv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/k8s/client_set.go → src/pkg/k8s/client_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 11 additions & 11 deletions src/k8s/controller.go → src/pkg/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/k8s/controller_test.go → src/pkg/k8s/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions src/k8s/fuzz_job.go → src/pkg/k8s/fuzz_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading