func getSupportingPasswdSlice() []string {
	return []string{
		"db_add_node", "db_add_subcluster", "db_remove_node",
		"db_remove_subcluster", "create_db", "restart_node", "start_db",
		"stop_db",
	}
}
GetSupportingPasswdSlice returns a list of admintools' tools
used inside the operator and for which the option --password pswd is supported
package cmds
import (
	"bytes"
	"context"
	"fmt"
	"io"
	"os"
	"strings"
	"github.com/go-logr/logr"
	corev1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/types"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/kubernetes/scheme"
	"k8s.io/client-go/rest"
	"k8s.io/client-go/tools/remotecommand"
)
type PodRunner interface {
	ExecInPod(ctx context.Context, podName types.NamespacedName, contName string, command ...string) (string, string, error)
	ExecVSQL(ctx context.Context, podName types.NamespacedName, contName string, command ...string) (string, string, error)
	ExecAdmintools(ctx context.Context, podName types.NamespacedName, contName string, command ...string) (string, string, error)
	CopyToPod(ctx context.Context, podName types.NamespacedName, contName string, sourceFile string,
		destFile string) (stdout, stderr string, err error)
}
type ClusterPodRunner struct {
	Log        logr.Logger
	Cfg        *rest.Config
	SUPassword string
}
func MakeClusterPodRunner(log logr.Logger, cfg *rest.Config, passwd string) *ClusterPodRunner {
	return &ClusterPodRunner{Log: log, Cfg: cfg, SUPassword: passwd}
}
func (c *ClusterPodRunner) logInfoCmd(podName types.NamespacedName, command ...string) {
	var sb strings.Builder
	for i := 0; i < len(command); i++ {
		switch command[i] {
		case "--password":
			sb.WriteString(command[i])
			sb.WriteString(" ")
			sb.WriteString("*******")
			i++
		default:
			sb.WriteString(command[i])
		}
		sb.WriteString(" ")
	}
	c.Log.Info("ExecInPod entry", "pod", podName, "command", sb.String())
}
func (c *ClusterPodRunner) ExecInPod(ctx context.Context, podName types.NamespacedName,
	contName string, command ...string) (stdout, stderr string, err error) {
	var (
		execOut bytes.Buffer
		execErr bytes.Buffer
	)
	err = c.postExec(podName, contName, command, &execOut, &execErr, nil)
	return execOut.String(), execErr.String(), err
}
func (c *ClusterPodRunner) CopyToPod(ctx context.Context, podName types.NamespacedName,
	contName string, sourceFile string, destFile string) (stdout, stderr string, err error) {
	var (
		execOut bytes.Buffer
		execErr bytes.Buffer
	)
	command := []string{"sh", "-c", fmt.Sprintf("cat > %s", destFile)}
	inFile, err := os.Open(sourceFile)
	if err != nil {
		return "", "", err
	}
	defer inFile.Close()
	err = c.postExec(podName, contName, command, &execOut, &execErr, inFile)
	return execOut.String(), execErr.String(), err
}
func (c *ClusterPodRunner) ExecVSQL(ctx context.Context, podName types.NamespacedName,
	contName string, command ...string) (stdout, stderr string, err error) {
	command = UpdateVsqlCmd(c.SUPassword, command...)
	return c.ExecInPod(ctx, podName, contName, command...)
}
func (c *ClusterPodRunner) ExecAdmintools(ctx context.Context, podName types.NamespacedName,
	contName string, command ...string) (stdout, stderr string, err error) {
	command = UpdateAdmintoolsCmd(c.SUPassword, command...)
	return c.ExecInPod(ctx, podName, contName, command...)
}
func UpdateVsqlCmd(passwd string, cmd ...string) []string {
	prefix := []string{"vsql"}
	if passwd != "" {
		prefix = []string{"vsql", "--password", passwd}
	}
	cmd = append(prefix, cmd...)
	return cmd
}
func UpdateAdmintoolsCmd(passwd string, cmd ...string) []string {
	prefix := []string{"/opt/vertica/bin/admintools"}
	cmd = append(prefix, cmd...)
	if passwd == "" {
		return cmd
	}
	supportingPasswdSlice := getSupportingPasswdSlice()
	for _, e := range supportingPasswdSlice {
		_, isPresent := Find(cmd, e)
		if isPresent {
			cmd = append(cmd, "--password", passwd)
			break
		}
	}
	return cmd
}
func Find(slice []string, option string) (int, bool) {
	for i, item := range slice {
		if item == option {
			return i, true
		}
	}
	return -1, false
}