-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Patryk Strusiewicz-Surmacki <[email protected]>
- Loading branch information
1 parent
6ed1c53
commit 3a02edb
Showing
25 changed files
with
1,264 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,9 @@ linters-settings: | |
disabled: true | ||
funlen: | ||
lines: 65 | ||
gosec: | ||
excludes: | ||
- G115 | ||
|
||
issues: | ||
exclude-rules: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ AGENT_IMG ?= ghcr.io/telekom/das-schiff-network-operator-agent:latest | |
SIDECAR_IMG ?= ghcr.io/telekom/frr-exporter:latest | ||
# Operator image URL to use all building/pushing image targets | ||
OPERATOR_IMG ?= ghcr.io/telekom/das-schiff-network-opeator:latest | ||
# Worker image URL to use all building/pushing image targets | ||
WORKER_IMG ?= ghcr.io/telekom/worker:latest | ||
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. | ||
ENVTEST_K8S_VERSION = 1.25 | ||
|
||
|
@@ -52,8 +54,13 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust | |
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
|
||
.PHONY: generate | ||
generate: controller-gen bpf-generate ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. | ||
generate: controller-gen bpf-generate ## Generate code containing DeepCopy, DeepCopyInto and DeepCopyObject method implementations and GRPC code. | ||
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." | ||
PATH=$(PATH):$(shell pwd)/bin $(PROTOC) --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative pkg/worker/pb/worker.proto | ||
|
||
.PHONY: generate-protobuff | ||
generate-protobuff: protoc ## Generate code containing DeepCopy, DeepCopyInto and DeepCopyObject method implementations. | ||
PATH=$(PATH):$(shell pwd)/bin $(PROTOC) --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative pkg/worker/pb/worker.proto | ||
|
||
.PHONY: fmt | ||
fmt: ## Run go fmt against code. | ||
|
@@ -83,10 +90,14 @@ operator-build: generate fmt vet ## Build agent binary. | |
agent-build: generate fmt vet ## Build agent binary. | ||
go build -o bin/agent cmd/agent/main.go | ||
|
||
.PHONY: sidecar-build | ||
.PHONY: sidecar-build ## Build sidecar (frr-exporter) binary. | ||
sidecar-build: build | ||
go build -o bin/frr-exporter cmd/frr-exporter/main.go | ||
|
||
.PHONY: worker-build ## Build worker binary. | ||
agent-build: generate fmt vet | ||
go build -o bin/worker cmd/worker/main.go | ||
|
||
.PHONY: run | ||
run: manifests generate fmt vet ## Run a controller from your host. | ||
go run ./cmd/agent/main.go | ||
|
@@ -96,6 +107,7 @@ docker-build: test ## Build docker image with the manager. | |
docker build -t ${OPERATOR_IMG} . | ||
docker build -t ${AGENT_IMG} -f agent.Dockerfile . | ||
docker build -t ${SIDECAR_IMG} -f frr-exporter.Dockerfile . | ||
docker build -t ${WORKER_IMG} -f worker.Dockerfile . | ||
|
||
.PHONY: docker-build-agent | ||
docker-build-agent: test ## Build docker image with the manager. | ||
|
@@ -109,6 +121,10 @@ docker-build-sidecar: test ## Build docker image with the manager. | |
docker-build-operator: test ## Build docker image with the manager. | ||
docker build -t ${OPERATOR_IMG} . | ||
|
||
.PHONY: docker-build-worker | ||
docker-build-worker: test ## Build docker image with the manager. | ||
docker build -t ${WORKER_IMG} -f worker.Dockerfile . | ||
|
||
.PHONY: docker-push | ||
docker-push: docker-push-agent docker-push-sidecar docker-push-operator | ||
|
||
|
@@ -124,6 +140,10 @@ docker-push-sidecar: ## Push docker image with the manager. | |
docker-push-operator: ## Push docker image with the manager. | ||
docker push ${OPERATOR_IMG} | ||
|
||
.PHONY: docker-push-worker | ||
docker-push-worker: ## Push docker image with the manager. | ||
docker push ${WORKER_IMG} | ||
|
||
##@ Release | ||
|
||
RELEASE_DIR ?= out | ||
|
@@ -164,6 +184,7 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in | |
cd config/agent && $(KUSTOMIZE) edit set image agent=${AGENT_IMG} | ||
cd config/agent && $(KUSTOMIZE) edit set image frr-exporter=${SIDECAR_IMG} | ||
cd config/operator && $(KUSTOMIZE) edit set image operator=${OPERATOR_IMG} | ||
cd config/worker && $(KUSTOMIZE) edit set image worker=${WORKER_IMG} | ||
$(KUSTOMIZE) build config/default | kubectl apply -f - | ||
|
||
.PHONY: undeploy | ||
|
@@ -203,3 +224,10 @@ GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\ | |
rm -rf $$TMP_DIR ;\ | ||
} | ||
endef | ||
|
||
PROTOC_DIR = $(shell pwd)/bin/protoc | ||
PROTOC = $(shell pwd)/bin/protoc/bin/protoc | ||
.PHONY: protoc | ||
protoc: ## Download controller-gen locally if necessary. | ||
mkdir -p $(PROTOC_DIR) && cd $(PROTOC_DIR) && wget -nc https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protoc-27.0-linux-x86_64.zip 2> /dev/null && unzip -nqq protoc-27.0-linux-x86_64.zip | ||
$(call go-get-tool,$(PROTOC_DIR),google.golang.org/protobuf/cmd/[email protected]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"net" | ||
"os" | ||
|
||
"github.com/go-logr/zapr" | ||
vrfigbpadapter "github.com/telekom/das-schiff-network-operator/pkg/adapters/vrf_igbp" | ||
"github.com/telekom/das-schiff-network-operator/pkg/anycast" | ||
"github.com/telekom/das-schiff-network-operator/pkg/frr" | ||
"github.com/telekom/das-schiff-network-operator/pkg/nl" | ||
"github.com/telekom/das-schiff-network-operator/pkg/worker" | ||
workerpb "github.com/telekom/das-schiff-network-operator/pkg/worker/pb" | ||
"go.uber.org/zap" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
func main() { | ||
var agentType string | ||
var port int | ||
flag.StringVar(&agentType, "agent", "vrf-igbp", "Use selected agent type (default: vrf-igbp).") | ||
flag.IntVar(&port, "port", worker.DefaultPort, fmt.Sprintf("gRPC listening port. (default: %d)", worker.DefaultPort)) | ||
|
||
zc := zap.NewProductionConfig() | ||
zc.Level = zap.NewAtomicLevelAt(zap.DebugLevel) | ||
zc.DisableStacktrace = true | ||
z, _ := zc.Build() | ||
log := zapr.NewLogger(z) | ||
log = log.WithName("agent") | ||
|
||
log.Info("agent's port", "port", port) | ||
|
||
anycastTracker := anycast.NewTracker(&nl.Toolkit{}) | ||
|
||
var err error | ||
var adapter worker.Adapter | ||
switch agentType { | ||
case "vrf-igbp": | ||
adapter, err = vrfigbpadapter.New(anycastTracker, log, frr.NewFRRManager(), nl.NewManager(&nl.Toolkit{})) | ||
default: | ||
log.Error(fmt.Errorf("agent is currently not supported"), "type", agentType) | ||
os.Exit(1) | ||
} | ||
|
||
if err != nil { | ||
log.Error(err, "error creating adapter") | ||
os.Exit(1) | ||
} | ||
|
||
log.Info("created adapter", "type", agentType) | ||
|
||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) | ||
if err != nil { | ||
log.Error(err, "error on listening start") | ||
os.Exit(1) | ||
} | ||
|
||
grpcServer := grpc.NewServer([]grpc.ServerOption{}...) | ||
srv := worker.NewServer(adapter, &log) | ||
workerpb.RegisterAgentServer(grpcServer, srv) | ||
|
||
log.Info("created server, start listening...") | ||
|
||
if err := grpcServer.Serve(lis); err != nil { | ||
log.Error(err, "grpc server error") | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ resources: | |
- ../rbac | ||
- ../agent | ||
- ../operator | ||
- ../worker | ||
- ../webhook | ||
- ../prometheus | ||
labels: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
resources: | ||
- worker.yaml | ||
|
||
generatorOptions: | ||
disableNameSuffixHash: true | ||
|
||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
images: | ||
- name: worker | ||
newName: ghcr.io/telekom/worker | ||
newTag: latest |
Oops, something went wrong.