func RocksdbEncryptionReadOnlyVolumeMount() core.VolumeMount {
	return core.VolumeMount{
		Name:      RocksdbEncryptionVolumeName,
		MountPath: RocksDBEncryptionVolumeMountDir,
		ReadOnly:  true,
	}
}
RocksdbEncryptionReadOnlyVolumeMount creates a volume mount structure for a RocksDB encryption key.
package k8sutil
import (
	"context"
	"fmt"
	"path/filepath"
	"strings"
	"time"
	"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod"
	"github.com/arangodb/kube-arangodb/pkg/util"
	"github.com/arangodb/kube-arangodb/pkg/util/errors"
	"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces"
	"k8s.io/apimachinery/pkg/types"
	"k8s.io/apimachinery/pkg/util/json"
	"k8s.io/apimachinery/pkg/api/resource"
	core "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
	ServerContainerName             = "server"
	ExporterContainerName           = "exporter"
	ArangodVolumeName               = "arangod-data"
	TlsKeyfileVolumeName            = "tls-keyfile"
	ClientAuthCAVolumeName          = "client-auth-ca"
	ClusterJWTSecretVolumeName      = "cluster-jwt"
	MasterJWTSecretVolumeName       = "master-jwt"
	LifecycleVolumeName             = "lifecycle"
	FoxxAppEphemeralVolumeName      = "ephemeral-apps"
	TMPEphemeralVolumeName          = "ephemeral-tmp"
	RocksdbEncryptionVolumeName     = "rocksdb-encryption"
	ExporterJWTVolumeName           = "exporter-jwt"
	ArangodVolumeMountDir           = "/data"
	RocksDBEncryptionVolumeMountDir = "/secrets/rocksdb/encryption"
	TLSKeyfileVolumeMountDir        = "/secrets/tls"
	TLSSNIKeyfileVolumeMountDir     = "/secrets/sni"
	ClientAuthCAVolumeMountDir      = "/secrets/client-auth/ca"
	ClusterJWTSecretVolumeMountDir  = "/secrets/cluster/jwt"
	ExporterJWTVolumeMountDir       = "/secrets/exporter/jwt"
	MasterJWTSecretVolumeMountDir   = "/secrets/master/jwt"
	ServerContainerConditionContainersNotReady = "ContainersNotReady"
	ServerContainerConditionPrefix             = "containers with unready status: "
)
func GetAnyVolumeByName(volumes []core.Volume, name string) (core.Volume, bool) {
	for _, c := range volumes {
		if c.Name == name {
			return c, true
		}
	}
	return core.Volume{}, false
}
func GetAnyVolumeMountByName(volumes []core.VolumeMount, name string) (core.VolumeMount, bool) {
	for _, c := range volumes {
		if c.Name == name {
			return c, true
		}
	}
	return core.VolumeMount{}, false
}
func IsPodReady(pod *core.Pod) bool {
	condition := getPodCondition(&pod.Status, core.PodReady)
	return condition != nil && condition.Status == core.ConditionTrue
}
func IsContainerReady(pod *core.Pod, container string) bool {
	condition := getPodCondition(&pod.Status, core.PodReady)
	if condition == nil {
		return false
	}
	if condition.Status == core.ConditionTrue {
		return true
	}
	if !IsContainerRunning(pod, container) {
		return false
	}
	switch condition.Reason {
	case ServerContainerConditionContainersNotReady:
		if strings.HasPrefix(condition.Message, ServerContainerConditionPrefix) {
			n := strings.TrimPrefix(condition.Message, ServerContainerConditionPrefix)
			return !strings.Contains(n, container)
		}
		return false
	default:
		return false
	}
}
func GetPodByName(pods []core.Pod, podName string) (core.Pod, bool) {
	for _, pod := range pods {
		if pod.GetName() == podName {
			return pod, true
		}
	}
	return core.Pod{}, false
}
func IsPodServerContainerRunning(pod *core.Pod) bool {
	return IsContainerRunning(pod, ServerContainerName)
}
func IsContainerRunning(pod *core.Pod, name string) bool {
	for _, c := range pod.Status.ContainerStatuses {
		if c.Name != name {
			continue
		}
		if c.State.Terminated != nil {
			return false
		} else {
			return true
		}
	}
	return false
}
func IsPodSucceeded(pod *core.Pod) bool {
	if pod.Status.Phase == core.PodSucceeded {
		return true
	} else {
		for _, c := range pod.Status.ContainerStatuses {
			if c.Name != ServerContainerName {
				continue
			}
			t := c.State.Terminated
			if t != nil {
				return t.ExitCode == 0
			}
		}
		return false
	}
}
func IsPodFailed(pod *core.Pod) bool {
	if pod.Status.Phase == core.PodFailed {
		return true
	} else {
		for _, c := range pod.Status.ContainerStatuses {
			if c.Name != ServerContainerName {
				continue
			}
			t := c.State.Terminated
			if t != nil {
				return t.ExitCode != 0
			}
		}
		return false
	}
}
func IsContainerFailed(container *core.ContainerStatus) bool {
	if c := container.State.Terminated; c != nil {
		if c.ExitCode != 0 {
			return true
		}
	}
	return false
}
func IsPodScheduled(pod *core.Pod) bool {
	condition := getPodCondition(&pod.Status, core.PodScheduled)
	return condition != nil && condition.Status == core.ConditionTrue
}
func IsPodNotScheduledFor(pod *core.Pod, timeout time.Duration) bool {
	condition := getPodCondition(&pod.Status, core.PodScheduled)
	return condition != nil &&
		condition.Status == core.ConditionFalse &&
		condition.LastTransitionTime.Time.Add(timeout).Before(time.Now())
}
func IsPodMarkedForDeletion(pod *core.Pod) bool {
	return pod.DeletionTimestamp != nil
}
func IsPodTerminating(pod *core.Pod) bool {
	return IsPodMarkedForDeletion(pod) && pod.Status.Phase == core.PodRunning
}
func IsArangoDBImageIDAndVersionPod(p *core.Pod) bool {
	role, found := p.GetLabels()[LabelKeyRole]
	return found && role == ImageIDAndVersionRole
}
func getPodCondition(status *core.PodStatus, condType core.PodConditionType) *core.PodCondition {
	for i := range status.Conditions {
		if status.Conditions[i].Type == condType {
			return &status.Conditions[i]
		}
	}
	return nil
}
func CreatePodName(deploymentName, role, id, suffix string) string {
	if len(suffix) > 0 && suffix[0] != '-' {
		suffix = "-" + suffix
	}
	return CreatePodHostName(deploymentName, role, id) + suffix
}
func CreatePodHostName(deploymentName, role, id string) string {
	return deploymentName + "-" + role + "-" + stripArangodPrefix(id)
}
func CreateTLSKeyfileSecretName(deploymentName, role, id string) string {
	return AppendTLSKeyfileSecretPostfix(CreatePodName(deploymentName, role, id, ""))
}
func AppendTLSKeyfileSecretPostfix(name string) string {
	return fmt.Sprintf("%s-tls-keyfile", name)
}
func ArangodVolumeMount() core.VolumeMount {
	return core.VolumeMount{
		Name:      ArangodVolumeName,
		MountPath: ArangodVolumeMountDir,
	}
}
func TlsKeyfileVolumeMount() core.VolumeMount {
	return core.VolumeMount{
		Name:      TlsKeyfileVolumeName,
		MountPath: TLSKeyfileVolumeMountDir,
		ReadOnly:  true,
	}
}
func ClientAuthCACertificateVolumeMount() core.VolumeMount {
	return core.VolumeMount{
		Name:      ClientAuthCAVolumeName,
		MountPath: ClientAuthCAVolumeMountDir,
	}
}
func MasterJWTVolumeMount() core.VolumeMount {
	return core.VolumeMount{
		Name:      MasterJWTSecretVolumeName,
		MountPath: MasterJWTSecretVolumeMountDir,
	}
}
func ClusterJWTVolumeMount() core.VolumeMount {
	return core.VolumeMount{
		Name:      ClusterJWTSecretVolumeName,
		MountPath: ClusterJWTSecretVolumeMountDir,
	}
}
func ExporterJWTVolumeMount() core.VolumeMount {
	return core.VolumeMount{
		Name:      ExporterJWTVolumeName,
		MountPath: ExporterJWTVolumeMountDir,
		ReadOnly:  true,
	}
}
func RocksdbEncryptionVolumeMount() core.VolumeMount {
	return core.VolumeMount{
		Name:      RocksdbEncryptionVolumeName,
		MountPath: RocksDBEncryptionVolumeMountDir,
	}
}