Skip to content

Commit bc320cd

Browse files
committed
Make ovs-vswitchd service 'other_config' option configurable
Signed-off-by: Ivan Kolodiazhnyi <[email protected]>
1 parent 0a5260b commit bc320cd

18 files changed

+77
-32
lines changed

api/v1/sriovnetworknodestate_types.go

+3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ type System struct {
119119
// +kubebuilder:validation:Enum=shared;exclusive
120120
//RDMA subsystem. Allowed value "shared", "exclusive".
121121
RdmaMode string `json:"rdmaMode,omitempty"`
122+
// OVS config. It will be provided for ovs-vswitchd service as other_config option
123+
// +kubebuilder:default:= "hw-offload=true"
124+
OvsConfig string `json:"ovsConfig,omitempty"`
122125
}
123126

124127
// SriovNetworkNodeStateStatus defines the observed state of SriovNetworkNodeState

api/v1/sriovnetworkpoolconfig_types.go

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ type OvsHardwareOffloadConfig struct {
3434
// On OpenShift:
3535
// Name is the name of MachineConfigPool to be enabled with OVS hardware offload
3636
Name string `json:"name,omitempty"`
37+
// OVS config. It will be provided for ovs-vswitchd service as other_config option
38+
// +kubebuilder:default:= "hw-offload=true"
39+
OvsConfig string `json:"rdmaMode,omitempty"`
3740
}
3841

3942
// SriovNetworkPoolConfigStatus defines the observed state of SriovNetworkPoolConfig

bindata/manifests/switchdev-config/ovs-units/ovs-vswitchd.service.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ dropins:
33
- name: 10-hw-offload.conf
44
contents: |
55
[Service]
6-
ExecStartPre=/bin/ovs-vsctl --no-wait set Open_vSwitch . other_config:hw-offload=true
6+
ExecStartPre=/bin/ovs-vsctl --no-wait set Open_vSwitch . other_config:{{ .OvsConfig }}

config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodestates.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ spec:
176176
type: array
177177
system:
178178
properties:
179+
ovsConfig:
180+
default: hw-offload=true
181+
description: OVS config. It will be provided for ovs-vswitchd
182+
service as other_config option
183+
type: string
179184
rdmaMode:
180185
description: RDMA subsystem. Allowed value "shared", "exclusive".
181186
enum:
@@ -346,6 +351,11 @@ spec:
346351
type: string
347352
system:
348353
properties:
354+
ovsConfig:
355+
default: hw-offload=true
356+
description: OVS config. It will be provided for ovs-vswitchd
357+
service as other_config option
358+
type: string
349359
rdmaMode:
350360
description: RDMA subsystem. Allowed value "shared", "exclusive".
351361
enum:

config/crd/bases/sriovnetwork.openshift.io_sriovnetworkpoolconfigs.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ spec:
110110
On OpenShift:
111111
Name is the name of MachineConfigPool to be enabled with OVS hardware offload
112112
type: string
113+
rdmaMode:
114+
default: hw-offload=true
115+
description: OVS config. It will be provided for ovs-vswitchd
116+
service as other_config option
117+
type: string
113118
type: object
114119
rdmaMode:
115120
description: RDMA subsystem. Allowed value "shared", "exclusive".

controllers/sriovnetworknodepolicy_controller.go

+1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ func (r *SriovNetworkNodePolicyReconciler) syncAllSriovNetworkNodeStates(ctx con
305305
}
306306
if netPoolConfig != nil {
307307
ns.Spec.System.RdmaMode = netPoolConfig.Spec.RdmaMode
308+
ns.Spec.System.OvsConfig = netPoolConfig.Spec.OvsHardwareOffloadConfig.OvsConfig
308309
}
309310
j, _ := json.Marshal(ns)
310311
logger.V(2).Info("SriovNetworkNodeState CR", "content", j)

controllers/sriovnetworkpoolconfig_controller.go

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ func (r *SriovNetworkPoolConfigReconciler) syncOvsHardwareOffloadMachineConfigs(
159159
}
160160

