-
Notifications
You must be signed in to change notification settings - Fork 133
Make ovs-vswitchd service 'other_config' option configurable #823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,4 @@ dropins: | |
| - name: 10-hw-offload.conf | ||
| contents: | | ||
| [Service] | ||
| ExecStartPre=/bin/ovs-vsctl --no-wait set Open_vSwitch . other_config:hw-offload=true | ||
| ExecStartPre=/bin/ovs-vsctl -t 5 set Open_vSwitch . external_ids:sriov-operator-owned-keys='{{ .ExternalIds }}' && /bin/ovs-vsctl/ovs-vsctl -t 5 get Open_vSwitch . external_ids:sriov-operator-owned-keys | xargs /bin/ovs-vsctl --no-wait remove Open_vSwitch . other_config && /bin/ovs-vsctl --no-wait set Open_vSwitch . {{ .OtherOvsConfig }} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
To fix this, you should first get the old keys, then remove them, then set the new keys. A simple fix for the typo is provided, but the logic should be revisited for robustness. ExecStartPre=/bin/ovs-vsctl -t 5 set Open_vSwitch . external_ids:sriov-operator-owned-keys='{{ .ExternalIds }}' && /bin/ovs-vsctl -t 5 get Open_vSwitch . external_ids:sriov-operator-owned-keys | xargs /bin/ovs-vsctl --no-wait remove Open_vSwitch . other_config && /bin/ovs-vsctl --no-wait set Open_vSwitch . {{ .OtherOvsConfig }} |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,7 +212,7 @@ var _ = Describe("Daemon Controller", Ordered, func() { | |
| // k8s plugin for k8s cluster type | ||
| if vars.ClusterType == constants.ClusterTypeKubernetes { | ||
| hostHelper.EXPECT().ReadServiceManifestFile(gomock.Any()).Return(&hostTypes.Service{Name: "test"}, nil).AnyTimes() | ||
| hostHelper.EXPECT().ReadServiceInjectionManifestFile(gomock.Any()).Return(&hostTypes.Service{Name: "test"}, nil).AnyTimes() | ||
| hostHelper.EXPECT().ReadServiceInjectionManifestFile(gomock.Any(), gomock.Any()).Return(&hostTypes.Service{Name: "test"}, nil).AnyTimes() | ||
| } | ||
|
|
||
| platformMock.EXPECT().Init().Return(nil) | ||
|
|
@@ -253,6 +253,16 @@ var _ = Describe("Daemon Controller", Ordered, func() { | |
| }, waitTime, retryTime).Should(Succeed()) | ||
| }) | ||
|
|
||
| Context("Config Daemon generic flow", func() { | ||
| BeforeEach(func() { | ||
| // k8s plugin for k8s cluster type | ||
| if vars.ClusterType == constants.ClusterTypeKubernetes { | ||
| hostHelper.EXPECT().ReadServiceManifestFile(gomock.Any()).Return(&hostTypes.Service{Name: "test"}, nil).AnyTimes() | ||
| hostHelper.EXPECT().ReadServiceInjectionManifestFile(gomock.Any(), gomock.Any()).Return(&hostTypes.Service{Name: "test"}, nil).AnyTimes() | ||
| } | ||
| }) | ||
| }) | ||
|
Comment on lines
+256
to
+264
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| Context("Config Daemon generic flow", func() { | ||
| It("Should expose nodeState Status section", func(ctx context.Context) { | ||
| originalInterface := sriovnetworkv1.InterfaceExt{ | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ import ( | |
|
|
||
| "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts" | ||
| "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/types" | ||
| "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/render" | ||
| "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils" | ||
| ) | ||
|
|
||
|
|
@@ -105,6 +106,34 @@ func (s *service) EnableService(service *types.Service) error { | |
| return err | ||
| } | ||
|
|
||
| // ReloadService reloads a systemd unit files on the host | ||
| func (s *service) ReloadService() error { | ||
| // Change root dir | ||
| exit, err := s.utilsHelper.Chroot(consts.Chroot) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer exit() | ||
|
|
||
| // Restart the service | ||
| _, _, err = s.utilsHelper.RunCommand("systemctl", "daemon-reload") | ||
| return err | ||
| } | ||
|
|
||
| // RestartService restarts systemd service with systemctl restart | ||
| func (s *service) RestartService(service *types.Service) error { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add unit-test for this
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| // Change root dir | ||
| exit, err := s.utilsHelper.Chroot(consts.Chroot) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer exit() | ||
|
|
||
| // Restart the service | ||
| _, _, err = s.utilsHelper.RunCommand("systemctl", "restart", service.Name) | ||
| return err | ||
| } | ||
|
|
||
| // CompareServices returns true if serviceA needs update(doesn't contain all fields from service B) | ||
| func (s *service) CompareServices(serviceA, serviceB *types.Service) (bool, error) { | ||
| optsA, err := unit.DeserializeOptions(strings.NewReader(serviceA.Content)) | ||
|
|
@@ -130,8 +159,12 @@ OUTER: | |
| return false, nil | ||
| } | ||
|
|
||
| func (s *service) renderOtherOvsConfigOption(ovsConfig map[string]string) (string, string) { | ||
| return utils.RenderOtherOvsConfigOption(ovsConfig) | ||
| } | ||
|
|
||
| // ReadServiceInjectionManifestFile reads service injection file | ||
| func (s *service) ReadServiceInjectionManifestFile(path string) (*types.Service, error) { | ||
| func (s *service) ReadServiceInjectionManifestFile(path string, ovsConfig map[string]string) (*types.Service, error) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add unit-test for this functionality |
||
| data, err := os.ReadFile(path) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -142,10 +175,20 @@ func (s *service) ReadServiceInjectionManifestFile(path string) (*types.Service, | |
| return nil, err | ||
| } | ||
|
|
||
| d := render.MakeRenderData() | ||
| externalIds, otherOvsConfig := s.renderOtherOvsConfigOption(ovsConfig) | ||
| d.Data["ExternalIds"] = externalIds | ||
| d.Data["OtherOvsConfig"] = otherOvsConfig | ||
|
|
||
| srv, err := render.RenderTemplate(serviceContent.Dropins[0].Contents, &d) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &types.Service{ | ||
| Name: serviceContent.Name, | ||
| Path: systemdDir + serviceContent.Name, | ||
| Content: serviceContent.Dropins[0].Contents, | ||
| Content: srv.String(), | ||
| }, nil | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package service | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| "go.uber.org/zap/zapcore" | ||
| "sigs.k8s.io/controller-runtime/pkg/log" | ||
| "sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
| ) | ||
|
|
||
| func TestSystemd(t *testing.T) { | ||
| log.SetLogger(zap.New( | ||
| zap.WriteTo(GinkgoWriter), | ||
| zap.Level(zapcore.Level(-2)), | ||
| zap.UseDevMode(true))) | ||
| RegisterFailHandler(Fail) | ||
| RunSpecs(t, "Package Service Suite") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSON tag
otherConfigfor theOvsConfigfield is inconsistent. Insriovnetworknodestate_types.go, theOvsConfigfield uses theovsConfigJSON tag. For consistency across the API, it would be better to useovsConfighere as well.