From c615a3ba42e9cbf2b7c794d547b768ba593523e8 Mon Sep 17 00:00:00 2001 From: Jorres Tarasov Date: Thu, 23 May 2024 17:18:22 +0200 Subject: [PATCH] fix: --ssh-args quote parsing once more --- .golangci.yml | 12 +++--------- cmd/maintenance/host.go | 5 ++++- cmd/restart.go | 7 ++++--- cmd/run.go | 7 ++++--- pkg/client/factory.go | 7 ++++--- pkg/maintenance/host.go | 3 +++ pkg/options/restart.go | 10 ---------- pkg/rolling/restarters/common_ssh.go | 13 +++++++++++-- 8 files changed, 33 insertions(+), 31 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index a48c7d8..33005db 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,14 +16,6 @@ run: #build-tags: # - mytag - # which dirs to skip: they won't be analyzed; - # can use regexp here: generated.*, regexp is applied on full path; - # default value is empty list, but next dnirs are always skipped independently - # from this option's value: - # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ - # skip-dirs: - skip-dirs-use-default: false - # which files to skip: they will be analyzed, but issues from them # won't be reported. Default value is empty list, but there is # no need to include all autogenerated files, we confidently recognize @@ -36,7 +28,7 @@ run: # output configuration options output: # colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number" - format: colored-line-number + formats: colored-line-number # print lines of code with issue, default is true print-issued-lines: true @@ -299,6 +291,8 @@ issues: exclude: - "has been deprecated since Go 1.16" + exclude-dirs-use-default: false + # Independently from option `exclude` we use default exclude patterns, # it can be disabled by this option. To list all # excluded by default patterns execute `golangci-lint run --help`. diff --git a/cmd/maintenance/host.go b/cmd/maintenance/host.go index ba61726..ea88454 100644 --- a/cmd/maintenance/host.go +++ b/cmd/maintenance/host.go @@ -25,11 +25,14 @@ func NewHostCmd() *cobra.Command { maintenanceHostOpts, rootOpts, ), RunE: func(cmd *cobra.Command, args []string) error { - client.InitConnectionFactory( + err := client.InitConnectionFactory( *rootOpts, options.Logger, options.DefaultRetryCount, ) + if err != nil { + return err + } taskId, err := maintenance.RequestHost(maintenanceHostOpts) if err != nil { diff --git a/cmd/restart.go b/cmd/restart.go index 6c9bb7f..0729387 100644 --- a/cmd/restart.go +++ b/cmd/restart.go @@ -28,11 +28,14 @@ func NewRestartCmd() *cobra.Command { var storageRestarter restarters.Restarter var tenantRestarter restarters.Restarter - client.InitConnectionFactory( + err := client.InitConnectionFactory( *rootOpts, options.Logger, options.DefaultRetryCount, ) + if err != nil { + return err + } if restartOpts.KubeconfigPath != "" { storageRestarter = restarters.NewStorageK8sRestarter( @@ -58,8 +61,6 @@ func NewRestartCmd() *cobra.Command { ) } - var err error - bothUnspecified := !restartOpts.Storage && !restartOpts.Tenant if restartOpts.Storage || bothUnspecified { diff --git a/cmd/run.go b/cmd/run.go index cc5a88f..037d3e5 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -34,13 +34,14 @@ func NewRunCmd() *cobra.Command { restartOpts, rootOpts, restarter.Opts, ), RunE: func(cmd *cobra.Command, args []string) error { - client.InitConnectionFactory( + err := client.InitConnectionFactory( *rootOpts, options.Logger, options.DefaultRetryCount, ) - - var err error + if err != nil { + return err + } bothUnspecified := !restartOpts.Storage && !restartOpts.Tenant diff --git a/pkg/client/factory.go b/pkg/client/factory.go index 0e4a2fa..92e1027 100644 --- a/pkg/client/factory.go +++ b/pkg/client/factory.go @@ -48,7 +48,7 @@ func InitConnectionFactory( rootOpts options.RootOptions, logger *zap.SugaredLogger, retryNumber int, -) (*Factory, error) { +) error { once.Do(func() { factory = &Factory{ auth: rootOpts.Auth, @@ -67,10 +67,10 @@ func InitConnectionFactory( }) if initErr != nil { - return nil, initErr + return initErr } - return factory, nil + return nil } func (f *Factory) Connection() (*grpc.ClientConn, error) { @@ -140,6 +140,7 @@ func (f *Factory) makeCredentials() (credentials.TransportCredentials, error) { if f.grpc.CaFile != "" { b, err := os.ReadFile(f.grpc.CaFile) if err != nil { + return nil, fmt.Errorf("failed to read the ca file: %w", err) } if !systemPool.AppendCertsFromPEM(b) { return nil, fmt.Errorf("credentials: failed to append certificates") diff --git a/pkg/maintenance/host.go b/pkg/maintenance/host.go index 853378d..99604b9 100644 --- a/pkg/maintenance/host.go +++ b/pkg/maintenance/host.go @@ -39,6 +39,9 @@ func RequestHost(opts *options.MaintenanceHostOpts) (string, error) { taskUID := MaintenanceTaskPrefix + uuid.New().String() nodes, err := getNodesOnHost(cms, opts.HostFQDN) + if err != nil { + return "", err + } taskParams := client.MaintenanceTaskParams{ TaskUID: taskUID, diff --git a/pkg/options/restart.go b/pkg/options/restart.go index e6476db..a324744 100644 --- a/pkg/options/restart.go +++ b/pkg/options/restart.go @@ -214,16 +214,6 @@ func (o *RestartOptions) GetAvailabilityMode() Ydb_Maintenance.AvailabilityMode title := strings.ToUpper(fmt.Sprintf("availability_mode_%s", o.AvailabilityMode)) value := Ydb_Maintenance.AvailabilityMode_value[title] - fmt.Sprintf("selected av mode\n arg: %s\n value: %v\n", o.AvailabilityMode, value) - - fmt.Println(`reference: -AvailabilityMode_value = map[string]int32{ - "AVAILABILITY_MODE_UNSPECIFIED": 0, - "AVAILABILITY_MODE_STRONG": 1, - "AVAILABILITY_MODE_WEAK": 2, - "AVAILABILITY_MODE_FORCE": 3, -}`) - return Ydb_Maintenance.AvailabilityMode(value) } diff --git a/pkg/rolling/restarters/common_ssh.go b/pkg/rolling/restarters/common_ssh.go index 8f97a9f..34c04c2 100644 --- a/pkg/rolling/restarters/common_ssh.go +++ b/pkg/rolling/restarters/common_ssh.go @@ -43,7 +43,7 @@ func (r sshRestarter) restartNodeBySystemdUnit( r.logger.Debugf("Restarting %s systemd unit", unitName) remoteRestartCommand := fmt.Sprintf( - `(test -x /bin/systemctl && sudo systemctl restart %s)`, + `"(test -x /bin/systemctl && sudo systemctl restart %s)"`, unitName, ) @@ -60,7 +60,16 @@ func (r sshRestarter) restartNodeBySystemdUnit( return fmt.Errorf("supported ssh commands: ssh, pssh, nssh. Specified: %s", sshCommand) } - cmd := exec.Command(sshCommand, fullSSHArgs...) + bashPath, err := exec.LookPath("bash") + if err != nil { + return err + } + + cmd := exec.Command( + bashPath, + "-c", + sshCommand+" "+strings.Join(fullSSHArgs, " "), + ) r.logger.Debugf("Full ssh command: `%s %v`", sshCommand, strings.Join(fullSSHArgs, " "))