executor

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2022 License: Apache-2.0 Imports: 23 Imported by: 1

Documentation

Overview

Package executor manages objects within k8s that implement virtual clusters.

For the most part, the exported functions in this package will create, update, or delete individual native k8s objects that make up parts of the virtual cluster. The exceptions are in guest.go, where the exported functions handle operations within a cluster member's OS.

Index

Constants

View Source
const (
	// ClusterAppLabel is a label placed on every created statefulset, pod,
	// and service, with a value of the KubeDirectorApp CR name.
	ClusterAppLabel = shared.KdDomainBase + "/kdapp"
	// ClusterAppCatalogLabel is a label placed on every created statefulset,
	// pod, and service, with a value "local" or "system" appropriately.
	ClusterAppCatalogLabel = shared.KdDomainBase + "/appCatalog"
	// ClusterRoleLabel is a label placed on every created pod, and
	// (non-headless) service, with a value of the relevant role ID.
	ClusterRoleLabel = shared.KdDomainBase + "/role"
	// HeadlessServiceLabel is a label placed on the statefulset and pods.
	// Used in a selector on the headless service.
	HeadlessServiceLabel = shared.KdDomainBase + "/headless"

	// ClusterAppAnnotation is an annotation placed on every created
	// statefulset, pod, and service, with a value of the KubeDirectorApp's
	// spec.label.name.
	ClusterAppAnnotation = shared.KdDomainBase + "/kdapp-prettyName"

	// AppContainerName is the name of KubeDirector app containers.
	AppContainerName = "app"
	// PvcNamePrefix (along with a hyphen) is prepended to the name of each
	// member PVC name that is auto-created for a statefulset.
	PvcNamePrefix = "p"

	// ProjectedVolNamePrefix is the prefix used for volume names/mounts for project volumes for a role
	ProjectedVolNamePrefix = "projected-vol-"
)

Variables

This section is empty.

Functions

func BackupAnnotationNeedsReconcile added in v0.7.0

func BackupAnnotationNeedsReconcile(
	reqLogger logr.Logger,
	cr *kdv1.KubeDirectorCluster,
	statusBackupShouldExist bool,
) bool

BackupAnnotationNeedsReconcile checks that the annotation exists and has the correct value in the in-memory CR.

func CreateDir

func CreateDir(
	reqLogger logr.Logger,
	obj runtime.Object,
	namespace string,
	podName string,
	expectedContainerID string,
	containerName string,
	dirName string,
	setPerms bool,
) error

CreateDir creates a directory (and any parent directories) as necessary in the filesystem of the given pod. If the setPerms option is true, the directory will have its permissions set to 700.

func CreateFile

func CreateFile(
	reqLogger logr.Logger,
	obj runtime.Object,
	namespace string,
	podName string,
	expectedContainerID string,
	containerName string,
	filePath string,
	reader io.Reader,
	setDirPerms bool,
) error

CreateFile takes the stream from the given reader, and writes it to the indicated filepath in the filesystem of the given pod. Parent directories will be created as needed. If the setDirPerms option is true, the directory containing the file will have its permissions set to 700.

func CreateHeadlessService

func CreateHeadlessService(
	cr *kdv1.KubeDirectorCluster,
) (*corev1.Service, error)

CreateHeadlessService creates in k8s the "cluster service" used for intra-cluster network communication and for defining the virtual cluster's DNS subdomain. Cluster service name is an important part of DNS identity, so if we had already used a name previously and are re-creating the service, re-use that same name instead of generating a new one.

func CreatePodService

func CreatePodService(
	cr *kdv1.KubeDirectorCluster,
	role *kdv1.Role,
	podName string,
) (*corev1.Service, error)

CreatePodService creates in k8s a service that exposes the designated service endpoints of a virtual cluster member. Depending on the app type definition, this will be either a NodePort service (default) or a LoadBalancer service. If there are no ports to configure for this service, no service object will be created and the function will return (nil, nil).

func CreateStatefulSet

func CreateStatefulSet(
	reqLogger logr.Logger,
	cr *kdv1.KubeDirectorCluster,
	nativeSystemdSupport bool,
	role *kdv1.Role,
	roleStatus *kdv1.RoleStatus,
) (*appsv1.StatefulSet, error)

CreateStatefulSet creates in k8s a zero-replicas statefulset for implementing the given role.

func DeletePVC

func DeletePVC(
	namespace string,
	pvcName string,
) error

DeletePVC deletes a persistent volume claim from k8s.

func DeletePodService

func DeletePodService(
	reqLogger logr.Logger,
	namespace string,
	serviceName string,
) error

DeletePodService deletes a per-member service from k8s.

func DeleteStatefulSet

func DeleteStatefulSet(
	namespace string,
	statefulSetName string,
) error

DeleteStatefulSet deletes a statefulset from k8s.

func ExecCommand added in v0.3.0

func ExecCommand(
	reqLogger logr.Logger,
	obj runtime.Object,
	namespace string,
	podName string,
	expectedContainerID string,
	containerName string,
	command []string,
	ioStreams *Streams,
) error

ExecCommand is a utility function for executing a command in a pod. It uses the given ioStreams to provide the command inputs and accept the command outputs.

func GenerateVolumeMounts added in v0.11.0

func GenerateVolumeMounts(
	cr *kdv1.KubeDirectorCluster,
	role *kdv1.Role,
	pvcNamePrefix string,
	nativeSystemdSupport bool,
	persistDirs []string,
) ([]v1.VolumeMount, []v1.Volume, error)

