Skip to content

Commit

Permalink
fix: --ssh-args quote parsing once more
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorres committed May 23, 2024
1 parent fd3069c commit c615a3b
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 31 deletions.
12 changes: 3 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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`.
Expand Down
5 changes: 4 additions & 1 deletion cmd/maintenance/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions cmd/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -58,8 +61,6 @@ func NewRestartCmd() *cobra.Command {
)
}

var err error

bothUnspecified := !restartOpts.Storage && !restartOpts.Tenant

if restartOpts.Storage || bothUnspecified {
Expand Down
7 changes: 4 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions pkg/client/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions pkg/maintenance/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions pkg/options/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
13 changes: 11 additions & 2 deletions pkg/rolling/restarters/common_ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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, " "))

Expand Down

0 comments on commit c615a3b

Please sign in to comment.