Skip to content

Commit 95a0b4e

Browse files
author
Daniel Beres
committed
sonic-wirelet implementation
Signed-off-by: Daniel Beres <daniel.beres@sap.com>
1 parent 3efa17c commit 95a0b4e

24 files changed

Lines changed: 2713 additions & 110 deletions

‎Dockerfile‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Build the manager binary
2-
FROM golang:1.25 AS builder
2+
# Keep the compiler on the host architecture. Buildx cross-compiles the static
3+
# binary for TARGETARCH below, avoiding slow QEMU emulation on Apple Silicon.
4+
FROM --platform=$BUILDPLATFORM golang:1.25.7 AS builder
35
ARG TARGETOS
46
ARG TARGETARCH
57

@@ -19,13 +21,15 @@ COPY . .
1921
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2022
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2123
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
22-
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
24+
25+
FROM builder AS wirelet-builder
26+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -o /out/wirelet ./cmd/wirelet-sonic
2327

2428
# Use distroless as minimal base image to package the manager binary
2529
# Refer to https://github.com/GoogleContainerTools/distroless for more details
26-
FROM gcr.io/distroless/static:nonroot
30+
FROM gcr.io/distroless/static:nonroot AS wirelet
2731
WORKDIR /
28-
COPY --from=builder /workspace/manager .
32+
COPY --from=wirelet-builder /out/wirelet /wirelet
2933
USER 65532:65532
3034

31-
ENTRYPOINT ["/manager"]
35+
ENTRYPOINT ["/wirelet"]

‎Makefile‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,15 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
204204
ENVTEST ?= $(LOCALBIN)/setup-envtest
205205
ADDLICENSE ?= $(LOCALBIN)/addlicense
206206
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
207+
PROTOC_GEN_GO ?= $(LOCALBIN)/protoc-gen-go
208+
PROTOC_GEN_GO_GRPC ?= $(LOCALBIN)/protoc-gen-go-grpc
207209

208210
## Tool Versions
209211
KUSTOMIZE_VERSION ?= v5.8.1
210212
CONTROLLER_TOOLS_VERSION ?= v0.20.1
211213
ADDLICENSE_VERSION ?= v1.1.1
214+
PROTOC_GEN_GO_VERSION ?= v1.36.8
215+
PROTOC_GEN_GO_GRPC_VERSION ?= v1.5.1
212216