GenerateVolumeMounts generates all of an app container's volume and mount specs for persistent storage, tmpfs and systemctl support that are appropriate for members of the given role. For systemctl support, nativeSystemdSupport flag is examined along with the app requirement. Additionally generate volume mount spec if a role has requested for volume projections.

func IsFileExists

func IsFileExists(
	reqLogger logr.Logger,
	obj runtime.Object,
	namespace string,
	podName string,
	expectedContainerID string,
	containerName string,
	filePath string,
) (bool, error)

IsFileExists probes whether the given pod's filesystem contains something at the indicated filepath. The returned boolean will be true if the file was found. If false, the returned error will be nil if the file is known to be missing, or non-nil if the probe failed to execute.

func MungObjectName added in v0.5.2

func MungObjectName(
	name string,
) string

MungObjectName is a utility function that truncates the object names to be below nameLengthLimit threshold set for the CrNameRole naming scheme. The function also replaces '.' (dot) and '_' (underscore) characters with a '-' (dash).

func ReadFile added in v0.2.0

func ReadFile(
	reqLogger logr.Logger,
	obj runtime.Object,
	namespace string,
	podName string,
	expectedContainerID string,
	containerName string,
	filePath string,
	writer io.Writer,
) (bool, error)

ReadFile takes the stream from the given writer, and writes to it the contents of the indicated filepath in the filesystem of the given pod. The returned boolean and error are interpreted in the same way as for IsFileExists.

func RemoveDir added in v0.3.0

func RemoveDir(
	reqLogger logr.Logger,
	obj runtime.Object,
	namespace string,
	podName string,
	expectedContainerID string,
	containerName string,
	dirName string,
	ignoreNotEmpty bool,
) error

RemoveDir removes a directory.

func RunScript

func RunScript(
	reqLogger logr.Logger,
	obj runtime.Object,
	namespace string,
	podName string,
	expectedContainerID string,
	containerName string,
	description string,
	reader io.Reader,
) error

RunScript takes the stream from the given reader, and executes it as a shell script in the given pod.

func SetBackupAnnotation added in v0.7.0

func SetBackupAnnotation(
	reqLogger logr.Logger,
	cr *kdv1.KubeDirectorCluster,
	statusBackupShouldExist bool,
) error

SetBackupAnnotation sets the annotation to the desired value. If the CR in K8s is successfully updated, the annotations of the in-memory CR (passed to this function) will also be updated to match.

func UpdateClusterStatus added in v0.3.0

func UpdateClusterStatus(
	cr *kdv1.KubeDirectorCluster,
	statusBackupShouldExist bool,
	statusBackup *kdv1.KubeDirectorStatusBackup,
) error

UpdateClusterStatus propagates status changes back to k8s. Roles or members in the status that have been marked for deletion (by having certain fields set to emptystring) will be removed before the writeback.

func UpdateClusterStatusBackupOwner added in v0.7.0

func UpdateClusterStatusBackupOwner(
	reqLogger logr.Logger,
	cr *kdv1.KubeDirectorCluster,
	statusBackup *kdv1.KubeDirectorStatusBackup,
) error

UpdateClusterStatusBackupOwner handles reconciliation only of the owner ref.

func UpdateHeadlessService

func UpdateHeadlessService(
	reqLogger logr.Logger,
	cr *kdv1.KubeDirectorCluster,
	service *corev1.Service,
) error

UpdateHeadlessService examines the current cluster service in k8s and may take steps to reconcile it to the desired spec.

func UpdatePodService

func UpdatePodService(
	reqLogger logr.Logger,
	cr *kdv1.KubeDirectorCluster,
	role *kdv1.Role,
	podName string,
	service *corev1.Service,
) error

UpdatePodService examines a current per-member service in k8s and may take steps to reconcile it to the desired spec. TBD: Currently this function handles changes only for serviceType and ownerReferences, and is only called if the service is known to already exist. If port-changing is supported in the future, either this function or its caller must take care of possibly transitioning to and from the "no ports" state which will involve deleting or creating the service object rather than just modifying.

func UpdateService added in v0.3.0

func UpdateService(
	reqLogger logr.Logger,
	obj runtime.Object,
	service *corev1.Service,
) error

UpdateService updates a service

func UpdateStatefulSetNonReplicas

func UpdateStatefulSetNonReplicas(
	reqLogger logr.Logger,
	cr *kdv1.KubeDirectorCluster,
	role *kdv1.Role,
	statefulSet *appsv1.StatefulSet,
) error

UpdateStatefulSetNonReplicas examines a current statefulset in k8s and may take steps to reconcile it to the desired spec, for properties other than the replicas count.

func UpdateStatefulSetReplicas

func UpdateStatefulSetReplicas(
	reqLogger logr.Logger,
	cr *kdv1.KubeDirectorCluster,
	replicas int32,
	statefulSet *appsv1.StatefulSet,
) error

UpdateStatefulSetReplicas modifies an existing statefulset in k8s to have the given number of replicas.

func UpdateStorageInitProgress added in v0.11.0

func UpdateStorageInitProgress(
	reqLogger logr.Logger,
	cr *kdv1.KubeDirectorCluster,
	memberStatus *kdv1.MemberStatus,
	initContainerStatus corev1.ContainerStatus,
)

UpdateStorageInitProgress parses rsync output (if available) and sets the memberStatus.StateDetail.StorageInitProgress field

Types

type Streams added in v0.3.0

type Streams struct {
	In     io.Reader
	Out    io.Writer
	ErrOut io.Writer
}

Streams for stdin, stdout, stderr of executed commands

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL