Skip to content
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: 1 addition & 1 deletion .github/workflows/label.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [pull_request_target]

jobs:
labeler:
runs-on: self-hosted
runs-on: [self-hosted, pod]
permissions:
issues: write
pull-requests: write
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
golint:
runs-on: self-hosted
runs-on: [self-hosted, pod]
steps:
- uses: actions/checkout@v3

Expand All @@ -16,7 +16,7 @@ jobs:

- uses: actions/setup-go@v4
with:
go-version: '1.23'
go-version: '1.20'

- name: Check golang lint
# skip it for branch main can't pass this check
Expand All @@ -30,7 +30,7 @@ jobs:
GOPROXY: https://goproxy.cn|https://proxy.golang.org|direct

generate-check:
runs-on: self-hosted
runs-on: [self-hosted, pod]
steps:
- uses: actions/checkout@v3

Expand All @@ -49,7 +49,7 @@ jobs:
run: echo "::error::Please run \"make generate\" or \"make docker-generate\" before commit."

commitlint:
runs-on: self-hosted
runs-on: [self-hosted, pod]
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -59,7 +59,7 @@ jobs:
configFile: .commitlintrc.json

helmlint:
runs-on: self-hosted
runs-on: [self-hosted, pod]
steps:
- uses: actions/checkout@v3
- uses: andstor/file-existence-action@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
publish:
runs-on: self-hosted
runs-on: [self-hosted, pod]
steps:
- uses: actions/checkout@v3

Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.PHONY: image-generate generate docker-generate test docker-test publish

COMMIT_ID:=$(shell git rev-parse --short HEAD)

CONTROLLER_GEN=$(shell which controller-gen)

image:
docker build -f build/image/release/Dockerfile -t registry.smtx.io/everoute/tr-controller . --build-arg RELEASE_VERSION="v0.0.0" --build-arg GIT_COMMIT="local" --build-arg PRODUCT_NAME="everoute"
docker build -f build/image/release/Dockerfile -t registry.smtx.io/everoute/tr-controller:$(COMMIT_ID) . --build-arg RELEASE_VERSION="v0.0.0" --build-arg GIT_COMMIT="local" --build-arg PRODUCT_NAME="everoute"

image-generate:
docker build -f build/image/generate/Dockerfile -t tr/generate ./build/image/generate/
Expand All @@ -21,10 +23,14 @@ docker-generate: image-generate
docker run --rm -iu 0:0 -w $(WORKDIR) -v $(CURDIR):$(WORKDIR) tr/generate make generate

test:
go test ./... --race --coverprofile coverage.out
go test ./... -gcflags=all=-l --race --coverprofile coverage.out

docker-test:
$(eval WORKDIR := /go/src/github.com/everoute/trafficredirect)
docker run --rm -iu 0:0 -w $(WORKDIR) -v $(CURDIR):$(WORKDIR) golang:1.20 make test
docker run --rm -iu 0:0 -w $(WORKDIR) -v $(CURDIR):$(WORKDIR) registry.smtx.io/sdn-base/golang:1.20 make test

debug-test:
$(eval WORKDIR := /go/src/github.com/everoute/trafficredirect)
docker run --rm -iu 0:0 -w $(WORKDIR) -v $(CURDIR):$(WORKDIR) registry.smtx.io/sdn-base/golang:1.20 bash

