From 484fa2a705400a043af3b6935b54e6616c02c80f Mon Sep 17 00:00:00 2001 From: Roi Vazquez Date: Tue, 9 Jan 2024 14:47:30 +0100 Subject: [PATCH 1/2] Fix sudo option in shardedredisbackups --- pkg/redis/backup/s3upload.go | 6 +++--- pkg/ssh/remote_exec.go | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/pkg/redis/backup/s3upload.go b/pkg/redis/backup/s3upload.go index 75635f7d..cec91ec2 100644 --- a/pkg/redis/backup/s3upload.go +++ b/pkg/redis/backup/s3upload.go @@ -70,8 +70,8 @@ func (br *Runner) UploadBackup(ctx context.Context) error { Logger: logger, CmdTimeout: 0, Commands: []ssh.Runnable{ - ssh.NewCommand(fmt.Sprintf("mv %s %s/%s", br.RedisDBFile, path.Dir(br.RedisDBFile), br.BackupFile())), - ssh.NewCommand(fmt.Sprintf("gzip -1 %s/%s", path.Dir(br.RedisDBFile), br.BackupFile())), + ssh.NewCommand(fmt.Sprintf("mv %s %s/%s", br.RedisDBFile, path.Dir(br.RedisDBFile), br.BackupFile())).WithSudo(br.SSHSudo), + ssh.NewCommand(fmt.Sprintf("gzip -1 %s/%s", path.Dir(br.RedisDBFile), br.BackupFile())).WithSudo(br.SSHSudo), ssh.NewScript(fmt.Sprintf("%s=%s %s=%s %s=%s python -", operatorutils.AWSRegionEnvvar, br.AWSRegion, operatorutils.AWSAccessKeyEnvvar, br.AWSAccessKeyID, @@ -79,7 +79,7 @@ func (br *Runner) UploadBackup(ctx context.Context) error { uploadScript, br.AWSSecretAccessKey, ), - ssh.NewCommand(fmt.Sprintf("rm -f %s/%s*", path.Dir(br.RedisDBFile), br.BackupFileBaseName())), + ssh.NewCommand(fmt.Sprintf("rm -f %s/%s*", path.Dir(br.RedisDBFile), br.BackupFileBaseName())).WithSudo(br.SSHSudo), }, } diff --git a/pkg/ssh/remote_exec.go b/pkg/ssh/remote_exec.go index 93fafe93..4848f61e 100644 --- a/pkg/ssh/remote_exec.go +++ b/pkg/ssh/remote_exec.go @@ -62,11 +62,13 @@ func (re *RemoteExecutor) Run() error { type Runnable interface { Run(*ssh.Client) (string, error) Info() string + WithSudo(bool) Runnable } type Command struct { value string sensitive []string + sudo bool } var _ Runnable = &Command{} @@ -75,8 +77,20 @@ func NewCommand(value string, sensitive ...string) *Command { return &Command{value: value, sensitive: sensitive} } +func (c *Command) WithSudo(sudo bool) Runnable { + c.sudo = sudo + return c +} + +func (c *Command) resolveValue() string { + if c.sudo { + return "sudo " + c.value + } + return c.value +} + func (c *Command) Info() string { - return fmt.Sprintf("run command: %s", hideSensitive(c.value, c.sensitive...)) + return fmt.Sprintf("run command: %s", hideSensitive(c.resolveValue(), c.sensitive...)) } func (c *Command) Run(client *ssh.Client) (string, error) { @@ -87,7 +101,7 @@ func (c *Command) Run(client *ssh.Client) (string, error) { } defer session.Close() - output, err := session.CombinedOutput(c.value) + output, err := session.CombinedOutput(c.resolveValue()) if err != nil { return string(output), err } @@ -99,6 +113,7 @@ type Script struct { value []byte interpreter string sensitive []string + sudo bool } var _ Runnable = &Script{} @@ -111,13 +126,25 @@ func NewScript(interpreter string, script string, sensitive ...string) *Script { } } +func (s *Script) WithSudo(sudo bool) Runnable { + s.sudo = sudo + return s +} + func (s *Script) Info() string { return fmt.Sprintf("run script with: '%s' \n'%s'", - hideSensitive(s.interpreter, s.sensitive...), + hideSensitive(s.resolveInterpreter(), s.sensitive...), hideSensitive(string(s.value), s.sensitive...), ) } +func (s *Script) resolveInterpreter() string { + if s.sudo { + return "sudo " + s.interpreter + } + return s.interpreter +} + func (s *Script) Run(client *ssh.Client) (string, error) { // Create a session. It is one session per command. session, err := client.NewSession() @@ -140,7 +167,7 @@ func (s *Script) Run(client *ssh.Client) (string, error) { chRsp := make(chan response) go func() { - output, err := session.CombinedOutput(s.interpreter) + output, err := session.CombinedOutput(s.resolveInterpreter()) if err != nil { chRsp <- response{output: output, err: err} return From c909d17b95f4eb655650b9450e40e5f9d68e354d Mon Sep 17 00:00:00 2001 From: Roi Vazquez Date: Tue, 9 Jan 2024 15:10:17 +0100 Subject: [PATCH 2/2] Bump release --- Makefile | 2 +- bundle/manifests/saas-operator.clusterserviceversion.yaml | 8 ++++---- config/manager/kustomization.yaml | 2 +- pkg/version/version.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 1fb4afca..3590abe1 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ # To re-generate a bundle for another specific version without changing the standard setup, you can: # - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2) # - use environment variables to overwrite this value (e.g export VERSION=0.0.2) -VERSION ?= 0.21.0-alpha.19 +VERSION ?= 0.21.0-alpha.20 # CHANNELS define the bundle channels used in the bundle. # Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable") diff --git a/bundle/manifests/saas-operator.clusterserviceversion.yaml b/bundle/manifests/saas-operator.clusterserviceversion.yaml index 57223292..f46ef4ef 100644 --- a/bundle/manifests/saas-operator.clusterserviceversion.yaml +++ b/bundle/manifests/saas-operator.clusterserviceversion.yaml @@ -598,7 +598,7 @@ metadata: capabilities: Basic Install categories: Integration & Delivery containerImage: quay.io/3scale/saas-operator - createdAt: "2024-01-08T17:25:42Z" + createdAt: "2024-01-09T13:50:20Z" description: |- The 3scale SaaS Operator creates and maintains a SaaS-ready deployment of the Red Hat 3scale API Management on OpenShift. @@ -606,7 +606,7 @@ metadata: operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 repository: https://github.com/3scale-ops/saas-operator support: Red Hat - name: saas-operator.v0.21.0-alpha.19 + name: saas-operator.v0.21.0-alpha.20 namespace: placeholder spec: apiservicedefinitions: {} @@ -4484,7 +4484,7 @@ spec: valueFrom: fieldRef: fieldPath: metadata.annotations['olm.targetNamespaces'] - image: quay.io/3scale/saas-operator:v0.21.0-alpha.19 + image: quay.io/3scale/saas-operator:v0.21.0-alpha.20 livenessProbe: httpGet: path: /healthz @@ -5048,4 +5048,4 @@ spec: provider: name: Red Hat url: https://www.3scale.net/ - version: 0.21.0-alpha.19 + version: 0.21.0-alpha.20 diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 9655be3f..545e1db5 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -13,4 +13,4 @@ kind: Kustomization images: - name: controller newName: quay.io/3scale/saas-operator - newTag: v0.21.0-alpha.19 + newTag: v0.21.0-alpha.20 diff --git a/pkg/version/version.go b/pkg/version/version.go index cf64c4de..11b87fa7 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -1,7 +1,7 @@ package version const ( - version string = "v0.21.0-alpha.19" + version string = "v0.21.0-alpha.20" ) // Current returns the current marin3r operator version