-
Notifications
You must be signed in to change notification settings - Fork 128
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.
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 { | ||
| // 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.Deserialize(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.
please add unit-test for this
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.
done