publish:
10 changes: 4 additions & 6 deletions api/trafficredirect/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (
// +kubebuilder:printcolumn:name="direct",type="string",JSONPath=".spec.direct"
// +kubebuilder:printcolumn:name="src-mac",type="string",JSONPath=".spec.match.srcMac"
// +kubebuilder:printcolumn:name="dst-mac",type="string",JSONPath=".spec.match.dstMac"
// +kubebuilder:printcolumn:name="vm",type="string",JSONPath=".spec.towerOption.vmID"
// +kubebuilder:printcolumn:name="vnic",type="string",JSONPath=".spec.towerOption.nic"
// +kubebuilder:printcolumn:name="vm",type="string",JSONPath=".spec.option.towerVM"

type Rule struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -29,17 +28,16 @@ type RuleSpec struct {
// +kubebuilder:validation:Enum=ingress;egress
Direct RuleDirect `json:"direct"`
// tower info for debug
TowerOption *TowerOption `json:"towerOption,omitempty"`
Option *Option `json:"option,omitempty"`
}

type RuleMatch struct {
SrcMac string `json:"srcMac,omitempty"`
DstMac string `json:"dstMac,omitempty"`
}

type TowerOption struct {
VMID string `json:"vmID,omitempty"`
Nic string `json:"nic,omitempty"`
type Option struct {
TowerVM string `json:"towerVM,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
6 changes: 3 additions & 3 deletions api/trafficredirect/v1alpha1/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func (r *Rule) validateSpec() error {
}
}

if r.Spec.TowerOption != nil {
if r.Spec.TowerOption.VMID == "" || r.Spec.TowerOption.Nic == "" {
return fmt.Errorf("must set tower option with vmid and nic")
if r.Spec.Option != nil {
if r.Spec.Option.TowerVM == "" {
return fmt.Errorf("must set option with tower vmid when option is set")
}
}
return nil
Expand Down
11 changes: 5 additions & 6 deletions api/trafficredirect/v1alpha1/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ func TestRule_validateSpec(t *testing.T) {
Spec: RuleSpec{
Direct: Egress,
Match: RuleMatch{DstMac: "00:11:22:33:44:55"},
TowerOption: &TowerOption{
VMID: "vm1", // Nic is missing
Option: &Option{
TowerVM: "",
},
},
},
wantErr: true,
errorText: "must set tower option with vmid and nic",
errorText: "must set option with tower vmid when option is set",
},
{
name: "valid rule with dst mac",
Expand Down Expand Up @@ -105,9 +105,8 @@ func TestRule_validateSpec(t *testing.T) {
Spec: RuleSpec{
Direct: Egress,
Match: RuleMatch{SrcMac: "aa:bb:cc:dd:ee:ff"},
TowerOption: &TowerOption{
VMID: "vm2",
Nic: "eth0",
Option: &Option{
TowerVM: "vm2",
},
},
},
Expand Down
38 changes: 19 additions & 19 deletions api/trafficredirect/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/image/generate/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20
FROM registry.smtx.io/sdn-base/golang:1.20

RUN go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.2 && \
go install k8s.io/code-generator/cmd/deepcopy-gen@kubernetes-1.27.7 && \
Expand Down
9 changes: 8 additions & 1 deletion cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/everoute/trafficredirect/api/trafficredirect/v1alpha1"
"github.com/everoute/trafficredirect/pkg/config"
"github.com/everoute/trafficredirect/pkg/constants"
"github.com/everoute/trafficredirect/pkg/controller/vnic"
"github.com/everoute/trafficredirect/pkg/tower/client"
)

var Scheme = runtime.NewScheme()
Expand Down Expand Up @@ -52,11 +54,16 @@ func main() {
if err := mgr.AddHealthzCheck("ping", healthz.Ping); err != nil {
klog.Fatalf("Failed to add healthz ping checker")
}

if err := (&v1alpha1.Rule{}).SetupWebhookWithManager(mgr); err != nil {
klog.Fatalf("unable to registry webhook for rule: %s", err)
}

towerCli := client.NewClient()
vnicCtrl := vnic.NewController(mgr, towerCli)
if err := mgr.Add(vnicCtrl); err != nil {
klog.Fatalf("Failed to add vnic ctrl to mgr: %s", err)
}

klog.Info("Start controller manager")
if err := mgr.Start(stopCtx); err != nil {
klog.Fatalf("Failed to start controller manager: %s", err)
Expand Down
11 changes: 3 additions & 8 deletions deploy/chart/templates/crds/tr.everoute.io_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ spec:
- jsonPath: .spec.match.dstMac
name: dst-mac
type: string
- jsonPath: .spec.towerOption.vmID
- jsonPath: .spec.option.towerVM
name: vm
type: string
- jsonPath: .spec.towerOption.nic
name: vnic
type: string
name: v1alpha1
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -65,12 +62,10 @@ spec:
srcMac:
type: string
type: object
towerOption:
option:
description: tower info for debug
properties:
nic:
type: string
vmID:
towerVM:
type: string
type: object
required:
Expand Down
Loading
Loading