Documentation
¶
Overview ¶
Package controller implements the Kubernetes controllers for managing test framework operations
Index ¶
- Constants
- Variables
- func EnsureCloudsConfigMapExists(ctx context.Context, instance client.Object, helper *helper.Helper, ...) (ctrl.Result, error)
- func GetCommonRbacRules(privileged bool) []rbacv1.PolicyRule
- func GetCustomDataConfigMapName(instance *testv1beta1.Tempest, workflowStepNum int) string
- func GetEnvVarsConfigMapName(instance *testv1beta1.Tempest, workflowStepNum int) string
- func GetStringField(v reflect.Value, fieldName string) string
- func GetStringHash(str string, hashLength int) string
- func IsEmpty(value interface{}) bool
- func MergeSections(main interface{}, workflow interface{})
- func SafetyCheck(v reflect.Value, fieldName string) (reflect.Value, error)
- type AnsibleTestReconciler
- func (r *AnsibleTestReconciler) GetLogger(ctx context.Context) logr.Logger
- func (r *AnsibleTestReconciler) PrepareAnsibleEnv(instance *testv1beta1.AnsibleTest) map[string]env.Setter
- func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error)
- func (r *AnsibleTestReconciler) SetupWithManager(mgr ctrl.Manager) error
- type HorizonTestReconciler
- func (r *HorizonTestReconciler) GetLogger(ctx context.Context) logr.Logger
- func (r *HorizonTestReconciler) PrepareHorizonTestEnvVars(instance *testv1beta1.HorizonTest) map[string]env.Setter
- func (r *HorizonTestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error)
- func (r *HorizonTestReconciler) SetupWithManager(mgr ctrl.Manager) error
- type NextAction
- type Reconciler
- func (r *Reconciler) AcquireLock(ctx context.Context, instance client.Object, h *helper.Helper, parallel bool) (bool, error)
- func (r *Reconciler) CheckSecretExists(ctx context.Context, instance client.Object, secretName string) bool
- func (r *Reconciler) CreatePod(ctx context.Context, h helper.Helper, podSpec *corev1.Pod) (ctrl.Result, error)
- func (r *Reconciler) EnsureLogsPVCExists(ctx context.Context, instance client.Object, helper *helper.Helper, ...) (ctrl.Result, error)
- func (r *Reconciler) EnsureNetworkAttachments(ctx context.Context, log logr.Logger, helper *helper.Helper, ...) (map[string]string, ctrl.Result, error)
- func (r *Reconciler) GetContainerImage(ctx context.Context, instance interface{}) (string, error)
- func (r *Reconciler) GetDefaultInt(variable int64, defaultValue ...string) string
- func (r *Reconciler) GetLastPod(ctx context.Context, instance client.Object) (*corev1.Pod, error)
- func (r *Reconciler) GetLockInfo(ctx context.Context, instance client.Object) (*corev1.ConfigMap, error)
- func (r *Reconciler) GetLogger() logr.Logger
- func (r *Reconciler) GetPVCLogsName(instance client.Object, workflowStepNum int) string
- func (r *Reconciler) GetPod(ctx context.Context, podName string, podNamespace string) (*corev1.Pod, error)
- func (r *Reconciler) GetPodName(instance interface{}, stepNum int) string
- func (r *Reconciler) GetScheme() *runtime.Scheme
- func (r *Reconciler) NextAction(ctx context.Context, instance client.Object, workflowLength int) (NextAction, int, error)
- func (r *Reconciler) PodExists(ctx context.Context, instance client.Object, workflowStepNum int) bool
- func (r *Reconciler) ReleaseLock(ctx context.Context, instance client.Object) (bool, error)
- func (r *Reconciler) VerifyNetworkAttachments(ctx context.Context, helper *helper.Helper, instance client.Object, ...) (ctrl.Result, error)
- type TempestReconciler
- type TobikoReconciler
- func (r *TobikoReconciler) GetLogger(ctx context.Context) logr.Logger
- func (r *TobikoReconciler) PrepareTobikoEnvVars(ctx context.Context, labels map[string]string, instance *testv1beta1.Tobiko, ...) map[string]env.Setter
- func (r *TobikoReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error)
- func (r *TobikoReconciler) SetupWithManager(mgr ctrl.Manager) error
Constants ¶
const ( // InfoWaitingOnPod is the info message when waiting for pod completion or lock release InfoWaitingOnPod = "Waiting on either pod to finish or release of the lock." // InfoTestingCompleted is the info message when all testing is completed InfoTestingCompleted = "Testing completed. All pods spawned by the test-operator finished." // InfoCreatingFirstPod is the info message when creating the first test pod InfoCreatingFirstPod = "Creating first test pod (workflow step %d)." // InfoCreatingNextPod is the info message when creating subsequent test pods InfoCreatingNextPod = "Creating next test pod (workflow step %d)." // InfoCanNotAcquireLock is the info message when lock acquisition fails InfoCanNotAcquireLock = "Can not acquire %s lock." // InfoCanNotReleaseLock is the info message when lock release fails InfoCanNotReleaseLock = "Can not release %s lock." )
const ( // Wait indicates that we should wait for the state of the OpenShift cluster // to change Wait = iota // CreateFirstPod indicates that the Reconcile loop should create the first pod // either specified in the .Spec section or in the .Spec.Workflow section. CreateFirstPod // CreateNextPod indicates that the Reconcile loop should create a next pod // specified in the .Spec.Workflow section (if .Spec.Workflow is defined) CreateNextPod // EndTesting indicates that all pods have already finished. The Reconcile // loop should end the testing and release resources that are required to // be release (e.g., global lock) EndTesting // Failure indicates that an unexpected error was encountered Failure )
const (
// ErrConfirmLockOwnership is the error message for lock ownership confirmation failures
ErrConfirmLockOwnership = "can not confirm ownership of %s lock"
)
const ( // RequeueAfterValue tells how much time should we wait before calling Reconcile // loop again. RequeueAfterValue = time.Second * 60 )
Variables ¶
var ( // ErrReceivedUnexpectedAction indicates that an unexpected action was received. ErrReceivedUnexpectedAction = errors.New("unexpected action received") // ErrFailedToDeleteLock indicates that the test-operator-lock could not be deleted. ErrFailedToDeleteLock = errors.New("failed to delete test-operator-lock") // ErrNetworkAttachmentsMismatch indicates that not all pods have interfaces with IPs as configured in NetworkAttachments. ErrNetworkAttachmentsMismatch = errors.New("not all pods have interfaces with ips as configured in NetworkAttachments") // ErrLockFieldMissing indicates that a required field is missing in the lock config map. ErrLockFieldMissing = errors.New("field is missing in the config map") // ErrFieldExpectedStruct indicates attempting to access a field on a non-struct type. ErrFieldExpectedStruct = errors.New("field cannot be accessed: expected struct") // ErrFieldNilPointer indicates attempting to dereference a nil pointer. ErrFieldNilPointer = errors.New("field cannot be accessed: nil pointer") // ErrFieldNotFound indicates a field name does not exist on the struct. ErrFieldNotFound = errors.New("field not found") )
Static error definitions for test operations
Functions ¶
func EnsureCloudsConfigMapExists ¶
func EnsureCloudsConfigMapExists( ctx context.Context, instance client.Object, helper *helper.Helper, labels map[string]string, ) (ctrl.Result, error)
EnsureCloudsConfigMapExists ensures that frameworks like Tobiko and Horizon have password values present in clouds.yaml. This code ensures that we set a default value of 12345678 when password value is missing in the clouds.yaml
func GetCommonRbacRules ¶
func GetCommonRbacRules(privileged bool) []rbacv1.PolicyRule
GetCommonRbacRules returns the common RBAC rules for test operations, with optional privileged permissions
func GetCustomDataConfigMapName ¶
func GetCustomDataConfigMapName(instance *testv1beta1.Tempest, workflowStepNum int) string
GetCustomDataConfigMapName returns the name of the custom data ConfigMap for the given workflow step
func GetEnvVarsConfigMapName ¶
func GetEnvVarsConfigMapName(instance *testv1beta1.Tempest, workflowStepNum int) string
GetEnvVarsConfigMapName returns the name of the environment variables ConfigMap for the given workflow step
func GetStringField ¶
GetStringField returns reflect string field safely
func GetStringHash ¶
GetStringHash returns a hash of the given string with the specified length
func IsEmpty ¶
func IsEmpty(value interface{}) bool
IsEmpty checks if the provided value is empty based on its type
func MergeSections ¶
func MergeSections(main interface{}, workflow interface{})
MergeSections iterates through all CR parameters and overrides them with non-empty values from the workflow section of the current step.
Types ¶
type AnsibleTestReconciler ¶
type AnsibleTestReconciler struct {
Reconciler
}
AnsibleTestReconciler reconciles an AnsibleTest object
func (*AnsibleTestReconciler) GetLogger ¶
func (r *AnsibleTestReconciler) GetLogger(ctx context.Context) logr.Logger
GetLogger returns a logger object with a prefix of "controller.name" and additional controller context fields
func (*AnsibleTestReconciler) PrepareAnsibleEnv ¶
func (r *AnsibleTestReconciler) PrepareAnsibleEnv( instance *testv1beta1.AnsibleTest, ) map[string]env.Setter
PrepareAnsibleEnv prepares environment variables for a single workflow step
func (*AnsibleTestReconciler) Reconcile ¶
func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error)
Reconcile - AnsibleTest
func (*AnsibleTestReconciler) SetupWithManager ¶
func (r *AnsibleTestReconciler) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager sets up the controller with the Manager.
type HorizonTestReconciler ¶
type HorizonTestReconciler struct {
Reconciler
}
HorizonTestReconciler reconciles a HorizonTest object
func (*HorizonTestReconciler) GetLogger ¶
func (r *HorizonTestReconciler) GetLogger(ctx context.Context) logr.Logger
GetLogger returns a logger object with a prefix of "controller.name" and additional controller context fields
func (*HorizonTestReconciler) PrepareHorizonTestEnvVars ¶
func (r *HorizonTestReconciler) PrepareHorizonTestEnvVars( instance *testv1beta1.HorizonTest, ) map[string]env.Setter
PrepareHorizonTestEnvVars prepares environment variables for HorizonTest execution
func (*HorizonTestReconciler) Reconcile ¶
func (r *HorizonTestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error)
Reconcile - HorizonTest
func (*HorizonTestReconciler) SetupWithManager ¶
func (r *HorizonTestReconciler) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager sets up the controller with the Manager.
type NextAction ¶
type NextAction int
NextAction holds an action that should be performed by the Reconcile loop.
type Reconciler ¶
type Reconciler struct {
Client client.Client
Kclient kubernetes.Interface
Log logr.Logger
Scheme *runtime.Scheme
}
Reconciler provides common functionality for all test framework reconcilers
func (*Reconciler) AcquireLock ¶
func (r *Reconciler) AcquireLock( ctx context.Context, instance client.Object, h *helper.Helper, parallel bool, ) (bool, error)
AcquireLock attempts to acquire a lock for the given instance to prevent concurrent operations
func (*Reconciler) CheckSecretExists ¶
func (r *Reconciler) CheckSecretExists(ctx context.Context, instance client.Object, secretName string) bool
CheckSecretExists checks if a secret with the given name exists in the same namespace as the instance
func (*Reconciler) CreatePod ¶
func (r *Reconciler) CreatePod( ctx context.Context, h helper.Helper, podSpec *corev1.Pod, ) (ctrl.Result, error)
CreatePod creates a pod based on a spec provided via PodSpec.
func (*Reconciler) EnsureLogsPVCExists ¶
func (r *Reconciler) EnsureLogsPVCExists( ctx context.Context, instance client.Object, helper *helper.Helper, labels map[string]string, StorageClassName string, workflowStepNum int, ) (ctrl.Result, error)
EnsureLogsPVCExists ensures that a PVC for logs exists for the given instance and workflow step
func (*Reconciler) EnsureNetworkAttachments ¶
func (r *Reconciler) EnsureNetworkAttachments( ctx context.Context, log logr.Logger, helper *helper.Helper, networkAttachments []string, namespace string, conditions *condition.Conditions, ) (map[string]string, ctrl.Result, error)
EnsureNetworkAttachments fetches NetworkAttachmentDefinitions and creates annotations
func (*Reconciler) GetContainerImage ¶
func (r *Reconciler) GetContainerImage( ctx context.Context, instance interface{}, ) (string, error)
GetContainerImage returns the container image to use for the given instance, either from the provided parameter or from configuration
func (*Reconciler) GetDefaultInt ¶
func (r *Reconciler) GetDefaultInt(variable int64, defaultValue ...string) string
GetDefaultInt returns the string representation of an integer value with optional default value
func (*Reconciler) GetLastPod ¶
func (r *Reconciler) GetLastPod( ctx context.Context, instance client.Object, ) (*corev1.Pod, error)
GetLastPod returns pod associated with an instance which has the highest value stored in the workflowStep label
func (*Reconciler) GetLockInfo ¶
func (r *Reconciler) GetLockInfo(ctx context.Context, instance client.Object) (*corev1.ConfigMap, error)
GetLockInfo retrieves the lock information ConfigMap for the given instance
func (*Reconciler) GetLogger ¶
func (r *Reconciler) GetLogger() logr.Logger
GetLogger returns the logger instance
func (*Reconciler) GetPVCLogsName ¶
func (r *Reconciler) GetPVCLogsName(instance client.Object, workflowStepNum int) string
GetPVCLogsName returns the name of the PVC for logs for the given instance and workflow step
func (*Reconciler) GetPod ¶
func (r *Reconciler) GetPod( ctx context.Context, podName string, podNamespace string, ) (*corev1.Pod, error)
GetPod returns pod that has a specific name (podName) in a given namespace (podNamespace).
func (*Reconciler) GetPodName ¶
func (r *Reconciler) GetPodName(instance interface{}, stepNum int) string
GetPodName returns the name of the pod for the given instance and workflow step
func (*Reconciler) GetScheme ¶
func (r *Reconciler) GetScheme() *runtime.Scheme
GetScheme returns the runtime scheme
func (*Reconciler) NextAction ¶
func (r *Reconciler) NextAction( ctx context.Context, instance client.Object, workflowLength int, ) (NextAction, int, error)
NextAction indicates what action needs to be performed by the Reconcile loop based on the current state of the OpenShift cluster.
func (*Reconciler) PodExists ¶
func (r *Reconciler) PodExists(ctx context.Context, instance client.Object, workflowStepNum int) bool
PodExists checks if a pod exists for the given instance and workflow step
func (*Reconciler) ReleaseLock ¶
ReleaseLock releases the lock for the given instance
func (*Reconciler) VerifyNetworkAttachments ¶
func (r *Reconciler) VerifyNetworkAttachments( ctx context.Context, helper *helper.Helper, instance client.Object, networkAttachments []string, serviceLabels map[string]string, nextWorkflowStep int, conditions *condition.Conditions, networkAttachmentStatus *map[string][]string, ) (ctrl.Result, error)
VerifyNetworkAttachments verifies network status on the pod and updates conditions
type TempestReconciler ¶
type TempestReconciler struct {
Reconciler
}
TempestReconciler reconciles a Tempest object
func (*TempestReconciler) GetLogger ¶
func (r *TempestReconciler) GetLogger(ctx context.Context) logr.Logger
GetLogger returns a logger object with a prefix of "controller.name" and additional controller context fields
func (*TempestReconciler) Reconcile ¶
func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error)
Reconcile - Tempest
func (*TempestReconciler) SetupWithManager ¶
func (r *TempestReconciler) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager sets up the controller with the Manager.
type TobikoReconciler ¶
type TobikoReconciler struct {
Reconciler
}
TobikoReconciler reconciles a Tobiko object
func (*TobikoReconciler) GetLogger ¶
func (r *TobikoReconciler) GetLogger(ctx context.Context) logr.Logger
GetLogger returns a logger object with a prefix of "controller.name" and additional controller context fields
func (*TobikoReconciler) PrepareTobikoEnvVars ¶
func (r *TobikoReconciler) PrepareTobikoEnvVars( ctx context.Context, labels map[string]string, instance *testv1beta1.Tobiko, helper *helper.Helper, workflowStepNum int, ) map[string]env.Setter
PrepareTobikoEnvVars prepares environment variables for a single workflow step
func (*TobikoReconciler) Reconcile ¶
func (r *TobikoReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error)
Reconcile - Tobiko
func (*TobikoReconciler) SetupWithManager ¶
func (r *TobikoReconciler) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager sets up the controller with the Manager.