161161
data := render.MakeRenderData()
162+
data.Data["OvsConfig"] = "hw-offload=true"
162163
mc, err := render.GenerateMachineConfig("bindata/manifests/switchdev-config", mcName, mcpName, true, &data)
163164
if err != nil {
164165
return err

deployment/sriov-network-operator-chart/crds/sriovnetwork.openshift.io_sriovnetworknodestates.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ spec:
176176
type: array
177177
system:
178178
properties:
179+
ovsConfig:
180+
default: hw-offload=true
181+
description: OVS config. It will be provided for ovs-vswitchd
182+
service as other_config option
183+
type: string
179184
rdmaMode:
180185
description: RDMA subsystem. Allowed value "shared", "exclusive".
181186
enum:
@@ -346,6 +351,11 @@ spec:
346351
type: string
347352
system:
348353
properties:
354+
ovsConfig:
355+
default: hw-offload=true
356+
description: OVS config. It will be provided for ovs-vswitchd
357+
service as other_config option
358+
type: string
349359
rdmaMode:
350360
description: RDMA subsystem. Allowed value "shared", "exclusive".
351361
enum:

deployment/sriov-network-operator-chart/crds/sriovnetwork.openshift.io_sriovnetworkpoolconfigs.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ spec:
110110
On OpenShift:
111111
Name is the name of MachineConfigPool to be enabled with OVS hardware offload
112112
type: string
113+
rdmaMode:
114+
default: hw-offload=true
115+
description: OVS config. It will be provided for ovs-vswitchd
116+
service as other_config option
117+
type: string
113118
type: object
114119
rdmaMode:
115120
description: RDMA subsystem. Allowed value "shared", "exclusive".

pkg/daemon/plugin.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ func loadPlugins(ns *sriovnetworkv1.SriovNetworkNodeState, helpers helper.HostHe
5252
loadedPlugins = loadedVendorPlugins
5353

5454
if vars.ClusterType != consts.ClusterTypeOpenshift {
55-
k8sPlugin, err := K8sPlugin(helpers)
56-
if err != nil {
57-
log.Log.Error(err, "loadPlugins(): failed to load the k8s plugin")
58-
return nil, err
59-
}
60-
55+
k8sPlugin := K8sPlugin(helpers)
6156
pluginName := k8sPlugin.Name()
6257
if !isPluginDisabled(pluginName, disabledPlugins) {
6358
loadedPlugins[pluginName] = k8sPlugin

pkg/daemon/plugin_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ var _ = Describe("config daemon plugin loading tests", func() {
5151

5252
// k8s plugin is ATM the only plugin which require mocking/faking, as its New method performs additional logic
5353
// other than simple plugin struct initialization
54-
K8sPlugin = func(_ helper.HostHelpersInterface) (plugin.VendorPlugin, error) {
55-
return &fakePlugin.FakePlugin{PluginName: "k8s"}, nil
54+
K8sPlugin = func(_ helper.HostHelpersInterface) plugin.VendorPlugin {
55+
return &fakePlugin.FakePlugin{PluginName: "k8s"}
5656
}
5757
})
5858

pkg/helper/mock/mock_helper.go

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/host/internal/service/service.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
1616
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/types"
17+
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/render"
1718
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils"
1819
)
1920

@@ -131,7 +132,7 @@ OUTER:
131132
}
132133

133134
// ReadServiceInjectionManifestFile reads service injection file
134-
func (s *service) ReadServiceInjectionManifestFile(path string) (*types.Service, error) {
135+
func (s *service) ReadServiceInjectionManifestFile(path, ovsConfig string) (*types.Service, error) {
135136
data, err := os.ReadFile(path)
136137
if err != nil {
137138
return nil, err
@@ -142,10 +143,18 @@ func (s *service) ReadServiceInjectionManifestFile(path string) (*types.Service,
142143
return nil, err
143144
}
144145

146+
d := render.MakeRenderData()
147+
d.Data["OvsConfig"] = ovsConfig
148+
149+
srv, err := render.RenderTemplate(serviceContent.Dropins[0].Contents, &d)
150+
if err != nil {
151+
return nil, err
152+
}
153+
145154
return &types.Service{
146155
Name: serviceContent.Name,
147156
Path: systemdDir + serviceContent.Name,
148-
Content: serviceContent.Dropins[0].Contents,
157+
Content: srv.String(),
149158
}, nil
150159
}
151160

pkg/host/mock/mock_host.go

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/host/types/interfaces.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ type ServiceInterface interface {
108108
// ReadServiceManifestFile reads the systemd manifest for a specific service
109109
ReadServiceManifestFile(path string) (*Service, error)
110110
// ReadServiceInjectionManifestFile reads the injection manifest file for the systemd service
111-
ReadServiceInjectionManifestFile(path string) (*Service, error)
111+
ReadServiceInjectionManifestFile(path, ovsConfig string) (*Service, error)
112112
// CompareServices returns true if serviceA needs update(doesn't contain all fields from service B)
113113
CompareServices(serviceA, serviceB *Service) (bool, error)
114114
// UpdateSystemService updates a system service on the host

pkg/plugins/k8s/k8s_plugin.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ const (
9393
)
9494

9595
// Initialize our plugin and set up initial values
96-
func NewK8sPlugin(helper helper.HostHelpersInterface) (plugins.VendorPlugin, error) {
96+
func NewK8sPlugin(helper helper.HostHelpersInterface) plugins.VendorPlugin {
9797
k8sPluging := &K8sPlugin{
9898
PluginName: PluginName,
9999
SpecVersion: "1.0",
100100
hostHelper: helper,
101101
updateTarget: &k8sUpdateTarget{},
102102
}
103103

104-
return k8sPluging, k8sPluging.readManifestFiles()
104+
return k8sPluging
105105
}
106106

107107
// Name returns the name of the plugin
@@ -117,6 +117,12 @@ func (p *K8sPlugin) Spec() string {
117117
// OnNodeStateChange Invoked when SriovNetworkNodeState CR is created or updated, return if need dain and/or reboot node
118118
func (p *K8sPlugin) OnNodeStateChange(new *sriovnetworkv1.SriovNetworkNodeState) (needDrain bool, needReboot bool, err error) {
119119
log.Log.Info("k8s plugin OnNodeStateChange()")
120+
err = p.readManifestFiles(new.Spec.System.OvsConfig)
121+
if err != nil {
122+
log.Log.Error(err, "k8s plugin OnNodeStateChange(): failed to read manifests")
123+
return
124+
}
125+
120126
needDrain = false
121127
needReboot = false
122128

@@ -171,8 +177,8 @@ func (p *K8sPlugin) Apply() error {
171177
return p.updateOVSService()
172178
}
173179

174-
func (p *K8sPlugin) readOpenVSwitchdManifest() error {
175-
openVSwitchService, err := p.hostHelper.ReadServiceInjectionManifestFile(ovsUnitFile)
180+
func (p *K8sPlugin) readOpenVSwitchdManifest(ovsConfig string) error {
181+
openVSwitchService, err := p.hostHelper.ReadServiceInjectionManifestFile(ovsUnitFile, ovsConfig)
176182
if err != nil {
177183
return err
178184
}
@@ -198,8 +204,8 @@ func (p *K8sPlugin) readSriovPostNetworkServiceManifest() error {
198204
return nil
199205
}
200206

201-
func (p *K8sPlugin) readManifestFiles() error {
202-
if err := p.readOpenVSwitchdManifest(); err != nil {
207+
func (p *K8sPlugin) readManifestFiles(ovsConfig string) error {
208+
if err := p.readOpenVSwitchdManifest(ovsConfig); err != nil {
203209
return err
204210
}
205211
if err := p.readSriovServiceManifest(); err != nil {

pkg/plugins/k8s/k8s_plugin_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ func (snm *serviceNameMatcher) String() string {
7070
var _ = Describe("K8s plugin", func() {
7171
var (
7272
k8sPlugin plugin.VendorPlugin
73-
err error
7473
testCtrl *gomock.Controller
7574
hostHelper *mock_helper.MockHostHelpersInterface
7675
)
@@ -91,10 +90,9 @@ var _ = Describe("K8s plugin", func() {
9190
for _, s := range []string{
9291
"bindata/manifests/switchdev-config/ovs-units/ovs-vswitchd.service.yaml",
9392
} {
94-
registerCall(hostHelper.EXPECT().ReadServiceInjectionManifestFile(s), realHostMgr.ReadServiceInjectionManifestFile)
93+
registerCall(hostHelper.EXPECT().ReadServiceInjectionManifestFile(s, ""), realHostMgr.ReadServiceInjectionManifestFile)
9594
}
96-
k8sPlugin, err = NewK8sPlugin(hostHelper)
97-
Expect(err).ToNot(HaveOccurred())
95+
k8sPlugin = NewK8sPlugin(hostHelper)
9896
})
9997

10098
AfterEach(func() {

pkg/render/render.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func RenderDir(manifestDir string, d *RenderData) ([]*unstructured.Unstructured,
7777
return out, nil
7878
}
7979

80+
// RenderTemplate renders provided template to string
8081
func RenderTemplate(template string, d *RenderData) (*bytes.Buffer, error) {
8182
return renderTemplate(template, d)
8283
}
@@ -117,7 +118,6 @@ func RenderFileTemplate(path string, d *RenderData) ([]*unstructured.Unstructure
117118
}
118119

119120
func renderTemplate(rawTemplate string, d *RenderData) (*bytes.Buffer, error) {
120-
121121
tmpl := template.New("template").Option("missingkey=error")
122122
if d.Funcs != nil {
123123
tmpl.Funcs(d.Funcs)
@@ -140,7 +140,6 @@ func renderTemplate(rawTemplate string, d *RenderData) (*bytes.Buffer, error) {
140140
}
141141

142142
func renderFileTemplate(path string, d *RenderData) (*bytes.Buffer, error) {
143-
144143
source, err := os.ReadFile(path)
145144
if err != nil {
146145
return nil, errors.Wrapf(err, "failed to read manifest %s", path)

0 commit comments

Comments
 (0)