Skip to content

Commit d8b964f

Browse files
committed
imp: remove host config controller
host flows are managed by another componenet no need for this controller Signed-off-by: Michael Filanov <[email protected]>
1 parent f7275f1 commit d8b964f

File tree

16 files changed

+3
-778
lines changed

16 files changed

+3
-778
lines changed

cmd/flowscontroller/main.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,12 @@ func main() {
6363
var probeAddr string
6464
var secureMetrics bool
6565
var enableHTTP2 bool
66-
var configMapNamespace string
67-
var configMapName string
6866
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
6967
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
7068
flag.BoolVar(&secureMetrics, "metrics-secure", false,
7169
"If set the metrics endpoint is served securely")
7270
flag.BoolVar(&enableHTTP2, "enable-http2", false,
7371
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
74-
flag.StringVar(&configMapNamespace, "cm-namespace", "default", "Spectrum-x config map namespace")
75-
flag.StringVar(&configMapName, "cm-name", "specx-config", "Spectrum-x config map name")
7672
opts := zap.Options{
7773
Development: true,
7874
}
@@ -154,19 +150,6 @@ func main() {
154150
os.Exit(1)
155151
}
156152

157-
if err = (&controller.HostConfigReconciler{
158-
NodeName: Options.NodeName,
159-
Client: mgr.GetClient(),
160-
Exec: &exec.Exec{},
161-
ConfigMapNamespace: configMapNamespace,
162-
ConfigMapName: configMapName,
163-
Flows: &controller.Flows{Exec: &exec.Exec{}, NetlinkLib: netlink.New()},
164-
OVSWatcher: ovsWatcherHostConfig,
165-
}).SetupWithManager(mgr); err != nil {
166-
setupLog.Error(err, "unable to create controller", "controller", "HostConfig")
167-
os.Exit(1)
168-
}
169-
170153
//+kubebuilder:scaffold:builder
171154

172155
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {

cmd/spectrum-x-manager/main.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,17 @@ import (
2626
// to ensure that exec-entrypoint and run can make use of them.
2727
_ "k8s.io/client-go/plugin/pkg/client/auth"
2828

29-
"k8s.io/apimachinery/pkg/fields"
3029
"k8s.io/apimachinery/pkg/runtime"
3130
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3231
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3332
ctrl "sigs.k8s.io/controller-runtime"
34-
"sigs.k8s.io/controller-runtime/pkg/cache"
35-
"sigs.k8s.io/controller-runtime/pkg/client"
3633
"sigs.k8s.io/controller-runtime/pkg/healthz"
3734
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3835
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
3936
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
4037
"sigs.k8s.io/controller-runtime/pkg/webhook"
4138

4239
"github.com/Mellanox/spectrum-x-operator/internal/version"
43-
44-
corev1 "k8s.io/api/core/v1"
4540
// +kubebuilder:scaffold:imports
4641
)
4742

@@ -74,8 +69,6 @@ func main() {
7469
var enableHTTP2 bool
7570
var tlsOpts []func(*tls.Config)
7671
var printVersion bool
77-
var configMapNamespace string
78-
var configMapName string
7972
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
8073
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
8174
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
@@ -87,8 +80,6 @@ func main() {
8780
flag.BoolVar(&enableHTTP2, "enable-http2", false,
8881
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
8982
flag.BoolVar(&printVersion, "version", false, "print version and exit")
90-
flag.StringVar(&configMapNamespace, "cm-namespace", "default", "Spectrum-x config map namespace")
91-
flag.StringVar(&configMapName, "cm-name", "specx-config", "Spectrum-x config map name")
9283
opts := zap.Options{
9384
Development: true,
9485
}
@@ -152,14 +143,6 @@ func main() {
152143
HealthProbeBindAddress: probeAddr,
153144
LeaderElection: enableLeaderElection,
154145
LeaderElectionID: "1f9fb416.nvidia.com",
155-
Cache: cache.Options{
156-
ByObject: map[client.Object]cache.ByObject{
157-
&corev1.ConfigMap{}: {
158-
Field: fields.ParseSelectorOrDie(fmt.Sprintf("metadata.name=%s,metadata.namespace=%s",
159-
configMapName, configMapNamespace)),
160-
},
161-
},
162-
},
163146
})
164147
if err != nil {
165148
setupLog.Error(err, "unable to start manager")

config/flowcontroller/daemonset.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ spec:
3939
containers:
4040
- command:
4141
- /flowcontroller
42-
args:
43-
- --cm-namespace=$(POD_NAMESPACE)
4442
image: controller:latest
4543
name: flowcontroller
4644
env:

config/manager/manager.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ spec:
5050
args:
5151
- --leader-elect
5252
- --health-probe-bind-address=:8081
53-
- --cm-namespace=$(POD_NAMESPACE)
5453
env:
5554
- name: POD_NAMESPACE
5655
valueFrom:

config/rbac/role.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ rules:
2828
- apiGroups:
2929
- ""
3030
resources:
31-
- configmaps
3231
- pods
3332
verbs:
3433
- create

internal/controller/flow_controller.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"fmt"
2323
"hash/fnv"
2424

25-
"github.com/Mellanox/spectrum-x-operator/pkg/config"
2625
"github.com/Mellanox/spectrum-x-operator/pkg/exec"
2726

2827
netdefv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
@@ -49,7 +48,6 @@ type FlowReconciler struct {
4948
}
5049

5150
//+kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch;create;update;patch;delete
52-
//+kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete
5351
//+kubebuilder:rbac:groups=core,resources=pods/status,verbs=get;update;patch
5452
//+kubebuilder:rbac:groups=core,resources=pods/finalizers,verbs=update
5553
//+kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;list;watch;create;update;patch;delete
@@ -154,29 +152,6 @@ func (r *FlowReconciler) repToBridge(rep string) (string, error) {
154152
return br, nil
155153
}
156154

157-
func getRailDevice(railName string, cfg *config.Config) (string, error) {
158-
for _, mapping := range cfg.RailDeviceMapping {
159-
if mapping.RailName == railName {
160-
return mapping.DevName, nil
161-
}
162-
}
163-
return "", fmt.Errorf("failed to find device for rail %s", railName)
164-
}
165-
166-
func getBridgeToRail(rail *config.HostRail, cfg *config.Config, exec exec.API) (string, error) {
167-
railDevice, err := getRailDevice(rail.Name, cfg)
168-
if err != nil {
169-
return "", fmt.Errorf("failed to get rail device for rail %s: %s", rail.Name, err)
170-
}
171-
172-
bridge, err := exec.Execute(fmt.Sprintf("ovs-vsctl port-to-br %s", railDevice))
173-
if err != nil {
174-
return "", fmt.Errorf("failed to get bridge to rail %s, device %s: %s", rail.Name, railDevice, err)
175-
}
176-
177-
return bridge, nil
178-
}
179-
180155
// SetupWithManager sets up the controller with the Manager.
181156
func (r *FlowReconciler) SetupWithManager(mgr ctrl.Manager) error {
182157
isPodRelevant := func(pod *corev1.Pod) bool {
@@ -221,11 +196,6 @@ func (r *FlowReconciler) SetupWithManager(mgr ctrl.Manager) error {
221196
Named("FlowReconciler").
222197
For(&corev1.Pod{}).
223198
WithEventFilter(predicate.NewPredicateFuncs(func(object client.Object) bool {
224-
// don't ignore config map changes - it may be topology config map
225-
if _, ok := object.(*corev1.ConfigMap); ok {
226-
return true
227-
}
228-
229199
pod, ok := object.(*corev1.Pod)
230200
if !ok {
231201
return false

internal/controller/flow_controller_test.go

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"fmt"
2323
"time"
2424

25-
"github.com/Mellanox/spectrum-x-operator/pkg/config"
2625
"github.com/Mellanox/spectrum-x-operator/pkg/exec"
2726

2827
gomock "github.com/golang/mock/gomock"
@@ -31,8 +30,6 @@ import (
3130
. "github.com/onsi/gomega"
3231
corev1 "k8s.io/api/core/v1"
3332
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34-
apiErrors "k8s.io/apimachinery/pkg/api/errors"
35-
"k8s.io/apimachinery/pkg/types"
3633
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3734
)
3835

@@ -290,86 +287,3 @@ var _ = Describe("Pod Controller", func() {
290287

291288
})
292289
})
293-
294-
295-
func validConfig() string {
296-
return `{
297-
"spectrum-x-networks": {
298-
"cross_rail_subnet": "192.0.0.0/8",
299-
"mtu": 9000,
300-
"rails": [
301-
{
302-
"name": "rail-1",
303-
"subnet": "192.0.0.0/11"
304-
},
305-
{
306-
"name": "rail-2",
307-
"subnet": "192.32.0.0/11"
308-
}
309-
]
310-
},
311-
"rail_device_mapping": [
312-
{
313-
"rail_name": "rail-1",
314-
"dev_name": "eth0"
315-
},
316-
{
317-
"rail_name": "rail-2",
318-
"dev_name": "eth1"
319-
}
320-
],
321-
"hosts": [
322-
{
323-
"host_id": "host-1",
324-
"rails": [
325-
{
326-
"name": "rail-1",
327-
"network": "192.0.0.0/31",
328-
"peer_leaf_port_ip": "172.0.0.0"
329-
},
330-
{
331-
"name": "rail-2",
332-
"network": "192.32.0.0/31",
333-
"peer_leaf_port_ip": "172.32.0.0"
334-
}
335-
]
336-
},
337-
{
338-
"host_id": "host-2",
339-
"rails": [
340-
{
341-
"name": "rail-1",
342-
"network": "192.0.0.2/31",
343-
"peer_leaf_port_ip": "172.0.0.2"
344-
},
345-
{
346-
"name": "rail-2",
347-
"network": "192.32.0.2/31",
348-
"peer_leaf_port_ip": "172.32.0.2"
349-
}
350-
]
351-
}
352-
]
353-
}`
354-
}
355-
356-
func updateConfigMap(ctx context.Context, ns string, data string) {
357-
d := map[string]string{config.ConfigMapKey: data}
358-
err := k8sClient.Create(ctx, &corev1.ConfigMap{
359-
ObjectMeta: metav1.ObjectMeta{Name: cmName, Namespace: ns},
360-
Data: d,
361-
})
362-
if err == nil {
363-
return
364-
}
365-
if apiErrors.IsAlreadyExists(err) {
366-
configMap := &corev1.ConfigMap{}
367-
Expect(k8sClient.Get(
368-
ctx, types.NamespacedName{Name: cmName, Namespace: ns}, configMap)).NotTo(HaveOccurred())
369-
configMap.Data = d
370-
Expect(k8sClient.Update(
371-
ctx, configMap)).NotTo(HaveOccurred())
372-
} else {
373-
Expect(err).NotTo(HaveOccurred())
374-
}
375-
}

internal/controller/flows.go

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,19 @@ package controller
1818
import (
1919
"fmt"
2020

21-
"github.com/Mellanox/spectrum-x-operator/pkg/config"
2221
"github.com/Mellanox/spectrum-x-operator/pkg/exec"
2322
libnetlink "github.com/Mellanox/spectrum-x-operator/pkg/lib/netlink"
2423
)
2524

2625
const (
27-
railPeerIP = "rail_peer_ip"
28-
railUplink = "rail_uplink"
26+
railPeerIP = "rail_peer_ip"
27+
railUplink = "rail_uplink"
28+
defaultPriority = 32768
2929
)
3030

3131
//go:generate ../../bin/mockgen -destination mock_flows.go -source flows.go -package controller
3232

3333
type FlowsAPI interface {
34-
DeleteBridgeDefaultFlows(bridge string) error
35-
AddHostRailFlows(bridge string, pf string, rail config.HostRail, infraRailSubnet string) error
3634
AddPodRailFlows(cookie uint64, vf, bridge, podIP, podMAC string) error
3735
DeletePodRailFlows(cookie uint64, bridge string) error
3836
}
@@ -44,68 +42,6 @@ type Flows struct {
4442
NetlinkLib libnetlink.NetlinkLib
4543
}
4644

47-
func (f *Flows) DeleteBridgeDefaultFlows(bridge string) error {
48-
// delete normal action flows - creating a secured bridge is not supported with sriov-network-operator
49-
// the error is ignored because in non secured bridge there are flows that cannot be deleted, specfically
50-
// for cookie=0, the first time will work but second reconcile will fail.
51-
// those are the default flows:
52-
// cookie=0x0, duration=1297.663s, table=254, n_packets=0, n_bytes=0, priority=0,reg0=0x1 actions=controller(reason=)
53-
// cookie=0x0, duration=1297.663s, table=254, n_packets=0, n_bytes=0, priority=2,recirc_id=0 actions=drop
54-
// cookie=0x0, duration=1297.663s, table=254, n_packets=0, n_bytes=0, priority=0,reg0=0x3 actions=drop
55-
// cookie=0x0, duration=1297.663s, table=254, n_packets=0, n_bytes=0, priority=0,reg0=0x2 actions=drop
56-
// once the bridge is created as secured this code will be removed
57-
_, _ = f.Exec.Execute(fmt.Sprintf("ovs-ofctl del-flows %s cookie=0x0/-1", bridge))
58-
59-
return nil
60-
}
61-
62-
func (f *Flows) AddHostRailFlows(bridge string, pf string, rail config.HostRail, infraRailSubnet string) error {
63-
link, err := f.NetlinkLib.LinkByName(bridge)
64-
if err != nil {
65-
return fmt.Errorf("failed to get interface %s: %w", bridge, err)
66-
}
67-
addrs, err := f.NetlinkLib.IPv4Addresses(link)
68-
if err != nil {
69-
return fmt.Errorf("failed to get addresses for interface %s: %w", bridge, err)
70-
}
71-
72-
// if we don't have all the addresses assigned we will have partial flows
73-
// checking for 2 addresses because we don't have a proper api between the controllers
74-
if len(addrs) != 2 {
75-
return fmt.Errorf("expected 2 addresses for interface %s, got %s", bridge, addrs)
76-
}
77-
78-
for _, addr := range addrs {
79-
flow := fmt.Sprintf(`ovs-ofctl add-flow %s "table=0,priority=%d,cookie=0x%x,arp,arp_tpa=%s,actions=output:local"`,
80-
bridge, defaultPriority, hostConfigCookie, addr.IP)
81-
if _, err := f.Exec.Execute(flow); err != nil {
82-
return fmt.Errorf("failed to exec [%s]: %s", flow, err)
83-
}
84-
85-
flow = fmt.Sprintf(`ovs-ofctl add-flow %s "table=0,priority=%d,cookie=0x%x,ip,nw_dst=%s,actions=output:local"`,
86-
bridge, defaultPriority, hostConfigCookie, addr.IP)
87-
if _, err := f.Exec.Execute(flow); err != nil {
88-
return fmt.Errorf("failed to exec [%s]: %s", flow, err)
89-
}
90-
}
91-
92-
// TOR is the gateway for the outer ip
93-
flow := fmt.Sprintf(`ovs-ofctl add-flow %s "table=0,priority=%d,cookie=0x%x,arp,arp_tpa=%s,actions=output:%s"`,
94-
bridge, defaultPriority, hostConfigCookie, rail.PeerLeafPortIP, pf)
95-
if _, err := f.Exec.Execute(flow); err != nil {
96-
return fmt.Errorf("failed to exec [%s]: %s", flow, err)
97-
}
98-
99-
flow = fmt.Sprintf(`ovs-ofctl add-flow %s "table=0,priority=%d,cookie=0x%x,`+
100-
`ip,in_port=local,nw_dst=%s,actions=output:%s"`,
101-
bridge, defaultPriority, hostConfigCookie, infraRailSubnet, pf)
102-
if _, err := f.Exec.Execute(flow); err != nil {
103-
return fmt.Errorf("failed to exec [%s]: %s", flow, err)
104-
}
105-
106-
return nil
107-
}
108-
10945
func (f *Flows) AddPodRailFlows(cookie uint64, vf, bridge, podIP, podMAC string) error {
11046
// ovs-ofctl add-flow -OOpenFlow13 $RAIL_BR "table=0, arp,arp_tpa=${CONTAINER_IP} actions=output:${REP_PORT}"
11147
flow := fmt.Sprintf(`ovs-ofctl add-flow %s "table=0,priority=%d,cookie=0x%x,arp,arp_tpa=%s,actions=output:%s"`,

internal/controller/flows_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,6 @@ var _ = Describe("Flows", func() {
7272
ctrl.Finish()
7373
})
7474

75-
Context("DeleteBridgeDefaultFlows", func() {
76-
It("should delete flows with cookie=0", func() {
77-
execMock.EXPECT().Execute("ovs-ofctl del-flows br-rail1 cookie=0x0/-1").Return("", nil)
78-
err := flows.DeleteBridgeDefaultFlows("br-rail1")
79-
Expect(err).Should(Succeed())
80-
})
81-
82-
It("should not return error if ovs-ofctl fails", func() {
83-
execMock.EXPECT().Execute("ovs-ofctl del-flows br-rail1 cookie=0x0/-1").Return("", fmt.Errorf("failed to delete flows"))
84-
err := flows.DeleteBridgeDefaultFlows("br-rail1")
85-
Expect(err).Should(Succeed())
86-
})
87-
})
88-
8975
Context("AddPodRailFlows", func() {
9076
var (
9177
mockLink *mock_netlink.MockLink

0 commit comments

Comments
 (0)