Skip to content

Commit fd0e8dc

Browse files
committed
feat: SR-IOV Controller implementation
Signed-off-by: Ivan Kolodiazhnyi <[email protected]>
1 parent 361d123 commit fd0e8dc

File tree

6 files changed

+540
-49
lines changed

6 files changed

+540
-49
lines changed

cmd/spectrum-x-manager/main.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import (
3939
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
4040
"sigs.k8s.io/controller-runtime/pkg/webhook"
4141

42+
sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
43+
4244
"github.com/Mellanox/spectrum-x-operator/internal/controller"
4345
"github.com/Mellanox/spectrum-x-operator/internal/version"
4446

@@ -55,9 +57,21 @@ var (
5557
func init() {
5658
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
5759
utilruntime.Must(nvipamv1.AddToScheme(scheme))
60+
utilruntime.Must(sriovnetworkv1.AddToScheme(scheme))
5861
// +kubebuilder:scaffold:scheme
5962
}
6063

64+
func setupChecks(mgr ctrl.Manager) {
65+
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
66+
setupLog.Error(err, "unable to set up health check")
67+
os.Exit(1)
68+
}
69+
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
70+
setupLog.Error(err, "unable to set up ready check")
71+
os.Exit(1)
72+
}
73+
}
74+
6175
func main() {
6276
var metricsAddr string
6377
var enableLeaderElection bool
@@ -69,6 +83,7 @@ func main() {
6983
var configMapNamespace string
7084
var configMapName string
7185
var cidrPoolsNamespace string
86+
var sriovObjNamespace string
7287
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
7388
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
7489
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
@@ -83,6 +98,7 @@ func main() {
8398
flag.StringVar(&configMapNamespace, "cm-namespace", "default", "Spectrum-x config map namespace")
8499
flag.StringVar(&configMapName, "cm-name", "specx-config", "Spectrum-x config map name")
85100
flag.StringVar(&cidrPoolsNamespace, "cidrpools-namespace", "default", "CIDRPools namespace")
101+
flag.StringVar(&sriovObjNamespace, "sriov-obj-namespace", "default", "SRIOV Network Operator namespace")
86102
opts := zap.Options{
87103
Development: true,
88104
}
@@ -170,17 +186,20 @@ func main() {
170186
os.Exit(1)
171187
}
172188

173-
// +kubebuilder:scaffold:builder
174-
175-
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
176-
setupLog.Error(err, "unable to set up health check")
177-
os.Exit(1)
178-
}
179-
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
180-
setupLog.Error(err, "unable to set up ready check")
189+
if err = (&controller.SRIOVReconciler{
190+
Client: mgr.GetClient(),
191+
ConfigMapNamespace: configMapNamespace,
192+
ConfigMapName: configMapName,
193+
SriovObjNamespace: sriovObjNamespace,
194+
}).SetupWithManager(mgr); err != nil {
195+
setupLog.Error(err, "unable to create SRIOVReconciler", "SRIOVReconciler", "ConfigMap")
181196
os.Exit(1)
182197
}
183198

199+
// +kubebuilder:scaffold:builder
200+
201+
setupChecks(mgr)
202+
184203
setupLog.Info("starting manager")
185204
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
186205
setupLog.Error(err, "problem running manager")

config/manager/manager.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ spec:
5252
- --health-probe-bind-address=:8081
5353
- --cm-namespace=$(POD_NAMESPACE)
5454
- --cidrpools-namespace=$(POD_NAMESPACE)
55+
- --sriov-obj-namespace=$(SRIOV_NAMESPACE)
5556
env:
5657
- name: POD_NAMESPACE
5758
valueFrom:

config/rbac/role.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,15 @@ rules:
5959
- get
6060
- list
6161
- patch
62+
- apiGroups:
63+
- sriovnetwork.openshift.io
64+
resources:
65+
- ovsnetworks
66+
- sriovnetworknodepolicies
67+
verbs:
68+
- create
69+
- delete
70+
- deletecollection
71+
- get
72+
- list
73+
- patch

go.mod

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/caarlos0/env/v11 v11.3.1
88
github.com/golang/mock v1.6.0
99
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.7.6
10+
github.com/k8snetworkplumbingwg/sriov-network-operator v1.5.1-0.20250406123337-cd029e38821c
1011
github.com/onsi/ginkgo/v2 v2.23.4
1112
github.com/onsi/gomega v1.37.0
1213
github.com/vishvananda/netlink v1.3.0
@@ -15,25 +16,42 @@ require (
1516
k8s.io/api v0.32.3
1617
k8s.io/apimachinery v0.32.3
1718
k8s.io/client-go v0.32.3
18-
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078
19+
k8s.io/utils v0.0.0-20241210054802-24370beab758
1920
sigs.k8s.io/controller-runtime v0.20.4
2021
)
2122

2223
require (
2324
cel.dev/expr v0.19.1 // indirect
25+
github.com/Masterminds/goutils v1.1.1 // indirect
26+
github.com/Masterminds/semver/v3 v3.3.0 // indirect
27+
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
28+
github.com/ajeddeloh/go-json v0.0.0-20200220154158-5ae607161559 // indirect
2429
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
25-
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
30+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
31+
github.com/aws/aws-sdk-go v1.55.5 // indirect
2632
github.com/beorn7/perks v1.0.1 // indirect
2733
github.com/blang/semver/v4 v4.0.0 // indirect
2834
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2935
github.com/cespare/xxhash/v2 v2.3.0 // indirect
36+
github.com/clarketm/json v1.17.1 // indirect
3037
github.com/containernetworking/cni v1.2.3 // indirect
38+
github.com/coreos/fcct v0.5.0 // indirect
39+
github.com/coreos/go-json v0.0.0-20230131223807-18775e0fb4fb // indirect
40+
github.com/coreos/go-semver v0.3.1 // indirect
41+
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect
42+
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
43+
github.com/coreos/ign-converter v0.0.0-20230417193809-cee89ea7d8ff // indirect
44+
github.com/coreos/ignition v0.35.0 // indirect
45+
github.com/coreos/ignition/v2 v2.15.0 // indirect
46+
github.com/coreos/vcontext v0.0.0-20230201181013-d72178a18687 // indirect
3147
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
32-
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
48+
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
49+
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
3350
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
3451
github.com/felixge/httpsnoop v1.0.4 // indirect
35-
github.com/fsnotify/fsnotify v1.7.0 // indirect
52+
github.com/fsnotify/fsnotify v1.8.0 // indirect
3653
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
54+
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 // indirect
3755
github.com/go-logr/logr v1.4.2 // indirect
3856
github.com/go-logr/stdr v1.2.2 // indirect
3957
github.com/go-logr/zapr v1.3.0 // indirect
@@ -45,27 +63,40 @@ require (
4563
github.com/golang/protobuf v1.5.4 // indirect
4664
github.com/google/btree v1.1.3 // indirect
4765
github.com/google/cel-go v0.22.0 // indirect
48-
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
66+
github.com/google/gnostic-models v0.6.9 // indirect
4967
github.com/google/go-cmp v0.7.0 // indirect
5068
github.com/google/gofuzz v1.2.0 // indirect
5169
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect
5270
github.com/google/uuid v1.6.0 // indirect
5371
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
72+
github.com/huandu/xstrings v1.3.2 // indirect
73+
github.com/imdario/mergo v0.3.16 // indirect
5474
github.com/inconshreveable/mousetrap v1.1.0 // indirect
5575
github.com/josharian/intern v1.0.0 // indirect
5676
github.com/json-iterator/go v1.1.12 // indirect
57-
github.com/mailru/easyjson v0.7.7 // indirect
77+
github.com/klauspost/compress v1.17.11 // indirect
78+
github.com/mailru/easyjson v0.9.0 // indirect
79+
github.com/mitchellh/copystructure v1.2.0 // indirect
80+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
5881
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5982
github.com/modern-go/reflect2 v1.0.2 // indirect
6083
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
84+
github.com/openshift/api v0.0.0-20250227152946-1ee1ef831100 // indirect
85+
github.com/openshift/client-go v0.0.0-20250125113824-8e1f0b8fa9a7 // indirect
86+
github.com/openshift/library-go v0.0.0-20250129210218-fe56c2cf5d70 // indirect
87+
github.com/openshift/machine-config-operator v0.0.1-0.20250320230514-53e78f3692ee // indirect
6188
github.com/pkg/errors v0.9.1 // indirect
62-
github.com/prometheus/client_golang v1.19.1 // indirect
89+
github.com/prometheus/client_golang v1.20.5 // indirect
6390
github.com/prometheus/client_model v0.6.1 // indirect
64-
github.com/prometheus/common v0.55.0 // indirect
91+
github.com/prometheus/common v0.62.0 // indirect
6592
github.com/prometheus/procfs v0.15.1 // indirect
93+
github.com/robfig/cron v1.2.0 // indirect
94+
github.com/shopspring/decimal v1.2.0 // indirect
95+
github.com/spf13/cast v1.7.0 // indirect
6696
github.com/spf13/cobra v1.9.1 // indirect
6797
github.com/spf13/pflag v1.0.6 // indirect
6898
github.com/stoewer/go-strcase v1.3.0 // indirect
99+
github.com/vincent-petithory/dataurl v1.0.0 // indirect
69100
github.com/vishvananda/netns v0.0.4 // indirect
70101
github.com/x448/float16 v0.8.4 // indirect
71102
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
@@ -79,13 +110,15 @@ require (
79110
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
80111
go.uber.org/automaxprocs v1.6.0 // indirect
81112
go.uber.org/zap v1.27.0 // indirect
82-
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
113+
go4.org v0.0.0-20200104003542-c7e774b10ea0 // indirect
114+
golang.org/x/crypto v0.36.0 // indirect
115+
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
83116
golang.org/x/net v0.37.0 // indirect
84117
golang.org/x/oauth2 v0.25.0 // indirect
85118
golang.org/x/sync v0.12.0 // indirect
86119
golang.org/x/term v0.30.0 // indirect
87120
golang.org/x/text v0.23.0 // indirect
88-
golang.org/x/time v0.7.0 // indirect
121+
golang.org/x/time v0.9.0 // indirect
89122
golang.org/x/tools v0.31.0 // indirect
90123
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
91124
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
@@ -94,14 +127,17 @@ require (
94127
google.golang.org/protobuf v1.36.6 // indirect
95128
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
96129
gopkg.in/inf.v0 v0.9.1 // indirect
130+
gopkg.in/yaml.v2 v2.4.0 // indirect
97131
gopkg.in/yaml.v3 v3.0.1 // indirect
98132
k8s.io/apiextensions-apiserver v0.32.1 // indirect
99133
k8s.io/apiserver v0.32.1 // indirect
100134
k8s.io/component-base v0.32.3 // indirect
101135
k8s.io/klog/v2 v2.130.1 // indirect
102-
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
136+
k8s.io/kube-aggregator v0.32.1 // indirect
137+
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 // indirect
103138
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0 // indirect
104-
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
105-
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
139+
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
140+
sigs.k8s.io/kube-storage-version-migrator v0.0.6-0.20230721195810-5c8923c5ff96 // indirect
141+
sigs.k8s.io/structured-merge-diff/v4 v4.5.0 // indirect
106142
sigs.k8s.io/yaml v1.4.0 // indirect
107143
)

0 commit comments

Comments
 (0)