213217
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
214218
ENVTEST_VERSION ?= $(shell v='$(call gomodver,sigs.k8s.io/controller-runtime)'; \
@@ -260,6 +264,25 @@ addlicense: $(ADDLICENSE) ## Download addlicense locally if necessary.
260264
$(ADDLICENSE): $(LOCALBIN)
261265
$(call go-install-tool,$(ADDLICENSE),github.com/google/addlicense,$(ADDLICENSE_VERSION))
262266

267+
.PHONY: generate-proto
268+
generate-proto: $(PROTOC_GEN_GO) $(PROTOC_GEN_GO_GRPC) ## Generate Go code from proto/sonic/v1alpha1/sonic.proto.
269+
protoc \
270+
--plugin=protoc-gen-go=$(PROTOC_GEN_GO) \
271+
--plugin=protoc-gen-go-grpc=$(PROTOC_GEN_GO_GRPC) \
272+
--go_out=. --go_opt=module=github.com/ironcore-dev/wire \
273+
--go-grpc_out=. --go-grpc_opt=module=github.com/ironcore-dev/wire \
274+
proto/sonic/v1alpha1/sonic.proto
275+
276+
.PHONY: protoc-gen-go
277+
protoc-gen-go: $(PROTOC_GEN_GO) ## Download protoc-gen-go locally if necessary.
278+
$(PROTOC_GEN_GO): $(LOCALBIN)
279+
$(call go-install-tool,$(PROTOC_GEN_GO),google.golang.org/protobuf/cmd/protoc-gen-go,$(PROTOC_GEN_GO_VERSION))
280+
281+
.PHONY: protoc-gen-go-grpc
282+
protoc-gen-go-grpc: $(PROTOC_GEN_GO_GRPC) ## Download protoc-gen-go-grpc locally if necessary.
283+
$(PROTOC_GEN_GO_GRPC): $(LOCALBIN)
284+
$(call go-install-tool,$(PROTOC_GEN_GO_GRPC),google.golang.org/grpc/cmd/protoc-gen-go-grpc,$(PROTOC_GEN_GO_GRPC_VERSION))
285+
263286
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
264287
# $1 - target path with name of binary
265288
# $2 - package url which can be installed

‎api/v1alpha1/cell_types.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type CellStatus struct {
6969
// +kubebuilder:resource
7070
// +kubebuilder:subresource:status
7171
// +kubebuilder:printcolumn:name="Node",type=string,JSONPath=`.spec.nodeRef.name`
72-
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.spec.phase`
72+
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.phase`
7373

7474
// Cell is the Schema for the cells API
7575
type Cell struct {

‎api/v1alpha1/interface_types.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ type InterfaceStatus struct {
7575
// +kubebuilder:resource:scope=Cluster
7676
// +kubebuilder:printcolumn:name="Node",type=string,JSONPath=`.spec.nodeRef.name`
7777
// +kubebuilder:printcolumn:name="Handle",type=string,JSONPath=`.spec.handle`
78-
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.operationState`
78+
// +kubebuilder:printcolumn:name="Admin_State",type=string,JSONPath=`.spec.adminState`
79+
// +kubebuilder:printcolumn:name="Operation_State",type=string,JSONPath=`.status.operationState`
7980

8081
// Interface is the Schema for the interfaces API
8182
type Interface struct {

‎cellruntime/cellruntime.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ type Runtime interface {
6464
}
6565

6666
type InterfaceState struct {
67-
Up bool
67+
AdminUp bool
68+
OperUp bool
6869
}
6970

7071
type CellStatus struct {

‎cellruntime/testing/fake.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const ProviderName = "fake"
1616
type FakeCellRuntime struct {
1717
sync.RWMutex
1818
Cells map[string]*FakeCell
19-
InterfaceStates map[string]bool
19+
InterfaceStates map[string]cellruntime.InterfaceState
2020
}
2121

2222
type FakeCell struct {
@@ -90,9 +90,7 @@ func (r *FakeCellRuntime) InterfaceState(ctx context.Context, iface string) (*ce
9090
if !ok {
9191
return nil, fmt.Errorf("interface %s %w", iface, cellruntime.ErrNotFound)
9292
}
93-
return &cellruntime.InterfaceState{
94-
Up: state,
95-
}, nil
93+
return &state, nil
9694
}
9795

9896
func (r *FakeCellRuntime) SetInterfaceAdminState(ctx context.Context, handle string, up bool) error {
@@ -102,6 +100,9 @@ func (r *FakeCellRuntime) SetInterfaceAdminState(ctx context.Context, handle str
102100
if _, ok := r.InterfaceStates[handle]; !ok {
103101
return fmt.Errorf("interface %s %w", handle, cellruntime.ErrNotFound)
104102
}
105-
r.InterfaceStates[handle] = up
103+
state := r.InterfaceStates[handle]
104+
state.AdminUp = up
105+
state.OperUp = up
106+
r.InterfaceStates[handle] = state
106107
return nil
107108
}

‎cmd/wirelet-sonic/main.go‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
package main
55

66
import (
7+
"crypto/tls"
78
"os"
89

910
"github.com/ironcore-dev/wire/api/v1alpha1"
1011
"github.com/ironcore-dev/wire/sonic"
1112
"github.com/ironcore-dev/wire/wirelet/cli"
1213
"github.com/spf13/pflag"
14+
"google.golang.org/grpc"
15+
"google.golang.org/grpc/credentials"
1316
"k8s.io/apimachinery/pkg/util/sets"
1417
ctrl "sigs.k8s.io/controller-runtime"
1518
"sigs.k8s.io/controller-runtime/pkg/log/zap"
@@ -19,10 +22,12 @@ func main() {
1922
var flags cli.Flags
2023
var name string
2124
var interfaces []string
25+
var sonicAddr string
2226

2327
flags.AddFlags(pflag.CommandLine)
2428
pflag.StringVar(&name, "name", name, "Name of the node")
2529
pflag.StringSliceVarP(&interfaces, "interface", "I", interfaces, "Names of the interfaces to reconcile")
30+
pflag.StringVar(&sonicAddr, "sonic-addr", "localhost:50051", "Address of the sonic-agent gRPC endpoint")
2631

2732
pflag.Parse()
2833

@@ -34,9 +39,16 @@ func main() {
3439
os.Exit(1)
3540
}
3641

42+
conn, err := grpc.NewClient(sonicAddr, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{InsecureSkipVerify: true})))
43+
if err != nil {
44+
setupLog.Error(err, "Error connecting to sonic-agent")
45+
os.Exit(1)
46+
}
47+
defer conn.Close()
48+
3749
interfaceSet := sets.New(interfaces...)
3850

39-
prov, err := sonic.NewRuntime()
51+
prov, err := sonic.NewRuntime(conn)
4052
if err != nil {
4153
setupLog.Error(err, "Error creating sonic runtime")
4254
os.Exit(1)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
apiVersion: wire.ironcore.dev/v1alpha1
2+
kind: Cell
3+
metadata:
4+
name: spine-1
5+
namespace: default
6+
spec:
7+
nodeRef:
8+
name: spine-1
9+
id: "100"
10+
hostname: spine-1
11+
ips:
12+
- fd00::1
13+
prefixes:
14+
- fd00::/48
15+
peers:
16+
- interfaceRef:
17+
name: spine-1-eth1
18+
---
19+
apiVersion: wire.ironcore.dev/v1alpha1
20+
kind: Cell
21+
metadata:
22+
name: leaf-1
23+
namespace: default
24+
spec:
25+
nodeRef:
26+
name: leaf-1
27+
id: "200"
28+
hostname: leaf-1
29+
ips:
30+
- fd00::2
31+
prefixes:
32+
- fd00::/48
33+
peers:
34+
- interfaceRef:
35+
name: leaf-1-eth0-0
36+
dhcpRelay: fd00::ffff
37+
- interfaceRef:
38+
name: leaf-1-eth1-0
39+
dhcpRelay: fd00::ffff
40+
- interfaceRef:
41+
name: leaf-1-eth2-0
42+
dhcpRelay: fd00::ffff
43+
# - interfaceRef:
44+
# name: leaf-1-eth3-0
45+
#dhcpRelay: fd00::ffff
46+
- interfaceRef:
47+
name: leaf-1-eth4-0
48+
dhcpRelay: fd00::ffff
49+
- interfaceRef:
50+
name: leaf-1-eth5-0
51+
dhcpRelay: fd00::ffff
52+
- interfaceRef:
53+
name: leaf-1-eth6-0
54+
dhcpRelay: fd00::ffff
55+
- interfaceRef:
56+
name: leaf-1-eth7-0
57+
dhcpRelay: fd00::ffff
58+
- interfaceRef:
59+
name: leaf-1-eth8-0
60+
dhcpRelay: fd00::ffff
61+
- interfaceRef:
62+
name: leaf-1-eth9-0
63+
dhcpRelay: fd00::ffff
64+
- interfaceRef:
65+
name: leaf-1-eth10-0
66+
dhcpRelay: fd00::ffff
67+
- interfaceRef:
68+
name: leaf-1-eth11-0
69+
dhcpRelay: fd00::ffff
70+
- interfaceRef:
71+
name: leaf-1-eth12-0
72+
dhcpRelay: fd00::ffff
73+
- interfaceRef:
74+
name: leaf-1-eth13-0
75+
dhcpRelay: fd00::ffff
76+
- interfaceRef:
77+
name: leaf-1-eth14-0
78+
dhcpRelay: fd00::ffff
79+
- interfaceRef:
80+
name: leaf-1-eth15-0
81+
dhcpRelay: fd00::ffff
82+
- interfaceRef:
83+
name: leaf-1-eth16-0
84+
dhcpRelay: fd00::ffff
85+
- interfaceRef:
86+
name: leaf-1-eth17-0
87+
dhcpRelay: fd00::ffff
88+
- interfaceRef:
89+
name: leaf-1-eth18-0
90+
dhcpRelay: fd00::ffff
91+
- interfaceRef:
92+
name: leaf-1-eth19-0
93+
dhcpRelay: fd00::ffff
94+
- interfaceRef:
95+
name: leaf-1-eth20-0
96+
dhcpRelay: fd00::ffff
97+
- interfaceRef:
98+
name: leaf-1-eth21-0
99+
dhcpRelay: fd00::ffff
100+
- interfaceRef:
101+
name: leaf-1-eth22-0
102+
dhcpRelay: fd00::ffff
103+
- interfaceRef:
104+
name: leaf-1-eth23-0
105+
dhcpRelay: fd00::ffff

0 commit comments

Comments
 (0)