From 5f82cd63fde8ca7632d4c81cc4da6cef34918a7f Mon Sep 17 00:00:00 2001 From: Vadim Eisenberg Date: Sun, 12 Jan 2025 17:24:06 +0200 Subject: [PATCH 1/4] make dataplanes dual (internal plus external together) --- felix/dataplane/decorator.go | 32 ++++++++++++++++++++++++++++++++ felix/dataplane/driver.go | 28 +++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 felix/dataplane/decorator.go diff --git a/felix/dataplane/decorator.go b/felix/dataplane/decorator.go new file mode 100644 index 00000000000..2b134e9e4dc --- /dev/null +++ b/felix/dataplane/decorator.go @@ -0,0 +1,32 @@ +// Copyright © 2024 NeuReality Ltd., and its licensors. All rights reserved. +// This software contains proprietary information of NeuReality Ltd. +// You shall use such proprietary information only as may be permitted in writing by NeuReality Ltd. +// All materials contained herein are the property of NeuReality Ltd. + +// THIS SOFTWARE IS PROVIDED BY NEUREALITY “AS IS” AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL NEUREALITY OR ITS LICENSORS +// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package dataplane + +type dataplaneDriverDecorator struct { + primaryDriver DataplaneDriver + secondaryDriver DataplaneDriver +} + +func (decorator dataplaneDriverDecorator) SendMessage(msg interface{}) error { + decorator.secondaryDriver.SendMessage(msg) + return decorator.primaryDriver.SendMessage(msg) // return message from the primary driver only +} + +func (decorator dataplaneDriverDecorator) RecvMessage() (msg interface{}, err error) { + return decorator.primaryDriver.RecvMessage() // receive message from the primary driver only +} diff --git a/felix/dataplane/driver.go b/felix/dataplane/driver.go index e7db5d4a238..2c3c74bdf8e 100644 --- a/felix/dataplane/driver.go +++ b/felix/dataplane/driver.go @@ -67,6 +67,11 @@ func StartDataplaneDriver( return &inactive.InactiveDataplane{}, nil } + var primaryDataplaneDriver DataplaneDriver + var primaryCmd *exec.Cmd + var secondaryDataplaneDriver DataplaneDriver + var secondaryCmd *exec.Cmd + if configParams.UseInternalDataplaneDriver { log.Info("Using internal (linux) dataplane driver.") // If kube ipvs interface is present, enable ipvs support. In BPF mode, we bypass kube-proxy so IPVS @@ -414,13 +419,30 @@ func StartDataplaneDriver( go aws.WaitForEC2SrcDstCheckUpdate(check, healthAggregator, updater, c) } - return intDP, nil - } else { + primaryDataplaneDriver = intDP + primaryCmd = nil + } + + if configParams.DataplaneDriver != "" { log.WithField("driver", configParams.DataplaneDriver).Info( "Using external dataplane driver.") - return extdataplane.StartExtDataplaneDriver(configParams.DataplaneDriver) + secondaryDataplaneDriver, secondaryCmd = extdataplane.StartExtDataplaneDriver(configParams.DataplaneDriver) + } + + if primaryDataplaneDriver != nil && secondaryDataplaneDriver == nil { + return primaryDataplaneDriver, primaryCmd } + + if primaryDataplaneDriver == nil && secondaryDataplaneDriver != nil { + return secondaryDataplaneDriver, secondaryCmd + } + + if primaryDataplaneDriver != nil && secondaryDataplaneDriver != nil { + return dataplaneDriverDecorator{primaryDriver: primaryDataplaneDriver, secondaryDriver: secondaryDataplaneDriver}, secondaryCmd + } + + return nil, nil } func SupportsBPF() error { From c32719632192574f15be6b2db68bdaaad876e44c Mon Sep 17 00:00:00 2001 From: Vadim Eisenberg Date: Thu, 16 Jan 2025 09:59:31 +0200 Subject: [PATCH 2/4] use Apache 2.0 license --- felix/dataplane/decorator.go | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/felix/dataplane/decorator.go b/felix/dataplane/decorator.go index 2b134e9e4dc..e1f51795885 100644 --- a/felix/dataplane/decorator.go +++ b/felix/dataplane/decorator.go @@ -1,19 +1,16 @@ -// Copyright © 2024 NeuReality Ltd., and its licensors. All rights reserved. -// This software contains proprietary information of NeuReality Ltd. -// You shall use such proprietary information only as may be permitted in writing by NeuReality Ltd. -// All materials contained herein are the property of NeuReality Ltd. - -// THIS SOFTWARE IS PROVIDED BY NEUREALITY “AS IS” AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL NEUREALITY OR ITS LICENSORS -// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Copyright (c) 2025 NeuReality Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package dataplane From c573dc2848c7f97fd307203e0f58c1005256a6f6 Mon Sep 17 00:00:00 2001 From: Vadim Eisenberg Date: Thu, 16 Jan 2025 10:57:19 +0200 Subject: [PATCH 3/4] rename decorator to multiplexer return errors from both drivers --- felix/dataplane/decorator.go | 29 -------------------------- felix/dataplane/driver.go | 2 +- felix/dataplane/multiplexer.go | 38 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 30 deletions(-) delete mode 100644 felix/dataplane/decorator.go create mode 100644 felix/dataplane/multiplexer.go diff --git a/felix/dataplane/decorator.go b/felix/dataplane/decorator.go deleted file mode 100644 index e1f51795885..00000000000 --- a/felix/dataplane/decorator.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2025 NeuReality Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dataplane - -type dataplaneDriverDecorator struct { - primaryDriver DataplaneDriver - secondaryDriver DataplaneDriver -} - -func (decorator dataplaneDriverDecorator) SendMessage(msg interface{}) error { - decorator.secondaryDriver.SendMessage(msg) - return decorator.primaryDriver.SendMessage(msg) // return message from the primary driver only -} - -func (decorator dataplaneDriverDecorator) RecvMessage() (msg interface{}, err error) { - return decorator.primaryDriver.RecvMessage() // receive message from the primary driver only -} diff --git a/felix/dataplane/driver.go b/felix/dataplane/driver.go index 2c3c74bdf8e..0aaff3309ff 100644 --- a/felix/dataplane/driver.go +++ b/felix/dataplane/driver.go @@ -439,7 +439,7 @@ func StartDataplaneDriver( } if primaryDataplaneDriver != nil && secondaryDataplaneDriver != nil { - return dataplaneDriverDecorator{primaryDriver: primaryDataplaneDriver, secondaryDriver: secondaryDataplaneDriver}, secondaryCmd + return dataplaneDriverMultiplexer{primaryDriver: primaryDataplaneDriver, secondaryDriver: secondaryDataplaneDriver}, secondaryCmd } return nil, nil diff --git a/felix/dataplane/multiplexer.go b/felix/dataplane/multiplexer.go new file mode 100644 index 00000000000..0f434c85a92 --- /dev/null +++ b/felix/dataplane/multiplexer.go @@ -0,0 +1,38 @@ +// Copyright (c) 2025 NeuReality Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package dataplane + +import "fmt" + +type dataplaneDriverMultiplexer struct { + primaryDriver DataplaneDriver + secondaryDriver DataplaneDriver +} + +func (multiplexer dataplaneDriverMultiplexer) SendMessage(msg interface{}) error { + secondaryErr := multiplexer.secondaryDriver.SendMessage(msg) + primaryError := multiplexer.primaryDriver.SendMessage(msg) + + if primaryError != nil || secondaryErr != nil { + fmt.Errorf("errors in sending message to drivers: primary driver error %w, secondary driver error %w", + primaryError, secondaryErr) + } + + return nil +} + +func (multiplexer dataplaneDriverMultiplexer) RecvMessage() (msg interface{}, err error) { + return multiplexer.primaryDriver.RecvMessage() // receive message from the primary driver only +} From d3857497479eb9b253396af11986ec63a2189478 Mon Sep 17 00:00:00 2001 From: Vadim Eisenberg Date: Wed, 22 Jan 2025 15:00:06 +0200 Subject: [PATCH 4/4] rename primaryError to primaryErr --- felix/dataplane/multiplexer.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/felix/dataplane/multiplexer.go b/felix/dataplane/multiplexer.go index 0f434c85a92..b9fa201829b 100644 --- a/felix/dataplane/multiplexer.go +++ b/felix/dataplane/multiplexer.go @@ -23,11 +23,11 @@ type dataplaneDriverMultiplexer struct { func (multiplexer dataplaneDriverMultiplexer) SendMessage(msg interface{}) error { secondaryErr := multiplexer.secondaryDriver.SendMessage(msg) - primaryError := multiplexer.primaryDriver.SendMessage(msg) + primaryErr := multiplexer.primaryDriver.SendMessage(msg) - if primaryError != nil || secondaryErr != nil { + if primaryErr != nil || secondaryErr != nil { fmt.Errorf("errors in sending message to drivers: primary driver error %w, secondary driver error %w", - primaryError, secondaryErr) + primaryErr, secondaryErr) } return nil