Files
my-rook-config/pkg/util/exec/translate_exec.go
T
Rakshith R bde286ef49 osd: re-open encrypted disk during osd-prepare-job if closed
This commit implements this corner case during osd-prepare job.
```
The encrypted block is not opened, this is an extreme corner case
The OSD deployment has been removed manually AND the node rebooted
So we need to re-open the block to re-hydrate the OSDInfo.

Handling this case would mean, writing the encryption key on a
temporary file, then call luksOpen to open the encrypted block and
then call ceph-volume to list against the opened encrypted block.
We don't implement this, yet and return an error.
```
When underlying PVC for osd are CSI provisioned, the encrypted device
is closed when PVC is unmounted due to osd pod being deleted.
Therefore, this may occur more frequently and needs to be handled.
This commit implements the fix for the same.

Signed-off-by: Rakshith R <rar@redhat.com>
2022-11-30 18:54:23 +05:30

70 lines
3.1 KiB
Go

/*
Copyright 2016 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package exec
import (
"time"
)
// TranslateCommandExecutor is an exec.Executor that translates every command before executing it
// This is useful to run the commands in a job with `kubectl run ...` when running the operator outside
// of Kubernetes and need to run tools that require running inside the cluster.
type TranslateCommandExecutor struct {
// Executor is probably a exec.CommandExecutor that will run the translated commands
Executor Executor
// Translator translates every command before running it
Translator func(command string, arg ...string) (string, []string)
}
// ExecuteCommand starts a process and wait for its completion
func (e *TranslateCommandExecutor) ExecuteCommand(command string, arg ...string) error {
transCommand, transArgs := e.Translator(command, arg...)
return e.Executor.ExecuteCommand(transCommand, transArgs...)
}
// ExecuteCommandWithStdin starts a process, provides stdin and wait for its completion with timeout.
func (e *TranslateCommandExecutor) ExecuteCommandWithStdin(timeout time.Duration, command string, stdin *string, arg ...string) error {
transCommand, transArgs := e.Translator(command, arg...)
return e.Executor.ExecuteCommandWithStdin(timeout, transCommand, stdin, transArgs...)
}
// ExecuteCommandWithEnv starts a process with an env variable and wait for its completion
func (e *TranslateCommandExecutor) ExecuteCommandWithEnv(env []string, command string, arg ...string) error {
transCommand, transArgs := e.Translator(command, arg...)
return e.Executor.ExecuteCommandWithEnv(env, transCommand, transArgs...)
}
// ExecuteCommandWithOutput starts a process and wait for its completion
func (e *TranslateCommandExecutor) ExecuteCommandWithOutput(command string, arg ...string) (string, error) {
transCommand, transArgs := e.Translator(command, arg...)
return e.Executor.ExecuteCommandWithOutput(transCommand, transArgs...)
}
// ExecuteCommandWithCombinedOutput starts a process and returns its stdout and stderr combined.
func (e *TranslateCommandExecutor) ExecuteCommandWithCombinedOutput(command string, arg ...string) (string, error) {
transCommand, transArgs := e.Translator(command, arg...)
return e.Executor.ExecuteCommandWithCombinedOutput(transCommand, transArgs...)
}
// ExecuteCommandWithTimeout starts a process and wait for its completion with timeout.
func (e *TranslateCommandExecutor) ExecuteCommandWithTimeout(timeout time.Duration, command string, arg ...string) (string, error) {
transCommand, transArgs := e.Translator(command, arg...)
return e.Executor.ExecuteCommandWithTimeout(timeout, transCommand, transArgs...)
}